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 4d71d54ca7f..e01db9fadf3 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 77631141aaa..9b3017bd16a 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 com.metamx.metrics.MonitorScheduler; 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.Collection; 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 class MemcachedCacheTest } } + @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 {