Search in sources :

Example 16 with NettyClient

use of com.ctrip.xpipe.netty.commands.NettyClient in project x-pipe by ctripcorp.

the class AbstractRedisCommandTest method testLogRequest.

// manual test
@Test
public void testLogRequest() throws Exception {
    XpipeNettyClientKeyedObjectPool keyedObjectPool = getXpipeNettyClientKeyedObjectPool();
    SimpleObjectPool<NettyClient> clientPool = keyedObjectPool.getKeyPool(new InetSocketAddress("127.0.0.1", 6379));
    ScheduledExecutorService scheduled = Executors.newScheduledThreadPool(1);
    InfoCommand infoCommand = new InfoCommand(clientPool, InfoCommand.INFO_TYPE.REPLICATION, scheduled);
    infoCommand.logResponse(false);
    // infoCommand.logRequest(false);
    infoCommand.execute().get();
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) InetSocketAddress(java.net.InetSocketAddress) XpipeNettyClientKeyedObjectPool(com.ctrip.xpipe.pool.XpipeNettyClientKeyedObjectPool) AbstractRedisTest(com.ctrip.xpipe.redis.core.AbstractRedisTest) Test(org.junit.Test)

Example 17 with NettyClient

use of com.ctrip.xpipe.netty.commands.NettyClient 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)

Example 18 with NettyClient

use of com.ctrip.xpipe.netty.commands.NettyClient in project x-pipe by ctripcorp.

the class ReplconfTest method test.

@Test
public void test() throws Exception {
    for (int i = 0; i < 100; i++) {
        FixedObjectPool<NettyClient> clientPool = null;
        try {
            clientPool = createClientPool(host, port);
            Replconf replconf = new Replconf(clientPool, ReplConfType.LISTENING_PORT, scheduled, String.valueOf(1234));
            replconf.execute().addListener(new CommandFutureListener<Object>() {

                @Override
                public void operationComplete(CommandFuture<Object> commandFuture) throws Exception {
                    logger.info("{}", commandFuture.get());
                }
            });
            Psync psync = new InMemoryPsync(clientPool, "?", -1L, scheduled);
            try {
                psync.execute().get(100, TimeUnit.MILLISECONDS);
                Assert.fail();
            } catch (TimeoutException e) {
            }
        } finally {
            if (clientPool != null) {
                clientPool.getObject().channel().close();
            }
        }
    }
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) Replconf(com.ctrip.xpipe.redis.core.protocal.cmd.Replconf) Psync(com.ctrip.xpipe.redis.core.protocal.Psync) InMemoryPsync(com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync) InMemoryPsync(com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync) TimeoutException(java.util.concurrent.TimeoutException) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 19 with NettyClient

use of com.ctrip.xpipe.netty.commands.NettyClient in project x-pipe by ctripcorp.

the class TransactionalCommand method doExecute.

@Override
protected void doExecute() throws CommandExecutionException {
    try {
        final NettyClient nettyClient = parentClientPool.borrowObject();
        SimpleObjectPool<NettyClient> clientPool = new FixedObjectPool<NettyClient>(nettyClient);
        startTransaction(clientPool);
        future().addListener(new CommandFutureListener<Object[]>() {

            @Override
            public void operationComplete(CommandFuture<Object[]> commandFuture) throws Exception {
                if (nettyClient != null) {
                    try {
                        parentClientPool.returnObject(nettyClient);
                    } catch (ReturnObjectException e) {
                        logger.error("[doExecute]" + this, e);
                    }
                }
            }
        });
    } catch (BorrowObjectException e) {
        throw new CommandExecutionException("execute " + this, e);
    }
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) ReturnObjectException(com.ctrip.xpipe.pool.ReturnObjectException) CommandExecutionException(com.ctrip.xpipe.command.CommandExecutionException) FixedObjectPool(com.ctrip.xpipe.pool.FixedObjectPool) CommandExecutionException(com.ctrip.xpipe.command.CommandExecutionException) ReturnObjectException(com.ctrip.xpipe.pool.ReturnObjectException) BorrowObjectException(com.ctrip.xpipe.pool.BorrowObjectException) BorrowObjectException(com.ctrip.xpipe.pool.BorrowObjectException)

Example 20 with NettyClient

use of com.ctrip.xpipe.netty.commands.NettyClient in project x-pipe by ctripcorp.

the class AbstractRedisMasterReplication method masterConnected.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void masterConnected(Channel channel) {
    connectedTime = System.currentTimeMillis();
    this.masterChannel = channel;
    clientPool = new FixedObjectPool<NettyClient>(new DefaultNettyClient(channel));
    checkTimeout(channel);
    checkKeeper();
    SequenceCommandChain chain = new SequenceCommandChain(false);
    chain.add(listeningPortCommand());
    chain.add(new FailSafeCommandWrapper<>(new Replconf(clientPool, ReplConfType.CAPA, scheduled, CAPA.EOF.toString(), CAPA.PSYNC2.toString())));
    try {
        executeCommand(chain).addListener(new CommandFutureListener() {

            @Override
            public void operationComplete(CommandFuture commandFuture) throws Exception {
                if (commandFuture.isSuccess()) {
                    sendReplicationCommand();
                } else {
                    logger.error("[operationComplete][listeningPortCommand]", commandFuture.cause());
                }
            }
        });
    } catch (Exception e) {
        logger.error("[masterConnected]" + channel, e);
    }
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) DefaultNettyClient(com.ctrip.xpipe.netty.commands.DefaultNettyClient) CommandFuture(com.ctrip.xpipe.api.command.CommandFuture) Replconf(com.ctrip.xpipe.redis.core.protocal.cmd.Replconf) CommandFutureListener(com.ctrip.xpipe.api.command.CommandFutureListener) DefaultNettyClient(com.ctrip.xpipe.netty.commands.DefaultNettyClient) CommandExecutionException(com.ctrip.xpipe.command.CommandExecutionException) IOException(java.io.IOException) XpipeException(com.ctrip.xpipe.exception.XpipeException) SequenceCommandChain(com.ctrip.xpipe.command.SequenceCommandChain)

Aggregations

NettyClient (com.ctrip.xpipe.netty.commands.NettyClient)37 InetSocketAddress (java.net.InetSocketAddress)31 Test (org.junit.Test)8 ExecutionException (java.util.concurrent.ExecutionException)6 AbstractTest (com.ctrip.xpipe.AbstractTest)4 InfoCommand (com.ctrip.xpipe.redis.core.protocal.cmd.InfoCommand)4 Server (com.ctrip.xpipe.simpleserver.Server)4 IOException (java.io.IOException)4 CommandExecutionException (com.ctrip.xpipe.command.CommandExecutionException)3 SequenceCommandChain (com.ctrip.xpipe.command.SequenceCommandChain)3 FixedObjectPool (com.ctrip.xpipe.pool.FixedObjectPool)3 AbstractRedisTest (com.ctrip.xpipe.redis.core.AbstractRedisTest)3 AbstractSentinelCommand (com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSentinelCommand)3 Replconf (com.ctrip.xpipe.redis.core.protocal.cmd.Replconf)3 DefaultEndPoint (com.ctrip.xpipe.endpoint.DefaultEndPoint)2 XpipeException (com.ctrip.xpipe.exception.XpipeException)2 NettyClientFactory (com.ctrip.xpipe.netty.commands.NettyClientFactory)2 XpipeObjectPoolFromKeyed (com.ctrip.xpipe.pool.XpipeObjectPoolFromKeyed)2 DefaultSlaveOfCommand (com.ctrip.xpipe.redis.core.protocal.cmd.DefaultSlaveOfCommand)2 InMemoryPsync (com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync)2