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()));
});
});
}
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");
}
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()));
}
}
Aggregations