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 testDumpManyRequestsOnQueue() throws Exception { int sendRequests = 10000; AtomicInteger receivedRequests = new AtomicInteger(); vertx.createHttpServer(createBaseServerOptions()).requestHandler(r-> { r.response().end(); if (receivedRequests.incrementAndGet() == sendRequests) { testComplete(); } }).listen(onSuccess(s -> { HttpClientOptions ops = createBaseClientOptions() .setDefaultPort(DEFAULT_HTTP_PORT) .setPipelining(true) .setKeepAlive(true); HttpClient client = vertx.createHttpClient(ops); IntStream.range(0, sendRequests).forEach(x -> client.getNow("/", r -> {})); })); await(); }
@Test public void testPoolingNoKeepAliveAndPipelining() { try { vertx.createHttpClient(new HttpClientOptions().setKeepAlive(false).setPipelining(true)); fail(); } catch (IllegalStateException ignore) { } }
@Test public void httpClientWebsocketConnectionFailureHandlerShouldBeCalled() throws Exception { int port = 7867; HttpClient client = vertx.createHttpClient(); client.websocket(port, "localhost", "", websocket -> { websocket.handler(data -> { fail("connection should not succeed"); }); }, throwable -> testComplete()); await(); }
@Override public void start() throws Exception { HttpClientOptions options = new HttpClientOptions().setProtocolVersion(HttpVersion.HTTP_2); vertx.createHttpClient(options ).getNow(8080, "localhost", "/", resp -> { System.out.println("Got response " + resp.statusCode() + " with protocol " + resp.version()); resp.bodyHandler(body -> System.out.println("Got data " + body.toString("ISO-8859-1"))); }); } }
@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(); }
@Test public void testClientMakeRequestHttp2WithSSLWithoutAlpn() throws Exception { client.close(); client = vertx.createHttpClient(createBaseClientOptions().setUseAlpn(false)); try { client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI); fail(); } catch (IllegalArgumentException ignore) { // Expected } }
@Override public void start() throws Exception { // Note! in real-life you wouldn't often set trust all to true as it could leave you open to man in the middle attacks. vertx.createHttpClient(new HttpClientOptions().setSsl(true).setTrustAll(true)).getNow(4443, "localhost", "/", resp -> { System.out.println("Got response " + resp.statusCode()); resp.bodyHandler(body -> System.out.println("Got data " + body.toString("ISO-8859-1"))); }); } }
@Test public void testClientContextWithKeepAlive() throws Exception { client.close(); client = vertx.createHttpClient(new HttpClientOptions().setKeepAlive(true).setPipelining(false).setMaxPoolSize(1)); testClientContext(); }
@Test public void testExecuteBlockingException() throws Exception { vertx.executeBlocking(fut -> { try { vertx.createHttpClient(createHttp2ClientOptions()); fail("HttpClient should not work with HTTP_2 inside executeBlocking"); } catch(Exception ex) { assertEquals("Cannot use HttpClient with HTTP_2 in a worker", ex.getMessage()); complete(); } }, null); await(); }
@Override public void start() throws Exception { HttpClientRequest request = vertx.createHttpClient(new HttpClientOptions()).put(8080, "localhost", "/", resp -> { System.out.println("Got response " + resp.statusCode()); resp.bodyHandler(body -> System.out.println("Got data " + body.toString("ISO-8859-1"))); }); request.setChunked(true); for (int i = 0; i < 10; i++) { request.write("client-chunk-" + i); } request.end(); } }
@Test public void testClientContextWithPipelining() throws Exception { client.close(); client = vertx.createHttpClient(new HttpClientOptions().setKeepAlive(true).setPipelining(true).setMaxPoolSize(1)); testClientContext(); }
@Test public void testHttp() throws Exception { HttpClient client = vertx.createHttpClient(); HttpServer server = vertx.createHttpServer().requestHandler(req -> { req.response().end("foo"); }); try { CountDownLatch listenLatch = new CountDownLatch(1); server.listen(8080, "vertx.io", onSuccess(s -> { listenLatch.countDown(); })); awaitLatch(listenLatch); client.getNow(8080, "vertx.io", "/somepath", onSuccess(resp -> { Buffer buffer = Buffer.buffer(); resp.handler(buffer::appendBuffer); resp.endHandler(v -> { assertEquals(Buffer.buffer("foo"), buffer); testComplete(); }); })); await(); } finally { client.close(); server.close(); } }
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 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 testServerActualPortWhenSet() { server .requestHandler(request -> { request.response().end("hello"); }) .listen(ar -> { assertEquals(ar.result().actualPort(), DEFAULT_HTTP_PORT); vertx.createHttpClient(createBaseClientOptions()).getNow(ar.result().actualPort(), DEFAULT_HTTP_HOST, "/", onSuccess(response -> { assertEquals(response.statusCode(), 200); response.bodyHandler(body -> { assertEquals(body.toString("UTF-8"), "hello"); testComplete(); }); })); }); 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)); }
@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 testClientLogging() throws Exception { client.close(); client = vertx.createHttpClient(createBaseClientOptions().setLogActivity(true)); TestLoggerFactory factory = testLogging(); if (this instanceof Http1xTest) { assertTrue(factory.hasName("io.netty.handler.logging.LoggingHandler")); } else { assertTrue(factory.hasName("io.netty.handler.codec.http2.Http2FrameLogger")); } }