Search in sources :

Example 26 with DefaultObjectMapper

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

the class IntervalLoadRuleTest method testSerdeNullTieredReplicants.

@Test
public void testSerdeNullTieredReplicants() throws Exception {
    IntervalLoadRule rule = new IntervalLoadRule(Intervals.of("0/3000"), null);
    ObjectMapper jsonMapper = new DefaultObjectMapper();
    Rule reread = jsonMapper.readValue(jsonMapper.writeValueAsString(rule), Rule.class);
    Assert.assertEquals(rule, reread);
    Assert.assertEquals(ImmutableMap.of(DruidServer.DEFAULT_TIER, DruidServer.DEFAULT_NUM_REPLICANTS), rule.getTieredReplicants());
}
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 27 with DefaultObjectMapper

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

the class IntervalLoadRuleTest method testMappingNullTieredReplicants.

@Test
public void testMappingNullTieredReplicants() throws Exception {
    String inputJson = "    {\n" + "      \"interval\": \"0000-01-01T00:00:00.000-05:50:36/3000-01-01T00:00:00.000-06:00\",\n" + "      \"type\": \"loadByInterval\"\n" + "    }";
    String expectedJson = "{\n" + "      \"interval\": \"0000-01-01T00:00:00.000-05:50:36/3000-01-01T00:00:00.000-06:00\",\n" + "      \"tieredReplicants\": {\n" + "        \"" + DruidServer.DEFAULT_TIER + "\": " + DruidServer.DEFAULT_NUM_REPLICANTS + "\n" + "      },\n" + "      \"type\": \"loadByInterval\"\n" + "    }";
    ObjectMapper jsonMapper = new DefaultObjectMapper();
    IntervalLoadRule inputIntervalLoadRule = jsonMapper.readValue(inputJson, IntervalLoadRule.class);
    IntervalLoadRule expectedIntervalLoadRule = jsonMapper.readValue(expectedJson, IntervalLoadRule.class);
    Assert.assertEquals(expectedIntervalLoadRule, inputIntervalLoadRule);
}
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 28 with DefaultObjectMapper

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

the class PeriodLoadRuleTest method testSerdeNull.

/**
 * test serialize/deserilize null values of {@link PeriodLoadRule#tieredReplicants} and {@link PeriodLoadRule#includeFuture}
 */
@Test
public void testSerdeNull() throws Exception {
    PeriodLoadRule rule = new PeriodLoadRule(new Period("P1D"), null, null);
    ObjectMapper jsonMapper = new DefaultObjectMapper();
    Rule reread = jsonMapper.readValue(jsonMapper.writeValueAsString(rule), Rule.class);
    Assert.assertEquals(rule.getPeriod(), ((PeriodLoadRule) reread).getPeriod());
    Assert.assertEquals(rule.isIncludeFuture(), ((PeriodLoadRule) reread).isIncludeFuture());
    Assert.assertEquals(PeriodLoadRule.DEFAULT_INCLUDE_FUTURE, rule.isIncludeFuture());
    Assert.assertEquals(rule.getTieredReplicants(), ((PeriodLoadRule) reread).getTieredReplicants());
    Assert.assertEquals(ImmutableMap.of(DruidServer.DEFAULT_TIER, DruidServer.DEFAULT_NUM_REPLICANTS), rule.getTieredReplicants());
}
Also used : Period(org.joda.time.Period) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 29 with DefaultObjectMapper

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

the class UserCompactionTaskTransformConfigTest method testSerde.

@Test
public void testSerde() throws IOException {
    NullHandling.initializeForTests();
    final UserCompactionTaskTransformConfig expected = new UserCompactionTaskTransformConfig(new SelectorDimFilter("dim1", "foo", null));
    final ObjectMapper mapper = new DefaultObjectMapper();
    final byte[] json = mapper.writeValueAsBytes(expected);
    final UserCompactionTaskTransformConfig fromJson = (UserCompactionTaskTransformConfig) mapper.readValue(json, UserCompactionTaskTransformConfig.class);
    Assert.assertEquals(expected, fromJson);
}
Also used : SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 30 with DefaultObjectMapper

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

the class LookupExtractorFactoryContainerTest method testSerde.

@Test
public void testSerde() throws Exception {
    String jsonStr = "{\n" + "\"version\": \"v1\",\n" + "\"lookupExtractorFactory\": {\n" + "   \"type\": \"test\"\n" + " }\n" + "}\n";
    final ObjectMapper mapper = new DefaultObjectMapper();
    mapper.registerSubtypes(TestLookupExtractorFactory.class);
    LookupExtractorFactoryContainer actual = mapper.readValue(mapper.writeValueAsString(mapper.readValue(jsonStr, LookupExtractorFactoryContainer.class)), LookupExtractorFactoryContainer.class);
    Assert.assertEquals(new LookupExtractorFactoryContainer("v1", new TestLookupExtractorFactory()), actual);
}
Also used : DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) 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