Search in sources :

Example 11 with ExtractionNamespace

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

the class StaticMapExtractionNamespaceCacheFactoryTest method setup.

@Before
public void setup() throws Exception {
    lifecycle = new Lifecycle();
    lifecycle.start();
    NoopServiceEmitter noopServiceEmitter = new NoopServiceEmitter();
    scheduler = new CacheScheduler(noopServiceEmitter, Collections.<Class<? extends ExtractionNamespace>, ExtractionNamespaceCacheFactory<?>>emptyMap(), new OnHeapNamespaceExtractionCacheManager(lifecycle, noopServiceEmitter));
}
Also used : ExtractionNamespaceCacheFactory(io.druid.query.lookup.namespace.ExtractionNamespaceCacheFactory) OnHeapNamespaceExtractionCacheManager(io.druid.server.lookup.namespace.cache.OnHeapNamespaceExtractionCacheManager) Lifecycle(io.druid.java.util.common.lifecycle.Lifecycle) StaticMapExtractionNamespace(io.druid.query.lookup.namespace.StaticMapExtractionNamespace) ExtractionNamespace(io.druid.query.lookup.namespace.ExtractionNamespace) NoopServiceEmitter(io.druid.server.metrics.NoopServiceEmitter) CacheScheduler(io.druid.server.lookup.namespace.cache.CacheScheduler) Before(org.junit.Before)

Example 12 with ExtractionNamespace

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

the class NamespaceLookupExtractorFactoryTest method testSimpleStartGetStop.

@Test
public void testSimpleStartGetStop() {
    final ExtractionNamespace extractionNamespace = new ExtractionNamespace() {

        @Override
        public long getPollMs() {
            return 0;
        }
    };
    expectScheduleAndWaitOnce(extractionNamespace);
    expectEntryGetCacheStateOnce(versionedCache);
    expectEmptyCache();
    expectVersionOnce("0");
    expectEntryCloseOnce();
    mockReplay();
    final NamespaceLookupExtractorFactory namespaceLookupExtractorFactory = new NamespaceLookupExtractorFactory(extractionNamespace, scheduler);
    Assert.assertTrue(namespaceLookupExtractorFactory.start());
    final LookupExtractor extractor = namespaceLookupExtractorFactory.get();
    Assert.assertNull(extractor.apply("foo"));
    Assert.assertTrue(namespaceLookupExtractorFactory.close());
    mockVerify();
}
Also used : ExtractionNamespace(io.druid.query.lookup.namespace.ExtractionNamespace) URIExtractionNamespace(io.druid.query.lookup.namespace.URIExtractionNamespace) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 13 with ExtractionNamespace

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

the class NamespaceLookupExtractorFactoryTest method testMustBeStarted.

@Test(expected = ISE.class)
public void testMustBeStarted() {
    final ExtractionNamespace extractionNamespace = new ExtractionNamespace() {

        @Override
        public long getPollMs() {
            return 0;
        }
    };
    final NamespaceLookupExtractorFactory namespaceLookupExtractorFactory = new NamespaceLookupExtractorFactory(extractionNamespace, scheduler);
    namespaceLookupExtractorFactory.get();
}
Also used : ExtractionNamespace(io.druid.query.lookup.namespace.ExtractionNamespace) URIExtractionNamespace(io.druid.query.lookup.namespace.URIExtractionNamespace) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with ExtractionNamespace

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

the class NamespaceExtractionCacheManagerExecutorsTest method setUp.

@Before
public void setUp() throws Exception {
    lifecycle = new Lifecycle();
    lifecycle.start();
    cacheManager = createCacheManager.apply(lifecycle);
    final Path tmpDir = temporaryFolder.newFolder().toPath();
    final ExtractionNamespaceCacheFactory<URIExtractionNamespace> cachePopulator = new ExtractionNamespaceCacheFactory<URIExtractionNamespace>() {

        @Override
        public CacheScheduler.VersionedCache populateCache(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.<Class<? extends ExtractionNamespace>, ExtractionNamespaceCacheFactory<?>>of(URIExtractionNamespace.class, cachePopulator), cacheManager);
    tmpFile = Files.createTempFile(tmpDir, "druidTestURIExtractionNS", ".dat").toFile();
    try (OutputStream ostream = new FileOutputStream(tmpFile)) {
        try (OutputStreamWriter out = new OutputStreamWriter(ostream)) {
            // 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();
        }
    }
}
Also used : Path(java.nio.file.Path) Lifecycle(io.druid.java.util.common.lifecycle.Lifecycle) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) NoopServiceEmitter(io.druid.server.metrics.NoopServiceEmitter) ExtractionNamespaceCacheFactory(io.druid.query.lookup.namespace.ExtractionNamespaceCacheFactory) URIExtractionNamespace(io.druid.query.lookup.namespace.URIExtractionNamespace) FileOutputStream(java.io.FileOutputStream) ExtractionNamespace(io.druid.query.lookup.namespace.ExtractionNamespace) URIExtractionNamespace(io.druid.query.lookup.namespace.URIExtractionNamespace) OutputStreamWriter(java.io.OutputStreamWriter) Before(org.junit.Before)

Aggregations

ExtractionNamespace (io.druid.query.lookup.namespace.ExtractionNamespace)14 URIExtractionNamespace (io.druid.query.lookup.namespace.URIExtractionNamespace)13 Test (org.junit.Test)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)11 Lifecycle (io.druid.java.util.common.lifecycle.Lifecycle)3 ExtractionNamespaceCacheFactory (io.druid.query.lookup.namespace.ExtractionNamespaceCacheFactory)3 NoopServiceEmitter (io.druid.server.metrics.NoopServiceEmitter)3 Before (org.junit.Before)3 CacheScheduler (io.druid.server.lookup.namespace.cache.CacheScheduler)2 OnHeapNamespaceExtractionCacheManager (io.druid.server.lookup.namespace.cache.OnHeapNamespaceExtractionCacheManager)2 SearchableVersionedDataFinder (io.druid.data.SearchableVersionedDataFinder)1 ISE (io.druid.java.util.common.ISE)1 JDBCExtractionNamespace (io.druid.query.lookup.namespace.JDBCExtractionNamespace)1 StaticMapExtractionNamespace (io.druid.query.lookup.namespace.StaticMapExtractionNamespace)1 LocalFileTimestampVersionFinder (io.druid.segment.loading.LocalFileTimestampVersionFinder)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Path (java.nio.file.Path)1 Response (javax.ws.rs.core.Response)1