Search in sources :

Example 31 with StatusResponseHolder

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

the class JankyServersTest method testHttpsEchoServer.

@Test
public void testHttpsEchoServer() throws Throwable {
    final Lifecycle lifecycle = new Lifecycle();
    try {
        final HttpClientConfig config = HttpClientConfig.builder().withSslContext(SSLContext.getDefault()).build();
        final HttpClient client = HttpClientInit.createClient(config, lifecycle);
        final ListenableFuture<StatusResponseHolder> response = client.go(new Request(HttpMethod.GET, new URL(StringUtils.format("https://localhost:%d/", echoServerSocket.getLocalPort()))), StatusResponseHandler.getInstance());
        expectedException.expect(ExecutionException.class);
        expectedException.expectMessage("org.jboss.netty.channel.ChannelException: Faulty channel in resource pool");
        response.get();
    } finally {
        lifecycle.stop();
    }
}
Also used : Lifecycle(org.apache.druid.java.util.common.lifecycle.Lifecycle) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) URL(java.net.URL) Test(org.junit.Test)

Example 32 with StatusResponseHolder

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

the class JankyServersTest method testHttpsConnectionClosingServer.

@Test
public void testHttpsConnectionClosingServer() throws Throwable {
    final Lifecycle lifecycle = new Lifecycle();
    try {
        final HttpClientConfig config = HttpClientConfig.builder().withSslContext(SSLContext.getDefault()).build();
        final HttpClient client = HttpClientInit.createClient(config, lifecycle);
        final ListenableFuture<StatusResponseHolder> response = client.go(new Request(HttpMethod.GET, new URL(StringUtils.format("https://localhost:%d/", closingServerSocket.getLocalPort()))), StatusResponseHandler.getInstance());
        Throwable e = null;
        try {
            response.get();
        } catch (ExecutionException e1) {
            e = e1.getCause();
            e1.printStackTrace();
        }
        Assert.assertTrue("ChannelException thrown by 'get'", isChannelClosedException(e));
    } finally {
        lifecycle.stop();
    }
}
Also used : Lifecycle(org.apache.druid.java.util.common.lifecycle.Lifecycle) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) ExecutionException(java.util.concurrent.ExecutionException) URL(java.net.URL) Test(org.junit.Test)

Example 33 with StatusResponseHolder

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

the class JankyServersTest method testHttpsSilentServer.

@Test
public void testHttpsSilentServer() throws Throwable {
    final Lifecycle lifecycle = new Lifecycle();
    try {
        final HttpClientConfig config = HttpClientConfig.builder().withSslContext(SSLContext.getDefault()).withSslHandshakeTimeout(new Duration(100)).build();
        final HttpClient client = HttpClientInit.createClient(config, lifecycle);
        final ListenableFuture<StatusResponseHolder> response = client.go(new Request(HttpMethod.GET, new URL(StringUtils.format("https://localhost:%d/", silentServerSocket.getLocalPort()))), StatusResponseHandler.getInstance());
        Throwable e = null;
        try {
            response.get();
        } catch (ExecutionException e1) {
            e = e1.getCause();
        }
        Assert.assertTrue("ChannelException thrown by 'get'", e instanceof ChannelException);
    } finally {
        lifecycle.stop();
    }
}
Also used : Lifecycle(org.apache.druid.java.util.common.lifecycle.Lifecycle) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) Duration(org.joda.time.Duration) ExecutionException(java.util.concurrent.ExecutionException) URL(java.net.URL) ChannelException(org.jboss.netty.channel.ChannelException) Test(org.junit.Test)

Example 34 with StatusResponseHolder

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

the class JankyServersTest method testHttpConnectionClosingServer.

@Test
public void testHttpConnectionClosingServer() throws Throwable {
    final Lifecycle lifecycle = new Lifecycle();
    try {
        final HttpClientConfig config = HttpClientConfig.builder().build();
        final HttpClient client = HttpClientInit.createClient(config, lifecycle);
        final ListenableFuture<StatusResponseHolder> response = client.go(new Request(HttpMethod.GET, new URL(StringUtils.format("http://localhost:%d/", closingServerSocket.getLocalPort()))), StatusResponseHandler.getInstance());
        Throwable e = null;
        try {
            response.get();
        } catch (ExecutionException e1) {
            e = e1.getCause();
            e1.printStackTrace();
        }
        Assert.assertTrue("ChannelException thrown by 'get'", isChannelClosedException(e));
    } finally {
        lifecycle.stop();
    }
}
Also used : Lifecycle(org.apache.druid.java.util.common.lifecycle.Lifecycle) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) ExecutionException(java.util.concurrent.ExecutionException) URL(java.net.URL) Test(org.junit.Test)

Example 35 with StatusResponseHolder

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

the class FriendlyServersTest method testCompressionCodecConfig.

@Test
public void testCompressionCodecConfig() throws Exception {
    final ExecutorService exec = Executors.newSingleThreadExecutor();
    final ServerSocket serverSocket = new ServerSocket(0);
    final AtomicBoolean foundAcceptEncoding = new AtomicBoolean();
    exec.submit(new Runnable() {

        @Override
        public void run() {
            while (!Thread.currentThread().isInterrupted()) {
                try (Socket clientSocket = serverSocket.accept();
                    BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream(), StandardCharsets.UTF_8));
                    OutputStream out = clientSocket.getOutputStream()) {
                    // Read headers
                    String header;
                    while (!(header = in.readLine()).equals("")) {
                        if ("Accept-Encoding: identity".equals(header)) {
                            foundAcceptEncoding.set(true);
                        }
                    }
                    out.write("HTTP/1.1 200 OK\r\nContent-Length: 6\r\n\r\nhello!".getBytes(StandardCharsets.UTF_8));
                } catch (Exception e) {
                // Suppress
                }
            }
        }
    });
    final Lifecycle lifecycle = new Lifecycle();
    try {
        final HttpClientConfig config = HttpClientConfig.builder().withCompressionCodec(HttpClientConfig.CompressionCodec.IDENTITY).build();
        final HttpClient client = HttpClientInit.createClient(config, lifecycle);
        final StatusResponseHolder response = client.go(new Request(HttpMethod.GET, new URL(StringUtils.format("http://localhost:%d/", serverSocket.getLocalPort()))), StatusResponseHandler.getInstance()).get();
        Assert.assertEquals(200, response.getStatus().getCode());
        Assert.assertEquals("hello!", response.getContent());
        Assert.assertTrue(foundAcceptEncoding.get());
    } finally {
        exec.shutdownNow();
        serverSocket.close();
        lifecycle.stop();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) OutputStream(java.io.OutputStream) Lifecycle(org.apache.druid.java.util.common.lifecycle.Lifecycle) ServerSocket(java.net.ServerSocket) ChannelException(org.jboss.netty.channel.ChannelException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) ExecutionException(java.util.concurrent.ExecutionException) URL(java.net.URL) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ExecutorService(java.util.concurrent.ExecutorService) BufferedReader(java.io.BufferedReader) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) Test(org.junit.Test)

Aggregations

StatusResponseHolder (org.apache.druid.java.util.http.client.response.StatusResponseHolder)69 URL (java.net.URL)50 Request (org.apache.druid.java.util.http.client.Request)42 ISE (org.apache.druid.java.util.common.ISE)33 ExecutionException (java.util.concurrent.ExecutionException)13 Test (org.junit.Test)12 Lifecycle (org.apache.druid.java.util.common.lifecycle.Lifecycle)10 Map (java.util.Map)8 ArrayList (java.util.ArrayList)6 TypeReference (com.fasterxml.jackson.core.type.TypeReference)5 IOException (java.io.IOException)5 RE (org.apache.druid.java.util.common.RE)5 ChannelException (org.jboss.netty.channel.ChannelException)5 List (java.util.List)4 ExecutorService (java.util.concurrent.ExecutorService)4 Future (java.util.concurrent.Future)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)3 BufferedReader (java.io.BufferedReader)3 InputStreamReader (java.io.InputStreamReader)3