use of org.apache.druid.query.lookup.namespace.UriExtractionNamespace in project druid by druid-io.
the class CacheSchedulerTest method setUp.
@Before
public void setUp() throws Exception {
lifecycle = new Lifecycle();
lifecycle.start();
cacheManager = createCacheManager.apply(lifecycle);
final Path tmpDir = temporaryFolder.newFolder().toPath();
final CacheGenerator<UriExtractionNamespace> cacheGenerator = new CacheGenerator<UriExtractionNamespace>() {
@Override
public CacheScheduler.VersionedCache generateCache(final UriExtractionNamespace extractionNamespace, final CacheScheduler.EntryImpl<UriExtractionNamespace> id, final String lastVersion, final CacheScheduler scheduler) throws InterruptedException {
// To make absolutely sure there is a unique currentTimeMillis
Thread.sleep(2);
String version = Long.toString(System.currentTimeMillis());
CacheScheduler.VersionedCache versionedCache = scheduler.createVersionedCache(id, version);
// Don't actually read off disk because TravisCI doesn't like that
versionedCache.getCache().put(KEY, VALUE);
return versionedCache;
}
};
scheduler = new CacheScheduler(new NoopServiceEmitter(), ImmutableMap.of(UriExtractionNamespace.class, cacheGenerator), cacheManager);
tmpFile = Files.createTempFile(tmpDir, "druidTestURIExtractionNS", ".dat").toFile();
try (OutputStream ostream = new FileOutputStream(tmpFile)) {
try (OutputStreamWriter out = new OutputStreamWriter(ostream, StandardCharsets.UTF_8)) {
// Since Travis sucks with disk related stuff, we override the disk reading part above.
// This is safe and should shake out any problem areas that accidentally read the file.
out.write("SHOULDN'T TRY TO PARSE");
out.flush();
}
}
}
use of org.apache.druid.query.lookup.namespace.UriExtractionNamespace in project druid by druid-io.
the class CacheSchedulerTest method testDelete.
private void testDelete() throws InterruptedException {
// Give it some time between attempts to update
final long period = 1_000L;
final UriExtractionNamespace namespace = getUriExtractionNamespace(period);
CacheScheduler.Entry entry = scheduler.scheduleAndWait(namespace, 10_000);
Assert.assertNotNull(entry);
final Future<?> future = entry.getUpdaterFuture();
Assert.assertFalse(future.isCancelled());
Assert.assertFalse(future.isDone());
entry.awaitTotalUpdates(1);
Assert.assertEquals(VALUE, entry.getCache().get(KEY));
entry.close();
try {
Assert.assertNull(future.get());
} catch (CancellationException e) {
// Ignore
} catch (ExecutionException e) {
if (!future.isCancelled()) {
throw new RuntimeException(e);
}
}
Assert.assertTrue(future.isCancelled());
Assert.assertTrue(future.isDone());
}
use of org.apache.druid.query.lookup.namespace.UriExtractionNamespace in project druid by druid-io.
the class CacheSchedulerTest method testShutdown.
@Test(timeout = 60_000L)
public void testShutdown() throws InterruptedException {
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)) {
// keep waiting
}
checkNoMoreRunning();
Assert.assertTrue(cacheManager.scheduledExecutorService().isShutdown());
Assert.assertTrue(cacheManager.scheduledExecutorService().isTerminated());
}
Aggregations