Search in sources :

Example 6 with DefaultMigrationCluster

use of com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationCluster in project x-pipe by ctripcorp.

the class MultiShardMigrationTest method testCRedisCheckFailed.

@Test
@DirtiesContext
public void testCRedisCheckFailed() throws TimeoutException {
    int failPos = randomInt(1, TEST_SHARD_CNT);
    for (int cnt = 1; cnt != TEST_SHARD_CNT + 1; ++cnt) {
        mockSuccessCheckCommand(migrationCommandBuilder, clusterName, getShardName(cnt), dcB, dcB);
        mockSuccessPrevPrimaryDcCommand(migrationCommandBuilder, clusterName, getShardName(cnt), dcA);
        mockSuccessNewPrimaryDcCommand(migrationCommandBuilder, clusterName, getShardName(cnt), dcB);
        mockSuccessOtherDcCommand(migrationCommandBuilder, clusterName, getShardName(cnt), dcB, dcA);
    }
    ((DefaultMigrationCluster) migrationCluster).setOuterClientService(new AbstractOuterClientService() {

        @Override
        public ClusterInfo getClusterInfo(String clusterName) throws Exception {
            return null;
        }
    });
    ClusterTbl originalCluster = clusterService.find(clusterId);
    Assert.assertEquals(ClusterStatus.Lock.toString(), originalCluster.getStatus());
    migrationCluster.process();
    sleep(1000);
    Assert.assertEquals(MigrationStatus.CheckingFail, migrationCluster.getStatus());
    ClusterTbl currentCluster = clusterService.find(clusterId);
    Assert.assertEquals(ClusterStatus.Lock.toString(), currentCluster.getStatus());
    ((DefaultMigrationCluster) migrationCluster).setOuterClientService(new AbstractOuterClientService() {

        @Override
        public ClusterInfo getClusterInfo(String clusterName) throws Exception {
            ClusterInfo clusterInfo = new ClusterInfo();
            clusterInfo.setGroups(Lists.newArrayList(new GroupInfo()));
            return clusterInfo;
        }
    });
    // again
    migrationCluster.process();
    waitConditionUntilTimeOut(() -> clusterService.find(clusterId).getStatus() == ClusterStatus.Normal.toString(), 2500);
    currentCluster = clusterService.find(clusterId);
    Assert.assertEquals(ClusterStatus.Normal.toString(), currentCluster.getStatus());
}
Also used : DefaultMigrationCluster(com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationCluster) AbstractOuterClientService(com.ctrip.xpipe.migration.AbstractOuterClientService) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Aggregations

DefaultMigrationCluster (com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationCluster)6 DefaultMigrationShard (com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationShard)4 Before (org.junit.Before)4 HashMap (java.util.HashMap)3 DcTbl (com.ctrip.xpipe.redis.console.model.DcTbl)2 MigrationClusterTbl (com.ctrip.xpipe.redis.console.model.MigrationClusterTbl)2 AbstractOuterClientService (com.ctrip.xpipe.migration.AbstractOuterClientService)1 BadRequestException (com.ctrip.xpipe.redis.console.exception.BadRequestException)1 MigrationCluster (com.ctrip.xpipe.redis.console.migration.model.MigrationCluster)1 MigrationEvent (com.ctrip.xpipe.redis.console.migration.model.MigrationEvent)1 DefaultMigrationEvent (com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationEvent)1 TimeoutException (java.util.concurrent.TimeoutException)1 Test (org.junit.Test)1 DirtiesContext (org.springframework.test.annotation.DirtiesContext)1