Search in sources :

Example 1 with ReflectionQueryToolChestWarehouse

use of org.apache.druid.query.ReflectionQueryToolChestWarehouse in project druid by druid-io.

the class DirectDruidClientTest method testRun.

@Test
public void testRun() throws Exception {
    final URL url = new URL(StringUtils.format("http://%s/druid/v2/", hostName));
    SettableFuture<InputStream> futureResult = SettableFuture.create();
    Capture<Request> capturedRequest = EasyMock.newCapture();
    EasyMock.expect(httpClient.go(EasyMock.capture(capturedRequest), EasyMock.<HttpResponseHandler>anyObject(), EasyMock.anyObject(Duration.class))).andReturn(futureResult).times(1);
    SettableFuture futureException = SettableFuture.create();
    EasyMock.expect(httpClient.go(EasyMock.capture(capturedRequest), EasyMock.<HttpResponseHandler>anyObject(), EasyMock.anyObject(Duration.class))).andReturn(futureException).times(1);
    EasyMock.expect(httpClient.go(EasyMock.capture(capturedRequest), EasyMock.<HttpResponseHandler>anyObject(), EasyMock.anyObject(Duration.class))).andReturn(SettableFuture.create()).atLeastOnce();
    EasyMock.replay(httpClient);
    DirectDruidClient client2 = new DirectDruidClient(new ReflectionQueryToolChestWarehouse(), QueryRunnerTestHelper.NOOP_QUERYWATCHER, new DefaultObjectMapper(), httpClient, "http", "foo2", new NoopServiceEmitter());
    QueryableDruidServer queryableDruidServer2 = new QueryableDruidServer(new DruidServer("test1", "localhost", null, 0, ServerType.HISTORICAL, DruidServer.DEFAULT_TIER, 0), client2);
    serverSelector.addServerAndUpdateSegment(queryableDruidServer2, serverSelector.getSegment());
    TimeBoundaryQuery query = Druids.newTimeBoundaryQueryBuilder().dataSource("test").build();
    query = query.withOverriddenContext(ImmutableMap.of(DirectDruidClient.QUERY_FAIL_TIME, Long.MAX_VALUE));
    Sequence s1 = client.run(QueryPlus.wrap(query));
    Assert.assertTrue(capturedRequest.hasCaptured());
    Assert.assertEquals(url, capturedRequest.getValue().getUrl());
    Assert.assertEquals(HttpMethod.POST, capturedRequest.getValue().getMethod());
    Assert.assertEquals(1, client.getNumOpenConnections());
    // simulate read timeout
    client.run(QueryPlus.wrap(query));
    Assert.assertEquals(2, client.getNumOpenConnections());
    futureException.setException(new ReadTimeoutException());
    Assert.assertEquals(1, client.getNumOpenConnections());
    // subsequent connections should work
    client.run(QueryPlus.wrap(query));
    client.run(QueryPlus.wrap(query));
    client.run(QueryPlus.wrap(query));
    Assert.assertTrue(client.getNumOpenConnections() == 4);
    // produce result for first connection
    futureResult.set(new ByteArrayInputStream(StringUtils.toUtf8("[{\"timestamp\":\"2014-01-01T01:02:03Z\", \"result\": 42.0}]")));
    List<Result> results = s1.toList();
    Assert.assertEquals(1, results.size());
    Assert.assertEquals(DateTimes.of("2014-01-01T01:02:03Z"), results.get(0).getTimestamp());
    Assert.assertEquals(3, client.getNumOpenConnections());
    client2.run(QueryPlus.wrap(query));
    client2.run(QueryPlus.wrap(query));
    Assert.assertEquals(2, client2.getNumOpenConnections());
    Assert.assertEquals(serverSelector.pick(null), queryableDruidServer2);
    EasyMock.verify(httpClient);
}
Also used : SettableFuture(com.google.common.util.concurrent.SettableFuture) ByteArrayInputStream(java.io.ByteArrayInputStream) PipedInputStream(java.io.PipedInputStream) InputStream(java.io.InputStream) ReadTimeoutException(org.jboss.netty.handler.timeout.ReadTimeoutException) Request(org.apache.druid.java.util.http.client.Request) QueryableDruidServer(org.apache.druid.client.selector.QueryableDruidServer) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) TimeBoundaryQuery(org.apache.druid.query.timeboundary.TimeBoundaryQuery) Sequence(org.apache.druid.java.util.common.guava.Sequence) URL(java.net.URL) QueryableDruidServer(org.apache.druid.client.selector.QueryableDruidServer) Result(org.apache.druid.query.Result) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) HttpResponseHandler(org.apache.druid.java.util.http.client.response.HttpResponseHandler) ReflectionQueryToolChestWarehouse(org.apache.druid.query.ReflectionQueryToolChestWarehouse) Test(org.junit.Test)

Example 2 with ReflectionQueryToolChestWarehouse

use of org.apache.druid.query.ReflectionQueryToolChestWarehouse in project druid by druid-io.

the class DirectDruidClientTest method setup.

@Before
public void setup() {
    httpClient = EasyMock.createMock(HttpClient.class);
    serverSelector = new ServerSelector(dataSegment, new HighestPriorityTierSelectorStrategy(new ConnectionCountServerSelectorStrategy()));
    client = new DirectDruidClient(new ReflectionQueryToolChestWarehouse(), QueryRunnerTestHelper.NOOP_QUERYWATCHER, new DefaultObjectMapper(), httpClient, "http", hostName, new NoopServiceEmitter());
    queryableDruidServer = new QueryableDruidServer(new DruidServer("test1", "localhost", null, 0, ServerType.HISTORICAL, DruidServer.DEFAULT_TIER, 0), client);
    serverSelector.addServerAndUpdateSegment(queryableDruidServer, serverSelector.getSegment());
}
Also used : ServerSelector(org.apache.druid.client.selector.ServerSelector) HttpClient(org.apache.druid.java.util.http.client.HttpClient) HighestPriorityTierSelectorStrategy(org.apache.druid.client.selector.HighestPriorityTierSelectorStrategy) ConnectionCountServerSelectorStrategy(org.apache.druid.client.selector.ConnectionCountServerSelectorStrategy) QueryableDruidServer(org.apache.druid.client.selector.QueryableDruidServer) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) ReflectionQueryToolChestWarehouse(org.apache.druid.query.ReflectionQueryToolChestWarehouse) QueryableDruidServer(org.apache.druid.client.selector.QueryableDruidServer) Before(org.junit.Before)

Aggregations

QueryableDruidServer (org.apache.druid.client.selector.QueryableDruidServer)2 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)2 ReflectionQueryToolChestWarehouse (org.apache.druid.query.ReflectionQueryToolChestWarehouse)2 NoopServiceEmitter (org.apache.druid.server.metrics.NoopServiceEmitter)2 SettableFuture (com.google.common.util.concurrent.SettableFuture)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 PipedInputStream (java.io.PipedInputStream)1 URL (java.net.URL)1 ConnectionCountServerSelectorStrategy (org.apache.druid.client.selector.ConnectionCountServerSelectorStrategy)1 HighestPriorityTierSelectorStrategy (org.apache.druid.client.selector.HighestPriorityTierSelectorStrategy)1 ServerSelector (org.apache.druid.client.selector.ServerSelector)1 Sequence (org.apache.druid.java.util.common.guava.Sequence)1 HttpClient (org.apache.druid.java.util.http.client.HttpClient)1 Request (org.apache.druid.java.util.http.client.Request)1 HttpResponseHandler (org.apache.druid.java.util.http.client.response.HttpResponseHandler)1 Result (org.apache.druid.query.Result)1 TimeBoundaryQuery (org.apache.druid.query.timeboundary.TimeBoundaryQuery)1 ReadTimeoutException (org.jboss.netty.handler.timeout.ReadTimeoutException)1 Before (org.junit.Before)1