Search in sources :

Example 11 with Injector

use of com.google.inject.Injector in project druid by druid-io.

the class IngestSegmentFirehoseFactoryTimelineTest method constructorFeeder.

@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> constructorFeeder() {
    final List<TestCase> testCases = ImmutableList.of(TC("2000/2000T02", 3, 7, DS("2000/2000T01", "v1", 0, IR("2000", 1), IR("2000T00:01", 2)), DS("2000T01/2000T02", "v1", 0, IR("2000T01", 4))), /* Adjacent segments */
    TC("2000/2000T02", 3, 7, DS("2000/2000T02", "v1", 0, IR("2000", 1), IR("2000T00:01", 2), IR("2000T01", 8)), DS("2000T01/2000T02", "v2", 0, IR("2000T01:01", 4))), /* 1H segment overlaid on top of 2H segment */
    TC("2000/2000-01-02", 4, 23, DS("2000/2000-01-02", "v1", 0, IR("2000", 1), IR("2000T00:01", 2), IR("2000T01", 8), IR("2000T02", 16)), DS("2000T01/2000T02", "v2", 0, IR("2000T01:01", 4))), /* 1H segment overlaid on top of 1D segment */
    TC("2000/2000T02", 4, 15, DS("2000/2000T02", "v1", 0, IR("2000", 1), IR("2000T00:01", 2), IR("2000T01", 8)), DS("2000/2000T02", "v1", 1, IR("2000T01:01", 4))), /* Segment set with two segments for the same interval */
    TC("2000T01/2000T02", 1, 2, DS("2000/2000T03", "v1", 0, IR("2000", 1), IR("2000T01", 2), IR("2000T02", 4))), /* Segment wider than desired interval */
    TC("2000T02/2000T04", 2, 12, DS("2000/2000T03", "v1", 0, IR("2000", 1), IR("2000T01", 2), IR("2000T02", 4)), DS("2000T03/2000T04", "v1", 0, IR("2000T03", 8))));
    final List<Object[]> constructors = Lists.newArrayList();
    for (final TestCase testCase : testCases) {
        final TaskActionClient taskActionClient = new TaskActionClient() {

            @Override
            public <RetType> RetType submit(TaskAction<RetType> taskAction) throws IOException {
                if (taskAction instanceof SegmentListUsedAction) {
                    // Expect the interval we asked for
                    final SegmentListUsedAction action = (SegmentListUsedAction) taskAction;
                    if (action.getIntervals().equals(ImmutableList.of(testCase.interval))) {
                        return (RetType) ImmutableList.copyOf(testCase.segments);
                    } else {
                        throw new IllegalArgumentException("WTF");
                    }
                } else {
                    throw new UnsupportedOperationException();
                }
            }
        };
        SegmentHandoffNotifierFactory notifierFactory = EasyMock.createNiceMock(SegmentHandoffNotifierFactory.class);
        EasyMock.replay(notifierFactory);
        final TaskToolboxFactory taskToolboxFactory = new TaskToolboxFactory(new TaskConfig(testCase.tmpDir.getAbsolutePath(), null, null, 50000, null, false, null, null), new TaskActionClientFactory() {

            @Override
            public TaskActionClient create(Task task) {
                return taskActionClient;
            }
        }, new NoopServiceEmitter(), // segment pusher
        null, // segment killer
        null, // segment mover
        null, // segment archiver
        null, // segment announcer,
        null, notifierFactory, // query runner factory conglomerate corporation unionized collective
        null, // query executor service
        null, // monitor scheduler
        null, new SegmentLoaderFactory(new SegmentLoaderLocalCacheManager(null, new SegmentLoaderConfig() {

            @Override
            public List<StorageLocationConfig> getLocations() {
                return Lists.newArrayList();
            }
        }, MAPPER)), MAPPER, INDEX_MERGER, INDEX_IO, null, null, INDEX_MERGER_V9);
        final Injector injector = Guice.createInjector(new Module() {

            @Override
            public void configure(Binder binder) {
                binder.bind(TaskToolboxFactory.class).toInstance(taskToolboxFactory);
            }
        });
        final IngestSegmentFirehoseFactory factory = new IngestSegmentFirehoseFactory(DATA_SOURCE, testCase.interval, new NoopDimFilter(), Arrays.asList(DIMENSIONS), Arrays.asList(METRICS), injector, INDEX_IO);
        constructors.add(new Object[] { testCase.toString(), factory, testCase.tmpDir, testCase.expectedCount, testCase.expectedSum });
    }
    return constructors;
}
Also used : Task(io.druid.indexing.common.task.Task) NoopDimFilter(io.druid.query.filter.NoopDimFilter) TaskAction(io.druid.indexing.common.actions.TaskAction) TaskActionClientFactory(io.druid.indexing.common.actions.TaskActionClientFactory) TaskConfig(io.druid.indexing.common.config.TaskConfig) Binder(com.google.inject.Binder) TaskToolboxFactory(io.druid.indexing.common.TaskToolboxFactory) Injector(com.google.inject.Injector) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) SegmentLoaderConfig(io.druid.segment.loading.SegmentLoaderConfig) SegmentLoaderFactory(io.druid.indexing.common.SegmentLoaderFactory) SegmentLoaderLocalCacheManager(io.druid.segment.loading.SegmentLoaderLocalCacheManager) NoopServiceEmitter(io.druid.server.metrics.NoopServiceEmitter) SegmentHandoffNotifierFactory(io.druid.segment.realtime.plumber.SegmentHandoffNotifierFactory) TaskActionClient(io.druid.indexing.common.actions.TaskActionClient) SegmentListUsedAction(io.druid.indexing.common.actions.SegmentListUsedAction) Module(com.google.inject.Module)

Example 12 with Injector

use of com.google.inject.Injector in project druid by druid-io.

the class IndexerZkConfigTest method testExactConfig.

@Test
public void testExactConfig() {
    final Injector injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.<Module>of(simpleZkConfigModule));
    propertyValues.setProperty(zkServiceConfigString + ".base", "/druid/metrics");
    JsonConfigurator configurator = injector.getBinding(JsonConfigurator.class).getProvider().get();
    JsonConfigProvider<ZkPathsConfig> zkPathsConfig = JsonConfigProvider.of(zkServiceConfigString, ZkPathsConfig.class);
    zkPathsConfig.inject(propertyValues, configurator);
    ZkPathsConfig zkPathsConfig1 = zkPathsConfig.get().get();
    IndexerZkConfig indexerZkConfig = new IndexerZkConfig(zkPathsConfig1, null, null, null, null, null);
    Assert.assertEquals("/druid/metrics/indexer", indexerZkConfig.getBase());
    Assert.assertEquals("/druid/metrics/indexer/announcements", indexerZkConfig.getAnnouncementsPath());
}
Also used : Injector(com.google.inject.Injector) JsonConfigurator(io.druid.guice.JsonConfigurator) Test(org.junit.Test)

Example 13 with Injector

use of com.google.inject.Injector in project druid by druid-io.

the class IndexerZkConfigTest method testNullConfig.

@Test
public void testNullConfig() {
    propertyValues.clear();
    final Injector injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.<Module>of(simpleZkConfigModule));
    JsonConfigurator configurator = injector.getBinding(JsonConfigurator.class).getProvider().get();
    JsonConfigProvider<ZkPathsConfig> zkPathsConfig = JsonConfigProvider.of(zkServiceConfigString, ZkPathsConfig.class);
    zkPathsConfig.inject(propertyValues, configurator);
    JsonConfigProvider<IndexerZkConfig> indexerZkConfig = JsonConfigProvider.of(indexerPropertyString, IndexerZkConfig.class);
    indexerZkConfig.inject(propertyValues, configurator);
    Assert.assertEquals("/druid/indexer/leaderLatchPath", indexerZkConfig.get().get().getLeaderLatchPath());
}
Also used : Injector(com.google.inject.Injector) JsonConfigurator(io.druid.guice.JsonConfigurator) Test(org.junit.Test)

Example 14 with Injector

use of com.google.inject.Injector in project druid by druid-io.

the class IndexerZkConfigTest method testSimpleConfig.

@Test
public void testSimpleConfig() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
    final Injector injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.<Module>of(simpleZkConfigModule));
    JsonConfigurator configurator = injector.getBinding(JsonConfigurator.class).getProvider().get();
    JsonConfigProvider<ZkPathsConfig> zkPathsConfig = JsonConfigProvider.of(zkServiceConfigString, ZkPathsConfig.class);
    zkPathsConfig.inject(propertyValues, configurator);
    JsonConfigProvider<IndexerZkConfig> indexerZkConfig = JsonConfigProvider.of(indexerPropertyString, IndexerZkConfig.class);
    indexerZkConfig.inject(propertyValues, configurator);
    IndexerZkConfig zkConfig = indexerZkConfig.get().get();
    ZkPathsConfig zkPathsConfig1 = zkPathsConfig.get().get();
    validateEntries(zkConfig);
    validateEntries(zkPathsConfig1);
    Assert.assertEquals(clobberableProperties.size(), assertions);
}
Also used : Injector(com.google.inject.Injector) JsonConfigurator(io.druid.guice.JsonConfigurator) Test(org.junit.Test)

Example 15 with Injector

use of com.google.inject.Injector in project druid by druid-io.

the class MetadataStorageTablesConfigTest method testSerdeMetadataStorageTablesConfig.

@Test
public void testSerdeMetadataStorageTablesConfig() throws Exception {
    Injector injector = Guice.createInjector(new Module() {

        @Override
        public void configure(Binder binder) {
            binder.install(new PropertiesModule(Arrays.asList("test.runtime.properties")));
            binder.install(new ConfigModule());
            binder.install(new DruidGuiceExtensions());
            JsonConfigProvider.bind(binder, "druid.metadata.storage.tables", MetadataStorageTablesConfig.class);
        }

        @Provides
        @LazySingleton
        public ObjectMapper jsonMapper() {
            return new DefaultObjectMapper();
        }
    });
    Properties props = injector.getInstance(Properties.class);
    MetadataStorageTablesConfig config = injector.getInstance(MetadataStorageTablesConfig.class);
    Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.base"), config.getBase());
    Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.segments"), config.getSegmentsTable());
    Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.rules"), config.getRulesTable());
    Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.config"), config.getConfigTable());
    Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.tasks"), config.getEntryTable(MetadataStorageTablesConfig.TASK_ENTRY_TYPE));
    Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.taskLog"), config.getLogTable(MetadataStorageTablesConfig.TASK_ENTRY_TYPE));
    Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.taskLock"), config.getLockTable(MetadataStorageTablesConfig.TASK_ENTRY_TYPE));
    Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.dataSource"), config.getDataSourceTable());
    Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.supervisors"), config.getSupervisorTable());
}
Also used : Provides(com.google.inject.Provides) Properties(java.util.Properties) Binder(com.google.inject.Binder) MetadataStorageTablesConfig(io.druid.metadata.MetadataStorageTablesConfig) Injector(com.google.inject.Injector) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Module(com.google.inject.Module) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

Injector (com.google.inject.Injector)2117 AbstractModule (com.google.inject.AbstractModule)624 Test (org.junit.Test)513 Module (com.google.inject.Module)386 Binder (com.google.inject.Binder)140 Before (org.junit.Before)116 Properties (java.util.Properties)110 Test (org.testng.annotations.Test)105 Key (com.google.inject.Key)91 HttpServletRequest (javax.servlet.http.HttpServletRequest)78 Map (java.util.Map)75 Provider (com.google.inject.Provider)74 TypeLiteral (com.google.inject.TypeLiteral)70 IOException (java.io.IOException)69 Set (java.util.Set)63 BeforeClass (org.junit.BeforeClass)61 File (java.io.File)59 ImmutableList (com.google.common.collect.ImmutableList)58 CConfiguration (co.cask.cdap.common.conf.CConfiguration)55 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)55