diff --git a/server/src/main/java/io/druid/client/cache/MemcachedCacheProvider.java b/server/src/main/java/io/druid/client/cache/MemcachedCacheProvider.java index 4d71d54ca7fc..e01db9fadf3c 100644 --- a/server/src/main/java/io/druid/client/cache/MemcachedCacheProvider.java +++ b/server/src/main/java/io/druid/client/cache/MemcachedCacheProvider.java @@ -17,15 +17,19 @@ package io.druid.client.cache; -import com.google.inject.Inject; +import com.fasterxml.jackson.annotation.JacksonInject; +import com.fasterxml.jackson.annotation.JsonCreator; import com.metamx.metrics.MonitorScheduler; public class MemcachedCacheProvider extends MemcachedCacheConfig implements CacheProvider { private final MonitorScheduler emitter; - @Inject - public MemcachedCacheProvider(MonitorScheduler emitter) + @JsonCreator + public MemcachedCacheProvider( + @JacksonInject + MonitorScheduler emitter + ) { this.emitter = emitter; } diff --git a/server/src/test/java/io/druid/client/cache/MemcachedCacheTest.java b/server/src/test/java/io/druid/client/cache/MemcachedCacheTest.java index 77631141aaaa..9b3017bd16a1 100644 --- a/server/src/test/java/io/druid/client/cache/MemcachedCacheTest.java +++ b/server/src/test/java/io/druid/client/cache/MemcachedCacheTest.java @@ -38,6 +38,7 @@ import io.druid.collections.ResourceHolder; import io.druid.collections.StupidResourceHolder; import io.druid.guice.GuiceInjectors; +import io.druid.guice.JsonConfigProvider; import io.druid.guice.ManageLifecycle; import io.druid.initialization.Initialization; import io.druid.jackson.DefaultObjectMapper; @@ -67,6 +68,7 @@ import java.util.Iterator; import java.util.Map; import java.util.Set; +import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CountDownLatch; @@ -159,6 +161,33 @@ public void configure(Binder binder) } } + @Test + public void testSimpleInjection() + { + final String uuid = UUID.randomUUID().toString(); + System.setProperty(uuid + ".type", "memcached"); + System.setProperty(uuid + ".hosts", "localhost"); + final MonitorScheduler monitorScheduler = EasyMock.createNiceMock(MonitorScheduler.class); + EasyMock.replay(monitorScheduler); + final Injector injector = Initialization.makeInjectorWithModules( + GuiceInjectors.makeStartupInjector(), ImmutableList.of( + new Module() + { + @Override + public void configure(Binder binder) + { + binder.bind(MonitorScheduler.class).toInstance(monitorScheduler); + 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()); + } + @Test public void testMonitor() throws Exception {