use of com.ctrip.xpipe.exception.SimpleErrorMessage in project x-pipe by ctripcorp.
the class AtLeastOneCheckerTest method testCheckerTimeout.
@Test
public void testCheckerTimeout() throws Exception {
Server server = startServer((String) null);
List<RedisMeta> redises = new LinkedList<>();
redises.add(new RedisMeta().setIp("localhost").setPort(server.getPort()));
SimpleErrorMessage check = new AtLeastOneChecker(redises, getXpipeNettyClientKeyedObjectPool(), scheduled).check();
Assert.assertEquals(SIMPLE_RETURN_CODE.FAIL, check.getErrorType());
}
use of com.ctrip.xpipe.exception.SimpleErrorMessage in project x-pipe by ctripcorp.
the class DefaultMetaServer method changePrimaryDcCheck.
@Override
public PrimaryDcCheckMessage changePrimaryDcCheck(String clusterId, String shardId, String newPrimaryDc, ForwardInfo forwardInfo) {
logger.info("[changePrimaryDcCheck]{}, {}, {}, {}", clusterId, shardId, newPrimaryDc, forwardInfo);
String currentPrimaryDc = dcMetaCache.getPrimaryDc(clusterId, shardId);
String currentDc = dcMetaCache.getCurrentDc();
if (newPrimaryDc.equalsIgnoreCase(currentPrimaryDc)) {
return new PrimaryDcCheckMessage(PRIMARY_DC_CHECK_RESULT.PRIMARY_DC_ALREADY_IS_NEW, String.format("%s already primary dc", newPrimaryDc));
}
if (currentDc.equalsIgnoreCase(newPrimaryDc)) {
List<RedisMeta> redises = dcMetaCache.getShardRedises(clusterId, shardId);
SimpleErrorMessage result = new AtLeastOneChecker(redises, keyedObjectPool, scheduled).check();
if (result.getErrorType() == SIMPLE_RETURN_CODE.SUCCESS) {
return new PrimaryDcCheckMessage(PRIMARY_DC_CHECK_RESULT.SUCCESS);
}
return new PrimaryDcCheckMessage(PRIMARY_DC_CHECK_RESULT.FAIL, "all redises dead:" + result.getErrorMessage());
}
return new PrimaryDcCheckMessage(PRIMARY_DC_CHECK_RESULT.SUCCESS, String.format("current dc :%s is not new primary: %s ", currentDc, newPrimaryDc));
}
use of com.ctrip.xpipe.exception.SimpleErrorMessage in project x-pipe by ctripcorp.
the class AtLeastOneCheckerTest method testCheckerSuccess.
@Test
public void testCheckerSuccess() throws Exception {
int count = 3;
List<RedisMeta> redises = new LinkedList<>();
Set<Integer> ports = randomPorts(count);
int i = 0;
for (int port : ports) {
if (i == count - 1) {
Server server = startServer(port, toRedisProtocalString("PONG"));
}
redises.add(new RedisMeta().setIp("localhost").setPort(port));
i++;
}
SimpleErrorMessage check = new AtLeastOneChecker(redises, getXpipeNettyClientKeyedObjectPool(), scheduled).check();
Assert.assertEquals(SIMPLE_RETURN_CODE.SUCCESS, check.getErrorType());
}
use of com.ctrip.xpipe.exception.SimpleErrorMessage in project x-pipe by ctripcorp.
the class AtLeastOneCheckerTest method testCheckerFail.
@Test
public void testCheckerFail() throws Exception {
int count = 3;
List<RedisMeta> redises = new LinkedList<>();
Set<Integer> ports = randomPorts(count);
for (int port : ports) {
redises.add(new RedisMeta().setIp("localhost").setPort(port));
}
SimpleErrorMessage check = new AtLeastOneChecker(redises, getXpipeNettyClientKeyedObjectPool(), scheduled).check();
Assert.assertEquals(SIMPLE_RETURN_CODE.FAIL, check.getErrorType());
logger.info("[testCheckerFail]{}", check.getErrorMessage());
}
use of com.ctrip.xpipe.exception.SimpleErrorMessage in project x-pipe by ctripcorp.
the class AtLeastOneCheckerTest method testCheckerFailTimeout.
@Test
public void testCheckerFailTimeout() throws Exception {
int port = randomPort();
List<RedisMeta> redises = new LinkedList<>();
redises.add(new RedisMeta().setIp("localhost").setPort(port));
startServer(port, new Callable<String>() {
@Override
public String call() throws Exception {
sleep(timeoutMilli * 2);
return toRedisProtocalString("PONG");
}
});
SimpleErrorMessage check = new AtLeastOneChecker(redises, getXpipeNettyClientKeyedObjectPool(), scheduled).check();
Assert.assertEquals(SIMPLE_RETURN_CODE.FAIL, check.getErrorType());
logger.info("[testCheckerFail]{}", check.getErrorMessage());
}
Aggregations