use of com.ctrip.xpipe.redis.console.model.ClusterTbl in project x-pipe by ctripcorp.
the class ClusterServiceTest method testLoad.
@Test
public void testLoad() {
ClusterTbl target_result = new ClusterTbl().setId(1).setClusterName("cluster1").setClusterLastModifiedTime("1234567");
assertEquals(clusterService.find("cluster1").getId(), target_result.getId());
assertEquals(clusterService.find("cluster1").getClusterName(), target_result.getClusterName());
}
use of com.ctrip.xpipe.redis.console.model.ClusterTbl in project x-pipe by ctripcorp.
the class DefaultMigrationClusterTest method testCancelOnMigrating.
@Test
@DirtiesContext
public void testCancelOnMigrating() {
mockSuccessCheckCommand(migrationCommandBuilder, "cluster1", "shard1", dcB, dcB);
mockSuccessPrevPrimaryDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcA);
mockFailNewPrimaryDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcB, new Throwable("mocked new fail"));
mockSuccessOtherDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcB, dcA);
ClusterTbl originalCluster = clusterService.find(1);
Assert.assertEquals(ClusterStatus.Lock.toString(), originalCluster.getStatus());
Assert.assertEquals(1, originalCluster.getActivedcId());
Assert.assertEquals(1, migrationCluster.getMigrationCluster().getSourceDcId());
Assert.assertEquals(2, migrationCluster.getMigrationCluster().getDestinationDcId());
Assert.assertEquals("Initiated", migrationCluster.getStatus().toString());
Assert.assertEquals(ShardMigrationResultStatus.FAIL, migrationShard.getShardMigrationResult().getStatus());
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.CHECK));
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_PREVIOUS_PRIMARY_DC));
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_NEW_PRIMARY_DC));
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_OTHER_DC));
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE));
migrationCluster.process();
sleep(1000);
DcMeta DcAMeta = dcMetaService.getDcMeta(dcA);
DcMeta DcBMeta = dcMetaService.getDcMeta(dcB);
Assert.assertEquals(dcA, DcAMeta.findCluster("cluster1").getActiveDc());
Assert.assertEquals(dcB, DcBMeta.findCluster("cluster1").getActiveDc());
ClusterTbl currentCluster = clusterService.find(1);
Assert.assertEquals(ClusterStatus.Migrating.toString(), currentCluster.getStatus());
Assert.assertEquals(1, currentCluster.getActivedcId());
Assert.assertEquals(ShardMigrationResultStatus.FAIL, migrationShard.getShardMigrationResult().getStatus());
Assert.assertTrue(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.CHECK));
Assert.assertTrue(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_PREVIOUS_PRIMARY_DC));
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_NEW_PRIMARY_DC));
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_OTHER_DC));
Assert.assertNull(migrationShard.getShardMigrationResult().getSteps().get(ShardMigrationStep.MIGRATE_OTHER_DC));
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE));
migrationCluster.cancel();
DcAMeta = dcMetaService.getDcMeta(dcA);
DcBMeta = dcMetaService.getDcMeta(dcB);
Assert.assertEquals(dcA, DcAMeta.findCluster("cluster1").getActiveDc());
Assert.assertEquals(dcA, DcBMeta.findCluster("cluster1").getActiveDc());
}
use of com.ctrip.xpipe.redis.console.model.ClusterTbl in project x-pipe by ctripcorp.
the class DefaultMigrationClusterTest method testCancelOnChecking.
@Test
@DirtiesContext
public void testCancelOnChecking() {
mockFailCheckCommand(migrationCommandBuilder, "cluster1", "shard1", dcB, dcB);
mockSuccessPrevPrimaryDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcA);
mockSuccessNewPrimaryDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcB);
mockSuccessOtherDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcB, dcA);
ClusterTbl originalCluster = clusterService.find(1);
Assert.assertEquals(ClusterStatus.Lock.toString(), originalCluster.getStatus());
Assert.assertEquals(1, originalCluster.getActivedcId());
Assert.assertEquals(1, migrationCluster.getMigrationCluster().getSourceDcId());
Assert.assertEquals(2, migrationCluster.getMigrationCluster().getDestinationDcId());
Assert.assertEquals("Initiated", migrationCluster.getStatus().toString());
Assert.assertEquals(ShardMigrationResultStatus.FAIL, migrationShard.getShardMigrationResult().getStatus());
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.CHECK));
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_PREVIOUS_PRIMARY_DC));
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_NEW_PRIMARY_DC));
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_OTHER_DC));
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE));
Assert.assertNull(migrationShard.getShardMigrationResult().getSteps().get(ShardMigrationStep.CHECK));
migrationCluster.process();
sleep(1000);
ClusterTbl currentCluster = clusterService.find(1);
Assert.assertEquals(ClusterStatus.Lock.toString(), currentCluster.getStatus());
Assert.assertEquals(1, currentCluster.getActivedcId());
Assert.assertEquals(ShardMigrationResultStatus.FAIL, migrationShard.getShardMigrationResult().getStatus());
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.CHECK));
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_PREVIOUS_PRIMARY_DC));
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_NEW_PRIMARY_DC));
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_OTHER_DC));
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE));
Assert.assertFalse(migrationShard.getShardMigrationResult().getSteps().get(ShardMigrationStep.CHECK).equals(""));
migrationCluster.cancel();
ClusterTbl afterCacelledCluster = clusterService.find(1);
Assert.assertEquals(ClusterStatus.Normal.toString(), afterCacelledCluster.getStatus());
Assert.assertEquals(MigrationStatus.Aborted.toString(), migrationCluster.getStatus().toString());
Assert.assertEquals(ShardMigrationResultStatus.FAIL, migrationShard.getShardMigrationResult().getStatus());
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.CHECK));
MigrationClusterTbl migrationCluster = migrationService.findMigrationCluster(1, 1);
Assert.assertEquals(MigrationStatus.Aborted.toString(), migrationCluster.getStatus());
}
use of com.ctrip.xpipe.redis.console.model.ClusterTbl in project x-pipe by ctripcorp.
the class DefaultMigrationClusterTest method testCancelOnInitiated.
@Test
@DirtiesContext
public void testCancelOnInitiated() {
mockSuccessCheckCommand(migrationCommandBuilder, "cluster1", "shard1", dcB, dcB);
mockSuccessPrevPrimaryDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcA);
mockSuccessNewPrimaryDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcB);
mockSuccessOtherDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcB, dcA);
ClusterTbl originalCluster = clusterService.find(1);
Assert.assertEquals(ClusterStatus.Lock.toString(), originalCluster.getStatus());
Assert.assertEquals("Initiated", migrationCluster.getStatus().toString());
Assert.assertEquals(ShardMigrationResultStatus.FAIL, migrationShard.getShardMigrationResult().getStatus());
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.CHECK));
migrationCluster.cancel();
ClusterTbl afterCacelledCluster = clusterService.find(1);
Assert.assertEquals(ClusterStatus.Normal.toString(), afterCacelledCluster.getStatus());
Assert.assertEquals(MigrationStatus.Aborted.toString(), migrationCluster.getStatus().toString());
Assert.assertEquals(ShardMigrationResultStatus.FAIL, migrationShard.getShardMigrationResult().getStatus());
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.CHECK));
MigrationClusterTbl migrationCluster = migrationService.findMigrationCluster(1, 1);
Assert.assertEquals(MigrationStatus.Aborted.toString(), migrationCluster.getStatus());
}
use of com.ctrip.xpipe.redis.console.model.ClusterTbl in project x-pipe by ctripcorp.
the class MigrationStatTest method prepareData.
private void prepareData() {
mockedMigrationCluster = (new MigrationClusterTbl()).setId(1).setEventId(1).setClusterId(1).setDestinationDcId(2).setStatus(MigrationStatus.Initiated.toString());
ClusterTbl clusterTbl = new ClusterTbl().setId(1).setClusterName("test-cluster").setActivedcId(1).setStatus(ClusterStatus.Lock.toString());
when(mockedClusterService.find(1)).thenReturn(clusterTbl);
List<ShardTbl> shards = new LinkedList<>();
shards.add((new ShardTbl()).setId(1).setClusterId(1).setShardName("test-shard"));
when(mockedShardService.findAllByClusterName("test-cluster")).thenReturn(shards);
List<DcTbl> dcs = new LinkedList<>();
dcs.add((new DcTbl()).setId(1).setDcName("ADC"));
dcs.add((new DcTbl()).setId(2).setDcName("BDC"));
when(mockedDcService.findClusterRelatedDc("test-cluster")).thenReturn(dcs);
when(mockedClusterService.find(anyString())).thenReturn(clusterTbl);
when(mockedClusterService.find(anyInt())).thenReturn(clusterTbl);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
clusterTbl.setStatus(((ClusterStatus) invocation.getArguments()[1]).toString());
return null;
}
}).when(mockedClusterService).updateStatusById(anyInt(), any());
}
Aggregations