Search in sources :

Example 11 with AsyncHttpClient

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();
    }
}
Also used : Response(org.asynchttpclient.Response) AsyncHttpDeferredObject(org.asynchttpclient.extras.jdeferred.AsyncHttpDeferredObject) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HttpProgress(org.asynchttpclient.extras.jdeferred.HttpProgress) CountDownLatch(java.util.concurrent.CountDownLatch) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) MultipleResults(org.jdeferred.multiple.MultipleResults)

Example 12 with AsyncHttpClient

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));
    }
}
Also used : AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) DefaultAsyncHttpClient(org.asynchttpclient.DefaultAsyncHttpClient) Test(org.testng.annotations.Test)

Example 13 with AsyncHttpClient

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");
}
Also used : AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) DefaultAsyncHttpClient(org.asynchttpclient.DefaultAsyncHttpClient) Test(org.testng.annotations.Test)

Example 14 with AsyncHttpClient

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));
    }
}
Also used : AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) DefaultAsyncHttpClient(org.asynchttpclient.DefaultAsyncHttpClient) Test(org.testng.annotations.Test)

Example 15 with AsyncHttpClient

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);
    }
}
Also used : DefaultAsyncHttpClient(org.asynchttpclient.DefaultAsyncHttpClient) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) DefaultAsyncHttpClient(org.asynchttpclient.DefaultAsyncHttpClient) Test(org.testng.annotations.Test)

Aggregations

AsyncHttpClient (org.asynchttpclient.AsyncHttpClient)146 Test (org.testng.annotations.Test)119 Response (org.asynchttpclient.Response)71 AbstractBasicTest (org.asynchttpclient.AbstractBasicTest)66 HttpServletResponse (javax.servlet.http.HttpServletResponse)40 CountDownLatch (java.util.concurrent.CountDownLatch)31 DefaultAsyncHttpClient (org.asynchttpclient.DefaultAsyncHttpClient)26 AtomicReference (java.util.concurrent.atomic.AtomicReference)23 RequestBuilder (org.asynchttpclient.RequestBuilder)16 IOException (java.io.IOException)14 RouteBuilder (org.apache.camel.builder.RouteBuilder)14 ExecutionException (java.util.concurrent.ExecutionException)13 Request (org.asynchttpclient.Request)13 WebSocket (org.asynchttpclient.ws.WebSocket)12 Test (org.junit.Test)11 AsyncHttpClientConfig (org.asynchttpclient.AsyncHttpClientConfig)10 File (java.io.File)9 WebSocketTextListener (org.asynchttpclient.ws.WebSocketTextListener)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7