use of org.jdeferred.DoneCallback in project async-http-client by AsyncHttpClient.
the class AsyncHttpTest method testPromiseAdapter.
public void testPromiseAdapter() throws IOException {
final CountDownLatch latch = new CountDownLatch(1);
final AtomicInteger successCount = new AtomicInteger();
final AtomicInteger progressCount = new AtomicInteger();
try (AsyncHttpClient client = asyncHttpClient()) {
Promise<Response, Throwable, HttpProgress> p1 = AsyncHttpDeferredObject.promise(client.prepareGet("http://gatling.io"));
p1.done(new DoneCallback<Response>() {
@Override
public void onDone(Response response) {
try {
assertEquals(response.getStatusCode(), 200);
successCount.incrementAndGet();
} finally {
latch.countDown();
}
}
}).progress(new ProgressCallback<HttpProgress>() {
@Override
public void onProgress(HttpProgress progress) {
progressCount.incrementAndGet();
}
});
latch.await();
assertTrue(progressCount.get() > 0);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
Aggregations