Refine search
@Test public void testDefaults() { assertRecordedDefaults(recordDefaults(ExchangeClientConfig.class) .setMaxBufferSize(new DataSize(32, Unit.MEGABYTE)) .setConcurrentRequestMultiplier(3) .setMinErrorDuration(new Duration(5, TimeUnit.MINUTES)) .setMaxErrorDuration(new Duration(5, TimeUnit.MINUTES)) .setMaxResponseSize(new HttpClientConfig().getMaxContentLength()) .setPageBufferClientMaxCallbackThreads(25) .setClientThreads(25) .setAcknowledgePages(true)); }
public BenchmarkQueryRunner(int warm, int runs, boolean debug, int maxFailures, URI serverUri, Optional<HostAndPort> socksProxy) { checkArgument(warm >= 0, "warm is negative"); this.warm = warm; checkArgument(runs >= 1, "runs must be at least 1"); this.runs = runs; checkArgument(maxFailures >= 0, "maxFailures must be at least 0"); this.maxFailures = maxFailures; this.debug = debug; requireNonNull(socksProxy, "socksProxy is null"); HttpClientConfig httpClientConfig = new HttpClientConfig(); if (socksProxy.isPresent()) { httpClientConfig.setSocksProxy(socksProxy.get()); } this.httpClient = new JettyHttpClient(httpClientConfig.setConnectTimeout(new Duration(10, TimeUnit.SECONDS))); OkHttpClient.Builder builder = new OkHttpClient.Builder(); setupCookieJar(builder); setupSocksProxy(builder, socksProxy); this.okHttpClient = builder.build(); nodes = getAllNodes(requireNonNull(serverUri, "serverUri is null")); }
.withTracing() .withConfigDefaults(config -> { config.setIdleTimeout(new Duration(30, SECONDS)); config.setRequestTimeout(new Duration(10, SECONDS)); }); bindLowMemoryKiller(LowMemoryKillerPolicy.NONE, NoneLowMemoryKiller.class); .withFilter(GenerateTraceTokenRequestFilter.class) .withConfigDefaults(config -> { config.setIdleTimeout(new Duration(30, SECONDS)); config.setRequestTimeout(new Duration(10, SECONDS)); config.setMaxConnectionsPerServer(250); });
@Inject @Provides @Exposed QueryStatsClient getQueryStatsClient(ObjectMapper objectMapper, @Named("databases.presto.server_address") String serverAddress) { // @Singleton does not work due: https://github.com/prestodb/tempto/issues/94 if (httpQueryStatsClient == null) { HttpClientConfig httpClientConfig = new HttpClientConfig(); httpClientConfig.setKeyStorePath(configuration.getString("databases.presto.https_keystore_path").orElse(null)); httpClientConfig.setKeyStorePassword(configuration.getString("databases.presto.https_keystore_password").orElse(null)); httpQueryStatsClient = new HttpQueryStatsClient(new JettyHttpClient(httpClientConfig), objectMapper, URI.create(serverAddress)); } return httpQueryStatsClient; } };
@Override protected void setup(Binder binder) { InternalCommunicationConfig internalCommunicationConfig = buildConfigObject(InternalCommunicationConfig.class); configBinder(binder).bindConfigGlobalDefaults(HttpClientConfig.class, config -> { config.setKeyStorePath(internalCommunicationConfig.getKeyStorePath()); config.setKeyStorePassword(internalCommunicationConfig.getKeyStorePassword()); }); install(installModuleIf(InternalCommunicationConfig.class, InternalCommunicationConfig::isKerberosEnabled, kerberosInternalCommunicationModule())); }
@Test public void testRequest() throws Exception { DummyServlet servlet = new DummyServlet(); TestingHttpServer server = createTestingHttpServer(servlet, ImmutableMap.of()); try { server.start(); try (HttpClient client = new JettyHttpClient(new HttpClientConfig().setConnectTimeout(new Duration(1, SECONDS)))) { StatusResponse response = client.execute(prepareGet().setUri(server.getBaseUrl()).build(), createStatusResponseHandler()); assertEquals(response.getStatusCode(), HttpServletResponse.SC_OK); assertEquals(servlet.getCallCount(), 1); } } finally { server.stop(); } }
@Test(expectedExceptions = Exception.class) public void testConnectReadRequestWriteJunkHangup() throws Exception { try (FakeServer fakeServer = new FakeServer(scheme, host, 10, "THIS\nIS\nJUNK\n\n".getBytes(), false)) { HttpClientConfig config = createClientConfig(); config.setConnectTimeout(new Duration(5, SECONDS)); config.setIdleTimeout(new Duration(5, SECONDS)); executeRequest(fakeServer, config); } }
@Test(expectedExceptions = IOException.class) public void testConnectNoReadClose() throws Exception { try (FakeServer fakeServer = new FakeServer(scheme, host, 0, null, true)) { HttpClientConfig config = new HttpClientConfig(); config.setConnectTimeout(new Duration(5, SECONDS)); config.setReadTimeout(new Duration(5, SECONDS)); executeRequest(fakeServer, config); } }
@Test public void testConnectionRefusedWithDefaultingResponseExceptionHandler() throws Exception { int port = findUnusedPort(); HttpClientConfig config = createClientConfig(); config.setConnectTimeout(new Duration(5, MILLISECONDS)); Request request = prepareGet() .setUri(new URI(scheme, null, host, port, "/", null, null)) .build(); Object expected = new Object(); assertEquals(executeRequest(config, request, new DefaultOnExceptionResponseHandler(expected)), expected); }
@Test public void testConfigDefaults() throws Exception { Injector injector = new Bootstrap( binder -> httpClientBinder(binder) .bindHttpClient("foo", FooClient.class) .withConfigDefaults(config -> config.setRequestTimeout(new Duration(33, MINUTES))), new TraceTokenModule()) .quiet() .strictConfig() .initialize(); JettyHttpClient httpClient = (JettyHttpClient) injector.getInstance(Key.get(HttpClient.class, FooClient.class)); assertEquals(httpClient.getRequestTimeoutMillis(), MINUTES.toMillis(33)); }
@Test(timeOut = 5000) public void testConnectTimeout() throws Exception { try (BackloggedServer server = new BackloggedServer()) { HttpClientConfig config = createClientConfig(); config.setConnectTimeout(new Duration(5, MILLISECONDS)); config.setIdleTimeout(new Duration(2, SECONDS)); Request request = prepareGet() .setUri(new URI(scheme, null, host, server.getPort(), "/", null, null)) .build(); long start = System.nanoTime(); try { executeRequest(config, request, new CaptureExceptionResponseHandler()); fail("expected exception"); } catch (CapturedException e) { Throwable t = e.getCause(); if (!(isConnectTimeout(t) || t instanceof ClosedChannelException)) { fail(format("unexpected exception: [%s]", getStackTraceAsString(t))); } assertLessThan(nanosSince(start), new Duration(300, MILLISECONDS)); } } }
@Test public void testHttp() throws Exception { createServer(); server.start(); try (JettyHttpClient httpClient = new JettyHttpClient(new HttpClientConfig().setHttp2Enabled(false))) { StatusResponse response = httpClient.execute(prepareGet().setUri(httpServerInfo.getHttpUri()).build(), createStatusResponseHandler()); assertEquals(response.getStatusCode(), HttpServletResponse.SC_OK); assertEquals(response.getHeader("X-Protocol"), "HTTP/1.1"); } try (JettyHttpClient httpClient = new JettyHttpClient(new HttpClientConfig().setHttp2Enabled(true))) { StatusResponse response = httpClient.execute(prepareGet().setUri(httpServerInfo.getHttpUri()).build(), createStatusResponseHandler()); assertEquals(response.getStatusCode(), HttpServletResponse.SC_OK); assertEquals(response.getHeader("X-Protocol"), "HTTP/2.0"); } }
@Test(expectedExceptions = ConnectException.class) public void testConnectionRefused() throws Exception { int port = findUnusedPort(); HttpClientConfig config = createClientConfig(); config.setConnectTimeout(new Duration(5, SECONDS)); Request request = prepareGet() .setUri(new URI(scheme, null, host, port, "/", null, null)) .build(); executeExceptionRequest(config, request); }
@Test(expectedExceptions = ConnectException.class) public void testConnectionRefused() throws Exception { int port = findUnusedPort(); HttpClientConfig config = createClientConfig(); config.setConnectTimeout(new Duration(5, MILLISECONDS)); Request request = prepareGet() .setUri(new URI(scheme, null, host, port, "/", null, null)) .build(); try { executeRequest(config, request, new CaptureExceptionResponseHandler()); fail("expected exception"); } catch (CapturedException e) { propagateIfInstanceOf(e.getCause(), Exception.class); propagate(e.getCause()); } }
@Test public void testHttpIsDisabled() throws Exception { config.setHttpEnabled(false); createServer(); server.start(); try (HttpClient client = new JettyHttpClient(new HttpClientConfig().setConnectTimeout(new Duration(2.0, TimeUnit.SECONDS)))) { StatusResponse response = client.execute(prepareGet().setUri(httpServerInfo.getHttpUri().resolve("/")).build(), createStatusResponseHandler()); if (response != null) { // TODO: this is a workaround for a bug in AHC (some race condition) fail("Expected connection refused, got response code: " + response.getStatusCode()); } } catch (RuntimeException e) { assertTrue(e.getCause() instanceof ConnectException, e.getCause().getClass() + " instanceof ConnectException"); } }
@Test(expectedExceptions = {IOException.class, TimeoutException.class}) public void testReadTimeout() throws Exception { HttpClientConfig config = createClientConfig() .setIdleTimeout(new Duration(500, MILLISECONDS)); URI uri = URI.create(baseURI.toASCIIString() + "/?sleep=1000"); Request request = prepareGet() .setUri(uri) .build(); executeRequest(config, request, new ExceptionResponseHandler()); }
@Test public void testClientCertificateJava() throws Exception { config.setHttpEnabled(false) .setAdminEnabled(false) .setHttpsEnabled(true) .setHttpsPort(0) .setKeystorePath(getResource("clientcert-java/server.keystore").getPath()) .setKeystorePassword("airlift"); createAndStartServer(createCertTestServlet()); HttpClientConfig clientConfig = new HttpClientConfig() .setKeyStorePath(getResource("clientcert-java/client.keystore").getPath()) .setKeyStorePassword("airlift") .setTrustStorePath(getResource("clientcert-java/client.truststore").getPath()) .setTrustStorePassword("airlift"); try (JettyHttpClient httpClient = new JettyHttpClient(clientConfig)) { StringResponse response = httpClient.execute( prepareGet().setUri(httpServerInfo.getHttpsUri()).build(), createStringResponseHandler()); assertEquals(response.getStatusCode(), HttpServletResponse.SC_OK); assertEquals(response.getBody(), "CN=testing,OU=Client,O=Airlift,L=Palo Alto,ST=CA,C=US"); } }
@Test public void testHttps() throws Exception { config.setHttpEnabled(false) .setHttpsEnabled(true) .setHttpsPort(0) .setKeystorePath(getResource("test.keystore.with.two.passwords").getPath()) .setKeystorePassword("airlift") .setKeyManagerPassword("airliftkey"); createAndStartServer(); HttpClientConfig http1ClientConfig = new HttpClientConfig() .setHttp2Enabled(false) .setTrustStorePath(getResource("test.truststore").getPath()) .setTrustStorePassword("airlift"); try (JettyHttpClient httpClient = new JettyHttpClient(http1ClientConfig)) { StatusResponse response = httpClient.execute(prepareGet().setUri(httpServerInfo.getHttpsUri()).build(), createStatusResponseHandler()); assertEquals(response.getStatusCode(), HttpServletResponse.SC_OK); assertEquals(response.getHeader("X-Protocol"), "HTTP/1.1"); } }
@Test public void testValidations() { assertFailsValidation(new HttpClientConfig().setConnectTimeout(null), "connectTimeout", "may not be null", NotNull.class); assertFailsValidation(new HttpClientConfig().setRequestTimeout(null), "requestTimeout", "may not be null", NotNull.class); assertFailsValidation(new HttpClientConfig().setIdleTimeout(null), "idleTimeout", "may not be null", NotNull.class); }
HttpClientConfig expected = new HttpClientConfig() .setHttp2Enabled(true) .setConnectTimeout(new Duration(4, SECONDS)) .setRequestTimeout(new Duration(15, SECONDS)) .setIdleTimeout(new Duration(5, SECONDS)) .setKeepAliveInterval(new Duration(6, SECONDS)) .setMaxConnections(12) .setMaxConnectionsPerServer(3) .setMaxRequestsQueuedPerDestination(10) .setMaxContentLength(new DataSize(1, MEGABYTE)) .setRequestBufferSize(new DataSize(42, KILOBYTE)) .setResponseBufferSize(new DataSize(43, KILOBYTE)) .setSocksProxy(HostAndPort.fromParts("localhost", 1080)) .setKeyStorePath("key-store") .setKeyStorePassword("key-store-password") .setTrustStorePath("trust-store") .setTrustStorePassword("trust-store-password") .setSecureRandomAlgorithm("NativePRNG") .setHttpsIncludedCipherSuites("TLS_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA") .setHttpsExcludedCipherSuites("TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA") .setAuthenticationEnabled(true) .setKerberosRemoteServiceName("airlift") .setKerberosPrincipal("airlift-client") .setHttp2InitialSessionReceiveWindowSize(new DataSize(7, MEGABYTE)) .setHttp2InitialStreamReceiveWindowSize(new DataSize(7, MEGABYTE)) .setHttp2InputBufferSize(new DataSize(1, MEGABYTE)) .setSelectorCount(16) .setRecordRequestComplete(false) .setConnectBlocking(true)