use of org.apache.druid.query.QueryException in project druid by druid-io.
the class SqlResourceTest method testAssertionErrorThrowsErrorWithFilterResponse.
@Test
public void testAssertionErrorThrowsErrorWithFilterResponse() throws Exception {
resource = new SqlResource(JSON_MAPPER, CalciteTests.TEST_AUTHORIZER_MAPPER, sqlLifecycleFactory, lifecycleManager, new ServerConfig() {
@Override
public boolean isShowDetailedJettyErrors() {
return true;
}
@Override
public ErrorResponseTransformStrategy getErrorResponseTransformStrategy() {
return new AllowedRegexErrorResponseTransformStrategy(ImmutableList.of());
}
});
String errorMessage = "could not assert";
SqlQuery badQuery = EasyMock.createMock(SqlQuery.class);
EasyMock.expect(badQuery.getQuery()).andReturn("SELECT ANSWER TO LIFE");
EasyMock.expect(badQuery.getContext()).andReturn(ImmutableMap.of("sqlQueryId", "id"));
EasyMock.expect(badQuery.getParameterList()).andThrow(new Error(errorMessage));
EasyMock.replay(badQuery);
final QueryException exception = doPost(badQuery).lhs;
Assert.assertNotNull(exception);
Assert.assertNull(exception.getMessage());
Assert.assertNull(exception.getHost());
Assert.assertEquals(exception.getErrorCode(), QueryInterruptedException.UNKNOWN_EXCEPTION);
Assert.assertNull(exception.getErrorClass());
Assert.assertTrue(lifecycleManager.getAll("id").isEmpty());
}
use of org.apache.druid.query.QueryException in project druid by druid-io.
the class SqlResourceTest method testCancelBetweenValidateAndPlan.
@Test
public void testCancelBetweenValidateAndPlan() throws Exception {
final String sqlQueryId = "toCancel";
lifecycleAddLatch = new CountDownLatch(1);
CountDownLatch validateAndAuthorizeLatch = new CountDownLatch(1);
validateAndAuthorizeLatchSupplier.set(new NonnullPair<>(validateAndAuthorizeLatch, true));
CountDownLatch planLatch = new CountDownLatch(1);
planLatchSupplier.set(new NonnullPair<>(planLatch, false));
Future<Response> future = executorService.submit(() -> resource.doPost(createSimpleQueryWithId(sqlQueryId, "SELECT DISTINCT dim1 FROM foo"), makeRegularUserReq()));
Assert.assertTrue(validateAndAuthorizeLatch.await(1, TimeUnit.SECONDS));
Assert.assertTrue(lifecycleAddLatch.await(1, TimeUnit.SECONDS));
Response response = resource.cancelQuery(sqlQueryId, mockRequestForCancel());
planLatch.countDown();
Assert.assertEquals(Status.ACCEPTED.getStatusCode(), response.getStatus());
Assert.assertTrue(lifecycleManager.getAll(sqlQueryId).isEmpty());
response = future.get();
Assert.assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus());
QueryException exception = JSON_MAPPER.readValue((byte[]) response.getEntity(), QueryException.class);
Assert.assertEquals(QueryInterruptedException.QUERY_CANCELLED, exception.getErrorCode());
}
use of org.apache.druid.query.QueryException in project druid by druid-io.
the class SqlResourceTest method testTooManyRequests.
@Test
public void testTooManyRequests() throws Exception {
sleep = true;
final int numQueries = 3;
final String sqlQueryId = "tooManyRequestsTest";
List<Future<Pair<QueryException, List<Map<String, Object>>>>> futures = new ArrayList<>(numQueries);
for (int i = 0; i < numQueries; i++) {
futures.add(executorService.submit(() -> {
try {
return doPost(new SqlQuery("SELECT COUNT(*) AS cnt, 'foo' AS TheFoo FROM druid.foo", null, false, false, false, ImmutableMap.of("priority", -5, BaseQuery.SQL_QUERY_ID, sqlQueryId), null), makeRegularUserReq());
} catch (Exception e) {
throw new RuntimeException(e);
}
}));
}
int success = 0;
int limited = 0;
for (int i = 0; i < numQueries; i++) {
Pair<QueryException, List<Map<String, Object>>> result = futures.get(i).get();
List<Map<String, Object>> rows = result.rhs;
if (rows != null) {
Assert.assertEquals(ImmutableList.of(ImmutableMap.of("cnt", 6, "TheFoo", "foo")), rows);
success++;
} else {
QueryException interruped = result.lhs;
Assert.assertEquals(QueryCapacityExceededException.ERROR_CODE, interruped.getErrorCode());
Assert.assertEquals(QueryCapacityExceededException.makeLaneErrorMessage(HiLoQueryLaningStrategy.LOW, 2), interruped.getMessage());
limited++;
}
}
Assert.assertEquals(2, success);
Assert.assertEquals(1, limited);
Assert.assertEquals(3, testRequestLogger.getSqlQueryLogs().size());
Assert.assertTrue(lifecycleManager.getAll(sqlQueryId).isEmpty());
}
use of org.apache.druid.query.QueryException in project druid by druid-io.
the class SqlResourceTest method testCancelBetweenPlanAndExecute.
@Test
public void testCancelBetweenPlanAndExecute() throws Exception {
final String sqlQueryId = "toCancel";
CountDownLatch planLatch = new CountDownLatch(1);
planLatchSupplier.set(new NonnullPair<>(planLatch, true));
CountDownLatch execLatch = new CountDownLatch(1);
executeLatchSupplier.set(new NonnullPair<>(execLatch, false));
Future<Response> future = executorService.submit(() -> resource.doPost(createSimpleQueryWithId(sqlQueryId, "SELECT DISTINCT dim1 FROM foo"), makeRegularUserReq()));
Assert.assertTrue(planLatch.await(1, TimeUnit.SECONDS));
Response response = resource.cancelQuery(sqlQueryId, mockRequestForCancel());
execLatch.countDown();
Assert.assertEquals(Status.ACCEPTED.getStatusCode(), response.getStatus());
Assert.assertTrue(lifecycleManager.getAll(sqlQueryId).isEmpty());
response = future.get();
Assert.assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus());
QueryException exception = JSON_MAPPER.readValue((byte[]) response.getEntity(), QueryException.class);
Assert.assertEquals(QueryInterruptedException.QUERY_CANCELLED, exception.getErrorCode());
}
use of org.apache.druid.query.QueryException in project druid by druid-io.
the class SqlResourceTest method testQueryTimeoutException.
@Test
public void testQueryTimeoutException() throws Exception {
final String sqlQueryId = "timeoutTest";
Map<String, Object> queryContext = ImmutableMap.of(QueryContexts.TIMEOUT_KEY, 1, BaseQuery.SQL_QUERY_ID, sqlQueryId);
final QueryException timeoutException = doPost(new SqlQuery("SELECT CAST(__time AS DATE), dim1, dim2, dim3 FROM druid.foo GROUP by __time, dim1, dim2, dim3 ORDER BY dim2 DESC", ResultFormat.OBJECT, false, false, false, queryContext, null)).lhs;
Assert.assertNotNull(timeoutException);
Assert.assertEquals(timeoutException.getErrorCode(), QueryTimeoutException.ERROR_CODE);
Assert.assertEquals(timeoutException.getErrorClass(), QueryTimeoutException.class.getName());
Assert.assertTrue(lifecycleManager.getAll(sqlQueryId).isEmpty());
}
Aggregations