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());
}
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());
}
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));
}
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));
}
Aggregations