Search in sources :

Example 1 with EventCollectingHandler

use of org.asynchttpclient.test.EventCollectingHandler in project async-http-client by AsyncHttpClient.

the class BasicHttpTest method newConnectionEventsAreFired.

@Test
public void newConnectionEventsAreFired() throws Throwable {
    withClient().run(client -> {
        withServer(server).run(server -> {
            Request request = get(getTargetUrl()).build();
            EventCollectingHandler handler = new EventCollectingHandler();
            client.executeRequest(request, handler).get(3, SECONDS);
            handler.waitForCompletion(3, SECONDS);
            Object[] expectedEvents = new Object[] { CONNECTION_POOL_EVENT, HOSTNAME_RESOLUTION_EVENT, HOSTNAME_RESOLUTION_SUCCESS_EVENT, CONNECTION_OPEN_EVENT, CONNECTION_SUCCESS_EVENT, REQUEST_SEND_EVENT, HEADERS_WRITTEN_EVENT, STATUS_RECEIVED_EVENT, HEADERS_RECEIVED_EVENT, CONNECTION_OFFER_EVENT, COMPLETED_EVENT };
            assertEquals(handler.firedEvents.toArray(), expectedEvents, "Got " + Arrays.toString(handler.firedEvents.toArray()));
        });
    });
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) EventCollectingHandler(org.asynchttpclient.test.EventCollectingHandler) Test(org.testng.annotations.Test) HttpTest(org.asynchttpclient.testserver.HttpTest)

Example 2 with EventCollectingHandler

use of org.asynchttpclient.test.EventCollectingHandler in project async-http-client by AsyncHttpClient.

the class BasicHttpsTest method testNormalEventsFired.

@Test
public void testNormalEventsFired() throws Throwable {
    logger.debug(">>> testNormalEventsFired");
    withClient(config().setSslEngineFactory(createSslEngineFactory())).run(client -> withServer(server).run(server -> {
        EventCollectingHandler handler = new EventCollectingHandler();
        server.enqueueEcho();
        client.preparePost(getTargetUrl()).setBody("whatever").execute(handler).get(3, SECONDS);
        handler.waitForCompletion(3, SECONDS);
        Object[] expectedEvents = new Object[] { CONNECTION_POOL_EVENT, HOSTNAME_RESOLUTION_EVENT, HOSTNAME_RESOLUTION_SUCCESS_EVENT, CONNECTION_OPEN_EVENT, CONNECTION_SUCCESS_EVENT, TLS_HANDSHAKE_EVENT, TLS_HANDSHAKE_SUCCESS_EVENT, REQUEST_SEND_EVENT, HEADERS_WRITTEN_EVENT, STATUS_RECEIVED_EVENT, HEADERS_RECEIVED_EVENT, CONNECTION_OFFER_EVENT, COMPLETED_EVENT };
        assertEquals(handler.firedEvents.toArray(), expectedEvents, "Got " + Arrays.toString(handler.firedEvents.toArray()));
    }));
    logger.debug("<<< testNormalEventsFired");
}
Also used : AfterClass(org.testng.annotations.AfterClass) KeepAliveStrategy(org.asynchttpclient.channel.KeepAliveStrategy) Arrays(java.util.Arrays) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) BeforeClass(org.testng.annotations.BeforeClass) HttpServletResponse(javax.servlet.http.HttpServletResponse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) Assert.assertNotNull(org.testng.Assert.assertNotNull) EventCollectingHandler(org.asynchttpclient.test.EventCollectingHandler) TestUtils(org.asynchttpclient.test.TestUtils) ExecutionException(java.util.concurrent.ExecutionException) Dsl.config(org.asynchttpclient.Dsl.config) CONTENT_TYPE(io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE) HttpServer(org.asynchttpclient.testserver.HttpServer) HttpTest(org.asynchttpclient.testserver.HttpTest) SECONDS(java.util.concurrent.TimeUnit.SECONDS) EventCollectingHandler(org.asynchttpclient.test.EventCollectingHandler) Test(org.testng.annotations.Test) HttpTest(org.asynchttpclient.testserver.HttpTest)

Example 3 with EventCollectingHandler

use of org.asynchttpclient.test.EventCollectingHandler in project async-http-client by AsyncHttpClient.

the class ConnectionPoolTest method testPooledEventsFired.

@Test
public void testPooledEventsFired() throws Exception {
    RequestBuilder request = get("http://localhost:" + port1 + "/Test");
    try (AsyncHttpClient client = asyncHttpClient()) {
        EventCollectingHandler firstHandler = new EventCollectingHandler();
        client.executeRequest(request, firstHandler).get(3, TimeUnit.SECONDS);
        firstHandler.waitForCompletion(3, TimeUnit.SECONDS);
        EventCollectingHandler secondHandler = new EventCollectingHandler();
        client.executeRequest(request, secondHandler).get(3, TimeUnit.SECONDS);
        secondHandler.waitForCompletion(3, TimeUnit.SECONDS);
        Object[] expectedEvents = new Object[] { CONNECTION_POOL_EVENT, CONNECTION_POOLED_EVENT, REQUEST_SEND_EVENT, HEADERS_WRITTEN_EVENT, STATUS_RECEIVED_EVENT, HEADERS_RECEIVED_EVENT, CONNECTION_OFFER_EVENT, COMPLETED_EVENT };
        assertEquals(secondHandler.firedEvents.toArray(), expectedEvents, "Got " + Arrays.toString(secondHandler.firedEvents.toArray()));
    }
}
Also used : EventCollectingHandler(org.asynchttpclient.test.EventCollectingHandler) Test(org.testng.annotations.Test)

Aggregations

EventCollectingHandler (org.asynchttpclient.test.EventCollectingHandler)3 Test (org.testng.annotations.Test)3 HttpTest (org.asynchttpclient.testserver.HttpTest)2 CONTENT_TYPE (io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE)1 Arrays (java.util.Arrays)1 ExecutionException (java.util.concurrent.ExecutionException)1 SECONDS (java.util.concurrent.TimeUnit.SECONDS)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Dsl.config (org.asynchttpclient.Dsl.config)1 KeepAliveStrategy (org.asynchttpclient.channel.KeepAliveStrategy)1 TestUtils (org.asynchttpclient.test.TestUtils)1 HttpServer (org.asynchttpclient.testserver.HttpServer)1 Assert.assertEquals (org.testng.Assert.assertEquals)1 Assert.assertNotNull (org.testng.Assert.assertNotNull)1 AfterClass (org.testng.annotations.AfterClass)1 BeforeClass (org.testng.annotations.BeforeClass)1