@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(); }
assertEquals(options, options.setIdleTimeout(10)); assertEquals(options, options.setIdleTimeoutUnit(TimeUnit.MILLISECONDS)); assertEquals(10, options.getIdleTimeout()); assertEquals(TimeUnit.MILLISECONDS, options.getIdleTimeoutUnit()); assertIllegalArgumentException(() -> options.setIdleTimeout(-1));
@Test public void testDisableIdleTimeoutInPool() throws Exception { server.requestHandler(req -> { req.response().end(); }); startServer(); client.close(); client = vertx.createHttpClient(createBaseClientOptions() .setIdleTimeout(1) .setMaxPoolSize(1) .setKeepAliveTimeout(10) ); client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onSuccess(resp -> { resp.endHandler(v1 -> { AtomicBoolean closed = new AtomicBoolean(); resp.request().connection().closeHandler(v2 -> { closed.set(true); }); vertx.setTimer(2000, id -> { assertFalse(closed.get()); testComplete(); }); }); })); await(); }
startServer(); client.close(); client = vertx.createHttpClient(clientOptions.setHttp2KeepAliveTimeout(5).setIdleTimeout(2)); HttpClientRequest req = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", onSuccess(resp -> { resp.exceptionHandler(err -> {
@Test public void testClientConnectionClosed() throws Exception { server.requestHandler(req -> { req.response().setChunked(true).write(Buffer.buffer("some-data")); }); startServer(); client = vertx.createHttpClient(createBaseClientOptions().setIdleTimeout(2)); FakeHttpClientMetrics metrics = FakeMetricsBase.getMetrics(client); HttpClientRequest req = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", onSuccess(resp -> { HttpClientMetric metric = metrics.getMetric(resp.request()); assertNotNull(metric); assertFalse(metric.failed.get()); resp.exceptionHandler(err -> { assertNull(metrics.getMetric(resp.request())); assertTrue(metric.failed.get()); testComplete(); }); })); req.end(); await(); }
client.close(); client = vertx.createHttpClient(new HttpClientOptions() .setIdleTimeout(2) .setProtocolVersion(HttpVersion.HTTP_2) .setDefaultPort(8080)
options.setSoLinger(soLinger); options.setUsePooledBuffers(usePooledBuffers); options.setIdleTimeout(idleTimeout); options.setKeyCertOptions(keyCertOptions); options.setTrustOptions(trustOptions);
startServer(); client.close(); client = vertx.createHttpClient(clientOptions.setIdleTimeout(2)); Context ctx = vertx.getOrCreateContext(); ctx.runOnContext(v1 -> {
@Override public HttpClientOptions createHttpClientOptions() { HttpVersion ver = ServiceRegistryConfig.INSTANCE.getHttpVersion(); HttpClientOptions httpClientOptions = new HttpClientOptions(); httpClientOptions.setProtocolVersion(ver); httpClientOptions.setConnectTimeout(ServiceRegistryConfig.INSTANCE.getConnectionTimeout()); httpClientOptions.setIdleTimeout(ServiceRegistryConfig.INSTANCE.getIdleWatchTimeout()); if (ver == HttpVersion.HTTP_2) { LOGGER.debug("service center ws client protocol version is HTTP/2"); httpClientOptions.setHttp2ClearTextUpgrade(false); } if (ServiceRegistryConfig.INSTANCE.isSsl()) { LOGGER.debug("service center ws client performs requests over TLS"); VertxTLSBuilder.buildHttpClientOptions(SSL_KEY, httpClientOptions); } return httpClientOptions; } }
private static HttpClientOptions createHttpClientOptions() { HttpClientOptions httpClientOptions = new HttpClientOptions(); httpClientOptions.setMaxPoolSize(TransportClientConfig.getConnectionMaxPoolSize()); httpClientOptions.setIdleTimeout(TransportClientConfig.getConnectionIdleTimeoutInSeconds()); httpClientOptions.setKeepAlive(TransportClientConfig.getConnectionKeepAlive()); httpClientOptions.setTryUseCompression(TransportClientConfig.getConnectionCompression()); httpClientOptions.setMaxHeaderSize(TransportClientConfig.getMaxHeaderSize()); VertxTLSBuilder.buildHttpClientOptions(SSL_KEY, httpClientOptions); return httpClientOptions; }
private static HttpClientOptions createHttp2ClientOptions() { HttpClientOptions httpClientOptions = new HttpClientOptions(); httpClientOptions.setUseAlpn(TransportClientConfig.getUseAlpn()) .setHttp2ClearTextUpgrade(false) .setProtocolVersion(HttpVersion.HTTP_2) .setIdleTimeout(TransportClientConfig.getHttp2ConnectionIdleTimeoutInSeconds()) .setHttp2MultiplexingLimit(TransportClientConfig.getHttp2MultiplexingLimit()) .setHttp2MaxPoolSize(TransportClientConfig.getHttp2ConnectionMaxPoolSize()) .setTryUseCompression(TransportClientConfig.getConnectionCompression()); VertxTLSBuilder.buildHttpClientOptions(SSL_KEY, httpClientOptions); return httpClientOptions; }
@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(); }
@Override public HttpClientOptions createHttpClientOptions() { HttpVersion ver = ServiceRegistryConfig.INSTANCE.getHttpVersion(); HttpClientOptions httpClientOptions = new HttpClientOptions(); httpClientOptions.setProtocolVersion(ver); httpClientOptions.setConnectTimeout(ServiceRegistryConfig.INSTANCE.getConnectionTimeout()); httpClientOptions.setIdleTimeout(ServiceRegistryConfig.INSTANCE.getIdleConnectionTimeout()); if (ServiceRegistryConfig.INSTANCE.isProxyEnable()) { ProxyOptions proxy = new ProxyOptions(); proxy.setHost(ServiceRegistryConfig.INSTANCE.getProxyHost()); proxy.setPort(ServiceRegistryConfig.INSTANCE.getProxyPort()); proxy.setUsername(ServiceRegistryConfig.INSTANCE.getProxyUsername()); proxy.setPassword(Encryptions.decode(ServiceRegistryConfig.INSTANCE.getProxyPasswd(), PROXY_KEY)); httpClientOptions.setProxyOptions(proxy); } if (ver == HttpVersion.HTTP_2) { LOGGER.debug("service center client protocol version is HTTP/2"); httpClientOptions.setHttp2ClearTextUpgrade(false); } if (ServiceRegistryConfig.INSTANCE.isSsl()) { LOGGER.debug("service center client performs requests over TLS"); VertxTLSBuilder.buildHttpClientOptions(SSL_KEY, httpClientOptions); } return httpClientOptions; } }
@Test public void testDisableIdleTimeoutInPool() throws Exception { server.requestHandler(req -> { req.response().end(); }); startServer(); client.close(); client = vertx.createHttpClient(createBaseClientOptions() .setIdleTimeout(1) .setMaxPoolSize(1) .setKeepAliveTimeout(10) ); client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> { resp.endHandler(v1 -> { AtomicBoolean closed = new AtomicBoolean(); resp.request().connection().closeHandler(v2 -> { closed.set(true); }); vertx.setTimer(2000, id -> { assertFalse(closed.get()); testComplete(); }); }); }); await(); }
@Test public void testClientConnectionClosed() throws Exception { server.requestHandler(req -> { req.response().setChunked(true).write(Buffer.buffer("some-data")); }); startServer(); client = vertx.createHttpClient(createBaseClientOptions().setIdleTimeout(2)); FakeHttpClientMetrics metrics = FakeMetricsBase.getMetrics(client); HttpClientRequest req = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath"); req.handler(resp -> { HttpClientMetric metric = metrics.getMetric(req); assertNotNull(metric); assertFalse(metric.failed.get()); resp.exceptionHandler(err -> { assertNull(metrics.getMetric(req)); assertTrue(metric.failed.get()); testComplete(); }); }); req.end(); await(); }
startServer(); client.close(); client = vertx.createHttpClient(clientOptions.setHttp2KeepAliveTimeout(5).setIdleTimeout(2)); HttpClientRequest req = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> { resp.exceptionHandler(err -> {
httpClientOptions.setIdleTimeout((int) (endpoint.getHttpClientOptions().getIdleTimeout() / 1000)); httpClientOptions.setConnectTimeout((int) endpoint.getHttpClientOptions().getConnectTimeout()); httpClientOptions.setUsePooledBuffers(true);
client.close(); client = vertx.createHttpClient(new HttpClientOptions() .setIdleTimeout(2) .setProtocolVersion(HttpVersion.HTTP_2) .setDefaultPort(8080)
options.setSoLinger(soLinger); options.setUsePooledBuffers(usePooledBuffers); options.setIdleTimeout(idleTimeout); options.setKeyCertOptions(keyCertOptions); options.setTrustOptions(trustOptions);
startServer(); client.close(); client = vertx.createHttpClient(clientOptions.setIdleTimeout(2)); Context ctx = vertx.getOrCreateContext(); ctx.runOnContext(v1 -> {