use of org.asynchttpclient.AsyncHttpClient in project async-http-client by AsyncHttpClient.
the class AsyncHttpTest method testMultiplePromiseAdapter.
public void testMultiplePromiseAdapter() throws IOException {
final CountDownLatch latch = new CountDownLatch(1);
final AtomicInteger successCount = new AtomicInteger();
try (AsyncHttpClient client = asyncHttpClient()) {
Promise<Response, Throwable, HttpProgress> p1 = AsyncHttpDeferredObject.promise(client.prepareGet("http://gatling.io"));
Promise<Response, Throwable, HttpProgress> p2 = AsyncHttpDeferredObject.promise(client.prepareGet("http://www.google.com"));
AsyncHttpDeferredObject deferredRequest = new AsyncHttpDeferredObject(client.prepareGet("http://jdeferred.org"));
deferredManager.when(p1, p2, deferredRequest).then(new DoneCallback<MultipleResults>() {
@Override
public void onDone(MultipleResults result) {
try {
assertEquals(result.size(), 3);
assertEquals(Response.class.cast(result.get(0).getResult()).getStatusCode(), 200);
assertEquals(Response.class.cast(result.get(1).getResult()).getStatusCode(), 200);
assertEquals(Response.class.cast(result.get(2).getResult()).getStatusCode(), 200);
successCount.incrementAndGet();
} finally {
latch.countDown();
}
}
});
latch.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
use of org.asynchttpclient.AsyncHttpClient in project async-http-client by AsyncHttpClient.
the class AbstractAsyncHttpClientFactoryTest method testFactoryWithSystemProperty.
// ==================================================================================================================================
/**
* If the class is specified via a system property then that class should be returned
*/
// ===================================================================================================================================
@Test(groups = "standalone")
public void testFactoryWithSystemProperty() throws IOException {
System.setProperty(AsyncImplHelper.ASYNC_HTTP_CLIENT_IMPL_SYSTEM_PROPERTY, TEST_CLIENT_CLASS_NAME);
AsyncHttpClientConfigHelper.reloadProperties();
try (AsyncHttpClient ahc = AsyncHttpClientFactory.getAsyncHttpClient()) {
Assert.assertTrue(ahc.getClass().equals(TestAsyncHttpClient.class));
}
}
use of org.asynchttpclient.AsyncHttpClient in project async-http-client by AsyncHttpClient.
the class AbstractAsyncHttpClientFactoryTest method testGetAsyncHttpClientProviderWithBadAsyncHttpClient.
@Test(groups = "standalone")
public void testGetAsyncHttpClientProviderWithBadAsyncHttpClient() throws IOException {
System.setProperty(AsyncImplHelper.ASYNC_HTTP_CLIENT_IMPL_SYSTEM_PROPERTY, BAD_CLIENT_CLASS_NAME);
AsyncHttpClientConfigHelper.reloadProperties();
try (AsyncHttpClient ahc = AsyncHttpClientFactory.getAsyncHttpClient()) {
//
} catch (AsyncHttpClientImplException e) {
assertException(e);
}
// Assert.fail("AsyncHttpClientImplException should have been thrown before this point");
}
use of org.asynchttpclient.AsyncHttpClient in project async-http-client by AsyncHttpClient.
the class AbstractAsyncHttpClientFactoryTest method testGetAsyncHttpClientConfigWithSystemProperty.
@Test(groups = "standalone")
public void testGetAsyncHttpClientConfigWithSystemProperty() throws IOException {
System.setProperty(AsyncImplHelper.ASYNC_HTTP_CLIENT_IMPL_SYSTEM_PROPERTY, TEST_CLIENT_CLASS_NAME);
AsyncHttpClientConfigHelper.reloadProperties();
try (AsyncHttpClient ahc = AsyncHttpClientFactory.getAsyncHttpClient()) {
Assert.assertTrue(ahc.getClass().equals(TestAsyncHttpClient.class));
}
}
use of org.asynchttpclient.AsyncHttpClient in project async-http-client by AsyncHttpClient.
the class AbstractAsyncHttpClientFactoryTest method testGetAsyncHttpClient.
/**
* If the property is not found via the system property or properties file the default instance of AsyncHttpClient should be returned.
*/
// ================================================================================================================
@Test(groups = "standalone")
public void testGetAsyncHttpClient() throws Exception {
try (AsyncHttpClient asyncHttpClient = AsyncHttpClientFactory.getAsyncHttpClient()) {
Assert.assertTrue(asyncHttpClient.getClass().equals(DefaultAsyncHttpClient.class));
assertClientWorks(asyncHttpClient);
}
}
Aggregations