@Test(groups = { "standalone", "default_provider" })
public void testMultipleEntityHeaders() throws IOException, ExecutionException, TimeoutException, InterruptedException {
final String[] clHeaders = new String[] { null, null };
AsyncHttpClient ahc = getAsyncHttpClient(null);
try {
Request req = new RequestBuilder("GET").setUrl("http://localhost:" + port1 + "/MultiEnt").build();
final CountDownLatch latch = new CountDownLatch(1);
ahc.executeRequest(req, new AsyncHandler<Void>() {
public void onThrowable(Throwable t) {
t.printStackTrace(System.out);
}
public STATE onBodyPartReceived(HttpResponseBodyPart objectHttpResponseBodyPart) throws Exception {
return STATE.CONTINUE;
}
public STATE onStatusReceived(HttpResponseStatus objectHttpResponseStatus) throws Exception {
return STATE.CONTINUE;
}
public STATE onHeadersReceived(HttpResponseHeaders response) throws Exception {
try {
int i = 0;
for (String header : response.getHeaders().get("Content-Length")) {
clHeaders[i++] = header;
}
} finally {
latch.countDown();
}
return STATE.CONTINUE;
}
public Void onCompleted() throws Exception {
return null;
}
}).get(3, TimeUnit.SECONDS);
if (!latch.await(2, TimeUnit.SECONDS)) {
fail("Time out");
}
assertNotNull(clHeaders[0]);
assertNotNull(clHeaders[1]);
// We can predict the order
try {
assertEquals(clHeaders[0], "2");
assertEquals(clHeaders[1], "1");
} catch (Throwable ex) {
assertEquals(clHeaders[0], "1");
assertEquals(clHeaders[1], "2");
}
} finally {
ahc.close();
}
}