Search in sources :

Example 11 with URIExtractionNamespace

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

the class NamespaceExtractionCacheManagerExecutorsTest method testShutdown.

@Test(timeout = 10_000)
public void testShutdown() throws NoSuchFieldException, IllegalAccessException, InterruptedException, ExecutionException {
    final long period = 5L;
    try {
        final URIExtractionNamespace namespace = getUriExtractionNamespace(period);
        try (CacheScheduler.Entry entry = scheduler.schedule(namespace)) {
            final Future<?> future = entry.getUpdaterFuture();
            entry.awaitNextUpdates(1);
            Assert.assertFalse(future.isCancelled());
            Assert.assertFalse(future.isDone());
            final long prior = scheduler.updatesStarted();
            entry.awaitNextUpdates(1);
            Assert.assertTrue(scheduler.updatesStarted() > prior);
        }
    } finally {
        lifecycle.stop();
    }
    while (!cacheManager.waitForServiceToEnd(1_000, TimeUnit.MILLISECONDS)) {
    }
    checkNoMoreRunning();
    Assert.assertTrue(cacheManager.scheduledExecutorService().isShutdown());
    Assert.assertTrue(cacheManager.scheduledExecutorService().isTerminated());
}
Also used : URIExtractionNamespace(io.druid.query.lookup.namespace.URIExtractionNamespace) URIExtractionNamespaceTest(io.druid.query.lookup.namespace.URIExtractionNamespaceTest) Test(org.junit.Test)

Example 12 with URIExtractionNamespace

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

the class NamespaceExtractionCacheManagerExecutorsTest method testPeriodicUpdatesScheduled.

@Test(timeout = 10_000)
public void testPeriodicUpdatesScheduled() throws ExecutionException, InterruptedException {
    final int repeatCount = 5;
    final long delay = 5;
    try {
        final URIExtractionNamespace namespace = getUriExtractionNamespace(delay);
        final long start = System.currentTimeMillis();
        try (CacheScheduler.Entry entry = scheduler.schedule(namespace)) {
            Assert.assertFalse(entry.getUpdaterFuture().isDone());
            Assert.assertFalse(entry.getUpdaterFuture().isCancelled());
            entry.awaitTotalUpdates(repeatCount);
            long minEnd = start + ((repeatCount - 1) * delay);
            long end = System.currentTimeMillis();
            Assert.assertTrue(String.format("Didn't wait long enough between runs. Expected more than %d was %d", minEnd - start, end - start), minEnd <= end);
        }
    } finally {
        lifecycle.stop();
        cacheManager.waitForServiceToEnd(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
    }
    checkNoMoreRunning();
}
Also used : URIExtractionNamespace(io.druid.query.lookup.namespace.URIExtractionNamespace) URIExtractionNamespaceTest(io.druid.query.lookup.namespace.URIExtractionNamespaceTest) Test(org.junit.Test)

Example 13 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 14 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 15 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