Refine search
public void setUp() throws Exception { super.setUp(); client = vertx.createHttpClient(new HttpClientOptions()); }
@Test public void testDummyHttpClientMetrics() { HttpClient client = vertx.createHttpClient(new HttpClientOptions()); assertFalse(client.isMetricsEnabled()); }
@Test public void testMultipleRecursiveCallsAndPipelining() throws Exception { int sendRequests = 100; AtomicInteger receivedRequests = new AtomicInteger(); server.requestHandler(x -> { x.response().end("hello"); }) .listen(8080, r -> { if (r.succeeded()) { HttpClient client = vertx.createHttpClient(new HttpClientOptions() .setKeepAlive(true) .setPipelining(true) .setDefaultPort(8080) ); IntStream.range(0, 5).forEach(i -> recursiveCall(client, receivedRequests, sendRequests)); } }); await(); }
@Override public void setUp() throws Exception { super.setUp(); client = vertx.createHttpClient(new HttpClientOptions()); server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT).setHost(DEFAULT_HTTP_HOST).setHandle100ContinueAutomatically(true)); }
public void setUp() throws Exception { super.setUp(); client = vertx.createHttpClient(new HttpClientOptions().setTryUseCompression(true)); clientraw = vertx.createHttpClient(new HttpClientOptions().setTryUseCompression(false)); HttpServerOptions serverOpts = new HttpServerOptions() .setPort(DEFAULT_HTTP_PORT) .setCompressionSupported(true); // server = vertx.createHttpServer(); serverWithMinCompressionLevel = vertx.createHttpServer(serverOpts.setPort(DEFAULT_HTTP_PORT - 1).setCompressionLevel(1)); serverWithMaxCompressionLevel = vertx.createHttpServer(serverOpts.setPort(DEFAULT_HTTP_PORT + 1).setCompressionLevel(9)); }
@Test public void testPoolingNoKeepAliveAndPipelining() { try { vertx.createHttpClient(new HttpClientOptions().setKeepAlive(false).setPipelining(true)); fail(); } catch (IllegalStateException ignore) { } }
@Override public void setUp() throws Exception { super.setUp(); client = vertx.createHttpClient(new HttpClientOptions()); server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT).setHost(DEFAULT_HTTP_HOST).setHandle100ContinueAutomatically(true)); }
@Override public void setUp() throws Exception { eventLoopGroups.clear(); super.setUp(); clientOptions = new HttpClientOptions(). setUseAlpn(true). setSsl(true). setTrustStoreOptions(Trust.SERVER_JKS.get()). setProtocolVersion(HttpVersion.HTTP_2); client = vertx.createHttpClient(clientOptions); }
@Override public void start() throws Exception { HttpClient client = vertx.createHttpClient(new HttpClientOptions().setMaxPoolSize(n)); for (int i = 0;i < n;i++) { AtomicBoolean responseReceived = new AtomicBoolean(); client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> { try { Thread.sleep(150); } catch (InterruptedException e) { fail(e); } responseReceived.set(true); // Complete later, if some timeout tasks have been queued, this will be executed after vertx.runOnContext(v -> complete()); }).exceptionHandler(err -> { fail("Was not expecting to get a timeout after the response is received"); }).setTimeout(500).end(); } } }, new DeploymentOptions().setWorker(true));
@Test public void testConnectionWindowSize() throws Exception { ServerBootstrap bootstrap = createH2Server((decoder, encoder) -> new Http2EventAdapter() { @Override public void onWindowUpdateRead(ChannelHandlerContext ctx, int streamId, int windowSizeIncrement) throws Http2Exception { vertx.runOnContext(v -> { assertEquals(65535, windowSizeIncrement); testComplete(); }); } }); ChannelFuture s = bootstrap.bind(DEFAULT_HTTPS_HOST, DEFAULT_HTTPS_PORT).sync(); client.close(); client = vertx.createHttpClient(new HttpClientOptions(clientOptions).setHttp2ConnectionWindowSize(65535 * 2)); client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> { }).end(); await(); }
@Test public void testClientContextWithKeepAlive() throws Exception { client.close(); client = vertx.createHttpClient(new HttpClientOptions().setKeepAlive(true).setPipelining(false).setMaxPoolSize(1)); testClientContext(); }
@Test public void testClientContextWithPipelining() throws Exception { client.close(); client = vertx.createHttpClient(new HttpClientOptions().setKeepAlive(true).setPipelining(true).setMaxPoolSize(1)); testClientContext(); }
@Test public void testClientWebsocketIdleTimeout() { client.close(); client = vertx.createHttpClient(new HttpClientOptions().setIdleTimeout(1)); server.websocketHandler(ws -> {}).listen(ar -> { client.websocket(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/", ws -> { ws.closeHandler(v -> testComplete()); }); }); await(); }
@Test public void testCrlInvalidPath() throws Exception { HttpClientOptions clientOptions = new HttpClientOptions(); clientOptions.setTrustOptions(Trust.SERVER_PEM_ROOT_CA.get()); clientOptions.setSsl(true); clientOptions.addCrlPath("/invalid.pem"); try { vertx.createHttpClient(clientOptions); fail("Was expecting a failure"); } catch (VertxException e) { assertNotNull(e.getCause()); assertEquals(NoSuchFileException.class, e.getCause().getCause().getClass()); } }
@Test public void testSendOpenRangeFileFromClasspath() { vertx.createHttpServer(new HttpServerOptions().setPort(8080)).requestHandler(res -> { res.response().sendFile("webroot/somefile.html", 6); }).listen(onSuccess(res -> { vertx.createHttpClient(new HttpClientOptions()).request(HttpMethod.GET, 8080, "localhost", "/", onSuccess(resp -> { resp.bodyHandler(buff -> { assertTrue(buff.toString().startsWith("<body>blah</body></html>")); testComplete(); }); })).end(); })); await(); }
@Test public void testSendFileFromClasspath() { vertx.createHttpServer(new HttpServerOptions().setPort(8080)).requestHandler(res -> { res.response().sendFile(webRoot + "/somefile.html"); }).listen(onSuccess(res -> { vertx.createHttpClient(new HttpClientOptions()).request(HttpMethod.GET, 8080, "localhost", "/", onSuccess(resp -> { resp.bodyHandler(buff -> { assertTrue(buff.toString().startsWith("<html><body>blah</body></html>")); testComplete(); }); })).end(); })); await(); }
@Test public void testClientOptionsCopiedBeforeUse() { client.close(); server.requestHandler(req -> { req.response().end(); }); server.listen(ar -> { assertTrue(ar.succeeded()); HttpClientOptions options = new HttpClientOptions(); client = vertx.createHttpClient(options); // Now change something - but server should ignore this options.setSsl(true); client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/uri", onSuccess(res -> { assertEquals(200, res.statusCode()); testComplete(); })).end(); }); await(); }
@Test public void testPerPeerPooling() throws Exception { client.close(); client = vertx.createHttpClient(new HttpClientOptions() .setMaxPoolSize(1) .setKeepAlive(true) .setPipelining(false)); testPerXXXPooling((i, handler) -> client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", handler).setHost("host" + i + ":8080"), HttpServerRequest::host); }
@Test public void testSendRangeFileFromClasspath() { vertx.createHttpServer(new HttpServerOptions().setPort(8080)).requestHandler(res -> { res.response().sendFile("webroot/somefile.html", 6, 6); }).listen(onSuccess(res -> { vertx.createHttpClient(new HttpClientOptions()).request(HttpMethod.GET, 8080, "localhost", "/", onSuccess(resp -> { resp.bodyHandler(buff -> { assertEquals("<body>", buff.toString()); testComplete(); }); })).end(); })); await(); }
@Test public void testUnknownContentLengthIsSetToZeroWithHTTP_1_0() throws Exception { server.requestHandler(req -> { req.response().write("Some-String").end(); }); startServer(); client.close(); client = vertx.createHttpClient(new HttpClientOptions().setProtocolVersion(HttpVersion.HTTP_1_0)); client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onSuccess(resp -> { assertNull(resp.getHeader("Content-Length")); testComplete(); })); await(); }