use of org.apache.druid.java.util.http.client.response.InputStreamResponseHandler in project druid by druid-io.
the class RemoteTaskRunner method streamTaskReports.
@Override
public Optional<ByteSource> streamTaskReports(final String taskId) {
final ZkWorker zkWorker = findWorkerRunningTask(taskId);
if (zkWorker == null) {
// Worker is not running this task, it might be available in deep storage
return Optional.absent();
} else {
TaskLocation taskLocation = runningTasks.get(taskId).getLocation();
final URL url = TaskRunnerUtils.makeTaskLocationURL(taskLocation, "/druid/worker/v1/chat/%s/liveReports", taskId);
return Optional.of(new ByteSource() {
@Override
public InputStream openStream() throws IOException {
try {
return httpClient.go(new Request(HttpMethod.GET, url), new InputStreamResponseHandler()).get();
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ExecutionException e) {
// Unwrap if possible
Throwables.propagateIfPossible(e.getCause(), IOException.class);
throw new RuntimeException(e);
}
}
});
}
}
use of org.apache.druid.java.util.http.client.response.InputStreamResponseHandler in project druid by druid-io.
the class JettyTest method testChunkNotFinalized.
// Tests that threads are not stuck when partial chunk is not finalized
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=424107
@Test
@Ignore
public // above bug is not fixed in jetty for gzip encoding, and the chunk is still finalized instead of throwing exception.
void testChunkNotFinalized() throws Exception {
ListenableFuture<InputStream> go = client.go(new Request(HttpMethod.GET, new URL("http://localhost:" + port + "/exception/exception")), new InputStreamResponseHandler());
try {
StringWriter writer = new StringWriter();
IOUtils.copy(go.get(), writer, "utf-8");
Assert.fail("Should have thrown Exception");
} catch (IOException e) {
// Expected.
}
}
use of org.apache.druid.java.util.http.client.response.InputStreamResponseHandler in project druid by druid-io.
the class JettyTest method testThreadNotStuckOnException.
@Test
public void testThreadNotStuckOnException() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
Executors.newSingleThreadExecutor().execute(new Runnable() {
@Override
public void run() {
try {
ListenableFuture<InputStream> go = client.go(new Request(HttpMethod.GET, new URL("http://localhost:" + port + "/exception/exception")), new InputStreamResponseHandler());
StringWriter writer = new StringWriter();
IOUtils.copy(go.get(), writer, "utf-8");
} catch (IOException e) {
// Expected.
} catch (Throwable t) {
throw new RuntimeException(t);
}
latch.countDown();
}
});
latch.await(5, TimeUnit.SECONDS);
}
use of org.apache.druid.java.util.http.client.response.InputStreamResponseHandler in project druid by druid-io.
the class JettyTest method testGzipRequestDecompression.
@Test
public void testGzipRequestDecompression() 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.POST, new URL("http://localhost:" + port + "/return"));
request.setHeader("Content-Encoding", "gzip");
request.setContent(MediaType.TEXT_PLAIN, out.toByteArray());
Assert.assertEquals(text, new String(IOUtils.toByteArray(client.go(request, new InputStreamResponseHandler()).get()), Charset.defaultCharset()));
}
use of org.apache.druid.java.util.http.client.response.InputStreamResponseHandler 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());
}
Aggregations