MigrationCheckingState extends AbstractMigrationState { @Override public void refresh() { MigrationCluster holder = getHolder(); ClusterStepResult clusterStepResult = holder.stepStatus(ShardMigrationStep.CHECK); if(clusterStepResult.isStepFinish()){ if(clusterStepResult.isStepSuccess()){ logger.debug("[refresh][check success]{}", this); updateAndProcess(nextAfterSuccess()); }else { logger.debug("[refresh][check fail]{}", this); updateAndStop(nextAfterFail()); } } } MigrationCheckingState(MigrationCluster holder); @Override void doAction(); @Override void refresh();  }
@Test public void testCheckSuccess() { int shardSize = getShardSize(); when(migrationCluster.stepStatus(ShardMigrationStep.CHECK)).thenReturn(new ClusterStepResult(shardSize, shardSize, shardSize)); checkingState.getStateActionState().tryAction(); checkingState.refresh(); sleep(50); migrationCluster.getMigrationShards().forEach(migrationShard -> verify(migrationShard).doCheck()); verify(migrationCluster).updateStat(isA(MigrationMigratingState.class)); verify(migrationCluster).process(); }
@Test public void testCheckRollback() { int shardSize = getShardSize(); when(migrationCluster.stepStatus(ShardMigrationStep.CHECK)).thenReturn(new ClusterStepResult(shardSize, shardSize, shardSize/2)); checkingState.getStateActionState().tryAction(); checkingState.refresh(); sleep(50); migrationCluster.getMigrationShards().forEach(migrationShard -> verify(migrationShard).doCheck()); verify(migrationCluster, times(0)).updateStat(isA(MigrationMigratingState.class)); verify(migrationCluster, times(0)).process(); checkingState.getStateActionState().tryRollback(); verify(migrationCluster).updateStat(isA(MigrationAbortedState.class)); verify(migrationCluster).process(); }