private void testClientConnectionHandler(boolean local, boolean global) throws Exception { server.requestHandler(req -> { req.response().end(); }); CountDownLatch listenLatch = new CountDownLatch(1); server.listen(onSuccess(s -> listenLatch.countDown())); awaitLatch(listenLatch); AtomicInteger status = new AtomicInteger(); Handler<HttpConnection> handler = conn -> status.getAndIncrement(); if (global) { client.connectionHandler(handler); } HttpClientRequest req = client.post(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp -> { assertEquals((local ? 1 : 0) + (global ? 1 : 0), status.getAndIncrement()); testComplete(); }); if (local) { req.connectionHandler(handler); } req.end(); await(); }
client = vertx.createHttpClient(new HttpClientOptions().setMaxPoolSize(1).setPipelining(true).setKeepAlive(true)); AtomicInteger connCount = new AtomicInteger(); client.connectionHandler(conn -> connCount.incrementAndGet()); HttpClientRequestImpl req = (HttpClientRequestImpl) client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/first", resp -> { fail();
private void testClientConnectionHandler(boolean local, boolean global) throws Exception { server.requestHandler(req -> { req.response().end(); }); CountDownLatch listenLatch = new CountDownLatch(1); server.listen(onSuccess(s -> listenLatch.countDown())); awaitLatch(listenLatch); AtomicInteger status = new AtomicInteger(); Handler<HttpConnection> handler = conn -> status.getAndIncrement(); if (global) { client.connectionHandler(handler); } HttpClientRequest req = client.post(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp -> { assertEquals((local ? 1 : 0) + (global ? 1 : 0), status.getAndIncrement()); testComplete(); }); if (local) { req.connectionHandler(handler); } req.end(); await(); }
/** * Set a connection handler for the client. This handler is called when a new connection is established. * @param handler * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.http.HttpClient connectionHandler(Handler<io.vertx.rxjava.core.http.HttpConnection> handler) { delegate.connectionHandler(new Handler<io.vertx.core.http.HttpConnection>() { public void handle(io.vertx.core.http.HttpConnection event) { handler.handle(io.vertx.rxjava.core.http.HttpConnection.newInstance(event)); } }); return this; }
/** * Set a connection handler for the client. This handler is called when a new connection is established. * @param handler * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.http.HttpClient connectionHandler(Handler<io.vertx.rxjava.core.http.HttpConnection> handler) { delegate.connectionHandler(new Handler<io.vertx.core.http.HttpConnection>() { public void handle(io.vertx.core.http.HttpConnection event) { handler.handle(io.vertx.rxjava.core.http.HttpConnection.newInstance(event)); } }); return this; }
client = vertx.createHttpClient(new HttpClientOptions().setMaxPoolSize(1).setPipelining(true).setKeepAlive(true)); AtomicInteger connCount = new AtomicInteger(); client.connectionHandler(conn -> connCount.incrementAndGet()); HttpClientRequest req = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/first", resp -> { fail();