Search in sources :

Example 1 with AbstractOuterClientService

use of com.ctrip.xpipe.migration.AbstractOuterClientService in project x-pipe by ctripcorp.

the class MigrationCheckingStateTest method testCheckCRedisFail.

@Test
public void testCheckCRedisFail() {
    when(migrationCluster.getOuterClientService()).thenReturn(new AbstractOuterClientService() {

        @Override
        public ClusterInfo getClusterInfo(String clusterName) throws Exception {
            ClusterInfo clusterInfo = new ClusterInfo();
            return clusterInfo;
        }
    });
    checkingState.action();
    verify(migrationCluster).markCheckFail(anyString());
    when(migrationCluster.getOuterClientService()).thenReturn(new AbstractOuterClientService() {

        @Override
        public ClusterInfo getClusterInfo(String clusterName) throws Exception {
            ClusterInfo clusterInfo = new ClusterInfo();
            clusterInfo.setGroups(Lists.newArrayList(new GroupInfo()));
            return clusterInfo;
        }
    });
    checkingState.action();
    verify(migrationCluster).markCheckFail(anyString());
}
Also used : AbstractOuterClientService(com.ctrip.xpipe.migration.AbstractOuterClientService) Test(org.junit.Test)

Example 2 with AbstractOuterClientService

use of com.ctrip.xpipe.migration.AbstractOuterClientService 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)

Example 3 with AbstractOuterClientService

use of com.ctrip.xpipe.migration.AbstractOuterClientService in project x-pipe by ctripcorp.

the class MigrationPublishStatTest method publishFailWithReturnFail.

@Test
public void publishFailWithReturnFail() {
    MigrationPublishState stat = new MigrationPublishState(migrationCluster);
    stat.setPublishService(new AbstractOuterClientService() {

        @Override
        public MigrationPublishResult doMigrationPublish(String clusterName, String shardName, String primaryDcName, InetSocketAddress newMaster) {
            MigrationPublishResult res = new MigrationPublishResult();
            res.setSuccess(false);
            return res;
        }

        @Override
        public MigrationPublishResult doMigrationPublish(String clusterName, String primaryDcName, List<InetSocketAddress> newMasters) {
            MigrationPublishResult res = new MigrationPublishResult();
            res.setSuccess(false);
            return res;
        }
    });
    stat.getStateActionState().tryAction();
    verify(migrationCluster).updateStat(isA(MigrationPublishState.class));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) AbstractOuterClientService(com.ctrip.xpipe.migration.AbstractOuterClientService) Test(org.junit.Test)

Example 4 with AbstractOuterClientService

use of com.ctrip.xpipe.migration.AbstractOuterClientService in project x-pipe by ctripcorp.

the class MigrationPublishStatTest method publishFailWithNetworkProblemTest.

@Test
public void publishFailWithNetworkProblemTest() {
    MigrationPublishState stat = new MigrationPublishState(migrationCluster);
    stat.setPublishService(new AbstractOuterClientService() {

        @Override
        public MigrationPublishResult doMigrationPublish(String clusterName, String shardName, String primaryDcName, InetSocketAddress newMaster) {
            throw new ResourceAccessException("test");
        }

        @Override
        public MigrationPublishResult doMigrationPublish(String clusterName, String primaryDcName, List<InetSocketAddress> newMasters) {
            throw new ResourceAccessException("test");
        }
    });
    stat.getStateActionState().tryAction();
    verify(migrationCluster).updateStat(isA(MigrationPublishState.class));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) AbstractOuterClientService(com.ctrip.xpipe.migration.AbstractOuterClientService) ResourceAccessException(org.springframework.web.client.ResourceAccessException) Test(org.junit.Test)

Aggregations

AbstractOuterClientService (com.ctrip.xpipe.migration.AbstractOuterClientService)4 Test (org.junit.Test)4 InetSocketAddress (java.net.InetSocketAddress)2 DefaultMigrationCluster (com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationCluster)1 TimeoutException (java.util.concurrent.TimeoutException)1 DirtiesContext (org.springframework.test.annotation.DirtiesContext)1 ResourceAccessException (org.springframework.web.client.ResourceAccessException)1