@Test public void testCausalCommandFailure() throws Exception { TcpPortCheckCommand tcpPortCheckCommand = new TcpPortCheckCommand("localhost", randomPort()); CausalCommand command = new CausalCommand<Boolean, String>() { @Override protected void onSuccess(Boolean result) { future().setSuccess("result: " + result); } @Override protected void onFailure(Throwable throwable) { future().setFailure(new CausalException("previous failed", throwable)); } }; command.getCausation(tcpPortCheckCommand.future()); tcpPortCheckCommand.execute().await(); CommandFuture commandFuture = command.execute(); Assert.assertTrue(commandFuture.isDone()); Assert.assertNotNull(commandFuture.cause()); Assert.assertTrue(commandFuture.cause() instanceof CausalException); }
@Override public CommandFuture<V> getCausation(CommandFuture<T> previousCommandFuture) { if(this.previous.compareAndSet(null, previousCommandFuture)) { previousCommandFuture.addListener(new CommandFutureListener<T>() { @Override public void operationComplete(CommandFuture<T> commandFuture) throws Exception { if(commandFuture.isSuccess()) { onSuccess(commandFuture.getNow()); } else { onFailure(commandFuture.cause()); } } }); return future(); } getLogger().error("[causal failure] previous already set"); return null; }
CausalCommand extends AbstractCommand implements Causal<CommandFuture<T>, CommandFuture<V>> { @Override public CommandFuture<V> getCausation(CommandFuture<T> previousCommandFuture) { if(this.previous.compareAndSet(null, previousCommandFuture)) { previousCommandFuture.addListener(new CommandFutureListener<T>() { @Override public void operationComplete(CommandFuture<T> commandFuture) throws Exception { if(commandFuture.isSuccess()) { onSuccess(commandFuture.getNow()); } else { onFailure(commandFuture.cause()); } } }); return future(); } getLogger().error("[causal failure] previous already set"); return null; } }
CausalCommand extends AbstractCommand implements Causal<CommandFuture<T>, CommandFuture<V>> { @Override public CommandFuture<V> getCausation(CommandFuture<T> previousCommandFuture) { if(this.previous.compareAndSet(null, previousCommandFuture)) { previousCommandFuture.addListener(new CommandFutureListener<T>() { @Override public void operationComplete(CommandFuture<T> commandFuture) throws Exception { if(commandFuture.isSuccess()) { onSuccess(commandFuture.getNow()); } else { onFailure(commandFuture.cause()); } } }); return future(); } getLogger().error("[causal failure] previous already set"); return null; }  }
CausalCommand extends AbstractCommand implements Causal<CommandFuture<T>, CommandFuture<V>> { @Override public CommandFuture<V> getCausation(CommandFuture<T> previousCommandFuture) { if(this.previous.compareAndSet(null, previousCommandFuture)) { previousCommandFuture.addListener(new CommandFutureListener<T>() { @Override public void operationComplete(CommandFuture<T> commandFuture) throws Exception { if(commandFuture.isSuccess()) { onSuccess(commandFuture.getNow()); } else { onFailure(commandFuture.cause()); } } }); return future(); } getLogger().error("[causal failure] previous already set"); return null; }  @Override CommandFuture<V> getCausation(CommandFuture<T> previousCommandFuture); @Override String getName(); }
CausalCommand extends AbstractCommand implements Causal<CommandFuture<T>, CommandFuture<V>> { @Override public CommandFuture<V> getCausation(CommandFuture<T> previousCommandFuture) { if(this.previous.compareAndSet(null, previousCommandFuture)) { previousCommandFuture.addListener(new CommandFutureListener<T>() { @Override public void operationComplete(CommandFuture<T> commandFuture) throws Exception { if(commandFuture.isSuccess()) { onSuccess(commandFuture.getNow()); } else { onFailure(commandFuture.cause()); } } }); return future(); } getLogger().error("[causal failure] previous already set"); return null; }  @Override CommandFuture<V> getCausation(CommandFuture<T> previousCommandFuture); @Override String getName();  }