Search in sources :

Example 1 with NamespaceExtractionCacheManager

use of io.druid.server.lookup.namespace.cache.NamespaceExtractionCacheManager in project druid by druid-io.

the class KafkaLookupExtractorFactoryTest method testSerDe.

@Test
public void testSerDe() throws Exception {
    final NamespaceExtractionCacheManager cacheManager = PowerMock.createStrictMock(NamespaceExtractionCacheManager.class);
    final String kafkaTopic = "some_topic";
    final Map<String, String> kafkaProperties = ImmutableMap.of("some_key", "some_value");
    final long connectTimeout = 999;
    final boolean injective = true;
    final KafkaLookupExtractorFactory factory = new KafkaLookupExtractorFactory(cacheManager, kafkaTopic, kafkaProperties, connectTimeout, injective);
    final KafkaLookupExtractorFactory otherFactory = mapper.readValue(mapper.writeValueAsString(factory), KafkaLookupExtractorFactory.class);
    Assert.assertEquals(kafkaTopic, otherFactory.getKafkaTopic());
    Assert.assertEquals(kafkaProperties, otherFactory.getKafkaProperties());
    Assert.assertEquals(connectTimeout, otherFactory.getConnectTimeout());
    Assert.assertEquals(injective, otherFactory.isInjective());
}
Also used : NamespaceExtractionCacheManager(io.druid.server.lookup.namespace.cache.NamespaceExtractionCacheManager) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with NamespaceExtractionCacheManager

use of io.druid.server.lookup.namespace.cache.NamespaceExtractionCacheManager in project druid by druid-io.

the class URIExtractionNamespaceCacheFactoryTest method getParameters.

@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> getParameters() throws NoSuchMethodException {
    final List<Object[]> compressionParams = ImmutableList.of(new Object[] { ".dat", new Function<File, OutputStream>() {

        @Nullable
        @Override
        public OutputStream apply(@Nullable File outFile) {
            try {
                return new FileOutputStream(outFile);
            } catch (IOException ex) {
                throw Throwables.propagate(ex);
            }
        }
    } }, new Object[] { ".gz", new Function<File, OutputStream>() {

        @Nullable
        @Override
        public OutputStream apply(@Nullable File outFile) {
            try {
                final FileOutputStream fos = new FileOutputStream(outFile);
                return new GZIPOutputStream(fos) {

                    @Override
                    public void close() throws IOException {
                        try {
                            super.close();
                        } finally {
                            fos.close();
                        }
                    }
                };
            } catch (IOException ex) {
                throw Throwables.propagate(ex);
            }
        }
    } });
    final List<Function<Lifecycle, NamespaceExtractionCacheManager>> cacheManagerCreators = ImmutableList.of(new Function<Lifecycle, NamespaceExtractionCacheManager>() {

        @Override
        public NamespaceExtractionCacheManager apply(Lifecycle lifecycle) {
            return new OnHeapNamespaceExtractionCacheManager(lifecycle, new NoopServiceEmitter());
        }
    }, new Function<Lifecycle, NamespaceExtractionCacheManager>() {

        @Override
        public NamespaceExtractionCacheManager apply(Lifecycle lifecycle) {
            return new OffHeapNamespaceExtractionCacheManager(lifecycle, new NoopServiceEmitter());
        }
    });
    return new Iterable<Object[]>() {

        @Override
        public Iterator<Object[]> iterator() {
            return new Iterator<Object[]>() {

                Iterator<Object[]> compressionIt = compressionParams.iterator();

                Iterator<Function<Lifecycle, NamespaceExtractionCacheManager>> cacheManagerCreatorsIt = cacheManagerCreators.iterator();

                Object[] compressions = compressionIt.next();

                @Override
                public boolean hasNext() {
                    return compressionIt.hasNext() || cacheManagerCreatorsIt.hasNext();
                }

                @Override
                public Object[] next() {
                    if (cacheManagerCreatorsIt.hasNext()) {
                        Function<Lifecycle, NamespaceExtractionCacheManager> cacheManagerCreator = cacheManagerCreatorsIt.next();
                        return new Object[] { compressions[0], compressions[1], cacheManagerCreator };
                    } else {
                        cacheManagerCreatorsIt = cacheManagerCreators.iterator();
                        compressions = compressionIt.next();
                        return next();
                    }
                }

                @Override
                public void remove() {
                    throw new UOE("Cannot remove");
                }
            };
        }
    };
}
Also used : OnHeapNamespaceExtractionCacheManager(io.druid.server.lookup.namespace.cache.OnHeapNamespaceExtractionCacheManager) GZIPOutputStream(java.util.zip.GZIPOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) Lifecycle(io.druid.java.util.common.lifecycle.Lifecycle) NoopServiceEmitter(io.druid.server.metrics.NoopServiceEmitter) UOE(io.druid.java.util.common.UOE) IOException(java.io.IOException) OffHeapNamespaceExtractionCacheManager(io.druid.server.lookup.namespace.cache.OffHeapNamespaceExtractionCacheManager) Function(com.google.common.base.Function) NamespaceExtractionCacheManager(io.druid.server.lookup.namespace.cache.NamespaceExtractionCacheManager) OffHeapNamespaceExtractionCacheManager(io.druid.server.lookup.namespace.cache.OffHeapNamespaceExtractionCacheManager) OnHeapNamespaceExtractionCacheManager(io.druid.server.lookup.namespace.cache.OnHeapNamespaceExtractionCacheManager) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileOutputStream(java.io.FileOutputStream) Iterator(java.util.Iterator) File(java.io.File) Nullable(javax.annotation.Nullable)

Aggregations

NamespaceExtractionCacheManager (io.druid.server.lookup.namespace.cache.NamespaceExtractionCacheManager)2 Function (com.google.common.base.Function)1 UOE (io.druid.java.util.common.UOE)1 Lifecycle (io.druid.java.util.common.lifecycle.Lifecycle)1 OffHeapNamespaceExtractionCacheManager (io.druid.server.lookup.namespace.cache.OffHeapNamespaceExtractionCacheManager)1 OnHeapNamespaceExtractionCacheManager (io.druid.server.lookup.namespace.cache.OnHeapNamespaceExtractionCacheManager)1 NoopServiceEmitter (io.druid.server.metrics.NoopServiceEmitter)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Iterator (java.util.Iterator)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 Nullable (javax.annotation.Nullable)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1