Fix memcached cache provider injection and add test

This commit is contained in:
Charles Allen 2015-09-21 15:00:22 -07:00
parent 6605a60ef0
commit 37eb83a1d0
2 changed files with 36 additions and 3 deletions

View File

@ -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;
}

View File

@ -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.<Module>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
{