mirror of https://github.com/apache/druid.git
Make CacheScheduler a singleton (#4293)
This commit is contained in:
parent
cdd521fb23
commit
7479cbde68
|
@ -232,4 +232,10 @@ public class NamespaceLookupExtractorFactory implements LookupExtractorFactory
|
||||||
readLock.unlock();
|
readLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
CacheScheduler getCacheScheduler()
|
||||||
|
{
|
||||||
|
return cacheScheduler;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import com.google.common.base.Throwables;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.metamx.emitter.service.ServiceEmitter;
|
import com.metamx.emitter.service.ServiceEmitter;
|
||||||
import com.metamx.emitter.service.ServiceMetricEvent;
|
import com.metamx.emitter.service.ServiceMetricEvent;
|
||||||
|
import io.druid.guice.LazySingleton;
|
||||||
import io.druid.java.util.common.ISE;
|
import io.druid.java.util.common.ISE;
|
||||||
import io.druid.java.util.common.logger.Logger;
|
import io.druid.java.util.common.logger.Logger;
|
||||||
import io.druid.query.lookup.namespace.ExtractionNamespace;
|
import io.druid.query.lookup.namespace.ExtractionNamespace;
|
||||||
|
@ -60,6 +61,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||||
* entry.close(); // close the last VersionedCache and unschedule future updates
|
* entry.close(); // close the last VersionedCache and unschedule future updates
|
||||||
* }</pre>
|
* }</pre>
|
||||||
*/
|
*/
|
||||||
|
@LazySingleton
|
||||||
public final class CacheScheduler
|
public final class CacheScheduler
|
||||||
{
|
{
|
||||||
private static final Logger log = new Logger(CacheScheduler.class);
|
private static final Logger log = new Logger(CacheScheduler.class);
|
||||||
|
|
|
@ -31,7 +31,6 @@ import com.google.inject.Binder;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Key;
|
import com.google.inject.Key;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
|
|
||||||
import io.druid.guice.GuiceInjectors;
|
import io.druid.guice.GuiceInjectors;
|
||||||
import io.druid.guice.JsonConfigProvider;
|
import io.druid.guice.JsonConfigProvider;
|
||||||
import io.druid.guice.annotations.Json;
|
import io.druid.guice.annotations.Json;
|
||||||
|
@ -42,8 +41,8 @@ import io.druid.java.util.common.ISE;
|
||||||
import io.druid.query.lookup.namespace.ExtractionNamespace;
|
import io.druid.query.lookup.namespace.ExtractionNamespace;
|
||||||
import io.druid.query.lookup.namespace.URIExtractionNamespace;
|
import io.druid.query.lookup.namespace.URIExtractionNamespace;
|
||||||
import io.druid.server.DruidNode;
|
import io.druid.server.DruidNode;
|
||||||
import io.druid.server.lookup.namespace.cache.NamespaceExtractionCacheManager;
|
|
||||||
import io.druid.server.lookup.namespace.cache.CacheScheduler;
|
import io.druid.server.lookup.namespace.cache.CacheScheduler;
|
||||||
|
import io.druid.server.lookup.namespace.cache.NamespaceExtractionCacheManager;
|
||||||
import org.easymock.EasyMock;
|
import org.easymock.EasyMock;
|
||||||
import org.easymock.IExpectationSetters;
|
import org.easymock.IExpectationSetters;
|
||||||
import org.joda.time.Period;
|
import org.joda.time.Period;
|
||||||
|
@ -440,21 +439,7 @@ public class NamespaceLookupExtractorFactoryTest
|
||||||
@Test
|
@Test
|
||||||
public void testSerDe() throws Exception
|
public void testSerDe() throws Exception
|
||||||
{
|
{
|
||||||
final Injector injector = Initialization.makeInjectorWithModules(
|
final Injector injector = makeInjector();
|
||||||
GuiceInjectors.makeStartupInjector(),
|
|
||||||
ImmutableList.of(
|
|
||||||
new Module()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void configure(Binder binder)
|
|
||||||
{
|
|
||||||
JsonConfigProvider.bindInstance(
|
|
||||||
binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, null)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
final ObjectMapper mapper = injector.getInstance(Key.get(ObjectMapper.class, Json.class));
|
final ObjectMapper mapper = injector.getInstance(Key.get(ObjectMapper.class, Json.class));
|
||||||
mapper.registerSubtypes(NamespaceLookupExtractorFactory.class);
|
mapper.registerSubtypes(NamespaceLookupExtractorFactory.class);
|
||||||
final String str = "{ \"type\": \"cachedNamespace\", \"extractionNamespace\": { \"type\": \"uri\", \"uriPrefix\": \"s3://bucket/prefix/\", \"fileRegex\": \"foo.*\\\\.gz\", \"namespaceParseSpec\": { \"format\": \"customJson\", \"keyFieldName\": \"someKey\", \"valueFieldName\": \"someVal\" }, \"pollPeriod\": \"PT5M\" } } }";
|
final String str = "{ \"type\": \"cachedNamespace\", \"extractionNamespace\": { \"type\": \"uri\", \"uriPrefix\": \"s3://bucket/prefix/\", \"fileRegex\": \"foo.*\\\\.gz\", \"namespaceParseSpec\": { \"format\": \"customJson\", \"keyFieldName\": \"someKey\", \"valueFieldName\": \"someVal\" }, \"pollPeriod\": \"PT5M\" } } }";
|
||||||
|
@ -484,21 +469,7 @@ public class NamespaceLookupExtractorFactoryTest
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleIntrospectionHandler() throws Exception
|
public void testSimpleIntrospectionHandler() throws Exception
|
||||||
{
|
{
|
||||||
final Injector injector = Initialization.makeInjectorWithModules(
|
final Injector injector = makeInjector();
|
||||||
GuiceInjectors.makeStartupInjector(),
|
|
||||||
ImmutableList.of(
|
|
||||||
new Module()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void configure(Binder binder)
|
|
||||||
{
|
|
||||||
JsonConfigProvider.bindInstance(
|
|
||||||
binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, null)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
final ObjectMapper mapper = injector.getInstance(Key.get(ObjectMapper.class, Json.class));
|
final ObjectMapper mapper = injector.getInstance(Key.get(ObjectMapper.class, Json.class));
|
||||||
mapper.registerSubtypes(NamespaceLookupExtractorFactory.class);
|
mapper.registerSubtypes(NamespaceLookupExtractorFactory.class);
|
||||||
final String str = "{ \"type\": \"cachedNamespace\", \"extractionNamespace\": { \"type\": \"staticMap\", \"map\": {\"foo\":\"bar\"} }, \"firstCacheTimeout\":10000 }";
|
final String str = "{ \"type\": \"cachedNamespace\", \"extractionNamespace\": { \"type\": \"staticMap\", \"map\": {\"foo\":\"bar\"} }, \"firstCacheTimeout\":10000 }";
|
||||||
|
@ -524,6 +495,40 @@ public class NamespaceLookupExtractorFactoryTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSingletonCacheScheduler() throws Exception
|
||||||
|
{
|
||||||
|
final Injector injector = makeInjector();
|
||||||
|
final ObjectMapper mapper = injector.getInstance(Key.get(ObjectMapper.class, Json.class));
|
||||||
|
mapper.registerSubtypes(NamespaceLookupExtractorFactory.class);
|
||||||
|
final String str1 = "{ \"type\": \"cachedNamespace\", \"extractionNamespace\": { \"type\": \"staticMap\", \"map\": {\"foo\":\"bar\"} }, \"firstCacheTimeout\":10000 }";
|
||||||
|
final NamespaceLookupExtractorFactory factory1 =
|
||||||
|
(NamespaceLookupExtractorFactory) mapper.readValue(str1, LookupExtractorFactory.class);
|
||||||
|
final String str2 = "{ \"type\": \"cachedNamespace\", \"extractionNamespace\": { \"type\": \"uri\", \"uriPrefix\": \"s3://bucket/prefix/\", \"fileRegex\": \"foo.*\\\\.gz\", \"namespaceParseSpec\": { \"format\": \"customJson\", \"keyFieldName\": \"someKey\", \"valueFieldName\": \"someVal\" }, \"pollPeriod\": \"PT5M\" } } }";
|
||||||
|
final NamespaceLookupExtractorFactory factory2 =
|
||||||
|
(NamespaceLookupExtractorFactory) mapper.readValue(str2, LookupExtractorFactory.class);
|
||||||
|
Assert.assertTrue(factory1.getCacheScheduler() == factory2.getCacheScheduler());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Injector makeInjector()
|
||||||
|
{
|
||||||
|
return Initialization.makeInjectorWithModules(
|
||||||
|
GuiceInjectors.makeStartupInjector(),
|
||||||
|
ImmutableList.of(
|
||||||
|
new Module()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void configure(Binder binder)
|
||||||
|
{
|
||||||
|
JsonConfigProvider.bindInstance(
|
||||||
|
binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, null)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExceptionalIntrospectionHandler() throws Exception
|
public void testExceptionalIntrospectionHandler() throws Exception
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue