@Test public void testServerConnectionHandler() throws Exception { AtomicInteger status = new AtomicInteger(); AtomicReference<HttpConnection> connRef = new AtomicReference<>(); server.connectionHandler(conn -> { assertEquals(0, status.getAndIncrement()); assertNull(connRef.getAndSet(conn)); }); server.requestHandler(req -> { assertEquals(1, status.getAndIncrement()); assertSame(connRef.get(), req.connection()); req.response().end(); }); CountDownLatch listenLatch = new CountDownLatch(1); server.listen(onSuccess(s -> listenLatch.countDown())); awaitLatch(listenLatch); client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp -> { testComplete(); }); await(); }
int totalRequests = maxRequests + maxConcurrency; Set<HttpConnection> serverConns = new HashSet<>(); server.connectionHandler(conn -> { serverConns.add(conn); assertTrue(serverConns.size() <= poolSize);
@Test public void testTooLongContentInHttpServerRequest() throws Exception { server.requestHandler(req -> { req.response().end(); }); server.connectionHandler(conn -> { conn.exceptionHandler(error -> { assertEquals(IllegalArgumentException.class, error.getClass()); testComplete(); }); }); startServer(); NetClient client = vertx.createNetClient(); try { client.connect(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, onSuccess(so -> { so.write("POST / HTTP/1.1\r\nContent-Length: 4\r\n\r\ntoolong\r\n"); })); await(); } finally { client.close(); } } @Test
@Test public void testServerConnectionExceptionHandler() throws Exception { server.connectionHandler(conn -> { conn.exceptionHandler(err -> { assertTrue(err instanceof TooLongFrameException); testComplete(); }); }); server.requestHandler(req -> { req.response().end(); }); CountDownLatch listenLatch = new CountDownLatch(1); server.listen(onSuccess(s -> listenLatch.countDown())); awaitLatch(listenLatch); client.close(); client = vertx.createHttpClient(new HttpClientOptions().setMaxPoolSize(1)); client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp1 -> { HttpClientRequest req = client.post(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp2 -> { }); req.putHeader("the_header", TestUtils.randomAlphaString(10000)); req.sendHead(); }); await(); }
@Test public void testServerShutdownConnection() throws Exception { waitFor(2); server.connectionHandler(HttpConnection::shutdown); server.requestHandler(req -> fail()); startServer(); AtomicInteger count = new AtomicInteger(); HttpClientRequest req1 = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", onFailure(err -> { if (count.getAndIncrement() == 0) { complete(); } })); req1.connectionHandler(conn -> { Context ctx = Vertx.currentContext(); conn.goAwayHandler(ga -> { assertOnIOContext(ctx); complete(); }); }); req1.end(); await(); }
waitFor(2); AtomicInteger serverStatus = new AtomicInteger(); server.connectionHandler(conn -> { if (serverStatus.getAndIncrement() == 0) { conn.goAwayHandler(ga -> {
@Test public void testSendPing() throws Exception { waitFor(2); Buffer expected = TestUtils.randomBuffer(8); Context ctx = vertx.getOrCreateContext(); server.close(); server.connectionHandler(conn -> { conn.pingHandler(data -> { assertEquals(expected, data); complete(); }); }); server.requestHandler(req -> {}); startServer(ctx); HttpClientRequest req = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> { }); req.connectionHandler(conn -> { conn.ping(expected, ar -> { assertTrue(ar.succeeded()); Buffer buff = ar.result(); assertEquals(expected, buff); complete(); }); }); req.end(); await(); }
@Test public void testInitialMaxConcurrentStreamZero() throws Exception { server.close(); server = vertx.createHttpServer(createBaseServerOptions().setInitialSettings(new Http2Settings().setMaxConcurrentStreams(0))); server.requestHandler(req -> { req.response().end(); }); server.connectionHandler(conn -> { vertx.setTimer(500, id -> { conn.updateSettings(new Http2Settings().setMaxConcurrentStreams(10)); }); }); startServer(); client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> { testComplete(); }).connectionHandler(conn -> { assertEquals(10, conn.remoteSettings().getMaxConcurrentStreams()); }).setTimeout(10000).exceptionHandler(this::fail).end(); await(); }
@Test public void testReceivePing() throws Exception { Buffer expected = TestUtils.randomBuffer(8); Context ctx = vertx.getOrCreateContext(); server.close(); server.connectionHandler(conn -> { conn.ping(expected, ar -> { }); }); server.requestHandler(req -> {}); startServer(ctx); HttpClientRequest req = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> { }); req.connectionHandler(conn -> { conn.pingHandler(data -> { assertEquals(expected, data); complete(); }); }); req.end(); await(); }
server = vertx.createHttpServer(serverOptions); Context otherContext = vertx.getOrCreateContext(); server.connectionHandler(conn -> { otherContext.runOnContext(v -> { conn.updateSettings(expectedSettings);
server.connectionHandler(conn -> complete()); AtomicInteger count = new AtomicInteger(); server.exceptionHandler(err -> {
req.response().end(); }); }).connectionHandler(conn -> { io.vertx.core.http.Http2Settings initialRemoteSettings = conn.remoteSettings(); assertEquals(initialSettings.isPushEnabled(), initialRemoteSettings.isPushEnabled());
@Test public void testServerConnectionHandler() throws Exception { AtomicInteger status = new AtomicInteger(); AtomicReference<HttpConnection> connRef = new AtomicReference<>(); server.connectionHandler(conn -> { assertEquals(0, status.getAndIncrement()); assertNull(connRef.getAndSet(conn)); }); server.requestHandler(req -> { assertEquals(1, status.getAndIncrement()); assertSame(connRef.get(), req.connection()); req.response().end(); }); CountDownLatch listenLatch = new CountDownLatch(1); server.listen(onSuccess(s -> listenLatch.countDown())); awaitLatch(listenLatch); client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp -> { testComplete(); }); await(); }
@Test public void testTooLongContentInHttpServerRequest() throws Exception { server.requestHandler(req -> { req.response().end(); }); server.connectionHandler(conn -> { conn.exceptionHandler(error -> { assertEquals(IllegalArgumentException.class, error.getClass()); testComplete(); }); }); startServer(); NetClient client = vertx.createNetClient(); try { client.connect(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, onSuccess(so -> { so.write("POST / HTTP/1.1\r\nContent-Length: 4\r\n\r\ntoolong\r\n"); })); await(); } finally { client.close(); } } @Test
@Test public void testServerConnectionExceptionHandler() throws Exception { server.connectionHandler(conn -> { conn.exceptionHandler(err -> { assertTrue(err instanceof TooLongFrameException); testComplete(); }); }); server.requestHandler(req -> { req.response().end(); }); CountDownLatch listenLatch = new CountDownLatch(1); server.listen(onSuccess(s -> listenLatch.countDown())); awaitLatch(listenLatch); client.close(); client = vertx.createHttpClient(new HttpClientOptions().setMaxPoolSize(1)); client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp1 -> { HttpClientRequest req = client.post(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp2 -> { }); req.putHeader("the_header", TestUtils.randomAlphaString(10000)); req.sendHead(); }); await(); }
@Test public void testServerShutdownConnection() throws Exception { waitFor(2); server.connectionHandler(HttpConnection::shutdown); server.requestHandler(req -> fail()); startServer(); HttpClientRequest req1 = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath"); req1.connectionHandler(conn -> { Context ctx = Vertx.currentContext(); conn.goAwayHandler(ga -> { assertOnIOContext(ctx); complete(); }); }); AtomicInteger count = new AtomicInteger(); req1.exceptionHandler(err -> { if (count.getAndIncrement() == 0) { complete(); } }); req1.handler(resp -> { fail(); }); req1.end(); await(); }
@Test public void testSendPing() throws Exception { waitFor(2); Buffer expected = TestUtils.randomBuffer(8); Context ctx = vertx.getOrCreateContext(); server.close(); server.connectionHandler(conn -> { conn.pingHandler(data -> { assertEquals(expected, data); complete(); }); }); server.requestHandler(req -> {}); startServer(ctx); HttpClientRequest req = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> { }); req.connectionHandler(conn -> { conn.ping(expected, ar -> { assertTrue(ar.succeeded()); Buffer buff = ar.result(); assertEquals(expected, buff); complete(); }); }); req.end(); await(); }
@Test public void testReceivePing() throws Exception { Buffer expected = TestUtils.randomBuffer(8); Context ctx = vertx.getOrCreateContext(); server.close(); server.connectionHandler(conn -> { conn.ping(expected, ar -> { }); }); server.requestHandler(req -> {}); startServer(ctx); HttpClientRequest req = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> { }); req.connectionHandler(conn -> { conn.pingHandler(data -> { assertEquals(expected, data); complete(); }); }); req.end(); await(); }
@Test public void testInitialMaxConcurrentStreamZero() throws Exception { server.close(); server = vertx.createHttpServer(createBaseServerOptions().setInitialSettings(new Http2Settings().setMaxConcurrentStreams(0))); server.requestHandler(req -> { req.response().end(); }); server.connectionHandler(conn -> { vertx.setTimer(500, id -> { conn.updateSettings(new Http2Settings().setMaxConcurrentStreams(10)); }); }); startServer(); client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> { testComplete(); }).connectionHandler(conn -> { assertEquals(10, conn.remoteSettings().getMaxConcurrentStreams()); }).setTimeout(10000).exceptionHandler(this::fail).end(); await(); }
server = vertx.createHttpServer(serverOptions); Context otherContext = vertx.getOrCreateContext(); server.connectionHandler(conn -> { otherContext.runOnContext(v -> { conn.updateSettings(expectedSettings);