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());
}
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();
}
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());
}
}
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));
}
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);
}
Aggregations