Search in sources :

Example 1 with URIExtractionNamespace

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

Example 2 with URIExtractionNamespace

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

Example 3 with URIExtractionNamespace

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"));
}
Also used : URIExtractionNamespace(io.druid.query.lookup.namespace.URIExtractionNamespace) CacheScheduler(io.druid.server.lookup.namespace.cache.CacheScheduler) URIExtractionNamespaceTest(io.druid.query.lookup.namespace.URIExtractionNamespaceTest) NamespaceExtractionCacheManagerExecutorsTest(io.druid.server.lookup.namespace.cache.NamespaceExtractionCacheManagerExecutorsTest) Test(org.junit.Test)

Example 4 with URIExtractionNamespace

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);
}
Also used : URIExtractionNamespace(io.druid.query.lookup.namespace.URIExtractionNamespace) File(java.io.File) URIExtractionNamespaceTest(io.druid.query.lookup.namespace.URIExtractionNamespaceTest) NamespaceExtractionCacheManagerExecutorsTest(io.druid.server.lookup.namespace.cache.NamespaceExtractionCacheManagerExecutorsTest) Test(org.junit.Test)

Example 5 with URIExtractionNamespace

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());
}
Also used : URIExtractionNamespace(io.druid.query.lookup.namespace.URIExtractionNamespace) ArrayList(java.util.ArrayList) Period(org.joda.time.Period) CacheScheduler(io.druid.server.lookup.namespace.cache.CacheScheduler) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) URIExtractionNamespaceTest(io.druid.query.lookup.namespace.URIExtractionNamespaceTest) NamespaceExtractionCacheManagerExecutorsTest(io.druid.server.lookup.namespace.cache.NamespaceExtractionCacheManagerExecutorsTest) Test(org.junit.Test)

Aggregations

URIExtractionNamespace (io.druid.query.lookup.namespace.URIExtractionNamespace)18 Test (org.junit.Test)15 URIExtractionNamespaceTest (io.druid.query.lookup.namespace.URIExtractionNamespaceTest)14 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)7 File (java.io.File)7 Period (org.joda.time.Period)7 CacheScheduler (io.druid.server.lookup.namespace.cache.CacheScheduler)6 NamespaceExtractionCacheManagerExecutorsTest (io.druid.server.lookup.namespace.cache.NamespaceExtractionCacheManagerExecutorsTest)6 OutputStreamWriter (java.io.OutputStreamWriter)6 FileWriter (java.io.FileWriter)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 URI (java.net.URI)2 Before (org.junit.Before)2 Lifecycle (io.druid.java.util.common.lifecycle.Lifecycle)1 ExtractionNamespace (io.druid.query.lookup.namespace.ExtractionNamespace)1 ExtractionNamespaceCacheFactory (io.druid.query.lookup.namespace.ExtractionNamespaceCacheFactory)1 LocalFileTimestampVersionFinder (io.druid.segment.loading.LocalFileTimestampVersionFinder)1 NoopServiceEmitter (io.druid.server.metrics.NoopServiceEmitter)1