Search in sources :

Example 11 with SlaveRole

use of com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole in project x-pipe by ctripcorp.

the class RoleCommandTest method testSlave.

@Test
public void testSlave() throws Exception {
    for (MASTER_STATE masterState : MASTER_STATE.values()) {
        Server slave = startServer("*5\r\n" + "$5\r\nslave\r\n" + "$9\r\nlocalhost\r\n" + ":6379\r\n" + "$" + masterState.getDesc().length() + "\r\n" + masterState.getDesc() + "\r\n" + ":477\r\n");
        RoleCommand roleCommand = new RoleCommand(getXpipeNettyClientKeyedObjectPool().getKeyPool(localhostInetAddress(slave.getPort())), 2000, false, scheduled);
        SlaveRole role = (SlaveRole) roleCommand.execute().get();
        Assert.assertEquals(SERVER_ROLE.SLAVE, role.getServerRole());
        Assert.assertEquals("localhost", role.getMasterHost());
        Assert.assertEquals(6379, role.getMasterPort());
        Assert.assertEquals(masterState, role.getMasterState());
        Assert.assertEquals(477, role.getMasterOffset());
    }
}
Also used : SlaveRole(com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole) Server(com.ctrip.xpipe.simpleserver.Server) RoleCommand(com.ctrip.xpipe.redis.core.protocal.cmd.RoleCommand) MASTER_STATE(com.ctrip.xpipe.redis.core.protocal.MASTER_STATE) Test(org.junit.Test)

Example 12 with SlaveRole

use of com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole in project x-pipe by ctripcorp.

the class RoleCommandTest method test.

@Test
public void test() throws Exception {
    SlaveRole role = new SlaveRole(SERVER_ROLE.KEEPER, "localhost", randomPort(), MASTER_STATE.REDIS_REPL_CONNECT, 0L);
    Server server = startServer(ByteBufUtils.readToString(role.format()));
    RoleCommand roleCommand = new RoleCommand("localhost", server.getPort(), scheduled);
    Role real = roleCommand.execute().get();
    logger.info("[test]{}", real);
    Assert.assertEquals(role, real);
}
Also used : SlaveRole(com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole) Role(com.ctrip.xpipe.redis.core.protocal.pojo.Role) SlaveRole(com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole) Server(com.ctrip.xpipe.simpleserver.Server) AbstractRedisTest(com.ctrip.xpipe.redis.core.AbstractRedisTest) Test(org.junit.Test)

Example 13 with SlaveRole

use of com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole in project x-pipe by ctripcorp.

the class PrimaryDcKeeperMasterChooserAlgorithmTest method testLongConnection.

@Test
public void testLongConnection() throws Exception {
    SlaveRole role = new SlaveRole(SERVER_ROLE.MASTER, "localhost", randomPort(), MASTER_STATE.REDIS_REPL_CONNECT, 0L);
    RedisMeta chosen = redises.get(0);
    Server server = startServer(chosen.getPort(), ByteBufUtils.readToString(role.format()));
    Assert.assertEquals(0, server.getConnected());
    for (int i = 0; i < 10; i++) {
        primaryAlgorithm.choose();
        Assert.assertEquals(1, server.getConnected());
    }
}
Also used : SlaveRole(com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole) Server(com.ctrip.xpipe.simpleserver.Server) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) Test(org.junit.Test)

Example 14 with SlaveRole

use of com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole in project x-pipe by ctripcorp.

the class AddKeeperCommandTest method testFailThenSuccess.

@Test
public void testFailThenSuccess() throws Exception {
    startServer(keeperPort, new Callable<String>() {

        long startTime = System.currentTimeMillis();

        @Override
        public String call() throws Exception {
            SlaveRole slaveRole = null;
            if (System.currentTimeMillis() - startTime <= timeoutMilli / 2) {
                slaveRole = new SlaveRole(SERVER_ROLE.KEEPER, "localhost", randomPort(), MASTER_STATE.REDIS_REPL_CONNECT, 0);
            } else {
                slaveRole = new SlaveRole(SERVER_ROLE.KEEPER, "localhost", randomPort(), MASTER_STATE.REDIS_REPL_CONNECTED, 0);
            }
            return ByteBufUtils.readToString(slaveRole.format());
        }
    });
    SlaveRole keeperRole = addKeeperCommand.execute().get();
    Assert.assertEquals(MASTER_STATE.REDIS_REPL_CONNECTED, keeperRole.getMasterState());
}
Also used : SlaveRole(com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

Aggregations

SlaveRole (com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole)14 Test (org.junit.Test)12 Server (com.ctrip.xpipe.simpleserver.Server)8 AbstractMetaServerTest (com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)5 RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)4 ExecutionException (java.util.concurrent.ExecutionException)4 RoleCommand (com.ctrip.xpipe.redis.core.protocal.cmd.RoleCommand)3 Role (com.ctrip.xpipe.redis.core.protocal.pojo.Role)3 AbstractExceptionLogTask (com.ctrip.xpipe.concurrent.AbstractExceptionLogTask)1 AbstractRedisTest (com.ctrip.xpipe.redis.core.AbstractRedisTest)1 KeeperMeta (com.ctrip.xpipe.redis.core.entity.KeeperMeta)1 MASTER_STATE (com.ctrip.xpipe.redis.core.protocal.MASTER_STATE)1 MasterRole (com.ctrip.xpipe.redis.core.protocal.pojo.MasterRole)1 ArrayParser (com.ctrip.xpipe.redis.core.protocal.protocal.ArrayParser)1 AbstractRedisKeeperTest (com.ctrip.xpipe.redis.keeper.AbstractRedisKeeperTest)1 Pair (com.ctrip.xpipe.tuple.Pair)1 ByteBuf (io.netty.buffer.ByteBuf)1 InetSocketAddress (java.net.InetSocketAddress)1 LinkedList (java.util.LinkedList)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1