Search in sources :

Example 36 with HttpClient

use of org.apache.druid.java.util.http.client.HttpClient in project druid by druid-io.

the class JettyTest method testNumConnectionsMetricHttps.

@Test
public void testNumConnectionsMetricHttps() throws Exception {
    String text = "hello";
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try (GZIPOutputStream gzipOutputStream = new GZIPOutputStream(out)) {
        gzipOutputStream.write(text.getBytes(Charset.defaultCharset()));
    }
    Request request = new Request(HttpMethod.GET, new URL("https://localhost:" + tlsPort + "/latched/hello"));
    request.setHeader("Content-Encoding", "gzip");
    request.setContent(MediaType.TEXT_PLAIN, out.toByteArray());
    HttpClient client;
    try {
        client = HttpClientInit.createClient(sslConfig, lifecycle);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    JettyServerModule jsm = injector.getInstance(JettyServerModule.class);
    latchedRequestState.reset();
    waitForJettyServerModuleActiveConnectionsZero(jsm);
    Assert.assertEquals(0, jsm.getActiveConnections());
    ListenableFuture<InputStream> go = client.go(request, new InputStreamResponseHandler());
    latchedRequestState.clientWaitForServerToStartRequest();
    Assert.assertEquals(1, jsm.getActiveConnections());
    latchedRequestState.clientReadyToFinishRequest();
    go.get();
    waitForJettyServerModuleActiveConnectionsZero(jsm);
    Assert.assertEquals(0, jsm.getActiveConnections());
}
Also used : InputStreamResponseHandler(org.apache.druid.java.util.http.client.response.InputStreamResponseHandler) GZIPOutputStream(java.util.zip.GZIPOutputStream) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) HttpClient(org.apache.druid.java.util.http.client.HttpClient) Request(org.apache.druid.java.util.http.client.Request) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JettyServerModule(org.apache.druid.server.initialization.jetty.JettyServerModule) URL(java.net.URL) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

HttpClient (org.apache.druid.java.util.http.client.HttpClient)36 Test (org.junit.Test)16 CredentialedHttpClient (org.apache.druid.java.util.http.client.CredentialedHttpClient)15 ArrayList (java.util.ArrayList)10 Test (org.testng.annotations.Test)10 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)9 List (java.util.List)9 CuratorFramework (org.apache.curator.framework.CuratorFramework)9 ZkPathsConfig (org.apache.druid.server.initialization.ZkPathsConfig)9 ImmutableList (com.google.common.collect.ImmutableList)8 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 DruidNodeDiscoveryProvider (org.apache.druid.discovery.DruidNodeDiscoveryProvider)8 TaskRunnerListener (org.apache.druid.indexing.overlord.TaskRunnerListener)8 TaskStorage (org.apache.druid.indexing.overlord.TaskStorage)8 HttpRemoteTaskRunnerConfig (org.apache.druid.indexing.overlord.config.HttpRemoteTaskRunnerConfig)8 Worker (org.apache.druid.indexing.worker.Worker)8 IndexerZkConfig (org.apache.druid.server.initialization.IndexerZkConfig)8 DiscoveryDruidNode (org.apache.druid.discovery.DiscoveryDruidNode)7 WorkerNodeService (org.apache.druid.discovery.WorkerNodeService)7