MigraMongo { public MigraMongoStatus migrateAsync() { final MigraMongoStatus dryRunStatus = dryRun(); if (dryRunStatus.migrationsApplied.isEmpty()) { return dryRunStatus; } logger.debug("Migration will be performed asynchronously"); executorService.submit(() -> { logger.debug("Running migration in a separate thread"); if (asyncInitializerFuntion != null) { logger.debug("Executing async initializer function"); asyncInitializerFuntion.run(); logger.debug("Async initializer function executed"); } final MigraMongoStatus status = migrate(); logger.debug("Migration in a separate thread returned status {}", status); }); dryRunStatus.status = MigrationStatus.IN_PROGRESS; return dryRunStatus; } MigraMongo(
            MongoDatabase database,
            MigrationHistoryService migrationEntryService,
            LockService lockService,
            ScriptLookupService scriptLookupService); void setAsyncInitializerFunction(Runnable function); MigraMongoStatus dryRun(); MigraMongoStatus migrate(); MigraMongoStatus migrateAsync(); MigraMongoStatus status(String fromVersion); MigraMongoStatus repair(String fromVersion, String toVersion); MigraMongoStatus rerun(String fromVersion, String toVersion); List<MigrationEntry> getMigrationEntries(); void destroyLocks();  }
@Test public void shouldNotMigrateAsynchWhenThereIsNothingToMigrate() throws Exception { mockLastMigrationApplied("1", "2"); final MigraMongoStatus status = migraMongo.migrateAsync(); assertThat(status.status, is(MigrationStatus.OK)); assertThat(status.migrationsApplied, hasSize(0)); }