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