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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations