Search in sources :

Example 6 with URIExtractionNamespace

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

the class NamespaceExtractionCacheManagerExecutorsTest method testSimpleSubmission.

@Test(timeout = 10_000)
public void testSimpleSubmission() throws ExecutionException, InterruptedException {
    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);
    waitFor(entry);
    Map<String, String> cache = entry.getCache();
    Assert.assertNull(cache.put("key", "val"));
    Assert.assertEquals("val", cache.get("key"));
}
Also used : URIExtractionNamespace(io.druid.query.lookup.namespace.URIExtractionNamespace) Period(org.joda.time.Period) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) URIExtractionNamespaceTest(io.druid.query.lookup.namespace.URIExtractionNamespaceTest) Test(org.junit.Test)

Example 7 with URIExtractionNamespace

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

the class NamespaceLookupExtractorFactoryTest method testSimpleSerde.

@Test
public void testSimpleSerde() throws Exception {
    final URIExtractionNamespace uriExtractionNamespace = new URIExtractionNamespace(temporaryFolder.newFolder().toURI(), null, null, new URIExtractionNamespace.ObjectMapperFlatDataParser(mapper), Period.millis(0), null);
    final NamespaceLookupExtractorFactory namespaceLookupExtractorFactory = new NamespaceLookupExtractorFactory(uriExtractionNamespace, scheduler);
    Assert.assertEquals(uriExtractionNamespace, mapper.readValue(mapper.writeValueAsString(namespaceLookupExtractorFactory), NamespaceLookupExtractorFactory.class).getExtractionNamespace());
}
Also used : URIExtractionNamespace(io.druid.query.lookup.namespace.URIExtractionNamespace) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with URIExtractionNamespace

use of io.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 (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);
    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 : 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 9 with URIExtractionNamespace

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

the class URIExtractionNamespaceCacheFactoryTest method testWeirdSchemaOnExactURI.

@Test
public void testWeirdSchemaOnExactURI() throws Exception {
    final URIExtractionNamespace extractionNamespace = new URIExtractionNamespace(new URI(FAKE_SCHEME, namespace.getUri().getUserInfo(), namespace.getUri().getHost(), namespace.getUri().getPort(), namespace.getUri().getPath(), namespace.getUri().getQuery(), namespace.getUri().getFragment()), null, null, namespace.getNamespaceParseSpec(), Period.millis((int) namespace.getPollMs()), null);
    Assert.assertNotNull(populator.populateCache(extractionNamespace, null, null, scheduler));
}
Also used : URIExtractionNamespace(io.druid.query.lookup.namespace.URIExtractionNamespace) URI(java.net.URI) URIExtractionNamespaceTest(io.druid.query.lookup.namespace.URIExtractionNamespaceTest) NamespaceExtractionCacheManagerExecutorsTest(io.druid.server.lookup.namespace.cache.NamespaceExtractionCacheManagerExecutorsTest) Test(org.junit.Test)

Example 10 with URIExtractionNamespace

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

the class URIExtractionNamespaceCacheFactoryTest method testMissing.

@Test(expected = FileNotFoundException.class)
public void testMissing() throws Exception {
    URIExtractionNamespace badNamespace = new URIExtractionNamespace(namespace.getUri(), null, null, 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)

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