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);
}
});
}
}
}
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);
}
Aggregations