Search in sources :

Example 6 with Module

use of com.google.inject.Module in project hadoop by apache.

the class TestNodesPage method setUp.

@Before
public void setUp() throws Exception {
    final RMContext mockRMContext = TestRMWebApp.mockRMContext(3, numberOfRacks, numberOfNodesPerRack, 8 * TestRMWebApp.GiB);
    injector = WebAppTests.createMockInjector(RMContext.class, mockRMContext, new Module() {

        @Override
        public void configure(Binder binder) {
            try {
                binder.bind(ResourceManager.class).toInstance(TestRMWebApp.mockRm(mockRMContext));
            } catch (IOException e) {
                throw new IllegalStateException(e);
            }
        }
    });
}
Also used : RMContext(org.apache.hadoop.yarn.server.resourcemanager.RMContext) Binder(com.google.inject.Binder) ResourceManager(org.apache.hadoop.yarn.server.resourcemanager.ResourceManager) IOException(java.io.IOException) Module(com.google.inject.Module) Before(org.junit.Before)

Example 7 with Module

use of com.google.inject.Module 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 8 with Module

use of com.google.inject.Module 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 9 with Module

use of com.google.inject.Module 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 10 with Module

use of com.google.inject.Module 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)

Aggregations

Module (com.google.inject.Module)386 Injector (com.google.inject.Injector)253 AbstractModule (com.google.inject.AbstractModule)252 Binder (com.google.inject.Binder)63 Test (org.junit.Test)51 PrivateModule (com.google.inject.PrivateModule)46 Provider (com.google.inject.Provider)44 ArrayList (java.util.ArrayList)30 CreationException (com.google.inject.CreationException)26 Guice.createInjector (com.google.inject.Guice.createInjector)25 Map (java.util.Map)24 Properties (java.util.Properties)22 ImmutableList (com.google.common.collect.ImmutableList)20 HashMap (java.util.HashMap)20 HashSet (java.util.HashSet)20 Key (com.google.inject.Key)19 Set (java.util.Set)19 ImmutableSet (com.google.common.collect.ImmutableSet)18 Binding (com.google.inject.Binding)17 List (java.util.List)17