Search in sources :

Example 6 with QueryUnsupportedException

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());
}
Also used : Response(javax.ws.rs.core.Response) BadJsonQueryException(org.apache.druid.query.BadJsonQueryException) QueryException(org.apache.druid.query.QueryException) ByteArrayInputStream(java.io.ByteArrayInputStream) QueryUnsupportedException(org.apache.druid.query.QueryUnsupportedException) Test(org.junit.Test)

Example 7 with QueryUnsupportedException

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()));
}
Also used : Response(javax.ws.rs.core.Response) QueryUnsupportedException(org.apache.druid.query.QueryUnsupportedException) Test(org.junit.Test)

Example 8 with QueryUnsupportedException

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());
}
Also used : UnsupportedSQLQueryException(org.apache.druid.sql.calcite.planner.UnsupportedSQLQueryException) QueryException(org.apache.druid.query.QueryException) QueryUnsupportedException(org.apache.druid.query.QueryUnsupportedException) Test(org.junit.Test)

Example 9 with QueryUnsupportedException

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));
}
Also used : Response(javax.ws.rs.core.Response) QueryUnsupportedException(org.apache.druid.query.QueryUnsupportedException) Test(org.junit.Test)

Aggregations

QueryUnsupportedException (org.apache.druid.query.QueryUnsupportedException)9 Response (javax.ws.rs.core.Response)5 QueryException (org.apache.druid.query.QueryException)4 Test (org.junit.Test)4 QueryCapacityExceededException (org.apache.druid.query.QueryCapacityExceededException)3 QueryTimeoutException (org.apache.druid.query.QueryTimeoutException)3 ResourceLimitExceededException (org.apache.druid.query.ResourceLimitExceededException)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 CountingOutputStream (com.google.common.io.CountingOutputStream)2 IOException (java.io.IOException)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Produces (javax.ws.rs.Produces)2 StreamingOutput (javax.ws.rs.core.StreamingOutput)2 BadJsonQueryException (org.apache.druid.query.BadJsonQueryException)2 BadQueryException (org.apache.druid.query.BadQueryException)2 Query (org.apache.druid.query.Query)2 QueryInterruptedException (org.apache.druid.query.QueryInterruptedException)2 QueryRunner (org.apache.druid.query.QueryRunner)2