private synchronized static Cluster getCluster ( URI baseUrl , String [ ] personalities ) throws IOException { final Entry < URI , Set < String > > key = Maps . immutableEntry ( baseUrl , ( Set < String > ) ImmutableSet . copyOf ( personalities ) ) ; Cluster result = CLUSTERS . get ( key ) ; if ( result != null ) { return result ; } result = new Cluster ( EmbeddedPostgreSQL . start ( ) ) ; final DBI dbi = new DBI ( result . getPg ( ) . getTemplateDatabase ( ) ) ; final Migratory migratory = new Migratory ( new MigratoryConfig ( ) { } , dbi , dbi ) ; migratory . addLocator ( new DatabasePreparerLocator ( migratory , baseUrl ) ) ; final MigrationPlan plan = new MigrationPlan ( ) ; int priority = 100 ; for ( final String personality : personalities ) { plan . addMigration ( personality , Integer . MAX_VALUE , priority -- ) ; } migratory . dbMigrate ( plan ) ; result . start ( ) ; CLUSTERS . put ( key , result ) ; return result ; }
Each schema set has its own database cluster . The template1 database has the schema preloaded so that each test case need only create a new database and not re - invoke Migratory .