Search in sources :

Example 21 with RedisMeta

use of com.ctrip.xpipe.redis.core.entity.RedisMeta in project x-pipe by ctripcorp.

the class DefaultSlaveOfJobTest method testSlavesSuccess.

@Test
public void testSlavesSuccess() throws Exception {
    List<RedisMeta> slaves = new LinkedList<>();
    List<Integer> ports = new LinkedList<>(randomPorts(2));
    slaves.add(new RedisMeta().setIp("localhost").setPort(ports.get(0)));
    slaves.add(new RedisMeta().setIp("localhost").setPort(ports.get(1)));
    startServer(ports.get(0), "+OK\r\n");
    startServer(ports.get(1), "+OK\r\n");
    Command<Void> command = new DefaultSlaveOfJob(slaves, "localhost", randomPort(), getXpipeNettyClientKeyedObjectPool(), scheduled, executors);
    command.execute().get(1, TimeUnit.SECONDS);
}
Also used : RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) LinkedList(java.util.LinkedList) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

Example 22 with RedisMeta

use of com.ctrip.xpipe.redis.core.entity.RedisMeta in project x-pipe by ctripcorp.

the class FirstNewMasterChooserTest method testRedis.

// run with real redis
// @Test
public void testRedis() {
    redises.clear();
    redises.add(new RedisMeta().setIp("localhost").setPort(6379));
    redises.add(new RedisMeta().setIp("localhost").setPort(6479));
    logger.info("{}", firstNewMasterChooser.choose(redises));
}
Also used : RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta)

Example 23 with RedisMeta

use of com.ctrip.xpipe.redis.core.entity.RedisMeta in project x-pipe by ctripcorp.

the class FirstNewMasterChooserTest method testSort.

@Test
public void testSort() {
    int allCount = 5;
    List<RedisMeta> redisMetas = new LinkedList<>();
    for (int i = 0; i < allCount; i++) {
        redisMetas.add(new RedisMeta().setPort(i));
    }
    Assert.assertEquals(0, firstNewMasterChooser.sortAccording(redisMetas, new LinkedList<>()).size());
    List<RedisMeta> alive = new LinkedList<>();
    for (int i = 4; i >= 2; i--) {
        alive.add(redisMetas.get(i));
    }
    List<RedisMeta> sorted = firstNewMasterChooser.sortAccording(redisMetas, alive);
    Assert.assertEquals(3, sorted.size());
    RedisMeta previous = null;
    for (RedisMeta redis : sorted) {
        if (previous != null) {
            Assert.assertTrue(redis.getPort() > previous.getPort());
        }
        previous = redis;
    }
}
Also used : RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) LinkedList(java.util.LinkedList) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

Example 24 with RedisMeta

use of com.ctrip.xpipe.redis.core.entity.RedisMeta in project x-pipe by ctripcorp.

the class PrimaryDcKeeperMasterChooserAlgorithmTest method testOneMaster.

@Test
public void testOneMaster() throws Exception {
    SlaveRole role = new SlaveRole(SERVER_ROLE.MASTER, "localhost", randomPort(), MASTER_STATE.REDIS_REPL_CONNECT, 0L);
    RedisMeta chosen = redises.get(0);
    startServer(chosen.getPort(), ByteBufUtils.readToString(role.format()));
    when(currentMetaManager.getKeeperMaster(clusterId, shardId)).thenReturn(null);
    Assert.assertEquals(new Pair<String, Integer>(chosen.getIp(), chosen.getPort()), primaryAlgorithm.choose());
    for (RedisMeta redisMeta : redises) {
        when(currentMetaManager.getKeeperMaster(clusterId, shardId)).thenReturn(new Pair<String, Integer>(redisMeta.getIp(), redisMeta.getPort()));
        Assert.assertEquals(new Pair<String, Integer>(chosen.getIp(), chosen.getPort()), primaryAlgorithm.choose());
    }
}
Also used : SlaveRole(com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) Test(org.junit.Test)

Example 25 with RedisMeta

use of com.ctrip.xpipe.redis.core.entity.RedisMeta in project x-pipe by ctripcorp.

the class PrimaryDcKeeperMasterChooserAlgorithmTest method befoePrimaryDcKeeperMasterChooserTest.

@Before
public void befoePrimaryDcKeeperMasterChooserTest() throws Exception {
    primaryAlgorithm = new PrimaryDcKeeperMasterChooserAlgorithm(clusterId, shardId, dcMetaCache, currentMetaManager, getXpipeNettyClientKeyedObjectPool(), 1, scheduled);
    redises = new LinkedList<>();
    int port1 = randomPort();
    redises.add(new RedisMeta().setIp("localhost").setPort(port1));
    redises.add(new RedisMeta().setIp("localhost").setPort(randomPort(Sets.newHashSet(port1))));
    when(dcMetaCache.getShardRedises(clusterId, shardId)).thenReturn(redises);
    when(dcMetaCache.isCurrentDcPrimary(clusterId, shardId)).thenReturn(true);
}
Also used : RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) Before(org.junit.Before)

Aggregations

RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)55 Test (org.junit.Test)26 LinkedList (java.util.LinkedList)14 AbstractMetaServerTest (com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)9 KeeperMeta (com.ctrip.xpipe.redis.core.entity.KeeperMeta)8 Before (org.junit.Before)7 SimpleErrorMessage (com.ctrip.xpipe.exception.SimpleErrorMessage)5 RedisKeeperServer (com.ctrip.xpipe.redis.keeper.RedisKeeperServer)5 AtLeastOneChecker (com.ctrip.xpipe.redis.meta.server.dcchange.impl.AtLeastOneChecker)5 ClusterMeta (com.ctrip.xpipe.redis.core.entity.ClusterMeta)4 ShardMeta (com.ctrip.xpipe.redis.core.entity.ShardMeta)4 SlaveRole (com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole)4 Pair (com.ctrip.xpipe.tuple.Pair)4 DcMeta (com.ctrip.xpipe.redis.core.entity.DcMeta)3 PrimaryDcChangeMessage (com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService.PrimaryDcChangeMessage)3 Server (com.ctrip.xpipe.simpleserver.Server)3 InetSocketAddress (java.net.InetSocketAddress)3 SERVER_ROLE (com.ctrip.xpipe.api.server.Server.SERVER_ROLE)2 AbstractExceptionLogTask (com.ctrip.xpipe.concurrent.AbstractExceptionLogTask)2 HostPort (com.ctrip.xpipe.endpoint.HostPort)2