Skip to content

Instantly share code, notes, and snippets.

@jfarcand
Created October 26, 2010 16:45
Show Gist options
  • Save jfarcand/647267 to your computer and use it in GitHub Desktop.
Save jfarcand/647267 to your computer and use it in GitHub Desktop.
@Test(groups = {"standalone", "async"})
public void asyncConnectInvalidHostFuture() throws Throwable {
AsyncHttpClient c = new AsyncHttpClient();
try {
Response response = c.preparePost("http://aninvalidhost:9999/").execute(new AsyncCompletionHandlerAdapter() {
/* @Override */
public void onThrowable(Throwable t) {
t.printStackTrace();
}
}).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());
}
}
}
@mickyp
Copy link

mickyp commented Oct 26, 2010

@test(groups = {"standalone", "async"})
public void asyncConnectInvalidHostFuture() throws Throwable {

    AsyncHttpClient c = new AsyncHttpClient();
    try {
         for (int i = 0; i <8; ++i){
            Response response = c.preparePost("http://aninvalidhost:9999/").execute(new AsyncCompletionHandlerAdapter() {
                /* @Override */
                public void onThrowable(Throwable t) {
                    t.printStackTrace();
                }
            });
           // never call get() to avoid waiting
           //.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());
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment