logger.info("{}: running test: testProgrammaticResume", getClass().getSimpleName());
AsyncHttpClient c = new AsyncHttpClient();
final AtomicReference<String> location = new AtomicReference<String>();
final AtomicReference<String> response = new AtomicReference<String>("");
final CountDownLatch latch = new CountDownLatch(1);
final CountDownLatch locationLatch = new CountDownLatch(1);
try {
c.prepareGet(urlTarget + "/suspendAndResume").execute(new AsyncHandler<String>() {
public void onThrowable(Throwable throwable) {
fail("onThrowable", throwable);
}
public STATE onBodyPartReceived(HttpResponseBodyPart bp) throws Exception {
logger.info("body part byte string: {}", new String(bp.getBodyPartBytes()));
response.set(response.get() + new String(bp.getBodyPartBytes()));
locationLatch.countDown();
return STATE.CONTINUE;
}
public STATE onStatusReceived(HttpResponseStatus hs) throws Exception {
return STATE.CONTINUE;
}
public STATE onHeadersReceived(HttpResponseHeaders rh) throws Exception {
location.set(rh.getHeaders().getFirstValue("Location"));
return STATE.CONTINUE;
}
public String onCompleted() throws Exception {
latch.countDown();
return "";
}
});
locationLatch.await(5, TimeUnit.SECONDS);
Response r = c.prepareGet(location.get()).execute().get(10, TimeUnit.SECONDS);
latch.await(20, TimeUnit.SECONDS);
assertNotNull(r);
assertEquals(r.getStatusCode(), 200);