Search in sources :

Example 1 with InputStreamResponseHandler

use of com.metamx.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.
    }
}
Also used : InputStreamResponseHandler(com.metamx.http.client.response.InputStreamResponseHandler) StringWriter(java.io.StringWriter) InputStream(java.io.InputStream) Request(com.metamx.http.client.Request) IOException(java.io.IOException) URL(java.net.URL) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with InputStreamResponseHandler

use of com.metamx.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) {
                Throwables.propagate(t);
            }
            latch.countDown();
        }
    });
    latch.await(5, TimeUnit.SECONDS);
}
Also used : InputStreamResponseHandler(com.metamx.http.client.response.InputStreamResponseHandler) StringWriter(java.io.StringWriter) Request(com.metamx.http.client.Request) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) URL(java.net.URL) Test(org.junit.Test)

Aggregations

Request (com.metamx.http.client.Request)2 InputStreamResponseHandler (com.metamx.http.client.response.InputStreamResponseHandler)2 IOException (java.io.IOException)2 StringWriter (java.io.StringWriter)2 URL (java.net.URL)2 Test (org.junit.Test)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 InputStream (java.io.InputStream)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Ignore (org.junit.Ignore)1