use of com.ctrip.xpipe.redis.core.entity.DcMeta in project x-pipe by ctripcorp.
the class RemoveUnusedRedisTest method beforeRemoveUnusedRedisTest.
@Before
public void beforeRemoveUnusedRedisTest() throws Exception {
MockitoAnnotations.initMocks(this);
// mock datas
XpipeMeta xpipeMeta = new XpipeMeta().addDc(new DcMeta());
when(metaCache.getXpipeMeta()).thenReturn(xpipeMeta);
manager.executors = Executors.newFixedThreadPool(OsUtils.getCpuCount());
manager.pingAndDelayExecutor = Executors.newFixedThreadPool(OsUtils.getCpuCount());
// random port to avoid port conflict
port = randomPort();
server = startServer(port, new Callable<String>() {
@Override
public String call() throws Exception {
return "+OK\r\n";
}
});
}
use of com.ctrip.xpipe.redis.core.entity.DcMeta in project x-pipe by ctripcorp.
the class DefaultMigrationClusterTest method testRollBackFailOnPartialSuccess.
@Test
@DirtiesContext
public void testRollBackFailOnPartialSuccess() {
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);
mockFailRollBackCommand(migrationCommandBuilder, "cluster1", "shard1", dcA);
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());
Assert.assertEquals(MigrationStatus.PartialSuccess, migrationCluster.getStatus());
migrationCluster.rollback();
sleep(1000);
DcAMeta = dcMetaService.getDcMeta(dcA);
DcBMeta = dcMetaService.getDcMeta(dcB);
Assert.assertEquals(dcA, DcAMeta.findCluster("cluster1").getActiveDc());
Assert.assertEquals(dcA, DcBMeta.findCluster("cluster1").getActiveDc());
Assert.assertEquals(MigrationStatus.RollBack, migrationCluster.getStatus());
ClusterTbl currentCluster = clusterService.find(1);
Assert.assertEquals(ClusterStatus.Rollback.toString(), currentCluster.getStatus());
Assert.assertEquals(1, currentCluster.getActivedcId());
}
use of com.ctrip.xpipe.redis.core.entity.DcMeta in project x-pipe by ctripcorp.
the class DefaultMigrationClusterTest method testForcePublishOnChecking.
@Test(expected = IllegalStateException.class)
@DirtiesContext
public void testForcePublishOnChecking() {
mockFailCheckCommand(migrationCommandBuilder, "cluster1", "shard1", dcB, dcB);
mockSuccessPrevPrimaryDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcA);
mockSuccessNewPrimaryDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcB);
mockSuccessOtherDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcB, dcA);
migrationCluster.process();
sleep(1000);
DcMeta DcAMeta = dcMetaService.getDcMeta(dcA);
DcMeta DcBMeta = dcMetaService.getDcMeta(dcB);
Assert.assertEquals(dcA, DcAMeta.findCluster("cluster1").getActiveDc());
Assert.assertEquals(dcA, DcBMeta.findCluster("cluster1").getActiveDc());
Assert.assertEquals(MigrationStatus.CheckingFail, migrationCluster.getStatus());
migrationCluster.forcePublish();
}
use of com.ctrip.xpipe.redis.core.entity.DcMeta in project x-pipe by ctripcorp.
the class DefaultMigrationClusterTest method testRollBackOnPartialSuccess.
@Test
@DirtiesContext
public void testRollBackOnPartialSuccess() {
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);
mockSuccessRollBackCommand(migrationCommandBuilder, "cluster1", "shard1", dcA);
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());
Assert.assertEquals(MigrationStatus.PartialSuccess, migrationCluster.getStatus());
migrationCluster.rollback();
sleep(1000);
DcAMeta = dcMetaService.getDcMeta(dcA);
DcBMeta = dcMetaService.getDcMeta(dcB);
Assert.assertEquals(dcA, DcAMeta.findCluster("cluster1").getActiveDc());
Assert.assertEquals(dcA, DcBMeta.findCluster("cluster1").getActiveDc());
Assert.assertEquals(MigrationStatus.Aborted, migrationCluster.getStatus());
ClusterTbl currentCluster = clusterService.find(1);
Assert.assertEquals(ClusterStatus.Normal.toString(), currentCluster.getStatus());
Assert.assertEquals(1, currentCluster.getActivedcId());
}
use of com.ctrip.xpipe.redis.core.entity.DcMeta in project x-pipe by ctripcorp.
the class DefaultMigrationClusterTest method testForcePublishOnPartialSuccess.
@Test
@DirtiesContext
public void testForcePublishOnPartialSuccess() {
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);
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());
Assert.assertEquals(MigrationStatus.PartialSuccess, migrationCluster.getStatus());
migrationCluster.forcePublish();
DcAMeta = dcMetaService.getDcMeta(dcA);
DcBMeta = dcMetaService.getDcMeta(dcB);
Assert.assertEquals(dcB, DcAMeta.findCluster("cluster1").getActiveDc());
Assert.assertEquals(dcB, DcBMeta.findCluster("cluster1").getActiveDc());
Assert.assertEquals(MigrationStatus.Success, migrationCluster.getStatus());
ClusterTbl currentCluster = clusterService.find(1);
Assert.assertEquals("Normal", currentCluster.getStatus());
Assert.assertEquals(2, currentCluster.getActivedcId());
}
Aggregations