Search in sources :

Example 1 with QueryInterruptedException

use of io.druid.query.QueryInterruptedException in project druid by druid-io.

the class DirectDruidClientTest method testCancel.

@Test
public void testCancel() throws Exception {
    HttpClient httpClient = EasyMock.createStrictMock(HttpClient.class);
    Capture<Request> capturedRequest = EasyMock.newCapture();
    ListenableFuture<Object> cancelledFuture = Futures.immediateCancelledFuture();
    SettableFuture<Object> cancellationFuture = SettableFuture.create();
    EasyMock.expect(httpClient.go(EasyMock.capture(capturedRequest), EasyMock.<HttpResponseHandler>anyObject())).andReturn(cancelledFuture).once();
    EasyMock.expect(httpClient.go(EasyMock.capture(capturedRequest), EasyMock.<HttpResponseHandler>anyObject())).andReturn(cancellationFuture).once();
    EasyMock.replay(httpClient);
    final ServerSelector serverSelector = new ServerSelector(new DataSegment("test", new Interval("2013-01-01/2013-01-02"), new DateTime("2013-01-01").toString(), Maps.<String, Object>newHashMap(), Lists.<String>newArrayList(), Lists.<String>newArrayList(), NoneShardSpec.instance(), 0, 0L), new HighestPriorityTierSelectorStrategy(new ConnectionCountServerSelectorStrategy()));
    DirectDruidClient client1 = new DirectDruidClient(new ReflectionQueryToolChestWarehouse(), QueryRunnerTestHelper.NOOP_QUERYWATCHER, new DefaultObjectMapper(), httpClient, "foo", new NoopServiceEmitter());
    QueryableDruidServer queryableDruidServer1 = new QueryableDruidServer(new DruidServer("test1", "localhost", 0, "historical", DruidServer.DEFAULT_TIER, 0), client1);
    serverSelector.addServerAndUpdateSegment(queryableDruidServer1, serverSelector.getSegment());
    TimeBoundaryQuery query = Druids.newTimeBoundaryQueryBuilder().dataSource("test").build();
    HashMap<String, List> context = Maps.newHashMap();
    cancellationFuture.set(new StatusResponseHolder(HttpResponseStatus.OK, new StringBuilder("cancelled")));
    Sequence results = client1.run(query, context);
    Assert.assertEquals(HttpMethod.DELETE, capturedRequest.getValue().getMethod());
    Assert.assertEquals(0, client1.getNumOpenConnections());
    QueryInterruptedException exception = null;
    try {
        Sequences.toList(results, Lists.newArrayList());
    } catch (QueryInterruptedException e) {
        exception = e;
    }
    Assert.assertNotNull(exception);
    EasyMock.verify(httpClient);
}
Also used : TimeBoundaryQuery(io.druid.query.timeboundary.TimeBoundaryQuery) DataSegment(io.druid.timeline.DataSegment) DateTime(org.joda.time.DateTime) QueryableDruidServer(io.druid.client.selector.QueryableDruidServer) ServerSelector(io.druid.client.selector.ServerSelector) HighestPriorityTierSelectorStrategy(io.druid.client.selector.HighestPriorityTierSelectorStrategy) StatusResponseHolder(com.metamx.http.client.response.StatusResponseHolder) List(java.util.List) QueryInterruptedException(io.druid.query.QueryInterruptedException) ConnectionCountServerSelectorStrategy(io.druid.client.selector.ConnectionCountServerSelectorStrategy) Request(com.metamx.http.client.Request) QueryableDruidServer(io.druid.client.selector.QueryableDruidServer) NoopServiceEmitter(io.druid.server.metrics.NoopServiceEmitter) Sequence(io.druid.java.util.common.guava.Sequence) HttpClient(com.metamx.http.client.HttpClient) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) HttpResponseHandler(com.metamx.http.client.response.HttpResponseHandler) ReflectionQueryToolChestWarehouse(io.druid.query.ReflectionQueryToolChestWarehouse) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 2 with QueryInterruptedException

use of io.druid.query.QueryInterruptedException in project druid by druid-io.

the class SqlResourceTest method testResourceLimitExceeded.

@Test
public void testResourceLimitExceeded() throws Exception {
    final QueryInterruptedException exception = doPost(new SqlQuery("SELECT DISTINCT dim1 FROM foo", ImmutableMap.<String, Object>of("maxMergingDictionarySize", 1))).lhs;
    Assert.assertNotNull(exception);
    Assert.assertEquals(exception.getErrorCode(), QueryInterruptedException.RESOURCE_LIMIT_EXCEEDED);
    Assert.assertEquals(exception.getErrorClass(), ResourceLimitExceededException.class.getName());
}
Also used : SqlQuery(io.druid.sql.http.SqlQuery) ResourceLimitExceededException(io.druid.query.ResourceLimitExceededException) QueryInterruptedException(io.druid.query.QueryInterruptedException) Test(org.junit.Test)

Example 3 with QueryInterruptedException

use of io.druid.query.QueryInterruptedException in project druid by druid-io.

the class SqlResourceTest method doPost.

// Returns either an error or a result.
private Pair<QueryInterruptedException, List<Map<String, Object>>> doPost(final SqlQuery query) throws Exception {
    final Response response = resource.doPost(query);
    if (response.getStatus() == 200) {
        final StreamingOutput output = (StreamingOutput) response.getEntity();
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        output.write(baos);
        return Pair.of(null, JSON_MAPPER.<List<Map<String, Object>>>readValue(baos.toByteArray(), new TypeReference<List<Map<String, Object>>>() {
        }));
    } else {
        return Pair.of(JSON_MAPPER.readValue((byte[]) response.getEntity(), QueryInterruptedException.class), null);
    }
}
Also used : Response(javax.ws.rs.core.Response) StreamingOutput(javax.ws.rs.core.StreamingOutput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) QueryInterruptedException(io.druid.query.QueryInterruptedException)

Example 4 with QueryInterruptedException

use of io.druid.query.QueryInterruptedException in project druid by druid-io.

the class SqlResourceTest method testCannotConvert.

@Test
public void testCannotConvert() throws Exception {
    // TRIM unsupported
    final QueryInterruptedException exception = doPost(new SqlQuery("SELECT TRIM(dim1) FROM druid.foo", null)).lhs;
    Assert.assertNotNull(exception);
    Assert.assertEquals(QueryInterruptedException.UNKNOWN_EXCEPTION, exception.getErrorCode());
    Assert.assertEquals(ISE.class.getName(), exception.getErrorClass());
    Assert.assertTrue(exception.getMessage().contains("Cannot build plan for query: SELECT TRIM(dim1) FROM druid.foo"));
}
Also used : SqlQuery(io.druid.sql.http.SqlQuery) ISE(io.druid.java.util.common.ISE) QueryInterruptedException(io.druid.query.QueryInterruptedException) Test(org.junit.Test)

Example 5 with QueryInterruptedException

use of io.druid.query.QueryInterruptedException in project druid by druid-io.

the class SqlResourceTest method testCannotValidate.

@Test
public void testCannotValidate() throws Exception {
    final QueryInterruptedException exception = doPost(new SqlQuery("SELECT dim3 FROM druid.foo", null)).lhs;
    Assert.assertNotNull(exception);
    Assert.assertEquals(QueryInterruptedException.UNKNOWN_EXCEPTION, exception.getErrorCode());
    Assert.assertEquals(ValidationException.class.getName(), exception.getErrorClass());
    Assert.assertTrue(exception.getMessage().contains("Column 'dim3' not found in any table"));
}
Also used : SqlQuery(io.druid.sql.http.SqlQuery) ValidationException(org.apache.calcite.tools.ValidationException) QueryInterruptedException(io.druid.query.QueryInterruptedException) Test(org.junit.Test)

Aggregations

QueryInterruptedException (io.druid.query.QueryInterruptedException)10 ISE (io.druid.java.util.common.ISE)4 Sequence (io.druid.java.util.common.guava.Sequence)4 List (java.util.List)4 Test (org.junit.Test)4 Function (com.google.common.base.Function)3 SqlQuery (io.druid.sql.http.SqlQuery)3 TimeoutException (java.util.concurrent.TimeoutException)3 DateTime (org.joda.time.DateTime)3 HttpClient (com.metamx.http.client.HttpClient)2 Request (com.metamx.http.client.Request)2 HttpResponseHandler (com.metamx.http.client.response.HttpResponseHandler)2 ConnectionCountServerSelectorStrategy (io.druid.client.selector.ConnectionCountServerSelectorStrategy)2 HighestPriorityTierSelectorStrategy (io.druid.client.selector.HighestPriorityTierSelectorStrategy)2 QueryableDruidServer (io.druid.client.selector.QueryableDruidServer)2 ServerSelector (io.druid.client.selector.ServerSelector)2 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)2 BaseSequence (io.druid.java.util.common.guava.BaseSequence)2 Query (io.druid.query.Query)2 QueryRunner (io.druid.query.QueryRunner)2