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