Search in sources :

Example 1 with PingCommand

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

the class DefaultSlaveOfCommandTest method testMultiServer.

@Test
public void testMultiServer() throws Exception {
    int begin = 10000;
    int count = 32;
    // make connection active
    for (int i = 0; i < count; i++) {
        int port = begin + i;
        SimpleObjectPool<NettyClient> keyPool = getXpipeNettyClientKeyedObjectPool().getKeyPool(new InetSocketAddress("127.0.0.1", port));
        new PingCommand(keyPool, scheduled).execute().get();
    }
    CountDownLatch latch = new CountDownLatch(count);
    for (int i = 0; i < count; i++) {
        int port = begin + i;
        SimpleObjectPool<NettyClient> keyPool = getXpipeNettyClientKeyedObjectPool().getKeyPool(new InetSocketAddress("127.0.0.1", port));
        long beginTime = System.currentTimeMillis();
        new DefaultSlaveOfCommand(keyPool, "127.0.0.1", 0, scheduled).execute(executors).addListener(new CommandFutureListener<String>() {

            @Override
            public void operationComplete(CommandFuture<String> commandFuture) throws Exception {
                long endTime = System.currentTimeMillis();
                long duration = endTime - beginTime;
                if (duration > 50) {
                    logger.warn("[timeout]127.0.0.1:{}, {}", port, duration);
                }
                latch.countDown();
            }
        });
    }
    latch.await();
    sleep(1000);
    logger.info("[testMultiServer][end]");
}
Also used : InetSocketAddress(java.net.InetSocketAddress) DefaultSlaveOfCommand(com.ctrip.xpipe.redis.core.protocal.cmd.DefaultSlaveOfCommand) CountDownLatch(java.util.concurrent.CountDownLatch) PingCommand(com.ctrip.xpipe.redis.core.protocal.cmd.PingCommand) NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) AbstractRedisTest(com.ctrip.xpipe.redis.core.AbstractRedisTest) Test(org.junit.Test)

Aggregations

NettyClient (com.ctrip.xpipe.netty.commands.NettyClient)1 AbstractRedisTest (com.ctrip.xpipe.redis.core.AbstractRedisTest)1 DefaultSlaveOfCommand (com.ctrip.xpipe.redis.core.protocal.cmd.DefaultSlaveOfCommand)1 PingCommand (com.ctrip.xpipe.redis.core.protocal.cmd.PingCommand)1 InetSocketAddress (java.net.InetSocketAddress)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1