Search in sources :

Example 21 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project druid by druid-io.

the class URIExtractionNamespaceCacheFactoryTest method simplePileONamespacesTest.

@Test
public void simplePileONamespacesTest() throws InterruptedException {
    final int size = 128;
    List<CacheScheduler.Entry> entries = new ArrayList<>(size);
    for (int i = 0; i < size; ++i) {
        URIExtractionNamespace namespace = new URIExtractionNamespace(tmpFile.toURI(), null, null, new URIExtractionNamespace.ObjectMapperFlatDataParser(URIExtractionNamespaceTest.registerTypes(new ObjectMapper())), new Period(0), null);
        CacheScheduler.Entry entry = scheduler.schedule(namespace);
        entries.add(entry);
        NamespaceExtractionCacheManagerExecutorsTest.waitFor(entry);
    }
    for (CacheScheduler.Entry entry : entries) {
        final Map<String, String> map = entry.getCache();
        Assert.assertEquals("bar", map.get("foo"));
        Assert.assertEquals(null, map.get("baz"));
        entry.close();
    }
    Assert.assertEquals(0, scheduler.getActiveEntries());
}
Also used : URIExtractionNamespace(io.druid.query.lookup.namespace.URIExtractionNamespace) ArrayList(java.util.ArrayList) Period(org.joda.time.Period) CacheScheduler(io.druid.server.lookup.namespace.cache.CacheScheduler) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) URIExtractionNamespaceTest(io.druid.query.lookup.namespace.URIExtractionNamespaceTest) NamespaceExtractionCacheManagerExecutorsTest(io.druid.server.lookup.namespace.cache.NamespaceExtractionCacheManagerExecutorsTest) Test(org.junit.Test)

Example 22 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project druid by druid-io.

the class NamespaceLookupExtractorFactoryTest method testSimpleIntrospectionHandler.

@Test
public void testSimpleIntrospectionHandler() throws Exception {
    final Injector injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.of(new Module() {

        @Override
        public void configure(Binder binder) {
            JsonConfigProvider.bindInstance(binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, null));
        }
    }));
    final ObjectMapper mapper = injector.getInstance(Key.get(ObjectMapper.class, Json.class));
    mapper.registerSubtypes(NamespaceLookupExtractorFactory.class);
    final String str = "{ \"type\": \"cachedNamespace\", \"extractionNamespace\": { \"type\": \"staticMap\", \"map\": {\"foo\":\"bar\"} }, \"firstCacheTimeout\":10000 }";
    final LookupExtractorFactory lookupExtractorFactory = mapper.readValue(str, LookupExtractorFactory.class);
    Assert.assertTrue(lookupExtractorFactory.start());
    try {
        final LookupIntrospectHandler handler = lookupExtractorFactory.getIntrospectHandler();
        Assert.assertNotNull(handler);
        final Class<? extends LookupIntrospectHandler> clazz = handler.getClass();
        Assert.assertNotNull(clazz.getMethod("getVersion").invoke(handler));
        Assert.assertEquals(ImmutableSet.of("foo"), ((Response) clazz.getMethod("getKeys").invoke(handler)).getEntity());
        Assert.assertEquals(ImmutableSet.of("bar"), ((Response) clazz.getMethod("getValues").invoke(handler)).getEntity());
        Assert.assertEquals(ImmutableMap.builder().put("foo", "bar").build(), ((Response) clazz.getMethod("getMap").invoke(handler)).getEntity());
    } finally {
        Assert.assertTrue(lookupExtractorFactory.close());
    }
}
Also used : Binder(com.google.inject.Binder) Injector(com.google.inject.Injector) DruidNode(io.druid.server.DruidNode) Self(io.druid.guice.annotations.Self) Json(io.druid.guice.annotations.Json) Module(com.google.inject.Module) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 23 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project druid by druid-io.

the class NamespaceExtractionCacheManagerExecutorsTest method testSimpleSubmission.

@Test(timeout = 10_000)
public void testSimpleSubmission() throws ExecutionException, InterruptedException {
    URIExtractionNamespace namespace = new URIExtractionNamespace(tmpFile.toURI(), null, null, new URIExtractionNamespace.ObjectMapperFlatDataParser(URIExtractionNamespaceTest.registerTypes(new ObjectMapper())), new Period(0), null);
    CacheScheduler.Entry entry = scheduler.schedule(namespace);
    waitFor(entry);
    Map<String, String> cache = entry.getCache();
    Assert.assertNull(cache.put("key", "val"));
    Assert.assertEquals("val", cache.get("key"));
}
Also used : URIExtractionNamespace(io.druid.query.lookup.namespace.URIExtractionNamespace) Period(org.joda.time.Period) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) URIExtractionNamespaceTest(io.druid.query.lookup.namespace.URIExtractionNamespaceTest) Test(org.junit.Test)

Example 24 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project druid by druid-io.

the class URIExtractionNamespaceTest method testExplicitJson.

@Test
public void testExplicitJson() throws IOException {
    final ObjectMapper mapper = registerTypes(new DefaultObjectMapper());
    URIExtractionNamespace namespace = mapper.readValue("{\"type\":\"uri\", \"uri\":\"file:/foo\", \"namespaceParseSpec\":{\"format\":\"simpleJson\"}, \"pollPeriod\":\"PT5M\"}", URIExtractionNamespace.class);
    Assert.assertEquals(URIExtractionNamespace.ObjectMapperFlatDataParser.class.getCanonicalName(), namespace.getNamespaceParseSpec().getClass().getCanonicalName());
    Assert.assertEquals("file:/foo", namespace.getUri().toString());
    Assert.assertEquals(5L * 60_000L, namespace.getPollMs());
}
Also used : DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 25 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project druid by druid-io.

the class URIExtractionNamespaceTest method testFlatDataNumeric.

@Test
public void testFlatDataNumeric() {
    final String keyField = "keyField";
    final String valueField = "valueField";
    final int n = 341879;
    final String nString = String.format("%d", n);
    URIExtractionNamespace.JSONFlatDataParser parser = new URIExtractionNamespace.JSONFlatDataParser(new ObjectMapper(), keyField, valueField);
    Assert.assertEquals("num string value", ImmutableMap.of("B", nString), parser.getParser().parse(String.format("{\"%s\":\"B\", \"%s\":\"%d\", \"FOO\":\"BAR\"}", keyField, valueField, n)));
    Assert.assertEquals("num string key", ImmutableMap.of(nString, "C"), parser.getParser().parse(String.format("{\"%s\":\"%d\", \"%s\":\"C\", \"FOO\":\"BAR\"}", keyField, n, valueField)));
    Assert.assertEquals("num value", ImmutableMap.of("B", nString), parser.getParser().parse(String.format("{\"%s\":\"B\", \"%s\":%d, \"FOO\":\"BAR\"}", keyField, valueField, n)));
    Assert.assertEquals("num key", ImmutableMap.of(nString, "C"), parser.getParser().parse(String.format("{\"%s\":%d, \"%s\":\"C\", \"FOO\":\"BAR\"}", keyField, n, valueField)));
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5262 Test (org.junit.Test)1989 IOException (java.io.IOException)837 JsonNode (com.fasterxml.jackson.databind.JsonNode)724 HashMap (java.util.HashMap)375 Map (java.util.Map)367 ArrayList (java.util.ArrayList)346 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)318 File (java.io.File)282 List (java.util.List)222 Test (org.junit.jupiter.api.Test)205 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)202 Before (org.junit.Before)202 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)197 InputStream (java.io.InputStream)143 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)137 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)127 Matchers.containsString (org.hamcrest.Matchers.containsString)127 TypeReference (com.fasterxml.jackson.core.type.TypeReference)108 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)99