Search in sources :

Example 11 with TimeBoundaryQuery

use of org.apache.druid.query.timeboundary.TimeBoundaryQuery 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 12 with TimeBoundaryQuery

use of org.apache.druid.query.timeboundary.TimeBoundaryQuery 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

TimeBoundaryQuery (org.apache.druid.query.timeboundary.TimeBoundaryQuery)12 Test (org.junit.Test)9 Sequence (org.apache.druid.java.util.common.guava.Sequence)5 Request (org.apache.druid.java.util.http.client.Request)5 HttpResponseHandler (org.apache.druid.java.util.http.client.response.HttpResponseHandler)5 MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)5 QueryableDruidServer (org.apache.druid.client.selector.QueryableDruidServer)4 Result (org.apache.druid.query.Result)4 Interval (org.joda.time.Interval)4 ResponseContext (org.apache.druid.query.context.ResponseContext)3 TimeBoundaryResultValue (org.apache.druid.query.timeboundary.TimeBoundaryResultValue)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 PipedInputStream (java.io.PipedInputStream)2 HighestPriorityTierSelectorStrategy (org.apache.druid.client.selector.HighestPriorityTierSelectorStrategy)2 RandomServerSelectorStrategy (org.apache.druid.client.selector.RandomServerSelectorStrategy)2 ServerSelector (org.apache.druid.client.selector.ServerSelector)2 QueryRunner (org.apache.druid.query.QueryRunner)2 DataSegment (org.apache.druid.timeline.DataSegment)2 Function (com.google.common.base.Function)1 ImmutableList (com.google.common.collect.ImmutableList)1