Search in sources :

Example 11 with ClusterMeta

use of com.ctrip.xpipe.redis.core.entity.ClusterMeta in project x-pipe by ctripcorp.

the class SingleShardMigrationTest method testMigrateOtherDcFail.

@Test
@DirtiesContext
public void testMigrateOtherDcFail() {
    mockSuccessCheckCommand(migrationCommandBuilder, "cluster1", "shard1", dcB, dcB);
    mockSuccessPrevPrimaryDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcA);
    mockSuccessNewPrimaryDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcB);
    mockFailOtherDcCommand(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);
    ClusterTbl currentCluster = clusterService.find(1);
    Assert.assertEquals(ClusterStatus.Normal.toString(), currentCluster.getStatus());
    Assert.assertEquals(2, currentCluster.getActivedcId());
    Assert.assertEquals(ShardMigrationResultStatus.SUCCESS, migrationShard.getShardMigrationResult().getStatus());
    Assert.assertTrue(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.CHECK));
    Assert.assertTrue(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_PREVIOUS_PRIMARY_DC));
    Assert.assertTrue(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_NEW_PRIMARY_DC));
    Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_OTHER_DC));
    Assert.assertTrue(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE));
    ClusterMeta prevPrimaryDcMeta = clusterMetaService.getClusterMeta(dcA, "cluster1");
    Assert.assertEquals(dcB, prevPrimaryDcMeta.getActiveDc());
    ClusterMeta newPrimaryDcMeta = clusterMetaService.getClusterMeta(dcB, "cluster1");
    Assert.assertEquals(dcB, newPrimaryDcMeta.getActiveDc());
}
Also used : ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl) MigrationClusterTbl(com.ctrip.xpipe.redis.console.model.MigrationClusterTbl) ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 12 with ClusterMeta

use of com.ctrip.xpipe.redis.core.entity.ClusterMeta in project x-pipe by ctripcorp.

the class SingleShardMigrationTest method testMigrateOtherDcExceptionFail.

@Test
@DirtiesContext
public void testMigrateOtherDcExceptionFail() {
    mockSuccessCheckCommand(migrationCommandBuilder, "cluster1", "shard1", dcB, dcB);
    mockSuccessPrevPrimaryDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcA);
    mockSuccessNewPrimaryDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcB);
    mockFailOtherDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcB, dcA, new Throwable("mocked other fail"));
    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);
    ClusterTbl currentCluster = clusterService.find(1);
    Assert.assertEquals(ClusterStatus.Normal.toString(), currentCluster.getStatus());
    Assert.assertEquals(2, currentCluster.getActivedcId());
    Assert.assertEquals(ShardMigrationResultStatus.SUCCESS, migrationShard.getShardMigrationResult().getStatus());
    Assert.assertTrue(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.CHECK));
    Assert.assertTrue(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_PREVIOUS_PRIMARY_DC));
    Assert.assertTrue(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_NEW_PRIMARY_DC));
    Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_OTHER_DC));
    Assert.assertTrue(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE));
    ClusterMeta prevPrimaryDcMeta = clusterMetaService.getClusterMeta(dcA, "cluster1");
    Assert.assertEquals(dcB, prevPrimaryDcMeta.getActiveDc());
    ClusterMeta newPrimaryDcMeta = clusterMetaService.getClusterMeta(dcB, "cluster1");
    Assert.assertEquals(dcB, newPrimaryDcMeta.getActiveDc());
}
Also used : ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl) MigrationClusterTbl(com.ctrip.xpipe.redis.console.model.MigrationClusterTbl) ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 13 with ClusterMeta

use of com.ctrip.xpipe.redis.core.entity.ClusterMeta in project x-pipe by ctripcorp.

the class EncodeTest method testEncode.

@Test
public void testEncode() {
    ClusterMeta clusterMeta = new ClusterMeta();
    // clusterMeta.addShard();
    clusterMeta.addShard(new ShardMeta());
    JsonCodec.INSTANCE.encode(clusterMeta);
    logger.info("{}", clusterMeta);
}
Also used : ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) ShardMeta(com.ctrip.xpipe.redis.core.entity.ShardMeta) Test(org.junit.Test) AbstractConsoleTest(com.ctrip.xpipe.redis.console.AbstractConsoleTest)

Example 14 with ClusterMeta

use of com.ctrip.xpipe.redis.core.entity.ClusterMeta in project x-pipe by ctripcorp.

the class DcMetaComparatorTest method testAdded.

@Test
public void testAdded() {
    ClusterMeta cluster = differentCluster(current);
    future.addCluster(cluster);
    DcMetaComparator dcMetaComparator = new DcMetaComparator(current, future);
    dcMetaComparator.compare();
    Assert.assertEquals(0, dcMetaComparator.getRemoved().size());
    Assert.assertEquals(1, dcMetaComparator.getAdded().size());
    Assert.assertEquals(cluster, dcMetaComparator.getAdded().toArray()[0]);
    Assert.assertEquals(0, dcMetaComparator.getMofified().size());
}
Also used : ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) Test(org.junit.Test)

Example 15 with ClusterMeta

use of com.ctrip.xpipe.redis.core.entity.ClusterMeta in project x-pipe by ctripcorp.

the class DcMetaComparatorTest method differentCluster.

protected ClusterMeta differentCluster(DcMeta current) {
    ClusterMeta result = new ClusterMeta();
    result.setId(randomString());
    return result;
}
Also used : ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta)

Aggregations

ClusterMeta (com.ctrip.xpipe.redis.core.entity.ClusterMeta)41 Test (org.junit.Test)25 ShardMeta (com.ctrip.xpipe.redis.core.entity.ShardMeta)13 ClusterTbl (com.ctrip.xpipe.redis.console.model.ClusterTbl)10 DirtiesContext (org.springframework.test.annotation.DirtiesContext)10 MigrationClusterTbl (com.ctrip.xpipe.redis.console.model.MigrationClusterTbl)8 DcMeta (com.ctrip.xpipe.redis.core.entity.DcMeta)5 AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)4 RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)4 ClusterMetaComparator (com.ctrip.xpipe.redis.core.meta.comparator.ClusterMetaComparator)3 AbstractMetaServerTest (com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)3 AbstractMetaServerClusterTest (com.ctrip.xpipe.redis.meta.server.cluster.AbstractMetaServerClusterTest)3 IOException (java.io.IOException)2 HttpServerErrorException (org.springframework.web.client.HttpServerErrorException)2 HostPort (com.ctrip.xpipe.endpoint.HostPort)1 NodeAdded (com.ctrip.xpipe.observer.NodeAdded)1 NodeDeleted (com.ctrip.xpipe.observer.NodeDeleted)1 AbstractConsoleTest (com.ctrip.xpipe.redis.console.AbstractConsoleTest)1 DataNotFoundException (com.ctrip.xpipe.redis.console.exception.DataNotFoundException)1 ServerException (com.ctrip.xpipe.redis.console.exception.ServerException)1