SameThreadCallbackService implements CallbackService { @Override public void run(Runnable runnable, Object orderingCtx, Promise<Void> promise) { try { runnable.run(); promise.setSuccess(null); } catch(Exception e) { promise.setFailure(new ClientException("Application code threw an exception from within a callback. See linked exception for more details.", e)); } }  @Override void run(Runnable runnable, Object orderingCtx, Promise<Void> promise);  }
@Test public void successfulCallback() { CallbackService cbs = new SameThreadCallbackService(); MockCallbackPromise future = new MockCallbackPromise(Method.SUCCESS); final AtomicBoolean run = new AtomicBoolean(false); cbs.run(new Runnable() { public void run() { run.set(true); } }, new Object(), future); assertTrue("Runnable should have been run!", run.get()); }
@Test public void exceptionThrownInCallback() { CallbackService cbs = new SameThreadCallbackService(); MockCallbackPromise future = new MockCallbackPromise(Method.FAILURE); final RuntimeException exception = new RuntimeException(); cbs.run(new Runnable() { public void run() { throw exception; } }, new Object(), future); assertSame("Exception should have been thrown from run()!", exception, future.getException().getCause()); }