Search in sources :

Example 6 with UriExtractionNamespace

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());
}
Also used : UriExtractionNamespace(org.apache.druid.query.lookup.namespace.UriExtractionNamespace) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) URI(java.net.URI) UriExtractionNamespaceTest(org.apache.druid.query.lookup.namespace.UriExtractionNamespaceTest) CacheSchedulerTest(org.apache.druid.server.lookup.namespace.cache.CacheSchedulerTest) Test(org.junit.Test)

Example 7 with UriExtractionNamespace

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"));
}
Also used : UriExtractionNamespace(org.apache.druid.query.lookup.namespace.UriExtractionNamespace) CacheScheduler(org.apache.druid.server.lookup.namespace.cache.CacheScheduler) UriExtractionNamespaceTest(org.apache.druid.query.lookup.namespace.UriExtractionNamespaceTest) CacheSchedulerTest(org.apache.druid.server.lookup.namespace.cache.CacheSchedulerTest) Test(org.junit.Test)

Example 8 with UriExtractionNamespace

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"));
}
Also used : Period(org.joda.time.Period) LocalFileTimestampVersionFinder(org.apache.druid.segment.loading.LocalFileTimestampVersionFinder) UriExtractionNamespace(org.apache.druid.query.lookup.namespace.UriExtractionNamespace) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) File(java.io.File) CacheScheduler(org.apache.druid.server.lookup.namespace.cache.CacheScheduler) Writer(java.io.Writer) UriExtractionNamespaceTest(org.apache.druid.query.lookup.namespace.UriExtractionNamespaceTest) Test(org.junit.Test)

Example 9 with UriExtractionNamespace

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());
    }
}
Also used : Period(org.joda.time.Period) UriExtractionNamespace(org.apache.druid.query.lookup.namespace.UriExtractionNamespace) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) File(java.io.File) CacheScheduler(org.apache.druid.server.lookup.namespace.cache.CacheScheduler) Writer(java.io.Writer) UriExtractionNamespaceTest(org.apache.druid.query.lookup.namespace.UriExtractionNamespaceTest) Test(org.junit.Test)

Example 10 with UriExtractionNamespace

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);
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) Period(org.joda.time.Period) OutputStreamWriter(java.io.OutputStreamWriter) UriExtractionNamespace(org.apache.druid.query.lookup.namespace.UriExtractionNamespace) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Before(org.junit.Before)

Aggregations

UriExtractionNamespace (org.apache.druid.query.lookup.namespace.UriExtractionNamespace)18 Test (org.junit.Test)15 UriExtractionNamespaceTest (org.apache.druid.query.lookup.namespace.UriExtractionNamespaceTest)14 File (java.io.File)7 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)7 Period (org.joda.time.Period)7 CacheScheduler (org.apache.druid.server.lookup.namespace.cache.CacheScheduler)6 CacheSchedulerTest (org.apache.druid.server.lookup.namespace.cache.CacheSchedulerTest)6 Writer (java.io.Writer)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 URI (java.net.URI)2 Before (org.junit.Before)2 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 CancellationException (java.util.concurrent.CancellationException)1 ExecutionException (java.util.concurrent.ExecutionException)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1