Search in sources :

Example 6 with CommandExecutionException

use of com.ctrip.xpipe.command.CommandExecutionException in project x-pipe by ctripcorp.

the class AbstractNettyCommand method doExecute.

@Override
protected void doExecute() throws CommandExecutionException {
    NettyClient nettyClient = null;
    try {
        logger.debug("[doExecute]{}", this);
        nettyClient = clientPool.borrowObject();
        ByteBuf byteBuf = getRequest();
        doSendRequest(nettyClient, byteBuf);
    } catch (BorrowObjectException e) {
        throw new CommandExecutionException("execute " + this, e);
    } finally {
        if (nettyClient != null) {
            try {
                clientPool.returnObject(nettyClient);
            } catch (ReturnObjectException e) {
                logger.error("[doExecute]", e);
            }
        }
        if (poolCreated) {
            future().addListener(new CommandFutureListener<V>() {

                @Override
                public void operationComplete(CommandFuture<V> commandFuture) throws Exception {
                    LifecycleHelper.stopIfPossible(clientPool);
                    LifecycleHelper.disposeIfPossible(clientPool);
                }
            });
        }
    }
}
Also used : ReturnObjectException(com.ctrip.xpipe.pool.ReturnObjectException) CommandExecutionException(com.ctrip.xpipe.command.CommandExecutionException) ByteBuf(io.netty.buffer.ByteBuf) BorrowObjectException(com.ctrip.xpipe.pool.BorrowObjectException) ReturnObjectException(com.ctrip.xpipe.pool.ReturnObjectException) CommandExecutionException(com.ctrip.xpipe.command.CommandExecutionException) BorrowObjectException(com.ctrip.xpipe.pool.BorrowObjectException)

Example 7 with CommandExecutionException

use of com.ctrip.xpipe.command.CommandExecutionException in project x-pipe by ctripcorp.

the class RequestResponseCommandTest method testTimeout.

@Test
public void testTimeout() throws CommandExecutionException, InterruptedException {
    TestCommand testCommand = new TestCommand("sleep 5000\r\n", 1000, clientPool, scheduled, null);
    CommandFuture<String> future = testCommand.execute();
    final AtomicReference<CommandFuture<String>> listenerFuture = new AtomicReference<CommandFuture<String>>(null);
    final CountDownLatch latch = new CountDownLatch(1);
    future.addListener(new CommandFutureListener<String>() {

        @Override
        public void operationComplete(CommandFuture<String> commandFuture) throws Exception {
            try {
                listenerFuture.set(commandFuture);
            } finally {
                latch.countDown();
            }
        }
    });
    try {
        future.get();
        Assert.fail();
    } catch (InterruptedException e) {
        Assert.fail();
    } catch (ExecutionException e) {
        if (!(e.getCause() instanceof CommandTimeoutException)) {
            Assert.fail();
        }
    }
    latch.await();
    Assert.assertTrue(listenerFuture.get() != null);
}
Also used : CommandFuture(com.ctrip.xpipe.api.command.CommandFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) IOException(java.io.IOException) CommandExecutionException(com.ctrip.xpipe.command.CommandExecutionException) ExecutionException(java.util.concurrent.ExecutionException) BorrowObjectException(com.ctrip.xpipe.pool.BorrowObjectException) CommandTimeoutException(com.ctrip.xpipe.command.CommandTimeoutException) CommandTimeoutException(com.ctrip.xpipe.command.CommandTimeoutException) CommandExecutionException(com.ctrip.xpipe.command.CommandExecutionException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test) AbstractTest(com.ctrip.xpipe.AbstractTest)

Aggregations

CommandExecutionException (com.ctrip.xpipe.command.CommandExecutionException)7 BorrowObjectException (com.ctrip.xpipe.pool.BorrowObjectException)4 IOException (java.io.IOException)3 AbstractTest (com.ctrip.xpipe.AbstractTest)2 CommandTimeoutException (com.ctrip.xpipe.command.CommandTimeoutException)2 NettyClient (com.ctrip.xpipe.netty.commands.NettyClient)2 ReturnObjectException (com.ctrip.xpipe.pool.ReturnObjectException)2 ExecutionException (java.util.concurrent.ExecutionException)2 Test (org.junit.Test)2 CommandFuture (com.ctrip.xpipe.api.command.CommandFuture)1 ParallelCommandChain (com.ctrip.xpipe.command.ParallelCommandChain)1 SequenceCommandChain (com.ctrip.xpipe.command.SequenceCommandChain)1 UntilSuccess (com.ctrip.xpipe.command.UntilSuccess)1 FixedObjectPool (com.ctrip.xpipe.pool.FixedObjectPool)1 RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)1 ConfigRewrite (com.ctrip.xpipe.redis.core.protocal.cmd.ConfigRewrite)1 XSlaveofCommand (com.ctrip.xpipe.redis.core.protocal.cmd.XSlaveofCommand)1 ByteBuf (io.netty.buffer.ByteBuf)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1