Search in sources :

Example 26 with Binder

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

the class JettyTest method setupInjector.

@Override
protected Injector setupInjector() {
    return Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.<Module>of(new Module() {

        @Override
        public void configure(Binder binder) {
            JsonConfigProvider.bindInstance(binder, Key.get(DruidNode.class, Self.class), new DruidNode("test", "localhost", null));
            binder.bind(JettyServerInitializer.class).to(JettyServerInit.class).in(LazySingleton.class);
            Multibinder<ServletFilterHolder> multibinder = Multibinder.newSetBinder(binder, ServletFilterHolder.class);
            multibinder.addBinding().toInstance(new ServletFilterHolder() {

                @Override
                public String getPath() {
                    return "/*";
                }

                @Override
                public Map<String, String> getInitParameters() {
                    return null;
                }

                @Override
                public Class<? extends Filter> getFilterClass() {
                    return DummyAuthFilter.class;
                }

                @Override
                public Filter getFilter() {
                    return null;
                }

                @Override
                public EnumSet<DispatcherType> getDispatcherType() {
                    return null;
                }
            });
            Jerseys.addResource(binder, SlowResource.class);
            Jerseys.addResource(binder, ExceptionResource.class);
            Jerseys.addResource(binder, DefaultResource.class);
            LifecycleModule.register(binder, Server.class);
        }
    }));
}
Also used : EnumSet(java.util.EnumSet) Self(io.druid.guice.annotations.Self) ServletFilterHolder(io.druid.server.initialization.jetty.ServletFilterHolder) Binder(com.google.inject.Binder) Filter(javax.servlet.Filter) DruidNode(io.druid.server.DruidNode) Module(com.google.inject.Module) LifecycleModule(io.druid.guice.LifecycleModule) Map(java.util.Map)

Example 27 with Binder

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

the class MetricsModuleTest method testSimpleInjectionWithValues.

@Test
public void testSimpleInjectionWithValues() {
    final String dataSource = "some datasource";
    final String taskId = "some task";
    final Injector injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.of(new Module() {

        @Override
        public void configure(Binder binder) {
            JsonConfigProvider.bindInstance(binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, null));
            binder.bind(Key.get(String.class, Names.named(DataSourceTaskIdHolder.DATA_SOURCE_BINDING))).toInstance(dataSource);
            binder.bind(Key.get(String.class, Names.named(DataSourceTaskIdHolder.TASK_ID_BINDING))).toInstance(taskId);
        }
    }));
    final DataSourceTaskIdHolder dimensionIdHolder = new DataSourceTaskIdHolder();
    injector.injectMembers(dimensionIdHolder);
    Assert.assertEquals(dataSource, dimensionIdHolder.getDataSource());
    Assert.assertEquals(taskId, dimensionIdHolder.getTaskId());
}
Also used : Binder(com.google.inject.Binder) Injector(com.google.inject.Injector) DruidNode(io.druid.server.DruidNode) Self(io.druid.guice.annotations.Self) Module(com.google.inject.Module) Test(org.junit.Test)

Example 28 with Binder

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

the class CalciteTests method createOperatorTable.

public static DruidOperatorTable createOperatorTable() {
    try {
        final Injector injector = Guice.createInjector(new Module() {

            @Override
            public void configure(final Binder binder) {
                // This Module is just to get a LookupReferencesManager with a usable "lookyloo" lookup.
                final LookupReferencesManager mock = EasyMock.createMock(LookupReferencesManager.class);
                EasyMock.expect(mock.get(EasyMock.eq("lookyloo"))).andReturn(new LookupExtractorFactory() {

                    @Override
                    public boolean start() {
                        throw new UnsupportedOperationException();
                    }

                    @Override
                    public boolean close() {
                        throw new UnsupportedOperationException();
                    }

                    @Override
                    public boolean replaces(@Nullable final LookupExtractorFactory other) {
                        throw new UnsupportedOperationException();
                    }

                    @Nullable
                    @Override
                    public LookupIntrospectHandler getIntrospectHandler() {
                        throw new UnsupportedOperationException();
                    }

                    @Override
                    public LookupExtractor get() {
                        return new MapLookupExtractor(ImmutableMap.of("a", "xa", "abc", "xabc"), false);
                    }
                }).anyTimes();
                EasyMock.replay(mock);
                binder.bind(LookupReferencesManager.class).toInstance(mock);
            }
        });
        final Set<SqlAggregator> aggregators = new HashSet<>();
        final Set<SqlExtractionOperator> extractionOperators = new HashSet<>();
        for (Class<? extends SqlAggregator> clazz : SqlModule.DEFAULT_AGGREGATOR_CLASSES) {
            aggregators.add(injector.getInstance(clazz));
        }
        for (Class<? extends SqlExtractionOperator> clazz : SqlModule.DEFAULT_EXTRACTION_OPERATOR_CLASSES) {
            extractionOperators.add(injector.getInstance(clazz));
        }
        return new DruidOperatorTable(aggregators, extractionOperators);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : LookupExtractorFactory(io.druid.query.lookup.LookupExtractorFactory) LookupReferencesManager(io.druid.query.lookup.LookupReferencesManager) DruidOperatorTable(io.druid.sql.calcite.planner.DruidOperatorTable) LookupExtractor(io.druid.query.lookup.LookupExtractor) MapLookupExtractor(io.druid.query.extraction.MapLookupExtractor) LookupIntrospectHandler(io.druid.query.lookup.LookupIntrospectHandler) Binder(com.google.inject.Binder) SqlExtractionOperator(io.druid.sql.calcite.expression.SqlExtractionOperator) Injector(com.google.inject.Injector) SqlAggregator(io.druid.sql.calcite.aggregation.SqlAggregator) MapLookupExtractor(io.druid.query.extraction.MapLookupExtractor) Module(com.google.inject.Module) SqlModule(io.druid.sql.guice.SqlModule) Nullable(javax.annotation.Nullable) HashSet(java.util.HashSet)

Example 29 with Binder

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

the class TimestampMinMaxAggregatorTest method setup.

@Before
public void setup() throws Exception {
    injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.of(new Module() {

        @Override
        public void configure(Binder binder) {
            binder.bindConstant().annotatedWith(Names.named("serviceName")).to("test");
            binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0);
        }
    }, new TimestampMinMaxModule()));
    mapper = injector.getInstance(ObjectMapper.class);
    String json = "{\"type\":\"" + aggType + "\",\"name\":\"" + aggType + "\",\"fieldName\":\"test\"}";
    aggregatorFactory = mapper.readValue(json, aggClass);
    selector = new TestObjectColumnSelector(values);
    selectorFactory = EasyMock.createMock(ColumnSelectorFactory.class);
    EasyMock.expect(selectorFactory.makeObjectColumnSelector("test")).andReturn(selector);
    EasyMock.replay(selectorFactory);
}
Also used : Binder(com.google.inject.Binder) ColumnSelectorFactory(io.druid.segment.ColumnSelectorFactory) Module(com.google.inject.Module) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 30 with Binder

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

the class OrcHadoopInputRowParserTest method setUp.

@Before
public void setUp() {
    injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.of(new Module() {

        @Override
        public void configure(Binder binder) {
            binder.bindConstant().annotatedWith(Names.named("serviceName")).to("test");
            binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0);
        }
    }, new OrcExtensionsModule()));
    mapper = injector.getInstance(ObjectMapper.class);
}
Also used : Binder(com.google.inject.Binder) Module(com.google.inject.Module) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Before(org.junit.Before)

Aggregations

Binder (com.google.inject.Binder)72 Module (com.google.inject.Module)65 Injector (com.google.inject.Injector)51 Test (org.junit.Test)41 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)13 Self (io.druid.guice.annotations.Self)12 DruidNode (io.druid.server.DruidNode)12 IOException (java.io.IOException)10 TypeLiteral (com.google.inject.TypeLiteral)9 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)9 Properties (java.util.Properties)8 RMContext (org.apache.hadoop.yarn.server.resourcemanager.RMContext)7 ResourceManager (org.apache.hadoop.yarn.server.resourcemanager.ResourceManager)7 ImmutableList (com.google.common.collect.ImmutableList)5 Lifecycle (io.druid.java.util.common.lifecycle.Lifecycle)5 List (java.util.List)5 Key (com.google.inject.Key)4 Provides (com.google.inject.Provides)4 LifecycleModule (io.druid.guice.LifecycleModule)4 HashSet (java.util.HashSet)4