Search in sources :

Example 76 with DefaultObjectMapper

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

the class SchemaRegistryBasedProtobufBytesDecoderTest method testUrl.

@Test
public void testUrl() throws Exception {
    String json = "{\"url\":\"http://localhost\",\"type\": \"schema_registry\"}";
    ObjectMapper mapper = new DefaultObjectMapper();
    mapper.setInjectableValues(new InjectableValues.Std().addValue(ObjectMapper.class, new DefaultObjectMapper()));
    SchemaRegistryBasedProtobufBytesDecoder decoder;
    decoder = (SchemaRegistryBasedProtobufBytesDecoder) mapper.readerFor(ProtobufBytesDecoder.class).readValue(json);
    // Then
    Assert.assertNotEquals(decoder.hashCode(), 0);
}
Also used : DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 77 with DefaultObjectMapper

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

the class SchemaRegistryBasedProtobufBytesDecoderTest method testParseHeader.

@Test
public void testParseHeader() throws JsonProcessingException {
    String json = "{\"url\":\"http://localhost\",\"type\":\"schema_registry\",\"config\":{},\"headers\":{\"druid.dynamic.config.provider\":{\"type\":\"mapString\", \"config\":{\"registry.header.prop.2\":\"value.2\", \"registry.header.prop.3\":\"value.3\"}},\"registry.header.prop.1\":\"value.1\",\"registry.header.prop.2\":\"value.4\"}}";
    ObjectMapper mapper = new DefaultObjectMapper();
    mapper.setInjectableValues(new InjectableValues.Std().addValue(ObjectMapper.class, new DefaultObjectMapper()));
    SchemaRegistryBasedProtobufBytesDecoder decoder;
    decoder = (SchemaRegistryBasedProtobufBytesDecoder) mapper.readerFor(ProtobufBytesDecoder.class).readValue(json);
    Map<String, String> header = DynamicConfigProviderUtils.extraConfigAndSetStringMap(decoder.getHeaders(), SchemaRegistryBasedProtobufBytesDecoder.DRUID_DYNAMIC_CONFIG_PROVIDER_KEY, new DefaultObjectMapper());
    // Then
    Assert.assertEquals(3, header.size());
    Assert.assertEquals("value.1", header.get("registry.header.prop.1"));
    Assert.assertEquals("value.2", header.get("registry.header.prop.2"));
    Assert.assertEquals("value.3", header.get("registry.header.prop.3"));
}
Also used : DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 78 with DefaultObjectMapper

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

the class PollingLookupSerDeserTest method testSerDeser.

@Test
public void testSerDeser() throws IOException {
    ObjectMapper mapper = new DefaultObjectMapper();
    PollingLookupFactory pollingLookupFactory = new PollingLookupFactory(Period.ZERO, dataFetcher, cacheFactory);
    mapper.registerSubtypes(MockDataFetcher.class);
    mapper.registerSubtypes(PollingLookupFactory.class);
    Assert.assertEquals(pollingLookupFactory, mapper.readerFor(LookupExtractorFactory.class).readValue(mapper.writeValueAsString(pollingLookupFactory)));
}
Also used : DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 79 with DefaultObjectMapper

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

the class ZtestPostAggregatorTest method testSerde.

@Test
public void testSerde() throws Exception {
    DefaultObjectMapper mapper = new DefaultObjectMapper();
    ZtestPostAggregator postAggregator1 = mapper.readValue(mapper.writeValueAsString(ztestPostAggregator), ZtestPostAggregator.class);
    Assert.assertEquals(ztestPostAggregator, postAggregator1);
    Assert.assertArrayEquals(ztestPostAggregator.getCacheKey(), postAggregator1.getCacheKey());
    Assert.assertEquals(ztestPostAggregator.getDependentFields(), postAggregator1.getDependentFields());
}
Also used : DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 80 with DefaultObjectMapper

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

the class PvaluefromZscorePostAggregatorTest method testSerde.

@Test
public void testSerde() throws Exception {
    DefaultObjectMapper mapper = new DefaultObjectMapper();
    PvaluefromZscorePostAggregator postAggregator1 = mapper.readValue(mapper.writeValueAsString(pvaluefromZscorePostAggregator), PvaluefromZscorePostAggregator.class);
    Assert.assertEquals(pvaluefromZscorePostAggregator, postAggregator1);
    Assert.assertArrayEquals(pvaluefromZscorePostAggregator.getCacheKey(), postAggregator1.getCacheKey());
    Assert.assertEquals(pvaluefromZscorePostAggregator.getDependentFields(), postAggregator1.getDependentFields());
}
Also used : DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Aggregations

DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)287 Test (org.junit.Test)245 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)177 File (java.io.File)26 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)25 PostAggregator (org.apache.druid.query.aggregation.PostAggregator)21 Before (org.junit.Before)21 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)20 InjectableValues (com.fasterxml.jackson.databind.InjectableValues)16 DataSegment (org.apache.druid.timeline.DataSegment)16 Period (org.joda.time.Period)16 ConstantPostAggregator (org.apache.druid.query.aggregation.post.ConstantPostAggregator)14 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)13 FieldAccessPostAggregator (org.apache.druid.query.aggregation.post.FieldAccessPostAggregator)12 DimensionsSpec (org.apache.druid.data.input.impl.DimensionsSpec)11 TaskStatus (org.apache.druid.indexer.TaskStatus)11 AvroStreamInputRowParserTest (org.apache.druid.data.input.AvroStreamInputRowParserTest)10 ImmutableList (com.google.common.collect.ImmutableList)9 Injector (com.google.inject.Injector)9 TimestampSpec (org.apache.druid.data.input.impl.TimestampSpec)9