Search in sources :

Example 6 with HttpResponseHandler

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

the class DirectDruidClientTest method testQueryInterruptionExceptionLogMessage.

@Test
public void testQueryInterruptionExceptionLogMessage() {
    SettableFuture<Object> interruptionFuture = SettableFuture.create();
    Capture<Request> capturedRequest = EasyMock.newCapture();
    final String hostName = "localhost:8080";
    EasyMock.expect(httpClient.go(EasyMock.capture(capturedRequest), EasyMock.<HttpResponseHandler>anyObject(), EasyMock.anyObject(Duration.class))).andReturn(interruptionFuture).anyTimes();
    EasyMock.replay(httpClient);
    // test error
    TimeBoundaryQuery query = Druids.newTimeBoundaryQueryBuilder().dataSource("test").build();
    query = query.withOverriddenContext(ImmutableMap.of(DirectDruidClient.QUERY_FAIL_TIME, Long.MAX_VALUE));
    interruptionFuture.set(new ByteArrayInputStream(StringUtils.toUtf8("{\"error\":\"testing1\",\"errorMessage\":\"testing2\"}")));
    Sequence results = client.run(QueryPlus.wrap(query));
    QueryInterruptedException actualException = null;
    try {
        results.toList();
    } catch (QueryInterruptedException e) {
        actualException = e;
    }
    Assert.assertNotNull(actualException);
    Assert.assertEquals("testing1", actualException.getErrorCode());
    Assert.assertEquals("testing2", actualException.getMessage());
    Assert.assertEquals(hostName, actualException.getHost());
    EasyMock.verify(httpClient);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Request(org.apache.druid.java.util.http.client.Request) TimeBoundaryQuery(org.apache.druid.query.timeboundary.TimeBoundaryQuery) Sequence(org.apache.druid.java.util.common.guava.Sequence) HttpResponseHandler(org.apache.druid.java.util.http.client.response.HttpResponseHandler) QueryInterruptedException(org.apache.druid.query.QueryInterruptedException) Test(org.junit.Test)

Example 7 with HttpResponseHandler

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

the class DirectDruidClientTest method testQueryTimeoutFromFuture.

@Test
public void testQueryTimeoutFromFuture() {
    SettableFuture<Object> noFuture = SettableFuture.create();
    Capture<Request> capturedRequest = EasyMock.newCapture();
    final String queryId = "never-ending-future";
    EasyMock.expect(httpClient.go(EasyMock.capture(capturedRequest), EasyMock.<HttpResponseHandler>anyObject(), EasyMock.anyObject(Duration.class))).andReturn(noFuture).anyTimes();
    EasyMock.replay(httpClient);
    TimeBoundaryQuery query = Druids.newTimeBoundaryQueryBuilder().dataSource("test").build();
    query = query.withOverriddenContext(ImmutableMap.of(DirectDruidClient.QUERY_FAIL_TIME, System.currentTimeMillis() + 500, "queryId", queryId));
    Sequence results = client.run(QueryPlus.wrap(query));
    QueryTimeoutException actualException = null;
    try {
        results.toList();
    } catch (QueryTimeoutException e) {
        actualException = e;
    }
    Assert.assertNotNull(actualException);
    Assert.assertEquals("Query timeout", actualException.getErrorCode());
    Assert.assertEquals(StringUtils.format("Query [%s] timed out!", queryId), actualException.getMessage());
    Assert.assertEquals(hostName, actualException.getHost());
    EasyMock.verify(httpClient);
}
Also used : QueryTimeoutException(org.apache.druid.query.QueryTimeoutException) Request(org.apache.druid.java.util.http.client.Request) TimeBoundaryQuery(org.apache.druid.query.timeboundary.TimeBoundaryQuery) Sequence(org.apache.druid.java.util.common.guava.Sequence) HttpResponseHandler(org.apache.druid.java.util.http.client.response.HttpResponseHandler) Test(org.junit.Test)

Aggregations

Request (org.apache.druid.java.util.http.client.Request)7 HttpResponseHandler (org.apache.druid.java.util.http.client.response.HttpResponseHandler)7 Sequence (org.apache.druid.java.util.common.guava.Sequence)5 TimeBoundaryQuery (org.apache.druid.query.timeboundary.TimeBoundaryQuery)5 Test (org.junit.Test)5 QueryTimeoutException (org.apache.druid.query.QueryTimeoutException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 PipedInputStream (java.io.PipedInputStream)2 URL (java.net.URL)2 StatusResponseHolder (org.apache.druid.java.util.http.client.response.StatusResponseHolder)2 QueryInterruptedException (org.apache.druid.query.QueryInterruptedException)2 JavaType (com.fasterxml.jackson.databind.JavaType)1 SettableFuture (com.google.common.util.concurrent.SettableFuture)1 IOException (java.io.IOException)1 PipedOutputStream (java.io.PipedOutputStream)1 SequenceInputStream (java.io.SequenceInputStream)1 Enumeration (java.util.Enumeration)1 BlockingQueue (java.util.concurrent.BlockingQueue)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1