Search in sources :

Example 86 with DefaultObjectMapper

use of io.druid.jackson.DefaultObjectMapper in project druid by druid-io.

the class URIExtractionNamespaceCacheFactoryTest method testDeleteOnScheduleFail.

@Test(timeout = 10_000)
public void testDeleteOnScheduleFail() throws Exception {
    Assert.assertNull(scheduler.scheduleAndWait(new URIExtractionNamespace(new URI("file://tmp/I_DONT_REALLY_EXIST" + UUID.randomUUID().toString()), null, null, new URIExtractionNamespace.JSONFlatDataParser(new DefaultObjectMapper(), "key", "val"), Period.millis(10000), null), 500));
    Assert.assertEquals(0, scheduler.getActiveEntries());
}
Also used : URIExtractionNamespace(io.druid.query.lookup.namespace.URIExtractionNamespace) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) URI(java.net.URI) URIExtractionNamespaceTest(io.druid.query.lookup.namespace.URIExtractionNamespaceTest) NamespaceExtractionCacheManagerExecutorsTest(io.druid.server.lookup.namespace.cache.NamespaceExtractionCacheManagerExecutorsTest) Test(org.junit.Test)

Example 87 with DefaultObjectMapper

use of io.druid.jackson.DefaultObjectMapper in project druid by druid-io.

the class URIExtractionNamespaceCacheFactoryTest method setUp.

@Before
public void setUp() throws Exception {
    lifecycle.start();
    tmpFileParent = new File(temporaryFolder.newFolder(), "☃");
    Assert.assertTrue(tmpFileParent.mkdir());
    Assert.assertTrue(tmpFileParent.isDirectory());
    tmpFile = Files.createTempFile(tmpFileParent.toPath(), "druidTestURIExtractionNS", suffix).toFile();
    final ObjectMapper mapper = new DefaultObjectMapper();
    try (OutputStream ostream = outStreamSupplier.apply(tmpFile)) {
        try (OutputStreamWriter out = new OutputStreamWriter(ostream)) {
            out.write(mapper.writeValueAsString(ImmutableMap.<String, String>of("boo", "bar", "foo", "bar", "", "MissingValue", "emptyString", "")));
        }
    }
    populator = new URIExtractionNamespaceCacheFactory(FINDERS);
    namespace = new URIExtractionNamespace(tmpFile.toURI(), null, null, new URIExtractionNamespace.ObjectMapperFlatDataParser(URIExtractionNamespaceTest.registerTypes(new ObjectMapper())), new Period(0), null);
}
Also used : URIExtractionNamespace(io.druid.query.lookup.namespace.URIExtractionNamespace) GZIPOutputStream(java.util.zip.GZIPOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) Period(org.joda.time.Period) OutputStreamWriter(java.io.OutputStreamWriter) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) File(java.io.File) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 88 with DefaultObjectMapper

use of io.druid.jackson.DefaultObjectMapper in project druid by druid-io.

the class QuantilesTest method testSerialization.

@Test
public void testSerialization() throws Exception {
    ObjectMapper mapper = new DefaultObjectMapper();
    float[] probabilities = new float[] { 0.25f, 0.5f, 0.75f };
    float[] quantiles = new float[] { 0.25f, 0.5f, 0.75f };
    float min = 0f;
    float max = 4f;
    String theString = mapper.writeValueAsString(new Quantiles(probabilities, quantiles, min, max));
    Object theObject = mapper.readValue(theString, Object.class);
    Assert.assertThat(theObject, CoreMatchers.instanceOf(LinkedHashMap.class));
    LinkedHashMap theMap = (LinkedHashMap) theObject;
    ArrayList theProbabilities = (ArrayList<Float>) theMap.get("probabilities");
    Assert.assertEquals(probabilities.length, theProbabilities.size());
    for (int i = 0; i < theProbabilities.size(); ++i) {
        Assert.assertEquals(probabilities[i], ((Number) theProbabilities.get(i)).floatValue(), 0.0001f);
    }
    ArrayList theQuantiles = (ArrayList<Float>) theMap.get("quantiles");
    Assert.assertEquals(quantiles.length, theQuantiles.size());
    for (int i = 0; i < theQuantiles.size(); ++i) {
        Assert.assertEquals(quantiles[i], ((Number) theQuantiles.get(i)).floatValue(), 0.0001f);
    }
    Assert.assertEquals("serialized min. matches expected min.", min, ((Number) theMap.get("min")).floatValue(), 0.0001f);
    Assert.assertEquals("serialized max. matches expected max.", max, ((Number) theMap.get("max")).floatValue(), 0.0001f);
}
Also used : ArrayList(java.util.ArrayList) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 89 with DefaultObjectMapper

use of io.druid.jackson.DefaultObjectMapper in project druid by druid-io.

the class URIExtractionNamespaceTest method testSimpleJSONSerDe.

@Test
public void testSimpleJSONSerDe() throws IOException {
    final ObjectMapper mapper = registerTypes(new DefaultObjectMapper());
    for (URIExtractionNamespace.FlatDataParser parser : ImmutableList.of(new URIExtractionNamespace.CSVFlatDataParser(ImmutableList.of("col1", "col2", "col3"), "col2", "col3"), new URIExtractionNamespace.ObjectMapperFlatDataParser(mapper), new URIExtractionNamespace.JSONFlatDataParser(mapper, "keyField", "valueField"), new URIExtractionNamespace.TSVFlatDataParser(ImmutableList.of("A", "B"), ",", null, "A", "B"))) {
        final String str = mapper.writeValueAsString(parser);
        final URIExtractionNamespace.FlatDataParser parser2 = mapper.readValue(str, URIExtractionNamespace.FlatDataParser.class);
        Assert.assertEquals(str, mapper.writeValueAsString(parser2));
    }
}
Also used : DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 90 with DefaultObjectMapper

use of io.druid.jackson.DefaultObjectMapper in project druid by druid-io.

the class URIExtractionNamespaceTest method testExplicitJsonException.

@Test(expected = JsonMappingException.class)
public void testExplicitJsonException() throws IOException {
    final ObjectMapper mapper = registerTypes(new DefaultObjectMapper());
    mapper.readValue("{\"type\":\"uri\", \"uri\":\"file:/foo\", \"namespaceParseSpec\":{\"format\":\"simpleJson\"}, \"pollPeriod\":\"PT5M\", \"versionRegex\":\"a.b.c\", \"namespace\":\"testNamespace\"}", URIExtractionNamespace.class);
}
Also used : DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Aggregations

DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)164 Test (org.junit.Test)133 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)112 Interval (org.joda.time.Interval)24 DateTime (org.joda.time.DateTime)17 DataSegment (io.druid.timeline.DataSegment)16 File (java.io.File)16 AggregatorFactory (io.druid.query.aggregation.AggregatorFactory)14 Before (org.junit.Before)13 Map (java.util.Map)11 Period (org.joda.time.Period)11 Query (io.druid.query.Query)9 Result (io.druid.query.Result)9 CountAggregatorFactory (io.druid.query.aggregation.CountAggregatorFactory)9 IOException (java.io.IOException)9 DataSchema (io.druid.segment.indexing.DataSchema)8 ImmutableMap (com.google.common.collect.ImmutableMap)7 Sequence (io.druid.java.util.common.guava.Sequence)7 UniformGranularitySpec (io.druid.segment.indexing.granularity.UniformGranularitySpec)7 List (java.util.List)7