Search in sources :

Example 51 with Injector

use of com.google.inject.Injector 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 52 with Injector

use of com.google.inject.Injector 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 53 with Injector

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

Example 54 with Injector

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

the class ComposingEmitterModuleTest method testGetEmitterViaRealGuice.

@Test
public void testGetEmitterViaRealGuice() {
    Injector injector = Guice.createInjector(new DruidGuiceExtensions(), new LifecycleModule(), new Module() {

        @Override
        public void configure(Binder binder) {
            Properties props = new Properties();
            props.put("druid.emitter.composing.emitters", "[\"" + testEmitterType + "\"]");
            binder.bind(Properties.class).toInstance(props);
            binder.bind(Validator.class).toInstance(Validation.buildDefaultValidatorFactory().getValidator());
            binder.bind(Emitter.class).annotatedWith(Names.named(testEmitterType)).toInstance(emitter);
        }
    }, new ComposingEmitterModule());
    injector.getInstance(Key.get(Emitter.class, Names.named("composing"))).start();
    EasyMock.verify(emitter);
}
Also used : Binder(com.google.inject.Binder) Emitter(com.metamx.emitter.core.Emitter) DruidGuiceExtensions(io.druid.guice.DruidGuiceExtensions) Injector(com.google.inject.Injector) Module(com.google.inject.Module) LifecycleModule(io.druid.guice.LifecycleModule) ComposingEmitterModule(io.druid.server.initialization.ComposingEmitterModule) Properties(java.util.Properties) ComposingEmitterModule(io.druid.server.initialization.ComposingEmitterModule) LifecycleModule(io.druid.guice.LifecycleModule) Test(org.junit.Test)

Example 55 with Injector

use of com.google.inject.Injector in project OpenAM by OpenRock.

the class SoapSTSInstanceStateServiceListenerTest method setUpTest.

@BeforeTest
public void setUpTest() {
    final Injector injector = Guice.createInjector(new TestModule());
    provider = injector.getInstance(SoapSTSInstanceStateProvider.class);
    serviceListener = injector.getInstance(Key.get(ServiceListener.class, Names.named(TokenGenerationModule.SOAP_STS_INSTANCE_STATE_LISTENER)));
}
Also used : Injector(com.google.inject.Injector) SoapSTSInstanceStateProvider(org.forgerock.openam.sts.tokengeneration.state.SoapSTSInstanceStateProvider) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

Injector (com.google.inject.Injector)2159 AbstractModule (com.google.inject.AbstractModule)623 Test (org.junit.Test)513 Module (com.google.inject.Module)364 Test (org.testng.annotations.Test)131 Before (org.junit.Before)116 Binder (com.google.inject.Binder)114 Properties (java.util.Properties)110 Key (com.google.inject.Key)84 Map (java.util.Map)78 HttpServletRequest (javax.servlet.http.HttpServletRequest)78 Provider (com.google.inject.Provider)74 IOException (java.io.IOException)71 TypeLiteral (com.google.inject.TypeLiteral)70 Set (java.util.Set)64 BeforeClass (org.junit.BeforeClass)61 File (java.io.File)60 CConfiguration (co.cask.cdap.common.conf.CConfiguration)55 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)55 PrivateModule (com.google.inject.PrivateModule)55