Search in sources :

Example 16 with URIExtractionNamespace

use of io.druid.query.lookup.namespace.URIExtractionNamespace in project druid by druid-io.

the class URIExtractionNamespaceCacheFactoryTest method testDeleteOnScheduleFail.

@Test(timeout = 10_000)
public void testDeleteOnScheduleFail() throws Exception {
    Assert.assertNull(scheduler.scheduleAndWait(new URIExtractionNamespace(new URI("file://tmp/I_DONT_REALLY_EXIST" + UUID.randomUUID().toString()), null, null, new URIExtractionNamespace.JSONFlatDataParser(new DefaultObjectMapper(), "key", "val"), Period.millis(10000), null), 500));
    Assert.assertEquals(0, scheduler.getActiveEntries());
}
Also used : URIExtractionNamespace(io.druid.query.lookup.namespace.URIExtractionNamespace) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) URI(java.net.URI) URIExtractionNamespaceTest(io.druid.query.lookup.namespace.URIExtractionNamespaceTest) NamespaceExtractionCacheManagerExecutorsTest(io.druid.server.lookup.namespace.cache.NamespaceExtractionCacheManagerExecutorsTest) Test(org.junit.Test)

Example 17 with URIExtractionNamespace

use of io.druid.query.lookup.namespace.URIExtractionNamespace in project druid by druid-io.

the class URIExtractionNamespaceCacheFactoryTest 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)) {
        try (OutputStreamWriter out = new OutputStreamWriter(ostream)) {
            out.write(mapper.writeValueAsString(ImmutableMap.<String, String>of("boo", "bar", "foo", "bar", "", "MissingValue", "emptyString", "")));
        }
    }
    populator = new URIExtractionNamespaceCacheFactory(FINDERS);
    namespace = new URIExtractionNamespace(tmpFile.toURI(), null, null, new URIExtractionNamespace.ObjectMapperFlatDataParser(URIExtractionNamespaceTest.registerTypes(new ObjectMapper())), new Period(0), null);
}
Also used : URIExtractionNamespace(io.druid.query.lookup.namespace.URIExtractionNamespace) GZIPOutputStream(java.util.zip.GZIPOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) Period(org.joda.time.Period) OutputStreamWriter(java.io.OutputStreamWriter) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) File(java.io.File) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 18 with URIExtractionNamespace

use of io.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 (OutputStreamWriter out = new FileWriter(tmpFile)) {
        out.write(mapper.writeValueAsString(ImmutableMap.<String, String>of("foo", "bar")));
    }
    final URIExtractionNamespaceCacheFactory factory = new URIExtractionNamespaceCacheFactory(ImmutableMap.<String, SearchableVersionedDataFinder>of("file", new LocalFileTimestampVersionFinder()));
    final URIExtractionNamespace namespace = new URIExtractionNamespace(tmpFile.toURI(), null, null, new URIExtractionNamespace.ObjectMapperFlatDataParser(URIExtractionNamespaceTest.registerTypes(new DefaultObjectMapper())), new Period(0), null);
    CacheScheduler.VersionedCache versionedCache = factory.populateCache(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 : FileWriter(java.io.FileWriter) Period(org.joda.time.Period) URIExtractionNamespace(io.druid.query.lookup.namespace.URIExtractionNamespace) OutputStreamWriter(java.io.OutputStreamWriter) LocalFileTimestampVersionFinder(io.druid.segment.loading.LocalFileTimestampVersionFinder) 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)

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