use of org.apache.druid.query.QueryUnsupportedException in project druid by druid-io.
the class QueryResourceTest method testUnsupportedQueryThrowsException.
@Test
public void testUnsupportedQueryThrowsException() throws IOException {
String errorMessage = "This will be support in Druid 9999";
ByteArrayInputStream badQuery = EasyMock.createMock(ByteArrayInputStream.class);
EasyMock.expect(badQuery.read(EasyMock.anyObject(), EasyMock.anyInt(), EasyMock.anyInt())).andThrow(new QueryUnsupportedException(errorMessage));
EasyMock.replay(badQuery);
EasyMock.replay(testServletRequest);
Response response = queryResource.doPost(badQuery, null, /*pretty*/
testServletRequest);
Assert.assertNotNull(response);
Assert.assertEquals(QueryUnsupportedException.STATUS_CODE, response.getStatus());
QueryException ex = jsonMapper.readValue((byte[]) response.getEntity(), QueryException.class);
Assert.assertEquals(errorMessage, ex.getMessage());
Assert.assertEquals(QueryUnsupportedException.ERROR_CODE, ex.getErrorCode());
}
use of org.apache.druid.query.QueryUnsupportedException in project druid by druid-io.
the class SqlResourceTest method testErrorResponseReturnNewQueryIdWhenNotSetInContext.
@Test
public void testErrorResponseReturnNewQueryIdWhenNotSetInContext() throws Exception {
String errorMessage = "This will be support in Druid 9999";
SqlQuery badQuery = EasyMock.createMock(SqlQuery.class);
EasyMock.expect(badQuery.getQuery()).andReturn("SELECT ANSWER TO LIFE");
EasyMock.expect(badQuery.getContext()).andReturn(ImmutableMap.of());
EasyMock.expect(badQuery.getParameterList()).andThrow(new QueryUnsupportedException(errorMessage));
EasyMock.replay(badQuery);
final Response response = resource.doPost(badQuery, req);
Assert.assertNotEquals(200, response.getStatus());
final MultivaluedMap<String, Object> headers = response.getMetadata();
Assert.assertTrue(headers.containsKey(SqlResource.SQL_QUERY_ID_RESPONSE_HEADER));
Assert.assertEquals(1, headers.get(SqlResource.SQL_QUERY_ID_RESPONSE_HEADER).size());
Assert.assertFalse(Strings.isNullOrEmpty(headers.get(SqlResource.SQL_QUERY_ID_RESPONSE_HEADER).get(0).toString()));
}
use of org.apache.druid.query.QueryUnsupportedException in project druid by druid-io.
the class SqlResourceTest method testUnsupportedQueryThrowsException.
@Test
public void testUnsupportedQueryThrowsException() throws Exception {
String errorMessage = "This will be support in Druid 9999";
SqlQuery badQuery = EasyMock.createMock(SqlQuery.class);
EasyMock.expect(badQuery.getQuery()).andReturn("SELECT ANSWER TO LIFE");
EasyMock.expect(badQuery.getContext()).andReturn(ImmutableMap.of(BaseQuery.SQL_QUERY_ID, "id"));
EasyMock.expect(badQuery.getParameterList()).andThrow(new QueryUnsupportedException(errorMessage));
EasyMock.replay(badQuery);
final QueryException exception = doPost(badQuery).lhs;
Assert.assertNotNull(exception);
Assert.assertEquals(QueryUnsupportedException.ERROR_CODE, exception.getErrorCode());
Assert.assertEquals(QueryUnsupportedException.class.getName(), exception.getErrorClass());
Assert.assertTrue(lifecycleManager.getAll("id").isEmpty());
}
use of org.apache.druid.query.QueryUnsupportedException in project druid by druid-io.
the class SqlResourceTest method testErrorResponseReturnSameQueryIdWhenSetInContext.
@Test
public void testErrorResponseReturnSameQueryIdWhenSetInContext() throws Exception {
String queryId = "id123";
String errorMessage = "This will be support in Druid 9999";
SqlQuery badQuery = EasyMock.createMock(SqlQuery.class);
EasyMock.expect(badQuery.getQuery()).andReturn("SELECT ANSWER TO LIFE");
EasyMock.expect(badQuery.getContext()).andReturn(ImmutableMap.of("sqlQueryId", queryId));
EasyMock.expect(badQuery.getParameterList()).andThrow(new QueryUnsupportedException(errorMessage));
EasyMock.replay(badQuery);
final Response response = resource.doPost(badQuery, req);
Assert.assertNotEquals(200, response.getStatus());
final MultivaluedMap<String, Object> headers = response.getMetadata();
Assert.assertTrue(headers.containsKey(SqlResource.SQL_QUERY_ID_RESPONSE_HEADER));
Assert.assertEquals(1, headers.get(SqlResource.SQL_QUERY_ID_RESPONSE_HEADER).size());
Assert.assertEquals(queryId, headers.get(SqlResource.SQL_QUERY_ID_RESPONSE_HEADER).get(0));
}
Aggregations