Search in sources :

Example 11 with UriExtractionNamespace

use of org.apache.druid.query.lookup.namespace.UriExtractionNamespace in project druid by druid-io.

the class UriCacheGeneratorTest 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, null);
    Assert.assertNotNull(generator.generateCache(extractionNamespace, null, null, scheduler));
}
Also used : UriExtractionNamespace(org.apache.druid.query.lookup.namespace.UriExtractionNamespace) 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 12 with UriExtractionNamespace

use of org.apache.druid.query.lookup.namespace.UriExtractionNamespace in project druid by druid-io.

the class UriCacheGeneratorTest 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, null);
    Assert.assertTrue(new File(namespace.getUri()).delete());
    generator.generateCache(badNamespace, null, null, scheduler);
}
Also used : UriExtractionNamespace(org.apache.druid.query.lookup.namespace.UriExtractionNamespace) File(java.io.File) UriExtractionNamespaceTest(org.apache.druid.query.lookup.namespace.UriExtractionNamespaceTest) CacheSchedulerTest(org.apache.druid.server.lookup.namespace.cache.CacheSchedulerTest) Test(org.junit.Test)

Example 13 with UriExtractionNamespace

use of org.apache.druid.query.lookup.namespace.UriExtractionNamespace in project druid by druid-io.

the class UriCacheGeneratorTest 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, null);
        CacheScheduler.Entry entry = scheduler.schedule(namespace);
        entries.add(entry);
        CacheSchedulerTest.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 : ArrayList(java.util.ArrayList) Period(org.joda.time.Period) UriExtractionNamespace(org.apache.druid.query.lookup.namespace.UriExtractionNamespace) CacheScheduler(org.apache.druid.server.lookup.namespace.cache.CacheScheduler) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) UriExtractionNamespaceTest(org.apache.druid.query.lookup.namespace.UriExtractionNamespaceTest) CacheSchedulerTest(org.apache.druid.server.lookup.namespace.cache.CacheSchedulerTest) Test(org.junit.Test)

Example 14 with UriExtractionNamespace

use of org.apache.druid.query.lookup.namespace.UriExtractionNamespace in project druid by druid-io.

the class UriCacheGeneratorTest 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, null);
    Assert.assertTrue(new File(namespace.getUri()).delete());
    generator.generateCache(badNamespace, null, null, scheduler);
}
Also used : UriExtractionNamespace(org.apache.druid.query.lookup.namespace.UriExtractionNamespace) File(java.io.File) UriExtractionNamespaceTest(org.apache.druid.query.lookup.namespace.UriExtractionNamespaceTest) CacheSchedulerTest(org.apache.druid.server.lookup.namespace.cache.CacheSchedulerTest) Test(org.junit.Test)

Example 15 with UriExtractionNamespace

use of org.apache.druid.query.lookup.namespace.UriExtractionNamespace in project druid by druid-io.

the class CacheSchedulerTest method testRunCount.

@Test(timeout = 60_000L)
public void testRunCount() throws InterruptedException {
    final int numWaits = 5;
    try {
        final UriExtractionNamespace namespace = getUriExtractionNamespace((long) 5);
        try (CacheScheduler.Entry entry = scheduler.schedule(namespace)) {
            final Future<?> future = entry.getUpdaterFuture();
            entry.awaitNextUpdates(numWaits);
            Assert.assertFalse(future.isDone());
        }
    } finally {
        lifecycle.stop();
    }
    while (!cacheManager.waitForServiceToEnd(1_000, TimeUnit.MILLISECONDS)) {
    // keep waiting
    }
    Assert.assertTrue(scheduler.updatesStarted() >= numWaits);
    checkNoMoreRunning();
}
Also used : UriExtractionNamespace(org.apache.druid.query.lookup.namespace.UriExtractionNamespace) UriExtractionNamespaceTest(org.apache.druid.query.lookup.namespace.UriExtractionNamespaceTest) Test(org.junit.Test)

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