Search in sources :

Example 1 with TimelineServerView

use of org.apache.druid.client.TimelineServerView in project druid by druid-io.

the class MovingAverageQueryTest method testQuery.

/**
 * Validate that the specified query behaves correctly.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testQuery() throws IOException {
    Query<?> query = jsonMapper.readValue(getQueryString(), Query.class);
    Assert.assertThat(query, IsInstanceOf.instanceOf(getExpectedQueryType()));
    List<MapBasedRow> expectedResults = jsonMapper.readValue(getExpectedResultString(), getExpectedResultType());
    Assert.assertNotNull(expectedResults);
    Assert.assertThat(expectedResults, IsInstanceOf.instanceOf(List.class));
    CachingClusteredClient baseClient = new CachingClusteredClient(warehouse, new TimelineServerView() {

        @Override
        public Optional<? extends TimelineLookup<String, ServerSelector>> getTimeline(DataSourceAnalysis analysis) {
            return Optional.empty();
        }

        @Override
        public List<ImmutableDruidServer> getDruidServers() {
            return null;
        }

        @Override
        public <T> QueryRunner<T> getQueryRunner(DruidServer server) {
            return null;
        }

        @Override
        public void registerTimelineCallback(Executor exec, TimelineCallback callback) {
        }

        @Override
        public void registerSegmentCallback(Executor exec, SegmentCallback callback) {
        }

        @Override
        public void registerServerRemovedCallback(Executor exec, ServerRemovedCallback callback) {
        }
    }, MapCache.create(100000), jsonMapper, new ForegroundCachePopulator(jsonMapper, new CachePopulatorStats(), -1), new CacheConfig(), new DruidHttpClientConfig() {

        @Override
        public long getMaxQueuedBytes() {
            return 0L;
        }
    }, new DruidProcessingConfig() {

        @Override
        public String getFormatString() {
            return null;
        }
    }, ForkJoinPool.commonPool(), QueryStackTests.DEFAULT_NOOP_SCHEDULER, new MapJoinableFactory(ImmutableSet.of(), ImmutableMap.of()), new NoopServiceEmitter());
    ClientQuerySegmentWalker walker = new ClientQuerySegmentWalker(new ServiceEmitter("", "", null) {

        @Override
        public void emit(Event event) {
        }
    }, baseClient, null, /* local client; unused in this test, so pass in null */
    warehouse, new MapJoinableFactory(ImmutableSet.of(), ImmutableMap.of()), retryConfig, jsonMapper, serverConfig, null, new CacheConfig());
    defineMocks();
    QueryPlus queryPlus = QueryPlus.wrap(query);
    final Sequence<?> res = query.getRunner(walker).run(queryPlus);
    List actualResults = new ArrayList();
    actualResults = (List<MapBasedRow>) res.accumulate(actualResults, Accumulators.list());
    expectedResults = consistentTypeCasting(expectedResults);
    actualResults = consistentTypeCasting(actualResults);
    Assert.assertEquals(expectedResults, actualResults);
}
Also used : ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) ArrayList(java.util.ArrayList) DataSourceAnalysis(org.apache.druid.query.planning.DataSourceAnalysis) DruidHttpClientConfig(org.apache.druid.guice.http.DruidHttpClientConfig) MapBasedRow(org.apache.druid.data.input.MapBasedRow) Executor(java.util.concurrent.Executor) CachePopulatorStats(org.apache.druid.client.cache.CachePopulatorStats) List(java.util.List) ArrayList(java.util.ArrayList) TimelineServerView(org.apache.druid.client.TimelineServerView) CacheConfig(org.apache.druid.client.cache.CacheConfig) MapJoinableFactory(org.apache.druid.segment.join.MapJoinableFactory) QueryPlus(org.apache.druid.query.QueryPlus) CachingClusteredClient(org.apache.druid.client.CachingClusteredClient) Optional(java.util.Optional) DruidServer(org.apache.druid.client.DruidServer) ImmutableDruidServer(org.apache.druid.client.ImmutableDruidServer) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) QueryRunner(org.apache.druid.query.QueryRunner) ClientQuerySegmentWalker(org.apache.druid.server.ClientQuerySegmentWalker) Event(org.apache.druid.java.util.emitter.core.Event) ForegroundCachePopulator(org.apache.druid.client.cache.ForegroundCachePopulator) DruidProcessingConfig(org.apache.druid.query.DruidProcessingConfig) TimelineLookup(org.apache.druid.timeline.TimelineLookup) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 2 with TimelineServerView

use of org.apache.druid.client.TimelineServerView in project druid by druid-io.

the class ClientInfoResourceTest method setup.

@Before
public void setup() {
    VersionedIntervalTimeline<String, ServerSelector> timeline = new VersionedIntervalTimeline<>(Ordering.natural());
    DruidServer server = new DruidServer("name", "host", null, 1234, ServerType.HISTORICAL, "tier", 0);
    addSegment(timeline, server, "1960-02-13/1961-02-14", ImmutableList.of("d5"), ImmutableList.of("m5"), "v0");
    // segments within [2014-02-13, 2014-02-18]
    addSegment(timeline, server, "2014-02-13/2014-02-14", ImmutableList.of("d1"), ImmutableList.of("m1"), "v0");
    addSegment(timeline, server, "2014-02-14/2014-02-15", ImmutableList.of("d1"), ImmutableList.of("m1"), "v0");
    addSegment(timeline, server, "2014-02-16/2014-02-17", ImmutableList.of("d1"), ImmutableList.of("m1"), "v0");
    addSegment(timeline, server, "2014-02-17/2014-02-18", ImmutableList.of("d2"), ImmutableList.of("m2"), "v0");
    // segments within [2015-02-01, 2015-02-13]
    addSegment(timeline, server, "2015-02-01/2015-02-07", ImmutableList.of("d1"), ImmutableList.of("m1"), "v1");
    addSegment(timeline, server, "2015-02-07/2015-02-13", ImmutableList.of("d1"), ImmutableList.of("m1"), "v1");
    addSegmentWithShardSpec(timeline, server, "2015-02-03/2015-02-05", ImmutableList.of("d1", "d2"), ImmutableList.of("m1", "m2"), "v2", new NumberedShardSpec(0, 2));
    addSegmentWithShardSpec(timeline, server, "2015-02-03/2015-02-05", ImmutableList.of("d1", "d2", "d3"), ImmutableList.of("m1", "m2", "m3"), "v2", new NumberedShardSpec(1, 2));
    addSegment(timeline, server, "2015-02-09/2015-02-10", ImmutableList.of("d1", "d3"), ImmutableList.of("m1", "m3"), "v2");
    addSegment(timeline, server, "2015-02-11/2015-02-12", ImmutableList.of("d3"), ImmutableList.of("m3"), "v2");
    // segments within [2015-03-13, 2015-03-19]
    addSegment(timeline, server, "2015-03-13/2015-03-19", ImmutableList.of("d1"), ImmutableList.of("m1"), "v3");
    addSegment(timeline, server, "2015-03-13/2015-03-14", ImmutableList.of("d1"), ImmutableList.of("m1"), "v4");
    addSegment(timeline, server, "2015-03-14/2015-03-15", ImmutableList.of("d1"), ImmutableList.of("m1"), "v5");
    addSegment(timeline, server, "2015-03-15/2015-03-16", ImmutableList.of("d1"), ImmutableList.of("m1"), "v6");
    // imcomplete segment
    addSegmentWithShardSpec(timeline, server, "2015-04-03/2015-04-05", ImmutableList.of("d4"), ImmutableList.of("m4"), "v7", new NumberedShardSpec(0, 2));
    serverInventoryView = EasyMock.createMock(FilteredServerInventoryView.class);
    EasyMock.expect(serverInventoryView.getInventory()).andReturn(ImmutableList.of(server)).anyTimes();
    timelineServerView = EasyMock.createMock(TimelineServerView.class);
    EasyMock.expect(timelineServerView.getTimeline(EasyMock.anyObject(DataSourceAnalysis.class))).andReturn((Optional) Optional.of(timeline));
    EasyMock.replay(serverInventoryView, timelineServerView);
    resource = getResourceTestHelper(serverInventoryView, timelineServerView, new SegmentMetadataQueryConfig());
}
Also used : FilteredServerInventoryView(org.apache.druid.client.FilteredServerInventoryView) ServerSelector(org.apache.druid.client.selector.ServerSelector) VersionedIntervalTimeline(org.apache.druid.timeline.VersionedIntervalTimeline) DruidServer(org.apache.druid.client.DruidServer) TimelineServerView(org.apache.druid.client.TimelineServerView) DataSourceAnalysis(org.apache.druid.query.planning.DataSourceAnalysis) NumberedShardSpec(org.apache.druid.timeline.partition.NumberedShardSpec) SegmentMetadataQueryConfig(org.apache.druid.query.metadata.SegmentMetadataQueryConfig) Before(org.junit.Before)

Example 3 with TimelineServerView

use of org.apache.druid.client.TimelineServerView in project druid by druid-io.

the class SqlModuleTest method makeInjectorWithProperties.

private Injector makeInjectorWithProperties(final Properties props) {
    return Guice.createInjector(ImmutableList.of(new DruidGuiceExtensions(), new LifecycleModule(), new ServerModule(), new JacksonModule(), (Module) binder -> {
        binder.bind(Validator.class).toInstance(Validation.buildDefaultValidatorFactory().getValidator());
        binder.bind(JsonConfigurator.class).in(LazySingleton.class);
        binder.bind(Properties.class).toInstance(props);
        binder.bind(ExprMacroTable.class).toInstance(ExprMacroTable.nil());
        binder.bind(AuthorizerMapper.class).toInstance(CalciteTests.TEST_AUTHORIZER_MAPPER);
        binder.bind(Escalator.class).toInstance(new NoopEscalator());
        binder.bind(ServiceEmitter.class).toInstance(serviceEmitter);
        binder.bind(RequestLogger.class).toInstance(new NoopRequestLogger());
        binder.bind(new TypeLiteral<Supplier<DefaultQueryConfig>>() {
        }).toInstance(Suppliers.ofInstance(new DefaultQueryConfig(null)));
        binder.bind(FilteredServerInventoryView.class).toInstance(inventoryView);
        binder.bind(TimelineServerView.class).toInstance(timelineServerView);
        binder.bind(DruidLeaderClient.class).annotatedWith(Coordinator.class).toInstance(druidLeaderClient);
        binder.bind(DruidLeaderClient.class).annotatedWith(IndexingService.class).toInstance(druidLeaderClient);
        binder.bind(DruidNodeDiscoveryProvider.class).toInstance(druidNodeDiscoveryProvider);
        binder.bind(GenericQueryMetricsFactory.class).toInstance(genericQueryMetricsFactory);
        binder.bind(QuerySegmentWalker.class).toInstance(querySegmentWalker);
        binder.bind(QueryToolChestWarehouse.class).toInstance(queryToolChestWarehouse);
        binder.bind(LookupExtractorFactoryContainerProvider.class).toInstance(lookupExtractorFactoryContainerProvider);
        binder.bind(JoinableFactory.class).toInstance(joinableFactory);
        binder.bind(SegmentLoader.class).toInstance(segmentLoader);
        binder.bind(QuerySchedulerProvider.class).in(LazySingleton.class);
        binder.bind(QueryScheduler.class).toProvider(QuerySchedulerProvider.class).in(LazySingleton.class);
    }, new SqlModule(props), new TestViewManagerModule()));
}
Also used : ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) DruidGuiceExtensions(org.apache.druid.guice.DruidGuiceExtensions) Properties(java.util.Properties) ExprMacroTable(org.apache.druid.math.expr.ExprMacroTable) JoinableFactory(org.apache.druid.segment.join.JoinableFactory) ServerModule(org.apache.druid.guice.ServerModule) QuerySegmentWalker(org.apache.druid.query.QuerySegmentWalker) NoopEscalator(org.apache.druid.server.security.NoopEscalator) Escalator(org.apache.druid.server.security.Escalator) NoopEscalator(org.apache.druid.server.security.NoopEscalator) TypeLiteral(com.google.inject.TypeLiteral) QuerySchedulerProvider(org.apache.druid.server.QuerySchedulerProvider) IndexingService(org.apache.druid.client.indexing.IndexingService) RequestLogger(org.apache.druid.server.log.RequestLogger) NoopRequestLogger(org.apache.druid.server.log.NoopRequestLogger) JsonConfigurator(org.apache.druid.guice.JsonConfigurator) LookupExtractorFactoryContainerProvider(org.apache.druid.query.lookup.LookupExtractorFactoryContainerProvider) AuthorizerMapper(org.apache.druid.server.security.AuthorizerMapper) DefaultQueryConfig(org.apache.druid.query.DefaultQueryConfig) TimelineServerView(org.apache.druid.client.TimelineServerView) QueryToolChestWarehouse(org.apache.druid.query.QueryToolChestWarehouse) LifecycleModule(org.apache.druid.guice.LifecycleModule) FilteredServerInventoryView(org.apache.druid.client.FilteredServerInventoryView) NoopRequestLogger(org.apache.druid.server.log.NoopRequestLogger) GenericQueryMetricsFactory(org.apache.druid.query.GenericQueryMetricsFactory) Coordinator(org.apache.druid.client.coordinator.Coordinator) JacksonModule(org.apache.druid.jackson.JacksonModule) SegmentLoader(org.apache.druid.segment.loading.SegmentLoader) DruidNodeDiscoveryProvider(org.apache.druid.discovery.DruidNodeDiscoveryProvider) Module(com.google.inject.Module) LifecycleModule(org.apache.druid.guice.LifecycleModule) JacksonModule(org.apache.druid.jackson.JacksonModule) DruidModule(org.apache.druid.initialization.DruidModule) ServerModule(org.apache.druid.guice.ServerModule) Validator(javax.validation.Validator)

Aggregations

TimelineServerView (org.apache.druid.client.TimelineServerView)3 DruidServer (org.apache.druid.client.DruidServer)2 FilteredServerInventoryView (org.apache.druid.client.FilteredServerInventoryView)2 ServiceEmitter (org.apache.druid.java.util.emitter.service.ServiceEmitter)2 DataSourceAnalysis (org.apache.druid.query.planning.DataSourceAnalysis)2 Module (com.google.inject.Module)1 TypeLiteral (com.google.inject.TypeLiteral)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 Properties (java.util.Properties)1 Executor (java.util.concurrent.Executor)1 Validator (javax.validation.Validator)1 CachingClusteredClient (org.apache.druid.client.CachingClusteredClient)1 ImmutableDruidServer (org.apache.druid.client.ImmutableDruidServer)1 CacheConfig (org.apache.druid.client.cache.CacheConfig)1 CachePopulatorStats (org.apache.druid.client.cache.CachePopulatorStats)1 ForegroundCachePopulator (org.apache.druid.client.cache.ForegroundCachePopulator)1 Coordinator (org.apache.druid.client.coordinator.Coordinator)1 IndexingService (org.apache.druid.client.indexing.IndexingService)1