mirror of https://github.com/apache/druid.git
* Renamed ExtractionNamespaceCacheFactory to CachePopulator, and related classes * Rename CachePopulator to CacheGenerator
This commit is contained in:
parent
b90c28e861
commit
ebabe14fbe
|
@ -26,25 +26,25 @@ import javax.annotation.Nullable;
|
|||
/**
|
||||
*
|
||||
*/
|
||||
public interface ExtractionNamespaceCacheFactory<T extends ExtractionNamespace>
|
||||
public interface CacheGenerator<T extends ExtractionNamespace>
|
||||
{
|
||||
/**
|
||||
* If the lookup source, encapsulated by this {@code ExtractionNamespaceCacheFactory}, has data newer than identified
|
||||
* If the lookup source, encapsulated by this {@code CacheGenerator}, has data newer than identified
|
||||
* by the given {@code lastVersion} (which is null at the first run of this method, or the version from the previous
|
||||
* run), this method creates a new {@code CacheScheduler.VersionedCache} with {@link
|
||||
* CacheScheduler#createVersionedCache}, called on the given {@code scheduler}, with the version string identifying
|
||||
* the current version of lookup source, populates the created {@code VersionedCache} and returns it. If the lookup
|
||||
* source is up-to-date, this methods returns null.
|
||||
*
|
||||
* @param namespace The ExtractionNamespace for which to populate data.
|
||||
* @param id An object uniquely corresponding to the {@link CacheScheduler.Entry}, for which this populateCache()
|
||||
* @param namespace The ExtractionNamespace for which to generate cache.
|
||||
* @param id An object uniquely corresponding to the {@link CacheScheduler.Entry}, for which this generateCache()
|
||||
* method is called. Also it has the same toString() representation, that is useful for logging
|
||||
* @param lastVersion The version which was last cached
|
||||
* @param scheduler Should be used only to call {@link CacheScheduler#createVersionedCache}.
|
||||
* @return the new cache along with the new version, or null if the last version is up-to-date.
|
||||
*/
|
||||
@Nullable
|
||||
CacheScheduler.VersionedCache populateCache(
|
||||
CacheScheduler.VersionedCache generateCache(
|
||||
T namespace,
|
||||
CacheScheduler.EntryImpl<T> id,
|
||||
String lastVersion,
|
|
@ -24,8 +24,8 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
|||
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
|
||||
@JsonSubTypes(value = {
|
||||
@JsonSubTypes.Type(name = "jdbc", value = JDBCExtractionNamespace.class),
|
||||
@JsonSubTypes.Type(name = "uri", value = URIExtractionNamespace.class),
|
||||
@JsonSubTypes.Type(name = "jdbc", value = JdbcExtractionNamespace.class),
|
||||
@JsonSubTypes.Type(name = "uri", value = UriExtractionNamespace.class),
|
||||
@JsonSubTypes.Type(name = StaticMapExtractionNamespace.TYPE_NAME, value = StaticMapExtractionNamespace.class)
|
||||
})
|
||||
/**
|
||||
|
|
|
@ -34,7 +34,7 @@ import javax.validation.constraints.NotNull;
|
|||
*
|
||||
*/
|
||||
@JsonTypeName("jdbc")
|
||||
public class JDBCExtractionNamespace implements ExtractionNamespace
|
||||
public class JdbcExtractionNamespace implements ExtractionNamespace
|
||||
{
|
||||
@JsonProperty
|
||||
private final MetadataStorageConnectorConfig connectorConfig;
|
||||
|
@ -50,7 +50,7 @@ public class JDBCExtractionNamespace implements ExtractionNamespace
|
|||
private final Period pollPeriod;
|
||||
|
||||
@JsonCreator
|
||||
public JDBCExtractionNamespace(
|
||||
public JdbcExtractionNamespace(
|
||||
@NotNull @JsonProperty(value = "connectorConfig", required = true)
|
||||
final MetadataStorageConnectorConfig connectorConfig,
|
||||
@NotNull @JsonProperty(value = "table", required = true)
|
||||
|
@ -109,7 +109,7 @@ public class JDBCExtractionNamespace implements ExtractionNamespace
|
|||
public String toString()
|
||||
{
|
||||
return String.format(
|
||||
"JDBCExtractionNamespace = { connectorConfig = { %s }, table = %s, keyColumn = %s, valueColumn = %s, tsColumn = %s, pollPeriod = %s}",
|
||||
"JdbcExtractionNamespace = { connectorConfig = { %s }, table = %s, keyColumn = %s, valueColumn = %s, tsColumn = %s, pollPeriod = %s}",
|
||||
connectorConfig.toString(),
|
||||
table,
|
||||
keyColumn,
|
||||
|
@ -129,7 +129,7 @@ public class JDBCExtractionNamespace implements ExtractionNamespace
|
|||
return false;
|
||||
}
|
||||
|
||||
JDBCExtractionNamespace that = (JDBCExtractionNamespace) o;
|
||||
JdbcExtractionNamespace that = (JdbcExtractionNamespace) o;
|
||||
|
||||
if (!connectorConfig.equals(that.connectorConfig)) {
|
||||
return false;
|
|
@ -59,7 +59,7 @@ import java.util.regex.PatternSyntaxException;
|
|||
*
|
||||
*/
|
||||
@JsonTypeName("uri")
|
||||
public class URIExtractionNamespace implements ExtractionNamespace
|
||||
public class UriExtractionNamespace implements ExtractionNamespace
|
||||
{
|
||||
@JsonProperty
|
||||
private final URI uri;
|
||||
|
@ -73,7 +73,7 @@ public class URIExtractionNamespace implements ExtractionNamespace
|
|||
private final Period pollPeriod;
|
||||
|
||||
@JsonCreator
|
||||
public URIExtractionNamespace(
|
||||
public UriExtractionNamespace(
|
||||
@JsonProperty(value = "uri", required = false)
|
||||
URI uri,
|
||||
@JsonProperty(value = "uriPrefix", required = false)
|
||||
|
@ -144,7 +144,7 @@ public class URIExtractionNamespace implements ExtractionNamespace
|
|||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "URIExtractionNamespace{" +
|
||||
return "UriExtractionNamespace{" +
|
||||
"uri=" + uri +
|
||||
", uriPrefix=" + uriPrefix +
|
||||
", namespaceParseSpec=" + namespaceParseSpec +
|
||||
|
@ -163,7 +163,7 @@ public class URIExtractionNamespace implements ExtractionNamespace
|
|||
return false;
|
||||
}
|
||||
|
||||
URIExtractionNamespace that = (URIExtractionNamespace) o;
|
||||
UriExtractionNamespace that = (UriExtractionNamespace) o;
|
||||
|
||||
if (getUri() != null ? !getUri().equals(that.getUri()) : that.getUri() != null) {
|
||||
return false;
|
|
@ -22,8 +22,8 @@ package io.druid.server.lookup.namespace;
|
|||
import io.druid.common.utils.JodaUtils;
|
||||
import io.druid.java.util.common.Pair;
|
||||
import io.druid.java.util.common.logger.Logger;
|
||||
import io.druid.query.lookup.namespace.ExtractionNamespaceCacheFactory;
|
||||
import io.druid.query.lookup.namespace.JDBCExtractionNamespace;
|
||||
import io.druid.query.lookup.namespace.CacheGenerator;
|
||||
import io.druid.query.lookup.namespace.JdbcExtractionNamespace;
|
||||
import io.druid.server.lookup.namespace.cache.CacheScheduler;
|
||||
import org.skife.jdbi.v2.DBI;
|
||||
import org.skife.jdbi.v2.Handle;
|
||||
|
@ -44,18 +44,17 @@ import java.util.concurrent.ConcurrentMap;
|
|||
/**
|
||||
*
|
||||
*/
|
||||
public final class JDBCExtractionNamespaceCacheFactory
|
||||
implements ExtractionNamespaceCacheFactory<JDBCExtractionNamespace>
|
||||
public final class JdbcCacheGenerator implements CacheGenerator<JdbcExtractionNamespace>
|
||||
{
|
||||
private static final Logger LOG = new Logger(JDBCExtractionNamespaceCacheFactory.class);
|
||||
private final ConcurrentMap<CacheScheduler.EntryImpl<JDBCExtractionNamespace>, DBI> dbiCache =
|
||||
private static final Logger LOG = new Logger(JdbcCacheGenerator.class);
|
||||
private final ConcurrentMap<CacheScheduler.EntryImpl<JdbcExtractionNamespace>, DBI> dbiCache =
|
||||
new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public CacheScheduler.VersionedCache populateCache(
|
||||
final JDBCExtractionNamespace namespace,
|
||||
final CacheScheduler.EntryImpl<JDBCExtractionNamespace> entryId,
|
||||
public CacheScheduler.VersionedCache generateCache(
|
||||
final JdbcExtractionNamespace namespace,
|
||||
final CacheScheduler.EntryImpl<JdbcExtractionNamespace> entryId,
|
||||
final String lastVersion,
|
||||
final CacheScheduler scheduler
|
||||
)
|
||||
|
@ -132,9 +131,9 @@ public final class JDBCExtractionNamespaceCacheFactory
|
|||
}
|
||||
}
|
||||
|
||||
private DBI ensureDBI(CacheScheduler.EntryImpl<JDBCExtractionNamespace> id, JDBCExtractionNamespace namespace)
|
||||
private DBI ensureDBI(CacheScheduler.EntryImpl<JdbcExtractionNamespace> id, JdbcExtractionNamespace namespace)
|
||||
{
|
||||
final CacheScheduler.EntryImpl<JDBCExtractionNamespace> key = id;
|
||||
final CacheScheduler.EntryImpl<JdbcExtractionNamespace> key = id;
|
||||
DBI dbi = null;
|
||||
if (dbiCache.containsKey(key)) {
|
||||
dbi = dbiCache.get(key);
|
||||
|
@ -151,7 +150,7 @@ public final class JDBCExtractionNamespaceCacheFactory
|
|||
return dbi;
|
||||
}
|
||||
|
||||
private Long lastUpdates(CacheScheduler.EntryImpl<JDBCExtractionNamespace> id, JDBCExtractionNamespace namespace)
|
||||
private Long lastUpdates(CacheScheduler.EntryImpl<JdbcExtractionNamespace> id, JdbcExtractionNamespace namespace)
|
||||
{
|
||||
final DBI dbi = ensureDBI(id, namespace);
|
||||
final String table = namespace.getTable();
|
|
@ -30,11 +30,11 @@ import io.druid.guice.LazySingleton;
|
|||
import io.druid.guice.PolyBind;
|
||||
import io.druid.initialization.DruidModule;
|
||||
import io.druid.query.lookup.NamespaceLookupExtractorFactory;
|
||||
import io.druid.query.lookup.namespace.ExtractionNamespaceCacheFactory;
|
||||
import io.druid.query.lookup.namespace.CacheGenerator;
|
||||
import io.druid.query.lookup.namespace.ExtractionNamespace;
|
||||
import io.druid.query.lookup.namespace.JDBCExtractionNamespace;
|
||||
import io.druid.query.lookup.namespace.JdbcExtractionNamespace;
|
||||
import io.druid.query.lookup.namespace.StaticMapExtractionNamespace;
|
||||
import io.druid.query.lookup.namespace.URIExtractionNamespace;
|
||||
import io.druid.query.lookup.namespace.UriExtractionNamespace;
|
||||
import io.druid.server.lookup.namespace.cache.NamespaceExtractionCacheManager;
|
||||
import io.druid.server.lookup.namespace.cache.OffHeapNamespaceExtractionCacheManager;
|
||||
import io.druid.server.lookup.namespace.cache.OnHeapNamespaceExtractionCacheManager;
|
||||
|
@ -59,7 +59,7 @@ public class NamespaceExtractionModule implements DruidModule
|
|||
);
|
||||
}
|
||||
|
||||
public static MapBinder<Class<? extends ExtractionNamespace>, ExtractionNamespaceCacheFactory<?>> getNamespaceFactoryMapBinder(
|
||||
public static MapBinder<Class<? extends ExtractionNamespace>, CacheGenerator<?>> getNamespaceFactoryMapBinder(
|
||||
final Binder binder
|
||||
)
|
||||
{
|
||||
|
@ -68,7 +68,7 @@ public class NamespaceExtractionModule implements DruidModule
|
|||
new TypeLiteral<Class<? extends ExtractionNamespace>>()
|
||||
{
|
||||
},
|
||||
new TypeLiteral<ExtractionNamespaceCacheFactory<?>>()
|
||||
new TypeLiteral<CacheGenerator<?>>()
|
||||
{
|
||||
}
|
||||
);
|
||||
|
@ -92,16 +92,16 @@ public class NamespaceExtractionModule implements DruidModule
|
|||
.in(LazySingleton.class);
|
||||
|
||||
getNamespaceFactoryMapBinder(binder)
|
||||
.addBinding(JDBCExtractionNamespace.class)
|
||||
.to(JDBCExtractionNamespaceCacheFactory.class)
|
||||
.addBinding(JdbcExtractionNamespace.class)
|
||||
.to(JdbcCacheGenerator.class)
|
||||
.in(LazySingleton.class);
|
||||
getNamespaceFactoryMapBinder(binder)
|
||||
.addBinding(URIExtractionNamespace.class)
|
||||
.to(URIExtractionNamespaceCacheFactory.class)
|
||||
.addBinding(UriExtractionNamespace.class)
|
||||
.to(UriCacheGenerator.class)
|
||||
.in(LazySingleton.class);
|
||||
getNamespaceFactoryMapBinder(binder)
|
||||
.addBinding(StaticMapExtractionNamespace.class)
|
||||
.to(StaticMapExtractionNamespaceCacheFactory.class)
|
||||
.to(StaticMapCacheGenerator.class)
|
||||
.in(LazySingleton.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,20 +19,20 @@
|
|||
|
||||
package io.druid.server.lookup.namespace;
|
||||
|
||||
import io.druid.query.lookup.namespace.ExtractionNamespaceCacheFactory;
|
||||
import io.druid.query.lookup.namespace.CacheGenerator;
|
||||
import io.druid.query.lookup.namespace.StaticMapExtractionNamespace;
|
||||
import io.druid.server.lookup.namespace.cache.CacheScheduler;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class StaticMapExtractionNamespaceCacheFactory implements ExtractionNamespaceCacheFactory<StaticMapExtractionNamespace>
|
||||
public final class StaticMapCacheGenerator implements CacheGenerator<StaticMapExtractionNamespace>
|
||||
{
|
||||
private final String version = UUID.randomUUID().toString();
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public CacheScheduler.VersionedCache populateCache(
|
||||
public CacheScheduler.VersionedCache generateCache(
|
||||
final StaticMapExtractionNamespace namespace,
|
||||
final CacheScheduler.EntryImpl<StaticMapExtractionNamespace> id,
|
||||
final String lastVersion,
|
||||
|
@ -43,7 +43,7 @@ public final class StaticMapExtractionNamespaceCacheFactory implements Extractio
|
|||
// Throwing AssertionError, because CacheScheduler doesn't suppress Errors and will stop trying to update
|
||||
// the cache periodically.
|
||||
throw new AssertionError(
|
||||
"StaticMapExtractionNamespaceCacheFactory could only be configured for a namespace which is scheduled "
|
||||
"StaticMapCacheGenerator could only be configured for a namespace which is scheduled "
|
||||
+ "to be updated once, not periodically. Last version: `" + lastVersion + "`");
|
||||
}
|
||||
CacheScheduler.VersionedCache versionedCache = scheduler.createVersionedCache(id, version);
|
|
@ -27,8 +27,8 @@ import io.druid.java.util.common.CompressionUtils;
|
|||
import io.druid.java.util.common.IAE;
|
||||
import io.druid.java.util.common.RetryUtils;
|
||||
import io.druid.java.util.common.logger.Logger;
|
||||
import io.druid.query.lookup.namespace.ExtractionNamespaceCacheFactory;
|
||||
import io.druid.query.lookup.namespace.URIExtractionNamespace;
|
||||
import io.druid.query.lookup.namespace.CacheGenerator;
|
||||
import io.druid.query.lookup.namespace.UriExtractionNamespace;
|
||||
import io.druid.segment.loading.URIDataPuller;
|
||||
import io.druid.server.lookup.namespace.cache.CacheScheduler;
|
||||
|
||||
|
@ -44,14 +44,14 @@ import java.util.regex.Pattern;
|
|||
/**
|
||||
*
|
||||
*/
|
||||
public final class URIExtractionNamespaceCacheFactory implements ExtractionNamespaceCacheFactory<URIExtractionNamespace>
|
||||
public final class UriCacheGenerator implements CacheGenerator<UriExtractionNamespace>
|
||||
{
|
||||
private static final int DEFAULT_NUM_RETRIES = 3;
|
||||
private static final Logger log = new Logger(URIExtractionNamespaceCacheFactory.class);
|
||||
private static final Logger log = new Logger(UriCacheGenerator.class);
|
||||
private final Map<String, SearchableVersionedDataFinder> pullers;
|
||||
|
||||
@Inject
|
||||
public URIExtractionNamespaceCacheFactory(
|
||||
public UriCacheGenerator(
|
||||
Map<String, SearchableVersionedDataFinder> pullers
|
||||
)
|
||||
{
|
||||
|
@ -60,9 +60,9 @@ public final class URIExtractionNamespaceCacheFactory implements ExtractionNames
|
|||
|
||||
@Override
|
||||
@Nullable
|
||||
public CacheScheduler.VersionedCache populateCache(
|
||||
final URIExtractionNamespace extractionNamespace,
|
||||
final CacheScheduler.EntryImpl<URIExtractionNamespace> entryId,
|
||||
public CacheScheduler.VersionedCache generateCache(
|
||||
final UriExtractionNamespace extractionNamespace,
|
||||
final CacheScheduler.EntryImpl<UriExtractionNamespace> entryId,
|
||||
@Nullable final String lastVersion,
|
||||
final CacheScheduler scheduler
|
||||
) throws Exception
|
|
@ -27,8 +27,8 @@ import com.metamx.emitter.service.ServiceMetricEvent;
|
|||
import io.druid.guice.LazySingleton;
|
||||
import io.druid.java.util.common.ISE;
|
||||
import io.druid.java.util.common.logger.Logger;
|
||||
import io.druid.query.lookup.namespace.CacheGenerator;
|
||||
import io.druid.query.lookup.namespace.ExtractionNamespace;
|
||||
import io.druid.query.lookup.namespace.ExtractionNamespaceCacheFactory;
|
||||
import sun.misc.Cleaner;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -70,9 +70,9 @@ public final class CacheScheduler
|
|||
{
|
||||
private final EntryImpl<T> impl;
|
||||
|
||||
private Entry(final T namespace, final ExtractionNamespaceCacheFactory<T> cachePopulator)
|
||||
private Entry(final T namespace, final CacheGenerator<T> cacheGenerator)
|
||||
{
|
||||
impl = new EntryImpl<>(namespace, this, cachePopulator);
|
||||
impl = new EntryImpl<>(namespace, this, cacheGenerator);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -143,18 +143,18 @@ public final class CacheScheduler
|
|||
private final AtomicReference<CacheState> cacheStateHolder = new AtomicReference<CacheState>(NoCache.CACHE_NOT_INITIALIZED);
|
||||
private final Future<?> updaterFuture;
|
||||
private final Cleaner entryCleaner;
|
||||
private final ExtractionNamespaceCacheFactory<T> cachePopulator;
|
||||
private final CacheGenerator<T> cacheGenerator;
|
||||
private final UpdateCounter updateCounter = new UpdateCounter();
|
||||
private final CountDownLatch startLatch = new CountDownLatch(1);
|
||||
|
||||
private EntryImpl(final T namespace, final Entry<T> entry, final ExtractionNamespaceCacheFactory<T> cachePopulator)
|
||||
private EntryImpl(final T namespace, final Entry<T> entry, final CacheGenerator<T> cacheGenerator)
|
||||
{
|
||||
try {
|
||||
this.namespace = namespace;
|
||||
this.asString = String.format("namespace [%s] : %s", namespace, super.toString());
|
||||
this.updaterFuture = schedule(namespace);
|
||||
this.entryCleaner = createCleaner(entry);
|
||||
this.cachePopulator = cachePopulator;
|
||||
this.cacheGenerator = cacheGenerator;
|
||||
activeEntries.incrementAndGet();
|
||||
}
|
||||
finally {
|
||||
|
@ -221,7 +221,7 @@ public final class CacheScheduler
|
|||
boolean updatedCacheSuccessfully = false;
|
||||
VersionedCache newVersionedCache = null;
|
||||
try {
|
||||
newVersionedCache = cachePopulator.populateCache(namespace, this, currentVersion, CacheScheduler.this
|
||||
newVersionedCache = cacheGenerator.generateCache(namespace, this, currentVersion, CacheScheduler.this
|
||||
);
|
||||
if (newVersionedCache != null) {
|
||||
CacheState previousCacheState = swapCacheState(newVersionedCache);
|
||||
|
@ -408,7 +408,7 @@ public final class CacheScheduler
|
|||
}
|
||||
}
|
||||
|
||||
private final Map<Class<? extends ExtractionNamespace>, ExtractionNamespaceCacheFactory<?>> namespacePopulatorMap;
|
||||
private final Map<Class<? extends ExtractionNamespace>, CacheGenerator<?>> namespaceGeneratorMap;
|
||||
private final NamespaceExtractionCacheManager cacheManager;
|
||||
private final AtomicLong updatesStarted = new AtomicLong(0);
|
||||
private final AtomicInteger activeEntries = new AtomicInteger();
|
||||
|
@ -416,11 +416,11 @@ public final class CacheScheduler
|
|||
@Inject
|
||||
public CacheScheduler(
|
||||
final ServiceEmitter serviceEmitter,
|
||||
final Map<Class<? extends ExtractionNamespace>, ExtractionNamespaceCacheFactory<?>> namespacePopulatorMap,
|
||||
final Map<Class<? extends ExtractionNamespace>, CacheGenerator<?>> namespaceGeneratorMap,
|
||||
NamespaceExtractionCacheManager cacheManager
|
||||
)
|
||||
{
|
||||
this.namespacePopulatorMap = namespacePopulatorMap;
|
||||
this.namespaceGeneratorMap = namespaceGeneratorMap;
|
||||
this.cacheManager = cacheManager;
|
||||
cacheManager.scheduledExecutorService().scheduleAtFixedRate(
|
||||
new Runnable()
|
||||
|
@ -452,7 +452,7 @@ public final class CacheScheduler
|
|||
}
|
||||
|
||||
/**
|
||||
* This method should be used from {@link ExtractionNamespaceCacheFactory#populateCache} implementations, to obtain
|
||||
* This method should be used from {@link io.druid.query.lookup.namespace.CacheGenerator#generateCache} implementations, to obtain
|
||||
* a {@link VersionedCache} to be returned.
|
||||
*
|
||||
* @param entryId an object uniquely corresponding to the {@link CacheScheduler.Entry}, for which VersionedCache is
|
||||
|
@ -502,11 +502,10 @@ public final class CacheScheduler
|
|||
|
||||
public <T extends ExtractionNamespace> Entry schedule(final T namespace)
|
||||
{
|
||||
final ExtractionNamespaceCacheFactory<T> populator =
|
||||
(ExtractionNamespaceCacheFactory<T>) namespacePopulatorMap.get(namespace.getClass());
|
||||
if (populator == null) {
|
||||
throw new ISE("Cannot find populator for namespace [%s]", namespace);
|
||||
final CacheGenerator<T> generator = (CacheGenerator<T>) namespaceGeneratorMap.get(namespace.getClass());
|
||||
if (generator == null) {
|
||||
throw new ISE("Cannot find generator for namespace [%s]", namespace);
|
||||
}
|
||||
return new Entry<>(namespace, populator);
|
||||
return new Entry<>(namespace, generator);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ import io.druid.initialization.Initialization;
|
|||
import io.druid.jackson.DefaultObjectMapper;
|
||||
import io.druid.java.util.common.ISE;
|
||||
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.lookup.namespace.cache.CacheScheduler;
|
||||
import io.druid.server.lookup.namespace.cache.NamespaceExtractionCacheManager;
|
||||
|
@ -109,10 +109,10 @@ public class NamespaceLookupExtractorFactoryTest
|
|||
@Test
|
||||
public void testSimpleSerde() throws Exception
|
||||
{
|
||||
final URIExtractionNamespace uriExtractionNamespace = new URIExtractionNamespace(
|
||||
final UriExtractionNamespace uriExtractionNamespace = new UriExtractionNamespace(
|
||||
temporaryFolder.newFolder().toURI(),
|
||||
null, null,
|
||||
new URIExtractionNamespace.ObjectMapperFlatDataParser(mapper),
|
||||
new UriExtractionNamespace.ObjectMapperFlatDataParser(mapper),
|
||||
|
||||
Period.millis(0),
|
||||
null
|
||||
|
@ -455,7 +455,7 @@ public class NamespaceLookupExtractorFactoryTest
|
|||
LookupExtractorFactory.class
|
||||
)));
|
||||
Assert.assertEquals(
|
||||
URIExtractionNamespace.class,
|
||||
UriExtractionNamespace.class,
|
||||
namespaceLookupExtractorFactory.getExtractionNamespace().getClass()
|
||||
);
|
||||
Assert.assertFalse(namespaceLookupExtractorFactory.replaces(mapper.readValue(str, LookupExtractorFactory.class)));
|
||||
|
|
|
@ -92,7 +92,7 @@ public class JSONFlatDataParserTest
|
|||
@Test
|
||||
public void testSimpleParse() throws Exception
|
||||
{
|
||||
final URIExtractionNamespace.JSONFlatDataParser parser = new URIExtractionNamespace.JSONFlatDataParser(
|
||||
final UriExtractionNamespace.JSONFlatDataParser parser = new UriExtractionNamespace.JSONFlatDataParser(
|
||||
MAPPER,
|
||||
"key",
|
||||
"val"
|
||||
|
@ -106,7 +106,7 @@ public class JSONFlatDataParserTest
|
|||
@Test
|
||||
public void testParseWithNullValues() throws Exception
|
||||
{
|
||||
final URIExtractionNamespace.JSONFlatDataParser parser = new URIExtractionNamespace.JSONFlatDataParser(
|
||||
final UriExtractionNamespace.JSONFlatDataParser parser = new UriExtractionNamespace.JSONFlatDataParser(
|
||||
MAPPER,
|
||||
"key",
|
||||
"otherVal"
|
||||
|
@ -120,7 +120,7 @@ public class JSONFlatDataParserTest
|
|||
@Test
|
||||
public void testParseWithEmptyValues() throws Exception
|
||||
{
|
||||
final URIExtractionNamespace.JSONFlatDataParser parser = new URIExtractionNamespace.JSONFlatDataParser(
|
||||
final UriExtractionNamespace.JSONFlatDataParser parser = new UriExtractionNamespace.JSONFlatDataParser(
|
||||
MAPPER,
|
||||
"key",
|
||||
"canBeEmpty"
|
||||
|
@ -134,7 +134,7 @@ public class JSONFlatDataParserTest
|
|||
@Test
|
||||
public void testFailParseOnKeyMissing() throws Exception
|
||||
{
|
||||
final URIExtractionNamespace.JSONFlatDataParser parser = new URIExtractionNamespace.JSONFlatDataParser(
|
||||
final UriExtractionNamespace.JSONFlatDataParser parser = new UriExtractionNamespace.JSONFlatDataParser(
|
||||
MAPPER,
|
||||
"keyWHOOPS",
|
||||
"val"
|
||||
|
|
|
@ -40,7 +40,7 @@ import java.util.Map;
|
|||
/**
|
||||
*
|
||||
*/
|
||||
public class URIExtractionNamespaceTest
|
||||
public class UriExtractionNamespaceTest
|
||||
{
|
||||
public static ObjectMapper registerTypes(
|
||||
final ObjectMapper mapper
|
||||
|
@ -62,7 +62,7 @@ public class URIExtractionNamespaceTest
|
|||
)
|
||||
)
|
||||
)
|
||||
).registerSubtypes(URIExtractionNamespace.class, URIExtractionNamespace.FlatDataParser.class);
|
||||
).registerSubtypes(UriExtractionNamespace.class, UriExtractionNamespace.FlatDataParser.class);
|
||||
|
||||
final GuiceAnnotationIntrospector guiceIntrospector = new GuiceAnnotationIntrospector();
|
||||
mapper.setAnnotationIntrospectors(
|
||||
|
@ -79,7 +79,7 @@ public class URIExtractionNamespaceTest
|
|||
@Test
|
||||
public void testCSV()
|
||||
{
|
||||
URIExtractionNamespace.CSVFlatDataParser parser = new URIExtractionNamespace.CSVFlatDataParser(
|
||||
UriExtractionNamespace.CSVFlatDataParser parser = new UriExtractionNamespace.CSVFlatDataParser(
|
||||
ImmutableList.of(
|
||||
"col1",
|
||||
"col2",
|
||||
|
@ -92,7 +92,7 @@ public class URIExtractionNamespaceTest
|
|||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testBadCSV()
|
||||
{
|
||||
URIExtractionNamespace.CSVFlatDataParser parser = new URIExtractionNamespace.CSVFlatDataParser(
|
||||
UriExtractionNamespace.CSVFlatDataParser parser = new UriExtractionNamespace.CSVFlatDataParser(
|
||||
ImmutableList.of(
|
||||
"col1",
|
||||
"col2",
|
||||
|
@ -105,7 +105,7 @@ public class URIExtractionNamespaceTest
|
|||
@Test(expected = NullPointerException.class)
|
||||
public void testBadCSV2()
|
||||
{
|
||||
URIExtractionNamespace.CSVFlatDataParser parser = new URIExtractionNamespace.CSVFlatDataParser(
|
||||
UriExtractionNamespace.CSVFlatDataParser parser = new UriExtractionNamespace.CSVFlatDataParser(
|
||||
ImmutableList.of(
|
||||
"col1",
|
||||
"col2",
|
||||
|
@ -118,7 +118,7 @@ public class URIExtractionNamespaceTest
|
|||
@Test
|
||||
public void testTSV()
|
||||
{
|
||||
URIExtractionNamespace.TSVFlatDataParser parser = new URIExtractionNamespace.TSVFlatDataParser(
|
||||
UriExtractionNamespace.TSVFlatDataParser parser = new UriExtractionNamespace.TSVFlatDataParser(
|
||||
ImmutableList.of("col1", "col2", "col3"),
|
||||
"|",
|
||||
null, "col2",
|
||||
|
@ -130,7 +130,7 @@ public class URIExtractionNamespaceTest
|
|||
@Test
|
||||
public void testWithListDelimiterTSV()
|
||||
{
|
||||
URIExtractionNamespace.TSVFlatDataParser parser = new URIExtractionNamespace.TSVFlatDataParser(
|
||||
UriExtractionNamespace.TSVFlatDataParser parser = new UriExtractionNamespace.TSVFlatDataParser(
|
||||
ImmutableList.of("col1", "col2", "col3"),
|
||||
"\\u0001",
|
||||
"\\u0002", "col2",
|
||||
|
@ -142,7 +142,7 @@ public class URIExtractionNamespaceTest
|
|||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testBadTSV()
|
||||
{
|
||||
URIExtractionNamespace.TSVFlatDataParser parser = new URIExtractionNamespace.TSVFlatDataParser(
|
||||
UriExtractionNamespace.TSVFlatDataParser parser = new UriExtractionNamespace.TSVFlatDataParser(
|
||||
ImmutableList.of("col1", "col2", "col3fdsfds"),
|
||||
",",
|
||||
null, "col2",
|
||||
|
@ -156,7 +156,7 @@ public class URIExtractionNamespaceTest
|
|||
@Test(expected = NullPointerException.class)
|
||||
public void testBadTSV2()
|
||||
{
|
||||
URIExtractionNamespace.TSVFlatDataParser parser = new URIExtractionNamespace.TSVFlatDataParser(
|
||||
UriExtractionNamespace.TSVFlatDataParser parser = new UriExtractionNamespace.TSVFlatDataParser(
|
||||
ImmutableList.of("col1", "col2", "col3"),
|
||||
",",
|
||||
null, "col2",
|
||||
|
@ -171,7 +171,7 @@ public class URIExtractionNamespaceTest
|
|||
{
|
||||
final String keyField = "keyField";
|
||||
final String valueField = "valueField";
|
||||
URIExtractionNamespace.JSONFlatDataParser parser = new URIExtractionNamespace.JSONFlatDataParser(
|
||||
UriExtractionNamespace.JSONFlatDataParser parser = new UriExtractionNamespace.JSONFlatDataParser(
|
||||
new ObjectMapper(),
|
||||
keyField,
|
||||
valueField
|
||||
|
@ -195,7 +195,7 @@ public class URIExtractionNamespaceTest
|
|||
{
|
||||
final String keyField = "keyField";
|
||||
final String valueField = "valueField";
|
||||
URIExtractionNamespace.JSONFlatDataParser parser = new URIExtractionNamespace.JSONFlatDataParser(
|
||||
UriExtractionNamespace.JSONFlatDataParser parser = new UriExtractionNamespace.JSONFlatDataParser(
|
||||
new ObjectMapper(),
|
||||
keyField,
|
||||
valueField
|
||||
|
@ -218,7 +218,7 @@ public class URIExtractionNamespaceTest
|
|||
{
|
||||
final String keyField = "keyField";
|
||||
final String valueField = "valueField";
|
||||
URIExtractionNamespace.JSONFlatDataParser parser = new URIExtractionNamespace.JSONFlatDataParser(
|
||||
UriExtractionNamespace.JSONFlatDataParser parser = new UriExtractionNamespace.JSONFlatDataParser(
|
||||
registerTypes(new ObjectMapper()),
|
||||
null,
|
||||
valueField
|
||||
|
@ -241,7 +241,7 @@ public class URIExtractionNamespaceTest
|
|||
{
|
||||
final String keyField = "keyField";
|
||||
final String valueField = "valueField";
|
||||
URIExtractionNamespace.JSONFlatDataParser parser = new URIExtractionNamespace.JSONFlatDataParser(
|
||||
UriExtractionNamespace.JSONFlatDataParser parser = new UriExtractionNamespace.JSONFlatDataParser(
|
||||
registerTypes(new ObjectMapper()),
|
||||
keyField,
|
||||
null
|
||||
|
@ -264,7 +264,7 @@ public class URIExtractionNamespaceTest
|
|||
{
|
||||
final String keyField = "keyField";
|
||||
final String valueField = "valueField";
|
||||
URIExtractionNamespace.JSONFlatDataParser parser = new URIExtractionNamespace.JSONFlatDataParser(
|
||||
UriExtractionNamespace.JSONFlatDataParser parser = new UriExtractionNamespace.JSONFlatDataParser(
|
||||
registerTypes(new ObjectMapper()),
|
||||
"",
|
||||
""
|
||||
|
@ -285,7 +285,7 @@ public class URIExtractionNamespaceTest
|
|||
@Test
|
||||
public void testObjectMapperFlatDataParser()
|
||||
{
|
||||
URIExtractionNamespace.ObjectMapperFlatDataParser parser = new URIExtractionNamespace.ObjectMapperFlatDataParser(
|
||||
UriExtractionNamespace.ObjectMapperFlatDataParser parser = new UriExtractionNamespace.ObjectMapperFlatDataParser(
|
||||
registerTypes(new ObjectMapper())
|
||||
);
|
||||
Assert.assertEquals(ImmutableMap.of("B", "C"), parser.getParser().parse("{\"B\":\"C\"}"));
|
||||
|
@ -295,22 +295,22 @@ public class URIExtractionNamespaceTest
|
|||
public void testSimpleJSONSerDe() throws IOException
|
||||
{
|
||||
final ObjectMapper mapper = registerTypes(new DefaultObjectMapper());
|
||||
for (URIExtractionNamespace.FlatDataParser parser : ImmutableList.of(
|
||||
new URIExtractionNamespace.CSVFlatDataParser(
|
||||
for (UriExtractionNamespace.FlatDataParser parser : ImmutableList.of(
|
||||
new UriExtractionNamespace.CSVFlatDataParser(
|
||||
ImmutableList.of(
|
||||
"col1",
|
||||
"col2",
|
||||
"col3"
|
||||
), "col2", "col3"
|
||||
),
|
||||
new URIExtractionNamespace.ObjectMapperFlatDataParser(mapper),
|
||||
new URIExtractionNamespace.JSONFlatDataParser(mapper, "keyField", "valueField"),
|
||||
new URIExtractionNamespace.TSVFlatDataParser(ImmutableList.of("A", "B"), ",", null, "A", "B")
|
||||
new UriExtractionNamespace.ObjectMapperFlatDataParser(mapper),
|
||||
new UriExtractionNamespace.JSONFlatDataParser(mapper, "keyField", "valueField"),
|
||||
new UriExtractionNamespace.TSVFlatDataParser(ImmutableList.of("A", "B"), ",", null, "A", "B")
|
||||
)) {
|
||||
final String str = mapper.writeValueAsString(parser);
|
||||
final URIExtractionNamespace.FlatDataParser parser2 = mapper.readValue(
|
||||
final UriExtractionNamespace.FlatDataParser parser2 = mapper.readValue(
|
||||
str,
|
||||
URIExtractionNamespace.FlatDataParser.class
|
||||
UriExtractionNamespace.FlatDataParser.class
|
||||
);
|
||||
Assert.assertEquals(str, mapper.writeValueAsString(parser2));
|
||||
}
|
||||
|
@ -320,17 +320,17 @@ public class URIExtractionNamespaceTest
|
|||
public void testSimpleToString() throws IOException
|
||||
{
|
||||
final ObjectMapper mapper = registerTypes(new DefaultObjectMapper());
|
||||
for (URIExtractionNamespace.FlatDataParser parser : ImmutableList.of(
|
||||
new URIExtractionNamespace.CSVFlatDataParser(
|
||||
for (UriExtractionNamespace.FlatDataParser parser : ImmutableList.of(
|
||||
new UriExtractionNamespace.CSVFlatDataParser(
|
||||
ImmutableList.of(
|
||||
"col1",
|
||||
"col2",
|
||||
"col3"
|
||||
), "col2", "col3"
|
||||
),
|
||||
new URIExtractionNamespace.ObjectMapperFlatDataParser(mapper),
|
||||
new URIExtractionNamespace.JSONFlatDataParser(mapper, "keyField", "valueField"),
|
||||
new URIExtractionNamespace.TSVFlatDataParser(ImmutableList.of("A", "B"), ",", null, "A", "B")
|
||||
new UriExtractionNamespace.ObjectMapperFlatDataParser(mapper),
|
||||
new UriExtractionNamespace.JSONFlatDataParser(mapper, "keyField", "valueField"),
|
||||
new UriExtractionNamespace.TSVFlatDataParser(ImmutableList.of("A", "B"), ",", null, "A", "B")
|
||||
)) {
|
||||
Assert.assertFalse(parser.toString().contains("@"));
|
||||
}
|
||||
|
@ -340,13 +340,13 @@ public class URIExtractionNamespaceTest
|
|||
public void testMatchedJson() throws IOException
|
||||
{
|
||||
final ObjectMapper mapper = registerTypes(new DefaultObjectMapper());
|
||||
URIExtractionNamespace namespace = mapper.readValue(
|
||||
UriExtractionNamespace namespace = mapper.readValue(
|
||||
"{\"type\":\"uri\", \"uriPrefix\":\"file:/foo\", \"namespaceParseSpec\":{\"format\":\"simpleJson\"}, \"pollPeriod\":\"PT5M\", \"versionRegex\":\"a.b.c\", \"namespace\":\"testNamespace\"}",
|
||||
URIExtractionNamespace.class
|
||||
UriExtractionNamespace.class
|
||||
);
|
||||
|
||||
Assert.assertEquals(
|
||||
URIExtractionNamespace.ObjectMapperFlatDataParser.class.getCanonicalName(),
|
||||
UriExtractionNamespace.ObjectMapperFlatDataParser.class.getCanonicalName(),
|
||||
namespace.getNamespaceParseSpec().getClass().getCanonicalName()
|
||||
);
|
||||
Assert.assertEquals("file:/foo", namespace.getUriPrefix().toString());
|
||||
|
@ -358,13 +358,13 @@ public class URIExtractionNamespaceTest
|
|||
public void testExplicitJson() throws IOException
|
||||
{
|
||||
final ObjectMapper mapper = registerTypes(new DefaultObjectMapper());
|
||||
URIExtractionNamespace namespace = mapper.readValue(
|
||||
UriExtractionNamespace namespace = mapper.readValue(
|
||||
"{\"type\":\"uri\", \"uri\":\"file:/foo\", \"namespaceParseSpec\":{\"format\":\"simpleJson\"}, \"pollPeriod\":\"PT5M\"}",
|
||||
URIExtractionNamespace.class
|
||||
UriExtractionNamespace.class
|
||||
);
|
||||
|
||||
Assert.assertEquals(
|
||||
URIExtractionNamespace.ObjectMapperFlatDataParser.class.getCanonicalName(),
|
||||
UriExtractionNamespace.ObjectMapperFlatDataParser.class.getCanonicalName(),
|
||||
namespace.getNamespaceParseSpec().getClass().getCanonicalName()
|
||||
);
|
||||
Assert.assertEquals("file:/foo", namespace.getUri().toString());
|
||||
|
@ -377,7 +377,7 @@ public class URIExtractionNamespaceTest
|
|||
final ObjectMapper mapper = registerTypes(new DefaultObjectMapper());
|
||||
mapper.readValue(
|
||||
"{\"type\":\"uri\", \"uri\":\"file:/foo\", \"namespaceParseSpec\":{\"format\":\"simpleJson\"}, \"pollPeriod\":\"PT5M\", \"versionRegex\":\"a.b.c\", \"namespace\":\"testNamespace\"}",
|
||||
URIExtractionNamespace.class
|
||||
UriExtractionNamespace.class
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -388,7 +388,7 @@ public class URIExtractionNamespaceTest
|
|||
final String valueField = "valueField";
|
||||
final int n = 341879;
|
||||
final String nString = String.format("%d", n);
|
||||
URIExtractionNamespace.JSONFlatDataParser parser = new URIExtractionNamespace.JSONFlatDataParser(
|
||||
UriExtractionNamespace.JSONFlatDataParser parser = new UriExtractionNamespace.JSONFlatDataParser(
|
||||
new ObjectMapper(),
|
||||
keyField,
|
||||
valueField
|
||||
|
@ -450,7 +450,7 @@ public class URIExtractionNamespaceTest
|
|||
@Test
|
||||
public void testSimpleJsonNumeric()
|
||||
{
|
||||
final URIExtractionNamespace.ObjectMapperFlatDataParser parser = new URIExtractionNamespace.ObjectMapperFlatDataParser(
|
||||
final UriExtractionNamespace.ObjectMapperFlatDataParser parser = new UriExtractionNamespace.ObjectMapperFlatDataParser(
|
||||
registerTypes(new DefaultObjectMapper())
|
||||
);
|
||||
final int n = 341879;
|
|
@ -24,11 +24,11 @@ import com.google.common.collect.ImmutableMap;
|
|||
import io.druid.data.SearchableVersionedDataFinder;
|
||||
import io.druid.jackson.DefaultObjectMapper;
|
||||
import io.druid.java.util.common.lifecycle.Lifecycle;
|
||||
import io.druid.query.lookup.namespace.ExtractionNamespaceCacheFactory;
|
||||
import io.druid.query.lookup.namespace.CacheGenerator;
|
||||
import io.druid.query.lookup.namespace.ExtractionNamespace;
|
||||
import io.druid.query.lookup.namespace.JDBCExtractionNamespace;
|
||||
import io.druid.query.lookup.namespace.URIExtractionNamespace;
|
||||
import io.druid.query.lookup.namespace.URIExtractionNamespaceTest;
|
||||
import io.druid.query.lookup.namespace.JdbcExtractionNamespace;
|
||||
import io.druid.query.lookup.namespace.UriExtractionNamespace;
|
||||
import io.druid.query.lookup.namespace.UriExtractionNamespaceTest;
|
||||
import io.druid.segment.loading.LocalFileTimestampVersionFinder;
|
||||
import io.druid.server.lookup.namespace.cache.CacheScheduler;
|
||||
import io.druid.server.lookup.namespace.cache.OnHeapNamespaceExtractionCacheManager;
|
||||
|
@ -51,7 +51,7 @@ import java.util.Map;
|
|||
*/
|
||||
public class NamespacedExtractorModuleTest
|
||||
{
|
||||
private static final ObjectMapper mapper = URIExtractionNamespaceTest.registerTypes(new DefaultObjectMapper());
|
||||
private static final ObjectMapper mapper = UriExtractionNamespaceTest.registerTypes(new DefaultObjectMapper());
|
||||
private CacheScheduler scheduler;
|
||||
private Lifecycle lifecycle;
|
||||
|
||||
|
@ -61,16 +61,16 @@ public class NamespacedExtractorModuleTest
|
|||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
final Map<Class<? extends ExtractionNamespace>, ExtractionNamespaceCacheFactory<?>> factoryMap =
|
||||
ImmutableMap.<Class<? extends ExtractionNamespace>, ExtractionNamespaceCacheFactory<?>>of(
|
||||
URIExtractionNamespace.class,
|
||||
new URIExtractionNamespaceCacheFactory(
|
||||
final Map<Class<? extends ExtractionNamespace>, CacheGenerator<?>> factoryMap =
|
||||
ImmutableMap.<Class<? extends ExtractionNamespace>, CacheGenerator<?>>of(
|
||||
UriExtractionNamespace.class,
|
||||
new UriCacheGenerator(
|
||||
ImmutableMap.<String, SearchableVersionedDataFinder>of(
|
||||
"file",
|
||||
new LocalFileTimestampVersionFinder()
|
||||
)
|
||||
),
|
||||
JDBCExtractionNamespace.class, new JDBCExtractionNamespaceCacheFactory()
|
||||
JdbcExtractionNamespace.class, new JdbcCacheGenerator()
|
||||
);
|
||||
lifecycle = new Lifecycle();
|
||||
lifecycle.start();
|
||||
|
@ -95,19 +95,19 @@ public class NamespacedExtractorModuleTest
|
|||
try (OutputStreamWriter out = new FileWriter(tmpFile)) {
|
||||
out.write(mapper.writeValueAsString(ImmutableMap.<String, String>of("foo", "bar")));
|
||||
}
|
||||
final URIExtractionNamespaceCacheFactory factory = new URIExtractionNamespaceCacheFactory(
|
||||
final UriCacheGenerator factory = new UriCacheGenerator(
|
||||
ImmutableMap.<String, SearchableVersionedDataFinder>of("file", new LocalFileTimestampVersionFinder())
|
||||
);
|
||||
final URIExtractionNamespace namespace = new URIExtractionNamespace(
|
||||
final UriExtractionNamespace namespace = new UriExtractionNamespace(
|
||||
tmpFile.toURI(),
|
||||
null, null,
|
||||
new URIExtractionNamespace.ObjectMapperFlatDataParser(
|
||||
URIExtractionNamespaceTest.registerTypes(new DefaultObjectMapper())
|
||||
new UriExtractionNamespace.ObjectMapperFlatDataParser(
|
||||
UriExtractionNamespaceTest.registerTypes(new DefaultObjectMapper())
|
||||
),
|
||||
new Period(0),
|
||||
null
|
||||
);
|
||||
CacheScheduler.VersionedCache versionedCache = factory.populateCache(namespace, null, null, scheduler);
|
||||
CacheScheduler.VersionedCache versionedCache = factory.generateCache(namespace, null, null, scheduler);
|
||||
Assert.assertNotNull(versionedCache);
|
||||
Map<String, String> map = versionedCache.getCache();
|
||||
Assert.assertEquals("bar", map.get("foo"));
|
||||
|
@ -121,10 +121,10 @@ public class NamespacedExtractorModuleTest
|
|||
try (OutputStreamWriter out = new FileWriter(tmpFile)) {
|
||||
out.write(mapper.writeValueAsString(ImmutableMap.<String, String>of("foo", "bar")));
|
||||
}
|
||||
final URIExtractionNamespace namespace = new URIExtractionNamespace(
|
||||
final UriExtractionNamespace namespace = new UriExtractionNamespace(
|
||||
tmpFile.toURI(),
|
||||
null, null,
|
||||
new URIExtractionNamespace.ObjectMapperFlatDataParser(URIExtractionNamespaceTest.registerTypes(new DefaultObjectMapper())),
|
||||
new UriExtractionNamespace.ObjectMapperFlatDataParser(UriExtractionNamespaceTest.registerTypes(new DefaultObjectMapper())),
|
||||
new Period(0),
|
||||
null
|
||||
);
|
||||
|
@ -142,11 +142,11 @@ public class NamespacedExtractorModuleTest
|
|||
try (OutputStreamWriter out = new FileWriter(tmpFile)) {
|
||||
out.write(mapper.writeValueAsString(ImmutableMap.<String, String>of("foo", "bar")));
|
||||
}
|
||||
final URIExtractionNamespace namespace = new URIExtractionNamespace(
|
||||
final UriExtractionNamespace namespace = new UriExtractionNamespace(
|
||||
tmpFile.toURI(),
|
||||
null, null,
|
||||
new URIExtractionNamespace.ObjectMapperFlatDataParser(
|
||||
URIExtractionNamespaceTest.registerTypes(new DefaultObjectMapper())
|
||||
new UriExtractionNamespace.ObjectMapperFlatDataParser(
|
||||
UriExtractionNamespaceTest.registerTypes(new DefaultObjectMapper())
|
||||
),
|
||||
new Period(0),
|
||||
null
|
||||
|
@ -163,11 +163,11 @@ public class NamespacedExtractorModuleTest
|
|||
try (OutputStreamWriter out = new FileWriter(tmpFile)) {
|
||||
out.write(mapper.writeValueAsString(ImmutableMap.<String, String>of("foo", "bar")));
|
||||
}
|
||||
final URIExtractionNamespace namespace = new URIExtractionNamespace(
|
||||
final UriExtractionNamespace namespace = new UriExtractionNamespace(
|
||||
tmpFile.toURI(),
|
||||
null, null,
|
||||
new URIExtractionNamespace.ObjectMapperFlatDataParser(
|
||||
URIExtractionNamespaceTest.registerTypes(new DefaultObjectMapper())
|
||||
new UriExtractionNamespace.ObjectMapperFlatDataParser(
|
||||
UriExtractionNamespaceTest.registerTypes(new DefaultObjectMapper())
|
||||
),
|
||||
new Period(0),
|
||||
null
|
||||
|
|
|
@ -21,7 +21,7 @@ package io.druid.server.lookup.namespace;
|
|||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import io.druid.java.util.common.lifecycle.Lifecycle;
|
||||
import io.druid.query.lookup.namespace.ExtractionNamespaceCacheFactory;
|
||||
import io.druid.query.lookup.namespace.CacheGenerator;
|
||||
import io.druid.query.lookup.namespace.ExtractionNamespace;
|
||||
import io.druid.query.lookup.namespace.StaticMapExtractionNamespace;
|
||||
import io.druid.server.lookup.namespace.cache.CacheScheduler;
|
||||
|
@ -35,7 +35,7 @@ import org.junit.Test;
|
|||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
public class StaticMapExtractionNamespaceCacheFactoryTest
|
||||
public class StaticMapCacheGeneratorTest
|
||||
{
|
||||
private static final Map<String, String> MAP = ImmutableMap.<String, String>builder().put("foo", "bar").build();
|
||||
|
||||
|
@ -50,7 +50,7 @@ public class StaticMapExtractionNamespaceCacheFactoryTest
|
|||
NoopServiceEmitter noopServiceEmitter = new NoopServiceEmitter();
|
||||
scheduler = new CacheScheduler(
|
||||
noopServiceEmitter,
|
||||
Collections.<Class<? extends ExtractionNamespace>, ExtractionNamespaceCacheFactory<?>>emptyMap(),
|
||||
Collections.<Class<? extends ExtractionNamespace>, CacheGenerator<?>>emptyMap(),
|
||||
new OnHeapNamespaceExtractionCacheManager(lifecycle, noopServiceEmitter)
|
||||
);
|
||||
}
|
||||
|
@ -62,11 +62,11 @@ public class StaticMapExtractionNamespaceCacheFactoryTest
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSimplePopulator() throws Exception
|
||||
public void testSimpleGenerator() throws Exception
|
||||
{
|
||||
final StaticMapExtractionNamespaceCacheFactory factory = new StaticMapExtractionNamespaceCacheFactory();
|
||||
final StaticMapCacheGenerator factory = new StaticMapCacheGenerator();
|
||||
final StaticMapExtractionNamespace namespace = new StaticMapExtractionNamespace(MAP);
|
||||
CacheScheduler.VersionedCache versionedCache = factory.populateCache(namespace, null, null, scheduler);
|
||||
CacheScheduler.VersionedCache versionedCache = factory.generateCache(namespace, null, null, scheduler);
|
||||
Assert.assertNotNull(versionedCache);
|
||||
Assert.assertEquals(factory.getVersion(), versionedCache.getVersion());
|
||||
Assert.assertEquals(MAP, versionedCache.getCache());
|
||||
|
@ -76,8 +76,8 @@ public class StaticMapExtractionNamespaceCacheFactoryTest
|
|||
@Test(expected = AssertionError.class)
|
||||
public void testNonNullLastVersionCausesAssertionError()
|
||||
{
|
||||
final StaticMapExtractionNamespaceCacheFactory factory = new StaticMapExtractionNamespaceCacheFactory();
|
||||
final StaticMapCacheGenerator factory = new StaticMapCacheGenerator();
|
||||
final StaticMapExtractionNamespace namespace = new StaticMapExtractionNamespace(MAP);
|
||||
factory.populateCache(namespace, null, factory.getVersion(), scheduler);
|
||||
factory.generateCache(namespace, null, factory.getVersion(), scheduler);
|
||||
}
|
||||
}
|
|
@ -29,14 +29,14 @@ import io.druid.jackson.DefaultObjectMapper;
|
|||
import io.druid.java.util.common.IAE;
|
||||
import io.druid.java.util.common.UOE;
|
||||
import io.druid.java.util.common.lifecycle.Lifecycle;
|
||||
import io.druid.query.lookup.namespace.CacheGenerator;
|
||||
import io.druid.query.lookup.namespace.ExtractionNamespace;
|
||||
import io.druid.query.lookup.namespace.ExtractionNamespaceCacheFactory;
|
||||
import io.druid.query.lookup.namespace.URIExtractionNamespace;
|
||||
import io.druid.query.lookup.namespace.URIExtractionNamespaceTest;
|
||||
import io.druid.query.lookup.namespace.UriExtractionNamespace;
|
||||
import io.druid.query.lookup.namespace.UriExtractionNamespaceTest;
|
||||
import io.druid.segment.loading.LocalFileTimestampVersionFinder;
|
||||
import io.druid.server.lookup.namespace.cache.CacheScheduler;
|
||||
import io.druid.server.lookup.namespace.cache.NamespaceExtractionCacheManager;
|
||||
import io.druid.server.lookup.namespace.cache.NamespaceExtractionCacheManagerExecutorsTest;
|
||||
import io.druid.server.lookup.namespace.cache.CacheSchedulerTest;
|
||||
import io.druid.server.lookup.namespace.cache.OffHeapNamespaceExtractionCacheManager;
|
||||
import io.druid.server.lookup.namespace.cache.OnHeapNamespaceExtractionCacheManager;
|
||||
import io.druid.server.metrics.NoopServiceEmitter;
|
||||
|
@ -76,7 +76,7 @@ import java.util.zip.GZIPOutputStream;
|
|||
*
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class URIExtractionNamespaceCacheFactoryTest
|
||||
public class UriCacheGeneratorTest
|
||||
{
|
||||
private static final String FAKE_SCHEME = "wabblywoo";
|
||||
private static final Map<String, SearchableVersionedDataFinder> FINDERS = ImmutableMap.<String, SearchableVersionedDataFinder>of(
|
||||
|
@ -232,13 +232,13 @@ public class URIExtractionNamespaceCacheFactoryTest
|
|||
};
|
||||
}
|
||||
|
||||
public URIExtractionNamespaceCacheFactoryTest(
|
||||
public UriCacheGeneratorTest(
|
||||
String suffix,
|
||||
Function<File, OutputStream> outStreamSupplier,
|
||||
Function<Lifecycle, NamespaceExtractionCacheManager> cacheManagerCreator
|
||||
) throws Exception
|
||||
{
|
||||
final Map<Class<? extends ExtractionNamespace>, ExtractionNamespaceCacheFactory<?>> namespaceFunctionFactoryMap = new HashMap<>();
|
||||
final Map<Class<? extends ExtractionNamespace>, CacheGenerator<?>> namespaceFunctionFactoryMap = new HashMap<>();
|
||||
this.suffix = suffix;
|
||||
this.outStreamSupplier = outStreamSupplier;
|
||||
this.lifecycle = new Lifecycle();
|
||||
|
@ -248,9 +248,9 @@ public class URIExtractionNamespaceCacheFactoryTest
|
|||
cacheManagerCreator.apply(lifecycle)
|
||||
);
|
||||
namespaceFunctionFactoryMap.put(
|
||||
URIExtractionNamespace.class,
|
||||
UriExtractionNamespace.class,
|
||||
|
||||
new URIExtractionNamespaceCacheFactory(FINDERS)
|
||||
new UriCacheGenerator(FINDERS)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -263,8 +263,8 @@ public class URIExtractionNamespaceCacheFactoryTest
|
|||
private CacheScheduler scheduler;
|
||||
private File tmpFile;
|
||||
private File tmpFileParent;
|
||||
private URIExtractionNamespaceCacheFactory populator;
|
||||
private URIExtractionNamespace namespace;
|
||||
private UriCacheGenerator generator;
|
||||
private UriExtractionNamespace namespace;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
|
@ -288,12 +288,12 @@ public class URIExtractionNamespaceCacheFactoryTest
|
|||
""
|
||||
)));
|
||||
}
|
||||
populator = new URIExtractionNamespaceCacheFactory(FINDERS);
|
||||
namespace = new URIExtractionNamespace(
|
||||
generator = new UriCacheGenerator(FINDERS);
|
||||
namespace = new UriExtractionNamespace(
|
||||
tmpFile.toURI(),
|
||||
null, null,
|
||||
new URIExtractionNamespace.ObjectMapperFlatDataParser(
|
||||
URIExtractionNamespaceTest.registerTypes(new ObjectMapper())
|
||||
new UriExtractionNamespace.ObjectMapperFlatDataParser(
|
||||
UriExtractionNamespaceTest.registerTypes(new ObjectMapper())
|
||||
),
|
||||
new Period(0),
|
||||
null
|
||||
|
@ -311,7 +311,7 @@ public class URIExtractionNamespaceCacheFactoryTest
|
|||
{
|
||||
Assert.assertEquals(0, scheduler.getActiveEntries());
|
||||
CacheScheduler.Entry entry = scheduler.schedule(namespace);
|
||||
NamespaceExtractionCacheManagerExecutorsTest.waitFor(entry);
|
||||
CacheSchedulerTest.waitFor(entry);
|
||||
Map<String, String> map = entry.getCache();
|
||||
Assert.assertEquals("bar", map.get("foo"));
|
||||
Assert.assertEquals(null, map.get("baz"));
|
||||
|
@ -320,7 +320,7 @@ public class URIExtractionNamespaceCacheFactoryTest
|
|||
@Test
|
||||
public void simpleTestRegex() throws IOException, ExecutionException, InterruptedException
|
||||
{
|
||||
final URIExtractionNamespace namespace = new URIExtractionNamespace(
|
||||
final UriExtractionNamespace namespace = new UriExtractionNamespace(
|
||||
null,
|
||||
Paths.get(this.namespace.getUri()).getParent().toUri(),
|
||||
Pattern.quote(Paths.get(this.namespace.getUri()).getFileName().toString()),
|
||||
|
@ -329,7 +329,7 @@ public class URIExtractionNamespaceCacheFactoryTest
|
|||
null
|
||||
);
|
||||
CacheScheduler.Entry entry = scheduler.schedule(namespace);
|
||||
NamespaceExtractionCacheManagerExecutorsTest.waitFor(entry);
|
||||
CacheSchedulerTest.waitFor(entry);
|
||||
Map<String, String> map = entry.getCache();
|
||||
Assert.assertNotNull(map);
|
||||
Assert.assertEquals("bar", map.get("foo"));
|
||||
|
@ -342,11 +342,11 @@ public class URIExtractionNamespaceCacheFactoryTest
|
|||
final int size = 128;
|
||||
List<CacheScheduler.Entry> entries = new ArrayList<>(size);
|
||||
for (int i = 0; i < size; ++i) {
|
||||
URIExtractionNamespace namespace = new URIExtractionNamespace(
|
||||
UriExtractionNamespace namespace = new UriExtractionNamespace(
|
||||
tmpFile.toURI(),
|
||||
null, null,
|
||||
new URIExtractionNamespace.ObjectMapperFlatDataParser(
|
||||
URIExtractionNamespaceTest.registerTypes(new ObjectMapper())
|
||||
new UriExtractionNamespace.ObjectMapperFlatDataParser(
|
||||
UriExtractionNamespaceTest.registerTypes(new ObjectMapper())
|
||||
),
|
||||
new Period(0),
|
||||
null
|
||||
|
@ -354,7 +354,7 @@ public class URIExtractionNamespaceCacheFactoryTest
|
|||
|
||||
CacheScheduler.Entry entry = scheduler.schedule(namespace);
|
||||
entries.add(entry);
|
||||
NamespaceExtractionCacheManagerExecutorsTest.waitFor(entry);
|
||||
CacheSchedulerTest.waitFor(entry);
|
||||
}
|
||||
|
||||
for (CacheScheduler.Entry entry : entries) {
|
||||
|
@ -371,7 +371,7 @@ public class URIExtractionNamespaceCacheFactoryTest
|
|||
{
|
||||
Assert.assertEquals(0, scheduler.getActiveEntries());
|
||||
|
||||
CacheScheduler.VersionedCache versionedCache = populator.populateCache(namespace, null, null, scheduler);
|
||||
CacheScheduler.VersionedCache versionedCache = generator.generateCache(namespace, null, null, scheduler);
|
||||
Assert.assertNotNull(versionedCache);
|
||||
Map<String, String> map = versionedCache.getCache();
|
||||
Assert.assertEquals("bar", map.get("foo"));
|
||||
|
@ -379,13 +379,13 @@ public class URIExtractionNamespaceCacheFactoryTest
|
|||
String version = versionedCache.getVersion();
|
||||
Assert.assertNotNull(version);
|
||||
|
||||
Assert.assertNull(populator.populateCache(namespace, null, version, scheduler));
|
||||
Assert.assertNull(generator.generateCache(namespace, null, version, scheduler));
|
||||
}
|
||||
|
||||
@Test(expected = FileNotFoundException.class)
|
||||
public void testMissing() throws Exception
|
||||
{
|
||||
URIExtractionNamespace badNamespace = new URIExtractionNamespace(
|
||||
UriExtractionNamespace badNamespace = new UriExtractionNamespace(
|
||||
namespace.getUri(),
|
||||
null, null,
|
||||
namespace.getNamespaceParseSpec(),
|
||||
|
@ -393,13 +393,13 @@ public class URIExtractionNamespaceCacheFactoryTest
|
|||
null
|
||||
);
|
||||
Assert.assertTrue(new File(namespace.getUri()).delete());
|
||||
populator.populateCache(badNamespace, null, null, scheduler);
|
||||
generator.generateCache(badNamespace, null, null, scheduler);
|
||||
}
|
||||
|
||||
@Test(expected = FileNotFoundException.class)
|
||||
public void testMissingRegex() throws Exception
|
||||
{
|
||||
URIExtractionNamespace badNamespace = new URIExtractionNamespace(
|
||||
UriExtractionNamespace badNamespace = new UriExtractionNamespace(
|
||||
null,
|
||||
Paths.get(namespace.getUri()).getParent().toUri(),
|
||||
Pattern.quote(Paths.get(namespace.getUri()).getFileName().toString()),
|
||||
|
@ -408,13 +408,13 @@ public class URIExtractionNamespaceCacheFactoryTest
|
|||
null
|
||||
);
|
||||
Assert.assertTrue(new File(namespace.getUri()).delete());
|
||||
populator.populateCache(badNamespace, null, null, scheduler);
|
||||
generator.generateCache(badNamespace, null, null, scheduler);
|
||||
}
|
||||
|
||||
@Test(expected = IAE.class)
|
||||
public void testExceptionalCreationDoubleURI()
|
||||
{
|
||||
new URIExtractionNamespace(
|
||||
new UriExtractionNamespace(
|
||||
namespace.getUri(),
|
||||
namespace.getUri(),
|
||||
null,
|
||||
|
@ -427,7 +427,7 @@ public class URIExtractionNamespaceCacheFactoryTest
|
|||
@Test(expected = IAE.class)
|
||||
public void testExceptionalCreationURIWithPattern()
|
||||
{
|
||||
new URIExtractionNamespace(
|
||||
new UriExtractionNamespace(
|
||||
namespace.getUri(),
|
||||
null,
|
||||
"",
|
||||
|
@ -440,7 +440,7 @@ public class URIExtractionNamespaceCacheFactoryTest
|
|||
@Test(expected = IAE.class)
|
||||
public void testExceptionalCreationURIWithLegacyPattern()
|
||||
{
|
||||
new URIExtractionNamespace(
|
||||
new UriExtractionNamespace(
|
||||
namespace.getUri(),
|
||||
null,
|
||||
null,
|
||||
|
@ -453,7 +453,7 @@ public class URIExtractionNamespaceCacheFactoryTest
|
|||
@Test(expected = IAE.class)
|
||||
public void testLegacyMix()
|
||||
{
|
||||
new URIExtractionNamespace(
|
||||
new UriExtractionNamespace(
|
||||
null,
|
||||
namespace.getUri(),
|
||||
"",
|
||||
|
@ -467,7 +467,7 @@ public class URIExtractionNamespaceCacheFactoryTest
|
|||
@Test(expected = IAE.class)
|
||||
public void testBadPattern()
|
||||
{
|
||||
new URIExtractionNamespace(
|
||||
new UriExtractionNamespace(
|
||||
null,
|
||||
namespace.getUri(),
|
||||
"[",
|
||||
|
@ -480,7 +480,7 @@ public class URIExtractionNamespaceCacheFactoryTest
|
|||
@Test
|
||||
public void testWeirdSchemaOnExactURI() throws Exception
|
||||
{
|
||||
final URIExtractionNamespace extractionNamespace = new URIExtractionNamespace(
|
||||
final UriExtractionNamespace extractionNamespace = new UriExtractionNamespace(
|
||||
new URI(
|
||||
FAKE_SCHEME,
|
||||
namespace.getUri().getUserInfo(),
|
||||
|
@ -496,19 +496,19 @@ public class URIExtractionNamespaceCacheFactoryTest
|
|||
Period.millis((int) namespace.getPollMs()),
|
||||
null
|
||||
);
|
||||
Assert.assertNotNull(populator.populateCache(extractionNamespace, null, null, scheduler));
|
||||
Assert.assertNotNull(generator.generateCache(extractionNamespace, null, null, scheduler));
|
||||
}
|
||||
|
||||
@Test(timeout = 10_000)
|
||||
public void testDeleteOnScheduleFail() throws Exception
|
||||
{
|
||||
Assert.assertNull(scheduler.scheduleAndWait(
|
||||
new URIExtractionNamespace(
|
||||
new UriExtractionNamespace(
|
||||
new URI("file://tmp/I_DONT_REALLY_EXIST" +
|
||||
UUID.randomUUID().toString()),
|
||||
null,
|
||||
null,
|
||||
new URIExtractionNamespace.JSONFlatDataParser(
|
||||
new UriExtractionNamespace.JSONFlatDataParser(
|
||||
new DefaultObjectMapper(),
|
||||
"key",
|
||||
"val"
|
|
@ -28,10 +28,10 @@ import com.google.common.util.concurrent.ListeningExecutorService;
|
|||
import com.google.common.util.concurrent.MoreExecutors;
|
||||
import io.druid.concurrent.Execs;
|
||||
import io.druid.java.util.common.lifecycle.Lifecycle;
|
||||
import io.druid.query.lookup.namespace.CacheGenerator;
|
||||
import io.druid.query.lookup.namespace.ExtractionNamespace;
|
||||
import io.druid.query.lookup.namespace.ExtractionNamespaceCacheFactory;
|
||||
import io.druid.query.lookup.namespace.URIExtractionNamespace;
|
||||
import io.druid.query.lookup.namespace.URIExtractionNamespaceTest;
|
||||
import io.druid.query.lookup.namespace.UriExtractionNamespace;
|
||||
import io.druid.query.lookup.namespace.UriExtractionNamespaceTest;
|
||||
import io.druid.server.metrics.NoopServiceEmitter;
|
||||
import org.joda.time.Period;
|
||||
import org.junit.After;
|
||||
|
@ -65,7 +65,7 @@ import java.util.concurrent.TimeoutException;
|
|||
*
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class NamespaceExtractionCacheManagerExecutorsTest
|
||||
public class CacheSchedulerTest
|
||||
{
|
||||
public static final Function<Lifecycle, NamespaceExtractionCacheManager> CREATE_ON_HEAP_CACHE_MANAGER =
|
||||
new Function<Lifecycle, NamespaceExtractionCacheManager>()
|
||||
|
@ -111,7 +111,7 @@ public class NamespaceExtractionCacheManagerExecutorsTest
|
|||
private CacheScheduler scheduler;
|
||||
private File tmpFile;
|
||||
|
||||
public NamespaceExtractionCacheManagerExecutorsTest(
|
||||
public CacheSchedulerTest(
|
||||
Function<Lifecycle, NamespaceExtractionCacheManager> createCacheManager
|
||||
)
|
||||
{
|
||||
|
@ -125,13 +125,13 @@ public class NamespaceExtractionCacheManagerExecutorsTest
|
|||
lifecycle.start();
|
||||
cacheManager = createCacheManager.apply(lifecycle);
|
||||
final Path tmpDir = temporaryFolder.newFolder().toPath();
|
||||
final ExtractionNamespaceCacheFactory<URIExtractionNamespace> cachePopulator = new
|
||||
ExtractionNamespaceCacheFactory<URIExtractionNamespace>()
|
||||
final CacheGenerator<UriExtractionNamespace> cacheGenerator = new
|
||||
CacheGenerator<UriExtractionNamespace>()
|
||||
{
|
||||
@Override
|
||||
public CacheScheduler.VersionedCache populateCache(
|
||||
final URIExtractionNamespace extractionNamespace,
|
||||
final CacheScheduler.EntryImpl<URIExtractionNamespace> id,
|
||||
public CacheScheduler.VersionedCache generateCache(
|
||||
final UriExtractionNamespace extractionNamespace,
|
||||
final CacheScheduler.EntryImpl<UriExtractionNamespace> id,
|
||||
final String lastVersion,
|
||||
final CacheScheduler scheduler
|
||||
) throws InterruptedException
|
||||
|
@ -146,9 +146,9 @@ public class NamespaceExtractionCacheManagerExecutorsTest
|
|||
};
|
||||
scheduler = new CacheScheduler(
|
||||
new NoopServiceEmitter(),
|
||||
ImmutableMap.<Class<? extends ExtractionNamespace>, ExtractionNamespaceCacheFactory<?>>of(
|
||||
URIExtractionNamespace.class,
|
||||
cachePopulator
|
||||
ImmutableMap.<Class<? extends ExtractionNamespace>, CacheGenerator<?>>of(
|
||||
UriExtractionNamespace.class,
|
||||
cacheGenerator
|
||||
),
|
||||
cacheManager
|
||||
);
|
||||
|
@ -172,11 +172,11 @@ public class NamespaceExtractionCacheManagerExecutorsTest
|
|||
@Test(timeout = 10_000)
|
||||
public void testSimpleSubmission() throws ExecutionException, InterruptedException
|
||||
{
|
||||
URIExtractionNamespace namespace = new URIExtractionNamespace(
|
||||
UriExtractionNamespace namespace = new UriExtractionNamespace(
|
||||
tmpFile.toURI(),
|
||||
null, null,
|
||||
new URIExtractionNamespace.ObjectMapperFlatDataParser(
|
||||
URIExtractionNamespaceTest.registerTypes(new ObjectMapper())
|
||||
new UriExtractionNamespace.ObjectMapperFlatDataParser(
|
||||
UriExtractionNamespaceTest.registerTypes(new ObjectMapper())
|
||||
),
|
||||
new Period(0),
|
||||
null
|
||||
|
@ -194,7 +194,7 @@ public class NamespaceExtractionCacheManagerExecutorsTest
|
|||
final int repeatCount = 5;
|
||||
final long delay = 5;
|
||||
try {
|
||||
final URIExtractionNamespace namespace = getUriExtractionNamespace(delay);
|
||||
final UriExtractionNamespace namespace = getUriExtractionNamespace(delay);
|
||||
final long start = System.currentTimeMillis();
|
||||
try (CacheScheduler.Entry entry = scheduler.schedule(namespace)) {
|
||||
|
||||
|
@ -305,7 +305,7 @@ public class NamespaceExtractionCacheManagerExecutorsTest
|
|||
throws InterruptedException, TimeoutException, ExecutionException
|
||||
{
|
||||
final long period = 1_000L;// Give it some time between attempts to update
|
||||
final URIExtractionNamespace namespace = getUriExtractionNamespace(period);
|
||||
final UriExtractionNamespace namespace = getUriExtractionNamespace(period);
|
||||
CacheScheduler.Entry entry = scheduler.scheduleAndWait(namespace, 10_000);
|
||||
Assert.assertNotNull(entry);
|
||||
final Future<?> future = entry.getUpdaterFuture();
|
||||
|
@ -332,13 +332,13 @@ public class NamespaceExtractionCacheManagerExecutorsTest
|
|||
Assert.assertTrue(future.isDone());
|
||||
}
|
||||
|
||||
private URIExtractionNamespace getUriExtractionNamespace(long period)
|
||||
private UriExtractionNamespace getUriExtractionNamespace(long period)
|
||||
{
|
||||
return new URIExtractionNamespace(
|
||||
return new UriExtractionNamespace(
|
||||
tmpFile.toURI(),
|
||||
null, null,
|
||||
new URIExtractionNamespace.ObjectMapperFlatDataParser(
|
||||
URIExtractionNamespaceTest.registerTypes(new ObjectMapper())
|
||||
new UriExtractionNamespace.ObjectMapperFlatDataParser(
|
||||
UriExtractionNamespaceTest.registerTypes(new ObjectMapper())
|
||||
),
|
||||
new Period(period),
|
||||
null
|
||||
|
@ -352,7 +352,7 @@ public class NamespaceExtractionCacheManagerExecutorsTest
|
|||
final long period = 5L;
|
||||
try {
|
||||
|
||||
final URIExtractionNamespace namespace = getUriExtractionNamespace(period);
|
||||
final UriExtractionNamespace namespace = getUriExtractionNamespace(period);
|
||||
|
||||
try (CacheScheduler.Entry entry = scheduler.schedule(namespace)) {
|
||||
final Future<?> future = entry.getUpdaterFuture();
|
||||
|
@ -383,7 +383,7 @@ public class NamespaceExtractionCacheManagerExecutorsTest
|
|||
{
|
||||
final int numWaits = 5;
|
||||
try {
|
||||
final URIExtractionNamespace namespace = getUriExtractionNamespace((long) 5);
|
||||
final UriExtractionNamespace namespace = getUriExtractionNamespace((long) 5);
|
||||
try (CacheScheduler.Entry entry = scheduler.schedule(namespace)) {
|
||||
final Future<?> future = entry.getUpdaterFuture();
|
||||
entry.awaitNextUpdates(numWaits);
|
|
@ -31,10 +31,10 @@ import io.druid.java.util.common.io.Closer;
|
|||
import io.druid.java.util.common.lifecycle.Lifecycle;
|
||||
import io.druid.java.util.common.logger.Logger;
|
||||
import io.druid.metadata.TestDerbyConnector;
|
||||
import io.druid.query.lookup.namespace.CacheGenerator;
|
||||
import io.druid.query.lookup.namespace.ExtractionNamespace;
|
||||
import io.druid.query.lookup.namespace.ExtractionNamespaceCacheFactory;
|
||||
import io.druid.query.lookup.namespace.JDBCExtractionNamespace;
|
||||
import io.druid.server.lookup.namespace.JDBCExtractionNamespaceCacheFactory;
|
||||
import io.druid.query.lookup.namespace.JdbcExtractionNamespace;
|
||||
import io.druid.server.lookup.namespace.JdbcCacheGenerator;
|
||||
import io.druid.server.metrics.NoopServiceEmitter;
|
||||
import org.joda.time.Period;
|
||||
import org.junit.After;
|
||||
|
@ -62,11 +62,11 @@ import java.util.concurrent.locks.ReentrantLock;
|
|||
*
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class JDBCExtractionNamespaceTest
|
||||
public class JdbcExtractionNamespaceTest
|
||||
{
|
||||
@Rule
|
||||
public final TestDerbyConnector.DerbyConnectorRule derbyConnectorRule = new TestDerbyConnector.DerbyConnectorRule();
|
||||
private static final Logger log = new Logger(JDBCExtractionNamespaceTest.class);
|
||||
private static final Logger log = new Logger(JdbcExtractionNamespaceTest.class);
|
||||
private static final String tableName = "abstractDbRenameTest";
|
||||
private static final String keyName = "keyName";
|
||||
private static final String valName = "valName";
|
||||
|
@ -87,7 +87,7 @@ public class JDBCExtractionNamespaceTest
|
|||
);
|
||||
}
|
||||
|
||||
public JDBCExtractionNamespaceTest(
|
||||
public JdbcExtractionNamespaceTest(
|
||||
String tsColumn
|
||||
)
|
||||
{
|
||||
|
@ -186,25 +186,25 @@ public class JDBCExtractionNamespaceTest
|
|||
NoopServiceEmitter noopServiceEmitter = new NoopServiceEmitter();
|
||||
scheduler = new CacheScheduler(
|
||||
noopServiceEmitter,
|
||||
ImmutableMap.<Class<? extends ExtractionNamespace>, ExtractionNamespaceCacheFactory<?>>of(
|
||||
JDBCExtractionNamespace.class,
|
||||
new ExtractionNamespaceCacheFactory<JDBCExtractionNamespace>()
|
||||
ImmutableMap.<Class<? extends ExtractionNamespace>, CacheGenerator<?>>of(
|
||||
JdbcExtractionNamespace.class,
|
||||
new CacheGenerator<JdbcExtractionNamespace>()
|
||||
{
|
||||
private final JDBCExtractionNamespaceCacheFactory delegate =
|
||||
new JDBCExtractionNamespaceCacheFactory();
|
||||
private final JdbcCacheGenerator delegate =
|
||||
new JdbcCacheGenerator();
|
||||
@Override
|
||||
public CacheScheduler.VersionedCache populateCache(
|
||||
final JDBCExtractionNamespace namespace,
|
||||
final CacheScheduler.EntryImpl<JDBCExtractionNamespace> id,
|
||||
public CacheScheduler.VersionedCache generateCache(
|
||||
final JdbcExtractionNamespace namespace,
|
||||
final CacheScheduler.EntryImpl<JdbcExtractionNamespace> id,
|
||||
final String lastVersion,
|
||||
final CacheScheduler scheduler
|
||||
) throws InterruptedException
|
||||
{
|
||||
updateLock.lockInterruptibly();
|
||||
try {
|
||||
log.debug("Running cache populator");
|
||||
log.debug("Running cache generator");
|
||||
try {
|
||||
return delegate.populateCache(namespace, id, lastVersion, scheduler);
|
||||
return delegate.generateCache(namespace, id, lastVersion, scheduler);
|
||||
}
|
||||
finally {
|
||||
updates.incrementAndGet();
|
||||
|
@ -355,7 +355,7 @@ public class JDBCExtractionNamespaceTest
|
|||
throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, ExecutionException,
|
||||
InterruptedException, TimeoutException
|
||||
{
|
||||
final JDBCExtractionNamespace extractionNamespace = new JDBCExtractionNamespace(
|
||||
final JdbcExtractionNamespace extractionNamespace = new JdbcExtractionNamespace(
|
||||
derbyConnectorRule.getMetadataConnectorConfig(),
|
||||
tableName,
|
||||
keyName,
|
||||
|
@ -364,7 +364,7 @@ public class JDBCExtractionNamespaceTest
|
|||
new Period(0)
|
||||
);
|
||||
try (CacheScheduler.Entry entry = scheduler.schedule(extractionNamespace)) {
|
||||
NamespaceExtractionCacheManagerExecutorsTest.waitFor(entry);
|
||||
CacheSchedulerTest.waitFor(entry);
|
||||
final Map<String, String> map = entry.getCache();
|
||||
|
||||
for (Map.Entry<String, String> e : renames.entrySet()) {
|
||||
|
@ -403,7 +403,7 @@ public class JDBCExtractionNamespaceTest
|
|||
private CacheScheduler.Entry ensureEntry()
|
||||
throws NoSuchFieldException, IllegalAccessException, InterruptedException
|
||||
{
|
||||
final JDBCExtractionNamespace extractionNamespace = new JDBCExtractionNamespace(
|
||||
final JdbcExtractionNamespace extractionNamespace = new JdbcExtractionNamespace(
|
||||
derbyConnectorRule.getMetadataConnectorConfig(),
|
||||
tableName,
|
||||
keyName,
|
|
@ -47,8 +47,8 @@ public class NamespaceExtractionCacheManagersTest
|
|||
public static Collection<Object[]> data()
|
||||
{
|
||||
return Arrays.asList(new Object[][]{
|
||||
{NamespaceExtractionCacheManagerExecutorsTest.CREATE_ON_HEAP_CACHE_MANAGER},
|
||||
{NamespaceExtractionCacheManagerExecutorsTest.CREATE_OFF_HEAP_CACHE_MANAGER}
|
||||
{CacheSchedulerTest.CREATE_ON_HEAP_CACHE_MANAGER},
|
||||
{CacheSchedulerTest.CREATE_OFF_HEAP_CACHE_MANAGER}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue