use of org.apache.druid.query.lookup.namespace.UriExtractionNamespace in project druid by druid-io.
the class UriCacheGeneratorTest method testDeleteOnScheduleFail.
@Test(timeout = 60_000L)
public void testDeleteOnScheduleFail() throws Exception {
Assert.assertNull(scheduler.scheduleAndWait(new UriExtractionNamespace(new URI("file://tmp/I_DONT_REALLY_EXIST" + UUID.randomUUID()), null, null, new UriExtractionNamespace.JSONFlatDataParser(new DefaultObjectMapper(), "key", "val"), Period.millis(10000), null, null), 500));
Assert.assertEquals(0, scheduler.getActiveEntries());
}
use of org.apache.druid.query.lookup.namespace.UriExtractionNamespace in project druid by druid-io.
the class UriCacheGeneratorTest method simpleTestRegex.
@Test
public void simpleTestRegex() throws 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, null);
CacheScheduler.Entry entry = scheduler.schedule(namespace);
CacheSchedulerTest.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 org.apache.druid.query.lookup.namespace.UriExtractionNamespace in project druid by druid-io.
the class NamespacedExtractorModuleTest method testNewTask.
@Test
public void testNewTask() throws Exception {
final File tmpFile = temporaryFolder.newFile();
try (Writer out = Files.newWriter(tmpFile, StandardCharsets.UTF_8)) {
out.write(MAPPER.writeValueAsString(ImmutableMap.of("foo", "bar")));
}
final UriCacheGenerator factory = new UriCacheGenerator(ImmutableMap.of("file", new LocalFileTimestampVersionFinder()));
final UriExtractionNamespace namespace = new UriExtractionNamespace(tmpFile.toURI(), null, null, new UriExtractionNamespace.ObjectMapperFlatDataParser(UriExtractionNamespaceTest.registerTypes(new DefaultObjectMapper())), new Period(0), null, null);
CacheScheduler.VersionedCache versionedCache = factory.generateCache(namespace, null, null, scheduler);
Assert.assertNotNull(versionedCache);
Map<String, String> map = versionedCache.getCache();
Assert.assertEquals("bar", map.get("foo"));
Assert.assertEquals(null, map.get("baz"));
}
use of org.apache.druid.query.lookup.namespace.UriExtractionNamespace in project druid by druid-io.
the class NamespacedExtractorModuleTest method testNewUpdate.
@Test
public void testNewUpdate() throws Exception {
final File tmpFile = temporaryFolder.newFile();
try (Writer out = Files.newWriter(tmpFile, StandardCharsets.UTF_8)) {
out.write(MAPPER.writeValueAsString(ImmutableMap.of("foo", "bar")));
}
final UriExtractionNamespace namespace = new UriExtractionNamespace(tmpFile.toURI(), null, null, new UriExtractionNamespace.ObjectMapperFlatDataParser(UriExtractionNamespaceTest.registerTypes(new DefaultObjectMapper())), new Period(0), null, null);
Assert.assertEquals(0, scheduler.getActiveEntries());
try (CacheScheduler.Entry entry = scheduler.scheduleAndWait(namespace, 10_000)) {
Assert.assertNotNull(entry);
entry.awaitTotalUpdates(1);
Assert.assertEquals(1, scheduler.getActiveEntries());
}
}
use of org.apache.druid.query.lookup.namespace.UriExtractionNamespace in project druid by druid-io.
the class UriCacheGeneratorTest method setUp.
@Before
public void setUp() throws Exception {
lifecycle.start();
tmpFileParent = new File(temporaryFolder.newFolder(), "☃");
Assert.assertTrue(tmpFileParent.mkdir());
Assert.assertTrue(tmpFileParent.isDirectory());
tmpFile = Files.createTempFile(tmpFileParent.toPath(), "druidTestURIExtractionNS", suffix).toFile();
final ObjectMapper mapper = new DefaultObjectMapper();
try (OutputStream ostream = outStreamSupplier.apply(tmpFile);
OutputStreamWriter out = new OutputStreamWriter(ostream, StandardCharsets.UTF_8)) {
out.write(mapper.writeValueAsString(ImmutableMap.of("boo", "bar", "foo", "bar", "", "MissingValue", "emptyString", "")));
}
generator = new UriCacheGenerator(FINDERS);
namespace = new UriExtractionNamespace(tmpFile.toURI(), null, null, new UriExtractionNamespace.ObjectMapperFlatDataParser(UriExtractionNamespaceTest.registerTypes(new ObjectMapper())), new Period(0), null, null);
}
Aggregations