DefaultCheckMigrationCommandBuilder extends AbstractService implements CheckMigrationCommandBuilder { @Override public Command<RetMessage> checkCommand(CHECK_MIGRATION_SYSTEM_STEP step) { Pair<String, String> clusterShard = consoleConfig.getClusterShardForMigrationSysCheck(); String clusterName = clusterShard.getKey(), shardName = clusterShard.getValue(); switch (step) { case CHECK_DATA_BASE: return checkDatabaseRetryCommand(clusterName); case CHECK_OUTER_CLIENT: return new CheckOuterClientCommand(clusterName); case CHECK_METASERVER: Map<String, String> metaServers = fetchMetaServerConfig(); return new CheckMetaServerCommand(metaServers, clusterName, shardName); } return null; } DefaultCheckMigrationCommandBuilder(ScheduledExecutorService scheduled, DcService dcService, ClusterService clusterService,
                                               OuterClientService outerClientService, ConsoleConfig consoleConfig); @Override Command<RetMessage> checkCommand(CHECK_MIGRATION_SYSTEM_STEP step);  }
@Test public void testCheckCommand() { Assert.assertTrue(builder.checkCommand(CHECK_MIGRATION_SYSTEM_STEP.CHECK_OUTER_CLIENT) instanceof DefaultCheckMigrationCommandBuilder.CheckOuterClientCommand); Assert.assertTrue(builder.checkCommand(CHECK_MIGRATION_SYSTEM_STEP.CHECK_METASERVER) instanceof DefaultCheckMigrationCommandBuilder.CheckMetaServerCommand); }
@Test(expected = ExecutionException.class) public void testCheckDataBase() throws ExecutionException, InterruptedException { when(clusterService.find(clusterId)).thenReturn(null); builder.checkCommand(CHECK_MIGRATION_SYSTEM_STEP.CHECK_DATA_BASE).execute().get(); }
@Test public void testCheckDataBaseWithResponse() throws ExecutionException, InterruptedException { when(clusterService.find(clusterId)).thenReturn(new ClusterTbl().setClusterName(clusterId).setId(1)); RetMessage message = builder.checkCommand(CHECK_MIGRATION_SYSTEM_STEP.CHECK_DATA_BASE).execute().get(); Assert.assertEquals(RetMessage.SUCCESS_STATE, message.getState()); logger.info("{}", message); }
@Test public void testCheckOuterClient() throws Exception { OuterClientService.ClusterInfo outerCluster = new OuterClientService.ClusterInfo(); outerCluster.setName(clusterId); when(outerClientService.getClusterInfo(clusterId)).thenReturn(outerCluster); RetMessage message = builder.checkCommand(CHECK_MIGRATION_SYSTEM_STEP.CHECK_OUTER_CLIENT).execute().get(); Assert.assertEquals(RetMessage.SUCCESS_STATE, message.getState()); }
@Test public void testCheckMetaServer() throws Exception { server = startServer(54321, "test"); when(dcService.findClusterRelatedDc(clusterId)).thenReturn(Lists.newArrayList(new DcTbl().setDcName("localmeta"))); Command<RetMessage> command = builder.checkCommand(CHECK_MIGRATION_SYSTEM_STEP.CHECK_METASERVER); RetMessage message = command.execute().get(); logger.info(""); logger.info("{}", message.getMessage()); Assert.assertEquals(RetMessage.FAIL_STATE, message.getState()); }
@Test @Ignore public void testCheckMetaServerManually() throws Exception { String metaServers = "{\n" + " \"NTGXH\": \"http: " \"FAT\": \"http: " \"FAT-AWS\": \"http: "}"; when(consoleConfig.getMetaservers()).thenReturn(metaServers); when(consoleConfig.getClusterShardForMigrationSysCheck()).thenReturn(Pair.from("cluster_shyin", "shard1")); builder = new DefaultCheckMigrationCommandBuilder(scheduled, dcService, clusterService, outerClientService, consoleConfig); RetMessage message = builder.checkCommand(CHECK_MIGRATION_SYSTEM_STEP.CHECK_METASERVER).execute().get(); logger.info("{}", message); }