use of io.druid.query.lookup.namespace.URIExtractionNamespace in project druid by druid-io.
the class NamespacedExtractorModuleTest method testListNamespaces.
@Test
public void testListNamespaces() throws Exception {
final File tmpFile = temporaryFolder.newFile();
try (OutputStreamWriter out = new FileWriter(tmpFile)) {
out.write(mapper.writeValueAsString(ImmutableMap.<String, String>of("foo", "bar")));
}
final URIExtractionNamespace namespace = new URIExtractionNamespace(tmpFile.toURI(), null, null, new URIExtractionNamespace.ObjectMapperFlatDataParser(URIExtractionNamespaceTest.registerTypes(new DefaultObjectMapper())), new Period(0), null);
try (CacheScheduler.Entry entry = scheduler.scheduleAndWait(namespace, 1_000)) {
Assert.assertNotNull(entry);
entry.awaitTotalUpdates(1);
Assert.assertEquals(1, scheduler.getActiveEntries());
}
}
use of io.druid.query.lookup.namespace.URIExtractionNamespace in project druid by druid-io.
the class NamespacedExtractorModuleTest method testDeleteNamespaces.
//(timeout = 10_000)
@Test
public void testDeleteNamespaces() throws Exception {
final File tmpFile = temporaryFolder.newFile();
try (OutputStreamWriter out = new FileWriter(tmpFile)) {
out.write(mapper.writeValueAsString(ImmutableMap.<String, String>of("foo", "bar")));
}
final URIExtractionNamespace namespace = new URIExtractionNamespace(tmpFile.toURI(), null, null, new URIExtractionNamespace.ObjectMapperFlatDataParser(URIExtractionNamespaceTest.registerTypes(new DefaultObjectMapper())), new Period(0), null);
try (CacheScheduler.Entry entry = scheduler.scheduleAndWait(namespace, 1_000)) {
Assert.assertNotNull(entry);
}
}
use of io.druid.query.lookup.namespace.URIExtractionNamespace in project druid by druid-io.
the class URIExtractionNamespaceCacheFactoryTest method simpleTestRegex.
@Test
public void simpleTestRegex() throws IOException, ExecutionException, InterruptedException {
final URIExtractionNamespace namespace = new URIExtractionNamespace(null, Paths.get(this.namespace.getUri()).getParent().toUri(), Pattern.quote(Paths.get(this.namespace.getUri()).getFileName().toString()), this.namespace.getNamespaceParseSpec(), Period.millis((int) this.namespace.getPollMs()), null);
CacheScheduler.Entry entry = scheduler.schedule(namespace);
NamespaceExtractionCacheManagerExecutorsTest.waitFor(entry);
Map<String, String> map = entry.getCache();
Assert.assertNotNull(map);
Assert.assertEquals("bar", map.get("foo"));
Assert.assertEquals(null, map.get("baz"));
}
use of io.druid.query.lookup.namespace.URIExtractionNamespace in project druid by druid-io.
the class URIExtractionNamespaceCacheFactoryTest method testMissingRegex.
@Test(expected = FileNotFoundException.class)
public void testMissingRegex() throws Exception {
URIExtractionNamespace badNamespace = new URIExtractionNamespace(null, Paths.get(namespace.getUri()).getParent().toUri(), Pattern.quote(Paths.get(namespace.getUri()).getFileName().toString()), namespace.getNamespaceParseSpec(), Period.millis((int) namespace.getPollMs()), null);
Assert.assertTrue(new File(namespace.getUri()).delete());
populator.populateCache(badNamespace, null, null, scheduler);
}
use of io.druid.query.lookup.namespace.URIExtractionNamespace in project druid by druid-io.
the class URIExtractionNamespaceCacheFactoryTest method simplePileONamespacesTest.
@Test
public void simplePileONamespacesTest() throws InterruptedException {
final int size = 128;
List<CacheScheduler.Entry> entries = new ArrayList<>(size);
for (int i = 0; i < size; ++i) {
URIExtractionNamespace namespace = new URIExtractionNamespace(tmpFile.toURI(), null, null, new URIExtractionNamespace.ObjectMapperFlatDataParser(URIExtractionNamespaceTest.registerTypes(new ObjectMapper())), new Period(0), null);
CacheScheduler.Entry entry = scheduler.schedule(namespace);
entries.add(entry);
NamespaceExtractionCacheManagerExecutorsTest.waitFor(entry);
}
for (CacheScheduler.Entry entry : entries) {
final Map<String, String> map = entry.getCache();
Assert.assertEquals("bar", map.get("foo"));
Assert.assertEquals(null, map.get("baz"));
entry.close();
}
Assert.assertEquals(0, scheduler.getActiveEntries());
}
Aggregations