Search in sources :

Example 1 with SimpleErrorMessage

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());
}
Also used : Server(com.ctrip.xpipe.simpleserver.Server) AtLeastOneChecker(com.ctrip.xpipe.redis.meta.server.dcchange.impl.AtLeastOneChecker) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) SimpleErrorMessage(com.ctrip.xpipe.exception.SimpleErrorMessage) LinkedList(java.util.LinkedList) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

Example 2 with SimpleErrorMessage

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));
}
Also used : PrimaryDcCheckMessage(com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService.PrimaryDcCheckMessage) AtLeastOneChecker(com.ctrip.xpipe.redis.meta.server.dcchange.impl.AtLeastOneChecker) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) SimpleErrorMessage(com.ctrip.xpipe.exception.SimpleErrorMessage)

Example 3 with SimpleErrorMessage

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());
}
Also used : Server(com.ctrip.xpipe.simpleserver.Server) AtLeastOneChecker(com.ctrip.xpipe.redis.meta.server.dcchange.impl.AtLeastOneChecker) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) SimpleErrorMessage(com.ctrip.xpipe.exception.SimpleErrorMessage) LinkedList(java.util.LinkedList) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

Example 4 with SimpleErrorMessage

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());
}
Also used : AtLeastOneChecker(com.ctrip.xpipe.redis.meta.server.dcchange.impl.AtLeastOneChecker) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) SimpleErrorMessage(com.ctrip.xpipe.exception.SimpleErrorMessage) LinkedList(java.util.LinkedList) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

Example 5 with SimpleErrorMessage

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());
}
Also used : AtLeastOneChecker(com.ctrip.xpipe.redis.meta.server.dcchange.impl.AtLeastOneChecker) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) SimpleErrorMessage(com.ctrip.xpipe.exception.SimpleErrorMessage) LinkedList(java.util.LinkedList) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

Aggregations

SimpleErrorMessage (com.ctrip.xpipe.exception.SimpleErrorMessage)5 RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)5 AtLeastOneChecker (com.ctrip.xpipe.redis.meta.server.dcchange.impl.AtLeastOneChecker)5 AbstractMetaServerTest (com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)4 LinkedList (java.util.LinkedList)4 Test (org.junit.Test)4 Server (com.ctrip.xpipe.simpleserver.Server)2 PrimaryDcCheckMessage (com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService.PrimaryDcCheckMessage)1