Search in sources :

Example 6 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 7 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)

Example 8 with Binder

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

the class CacheMonitorTest method testOptionalInject.

@Test
public void testOptionalInject() throws Exception {
    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));
        }
    }));
    CacheMonitor monitor = injector.getInstance(CacheMonitor.class);
    Assert.assertNull(monitor.cache);
}
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 9 with Binder

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

the class MockMemcachedClient method testSimpleInjection.

@Test
public void testSimpleInjection() {
    final String uuid = UUID.randomUUID().toString();
    System.setProperty(uuid + ".type", "memcached");
    System.setProperty(uuid + ".hosts", "localhost");
    final Injector injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.<Module>of(new Module() {

        @Override
        public void configure(Binder binder) {
            binder.bindConstant().annotatedWith(Names.named("serviceName")).to("druid/test/memcached");
            binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0);
            binder.bind(Cache.class).toProvider(CacheProvider.class);
            JsonConfigProvider.bind(binder, uuid, CacheProvider.class);
        }
    }));
    final CacheProvider memcachedCacheProvider = injector.getInstance(CacheProvider.class);
    Assert.assertNotNull(memcachedCacheProvider);
    Assert.assertEquals(MemcachedCacheProvider.class, memcachedCacheProvider.getClass());
}
Also used : Binder(com.google.inject.Binder) Injector(com.google.inject.Injector) Module(com.google.inject.Module) Test(org.junit.Test)

Example 10 with Binder

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

the class MockMemcachedClient method testBasicInjection.

@Test
public void testBasicInjection() throws Exception {
    final MemcachedCacheConfig config = new MemcachedCacheConfig() {

        @Override
        public String getHosts() {
            return "127.0.0.1:22";
        }
    };
    Injector injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.of(new Module() {

        @Override
        public void configure(Binder binder) {
            binder.bindConstant().annotatedWith(Names.named("serviceName")).to("druid/test/memcached");
            binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0);
            binder.bind(MemcachedCacheConfig.class).toInstance(config);
            binder.bind(Cache.class).toProvider(MemcachedProviderWithConfig.class).in(ManageLifecycle.class);
        }
    }));
    Lifecycle lifecycle = injector.getInstance(Lifecycle.class);
    lifecycle.start();
    try {
        Cache cache = injector.getInstance(Cache.class);
        Assert.assertEquals(MemcachedCache.class, cache.getClass());
    } finally {
        lifecycle.stop();
    }
}
Also used : Binder(com.google.inject.Binder) Injector(com.google.inject.Injector) ManageLifecycle(io.druid.guice.ManageLifecycle) Lifecycle(io.druid.java.util.common.lifecycle.Lifecycle) Module(com.google.inject.Module) Test(org.junit.Test)

Aggregations

Binder (com.google.inject.Binder)67 Module (com.google.inject.Module)64 Injector (com.google.inject.Injector)49 Test (org.junit.Test)40 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 Provides (com.google.inject.Provides)4 LifecycleModule (io.druid.guice.LifecycleModule)4 HashSet (java.util.HashSet)4 AnnotationIntrospectorPair (com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair)3