Search in sources :

Example 1 with ChooseNewMasterFailException

use of com.ctrip.xpipe.redis.meta.server.dcchange.exception.ChooseNewMasterFailException in project x-pipe by ctripcorp.

the class FirstNewMasterChooserTest method testMultiMaster.

@Test
public void testMultiMaster() throws Exception {
    int addRedisCount = 5;
    Set<Integer> ports = new HashSet<>();
    redises.forEach(redisMeta -> ports.add(redisMeta.getPort()));
    for (int i = 0; i < addRedisCount; i++) {
        int port = randomPort(ports);
        redises.add(new RedisMeta().setIp("localhost").setPort(port));
    }
    for (RedisMeta redis : redises) {
        startSlaveFakeRedis(redis.getPort(), SERVER_ROLE.MASTER);
    }
    try {
        RedisMeta choose = firstNewMasterChooser.choose(redises);
        Assert.fail();
    } catch (ChooseNewMasterFailException e) {
        Assert.assertEquals(redises.size(), e.getRedises().size());
    }
}
Also used : ChooseNewMasterFailException(com.ctrip.xpipe.redis.meta.server.dcchange.exception.ChooseNewMasterFailException) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) HashSet(java.util.HashSet) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

Aggregations

RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)1 AbstractMetaServerTest (com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)1 ChooseNewMasterFailException (com.ctrip.xpipe.redis.meta.server.dcchange.exception.ChooseNewMasterFailException)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1