Search in sources :

Example 1 with CacheModule

use of io.druid.guice.CacheModule in project druid by druid-io.

the class HybridCacheTest method testInjection.

@Test
public void testInjection() throws Exception {
    final String prefix = "testInjectHybridCache";
    System.setProperty(prefix + ".type", "hybrid");
    System.setProperty(prefix + ".l1.type", "local");
    System.setProperty(prefix + ".l2.type", "memcached");
    System.setProperty(prefix + ".l2.hosts", "localhost:11711");
    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("hybridTest");
            binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0);
            binder.install(new CacheModule(prefix));
        }
    }));
    final CacheProvider cacheProvider = injector.getInstance(Key.get(CacheProvider.class, Global.class));
    Assert.assertNotNull(cacheProvider);
    Assert.assertEquals(HybridCacheProvider.class, cacheProvider.getClass());
    final Cache cache = cacheProvider.get();
    Assert.assertNotNull(cache);
    Assert.assertFalse(cache.isLocal());
    Assert.assertEquals(LocalCacheProvider.class, ((HybridCacheProvider) cacheProvider).level1.getClass());
    Assert.assertEquals(MemcachedCacheProvider.class, ((HybridCacheProvider) cacheProvider).level2.getClass());
}
Also used : Binder(com.google.inject.Binder) Injector(com.google.inject.Injector) CacheModule(io.druid.guice.CacheModule) Module(com.google.inject.Module) CacheModule(io.druid.guice.CacheModule) Global(io.druid.guice.annotations.Global) Test(org.junit.Test)

Aggregations

Binder (com.google.inject.Binder)1 Injector (com.google.inject.Injector)1 Module (com.google.inject.Module)1 CacheModule (io.druid.guice.CacheModule)1 Global (io.druid.guice.annotations.Global)1 Test (org.junit.Test)1