mirror of https://github.com/apache/druid.git
Fix memcached cache provider injection and add test
This commit is contained in:
parent
6605a60ef0
commit
37eb83a1d0
|
@ -17,15 +17,19 @@
|
||||||
|
|
||||||
package io.druid.client.cache;
|
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;
|
import com.metamx.metrics.MonitorScheduler;
|
||||||
|
|
||||||
public class MemcachedCacheProvider extends MemcachedCacheConfig implements CacheProvider
|
public class MemcachedCacheProvider extends MemcachedCacheConfig implements CacheProvider
|
||||||
{
|
{
|
||||||
private final MonitorScheduler emitter;
|
private final MonitorScheduler emitter;
|
||||||
|
|
||||||
@Inject
|
@JsonCreator
|
||||||
public MemcachedCacheProvider(MonitorScheduler emitter)
|
public MemcachedCacheProvider(
|
||||||
|
@JacksonInject
|
||||||
|
MonitorScheduler emitter
|
||||||
|
)
|
||||||
{
|
{
|
||||||
this.emitter = emitter;
|
this.emitter = emitter;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ import com.metamx.metrics.MonitorScheduler;
|
||||||
import io.druid.collections.ResourceHolder;
|
import io.druid.collections.ResourceHolder;
|
||||||
import io.druid.collections.StupidResourceHolder;
|
import io.druid.collections.StupidResourceHolder;
|
||||||
import io.druid.guice.GuiceInjectors;
|
import io.druid.guice.GuiceInjectors;
|
||||||
|
import io.druid.guice.JsonConfigProvider;
|
||||||
import io.druid.guice.ManageLifecycle;
|
import io.druid.guice.ManageLifecycle;
|
||||||
import io.druid.initialization.Initialization;
|
import io.druid.initialization.Initialization;
|
||||||
import io.druid.jackson.DefaultObjectMapper;
|
import io.druid.jackson.DefaultObjectMapper;
|
||||||
|
@ -67,6 +68,7 @@ import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
import java.util.concurrent.CountDownLatch;
|
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
|
@Test
|
||||||
public void testMonitor() throws Exception
|
public void testMonitor() throws Exception
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue