Search in sources :

Example 6 with DcMeta

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";
        }
    });
}
Also used : XpipeMeta(com.ctrip.xpipe.redis.core.entity.XpipeMeta) DcMeta(com.ctrip.xpipe.redis.core.entity.DcMeta) Callable(java.util.concurrent.Callable) Before(org.junit.Before)

Example 7 with DcMeta

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());
}
Also used : ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl) MigrationClusterTbl(com.ctrip.xpipe.redis.console.model.MigrationClusterTbl) DcMeta(com.ctrip.xpipe.redis.core.entity.DcMeta) Test(org.junit.Test) AbstractMigrationTest(com.ctrip.xpipe.redis.console.migration.AbstractMigrationTest) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 8 with DcMeta

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();
}
Also used : DcMeta(com.ctrip.xpipe.redis.core.entity.DcMeta) Test(org.junit.Test) AbstractMigrationTest(com.ctrip.xpipe.redis.console.migration.AbstractMigrationTest) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 9 with DcMeta

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());
}
Also used : ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl) MigrationClusterTbl(com.ctrip.xpipe.redis.console.model.MigrationClusterTbl) DcMeta(com.ctrip.xpipe.redis.core.entity.DcMeta) Test(org.junit.Test) AbstractMigrationTest(com.ctrip.xpipe.redis.console.migration.AbstractMigrationTest) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 10 with DcMeta

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());
}
Also used : ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl) MigrationClusterTbl(com.ctrip.xpipe.redis.console.model.MigrationClusterTbl) DcMeta(com.ctrip.xpipe.redis.core.entity.DcMeta) Test(org.junit.Test) AbstractMigrationTest(com.ctrip.xpipe.redis.console.migration.AbstractMigrationTest) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Aggregations

DcMeta (com.ctrip.xpipe.redis.core.entity.DcMeta)31 Test (org.junit.Test)19 DirtiesContext (org.springframework.test.annotation.DirtiesContext)7 AbstractMigrationTest (com.ctrip.xpipe.redis.console.migration.AbstractMigrationTest)6 ClusterTbl (com.ctrip.xpipe.redis.console.model.ClusterTbl)5 ClusterMeta (com.ctrip.xpipe.redis.core.entity.ClusterMeta)5 XpipeMeta (com.ctrip.xpipe.redis.core.entity.XpipeMeta)5 AbstractMultiDcTest (com.ctrip.xpipe.redis.integratedtest.full.multidc.AbstractMultiDcTest)5 MigrationClusterTbl (com.ctrip.xpipe.redis.console.model.MigrationClusterTbl)4 AbstractRedisTest (com.ctrip.xpipe.redis.core.AbstractRedisTest)4 ShardMeta (com.ctrip.xpipe.redis.core.entity.ShardMeta)4 LinkedList (java.util.LinkedList)4 RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)3 HostPort (com.ctrip.xpipe.endpoint.HostPort)2 LeaderElectorManager (com.ctrip.xpipe.api.cluster.LeaderElectorManager)1 Codec (com.ctrip.xpipe.api.codec.Codec)1 JsonCodec (com.ctrip.xpipe.codec.JsonCodec)1 ParallelCommandChain (com.ctrip.xpipe.command.ParallelCommandChain)1 AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)1 ServerException (com.ctrip.xpipe.redis.console.exception.ServerException)1