Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memcached cache provider injection and add test #1758

Merged
merged 1 commit into from
Sep 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
29 changes: 29 additions & 0 deletions server/src/test/java/io/druid/client/cache/MemcachedCacheTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.<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
{
Expand Down