//ning === http://github.com/ning/async-http-client
@Test
public void doSimpleAsyncRequestTestWithNing() throws IOException, InterruptedException {
int iterations = 100;
final CountDownLatch latch = new CountDownLatch(iterations);
AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
for (int i = 1; i <= iterations; i++) {
asyncHttpClient.prepareGet("http://localhost:" + PORT + "/").
execute(new AsyncCompletionHandler<com.ning.http.client.Response>(){
@Override
public com.ning.http.client.Response onCompleted(com.ning.http.client.Response response) throws Exception{
String body = response.getResponseBody();
assertEquals(expectedPayload, body);
{
List<String> expectedHeaders = Arrays.asList(new String[] {"Server", "Date", "Content-Length", "Etag", "Connection"});
assertEquals(200, response.getStatusCode());
assertEquals(expectedHeaders.size(), response.getHeaders().size());
for (String header : expectedHeaders) {
assertTrue(response.getHeader(header) != null);
}
assertEquals(expectedPayload.length()+"", response.getHeader("Content-Length"));
}
latch.countDown();
return response;
}
@Override
public void onThrowable(Throwable t){
assertTrue(false);
}
});
}
latch.await(15 * 1000, TimeUnit.MILLISECONDS);
assertEquals(0, latch.getCount());
}