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