@Test(groups = { "standalone", "default_provider" })
public void closeConnectionTest() throws Exception {
AsyncHttpClient c = getAsyncHttpClient(null);
try {
Response r = c.prepareGet(getTargetUrl()).execute(new AsyncHandler<Response>() {
private Response.ResponseBuilder builder = new Response.ResponseBuilder();
public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception {
builder.accumulate(content);
return STATE.CONTINUE;
}
public void onThrowable(Throwable t) {
}
public STATE onBodyPartReceived(HttpResponseBodyPart content) throws Exception {
builder.accumulate(content);
if (content.isLast()) {
content.markUnderlyingConnectionAsToBeClosed();
}
return STATE.CONTINUE;
}
public STATE onStatusReceived(HttpResponseStatus responseStatus) throws Exception {
builder.accumulate(responseStatus);
return STATE.CONTINUE;
}
public Response onCompleted() throws Exception {
return builder.build();
}
}).get();
assertNotNull(r);
assertEquals(r.getStatusCode(), 200);
} finally {
c.close();
}
}