Skip to content

Instantly share code, notes, and snippets.

@jfarcand
Created October 28, 2010 13:33
Show Gist options
  • Save jfarcand/651348 to your computer and use it in GitHub Desktop.
Save jfarcand/651348 to your computer and use it in GitHub Desktop.
@Test(groups = {"standalone", "async"})
public void asyncConnectInvalidFuture() throws Throwable {
AsyncHttpClient c = new AsyncHttpClient();
final AtomicInteger count = new AtomicInteger();
for (int i = 0; i < 20; i++) {
try {
Response response = c.preparePost("http://127.0.0.1:9999/").execute(new AsyncCompletionHandlerAdapter() {
/* @Override */
public void onThrowable(Throwable t) {
count.incrementAndGet();
}
}).get();
assertNull(response, "Should have thrown ExecutionException");
} catch (ExecutionException ex) {
Throwable cause = ex.getCause();
if (!(cause instanceof ConnectException)) {
fail("Should have been caused by ConnectException, not by " + cause.getClass().getName());
}
}
}
assertEquals(count.get(), 20);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment