From f58fd5b75f0298232607d600e375e59cd478444a Mon Sep 17 00:00:00 2001 From: Abhishek Radhakrishnan Date: Fri, 26 Jan 2024 16:35:12 -0800 Subject: [PATCH] Remove TestObjectMapper in favor of DefaultObjectMapper. (#15769) Remove dilemma on what object mapper class to use in tests since the DefaultObjectMapper class provides all the same settings and goodies. --- .../druid/jackson/DefaultObjectMapper.java | 4 +- .../org/apache/druid/TestObjectMapper.java | 70 ------------------- .../input/impl/DelimitedParseSpecTest.java | 4 +- .../input/impl/InputRowParserSerdeTest.java | 4 +- .../data/input/impl/JSONParseSpecTest.java | 4 +- .../data/input/impl/JSONPathSpecTest.java | 4 +- .../input/impl/JavaScriptParseSpecTest.java | 4 +- .../data/input/impl/RegexParseSpecTest.java | 4 +- .../druid/guice/JsonConfiguratorTest.java | 24 +++---- .../druid/indexer/TaskStatusPlusTest.java | 57 ++------------- .../druid/timeline/DataSegmentTest.java | 4 +- .../timeline/SegmentStatusInClusterTest.java | 4 +- .../timeline/partition/NoneShardSpecTest.java | 12 ++-- 13 files changed, 43 insertions(+), 156 deletions(-) delete mode 100644 processing/src/test/java/org/apache/druid/TestObjectMapper.java diff --git a/processing/src/main/java/org/apache/druid/jackson/DefaultObjectMapper.java b/processing/src/main/java/org/apache/druid/jackson/DefaultObjectMapper.java index 7e530836c2f..1a6186bbc8a 100644 --- a/processing/src/main/java/org/apache/druid/jackson/DefaultObjectMapper.java +++ b/processing/src/main/java/org/apache/druid/jackson/DefaultObjectMapper.java @@ -46,12 +46,12 @@ public class DefaultObjectMapper extends ObjectMapper public DefaultObjectMapper() { - this((JsonFactory) null, null); + this(null, null); } public DefaultObjectMapper(String serviceName) { - this((JsonFactory) null, serviceName); + this(null, serviceName); } public DefaultObjectMapper(DefaultObjectMapper mapper) diff --git a/processing/src/test/java/org/apache/druid/TestObjectMapper.java b/processing/src/test/java/org/apache/druid/TestObjectMapper.java deleted file mode 100644 index a552c4bdab8..00000000000 --- a/processing/src/test/java/org/apache/druid/TestObjectMapper.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.druid; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.MapperFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.databind.deser.std.StdDeserializer; -import com.fasterxml.jackson.databind.module.SimpleModule; -import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; -import org.apache.druid.java.util.common.Intervals; -import org.joda.time.Interval; - -import java.io.IOException; - -/** - */ -public class TestObjectMapper extends ObjectMapper -{ - public TestObjectMapper() - { - configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - configure(MapperFeature.AUTO_DETECT_GETTERS, false); - configure(MapperFeature.AUTO_DETECT_FIELDS, false); - configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false); - configure(MapperFeature.AUTO_DETECT_SETTERS, false); - configure(SerializationFeature.INDENT_OUTPUT, false); - registerModule(new TestModule()); - } - - public static class TestModule extends SimpleModule - { - TestModule() - { - addSerializer(Interval.class, ToStringSerializer.instance); - addDeserializer( - Interval.class, - new StdDeserializer(Interval.class) - { - @Override - public Interval deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) - throws IOException - { - return Intervals.of(jsonParser.getText()); - } - } - ); - } - } -} diff --git a/processing/src/test/java/org/apache/druid/data/input/impl/DelimitedParseSpecTest.java b/processing/src/test/java/org/apache/druid/data/input/impl/DelimitedParseSpecTest.java index f8653a072db..0d3b4864035 100644 --- a/processing/src/test/java/org/apache/druid/data/input/impl/DelimitedParseSpecTest.java +++ b/processing/src/test/java/org/apache/druid/data/input/impl/DelimitedParseSpecTest.java @@ -20,7 +20,7 @@ package org.apache.druid.data.input.impl; import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.druid.TestObjectMapper; +import org.apache.druid.jackson.DefaultObjectMapper; import org.junit.Assert; import org.junit.Test; @@ -30,7 +30,7 @@ import java.util.Collections; public class DelimitedParseSpecTest { - private final ObjectMapper jsonMapper = new TestObjectMapper(); + private final ObjectMapper jsonMapper = new DefaultObjectMapper(); @Test public void testSerde() throws IOException diff --git a/processing/src/test/java/org/apache/druid/data/input/impl/InputRowParserSerdeTest.java b/processing/src/test/java/org/apache/druid/data/input/impl/InputRowParserSerdeTest.java index 34a3722fc20..a9df0e1e0e6 100644 --- a/processing/src/test/java/org/apache/druid/data/input/impl/InputRowParserSerdeTest.java +++ b/processing/src/test/java/org/apache/druid/data/input/impl/InputRowParserSerdeTest.java @@ -23,9 +23,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; -import org.apache.druid.TestObjectMapper; import org.apache.druid.data.input.ByteBufferInputRowParser; import org.apache.druid.data.input.InputRow; +import org.apache.druid.jackson.DefaultObjectMapper; import org.apache.druid.java.util.common.DateTimes; import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.java.util.common.parsers.JSONPathFieldSpec; @@ -42,7 +42,7 @@ import java.util.List; public class InputRowParserSerdeTest { - private final ObjectMapper jsonMapper = new TestObjectMapper(); + private final ObjectMapper jsonMapper = new DefaultObjectMapper(); @Test public void testStringInputRowParserSerde() throws Exception diff --git a/processing/src/test/java/org/apache/druid/data/input/impl/JSONParseSpecTest.java b/processing/src/test/java/org/apache/druid/data/input/impl/JSONParseSpecTest.java index b89c11258b0..dfb9d73d243 100644 --- a/processing/src/test/java/org/apache/druid/data/input/impl/JSONParseSpecTest.java +++ b/processing/src/test/java/org/apache/druid/data/input/impl/JSONParseSpecTest.java @@ -22,7 +22,7 @@ package org.apache.druid.data.input.impl; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableList; import nl.jqno.equalsverifier.EqualsVerifier; -import org.apache.druid.TestObjectMapper; +import org.apache.druid.jackson.DefaultObjectMapper; import org.apache.druid.java.util.common.parsers.JSONPathFieldSpec; import org.apache.druid.java.util.common.parsers.JSONPathFieldType; import org.apache.druid.java.util.common.parsers.JSONPathSpec; @@ -39,7 +39,7 @@ import java.util.Map; public class JSONParseSpecTest { - private final ObjectMapper jsonMapper = new TestObjectMapper(); + private final ObjectMapper jsonMapper = new DefaultObjectMapper(); @Test public void testParseRow() diff --git a/processing/src/test/java/org/apache/druid/data/input/impl/JSONPathSpecTest.java b/processing/src/test/java/org/apache/druid/data/input/impl/JSONPathSpecTest.java index 6d7b67b5cd8..7cbf2e0dc00 100644 --- a/processing/src/test/java/org/apache/druid/data/input/impl/JSONPathSpecTest.java +++ b/processing/src/test/java/org/apache/druid/data/input/impl/JSONPathSpecTest.java @@ -20,7 +20,7 @@ package org.apache.druid.data.input.impl; import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.druid.TestObjectMapper; +import org.apache.druid.jackson.DefaultObjectMapper; import org.apache.druid.java.util.common.parsers.JSONPathFieldSpec; import org.apache.druid.java.util.common.parsers.JSONPathFieldType; import org.apache.druid.java.util.common.parsers.JSONPathSpec; @@ -33,7 +33,7 @@ import java.util.List; public class JSONPathSpecTest { - private final ObjectMapper jsonMapper = new TestObjectMapper(); + private final ObjectMapper jsonMapper = new DefaultObjectMapper(); @Test public void testSerde() throws IOException diff --git a/processing/src/test/java/org/apache/druid/data/input/impl/JavaScriptParseSpecTest.java b/processing/src/test/java/org/apache/druid/data/input/impl/JavaScriptParseSpecTest.java index e0fe2277ad8..bf9c0e56684 100644 --- a/processing/src/test/java/org/apache/druid/data/input/impl/JavaScriptParseSpecTest.java +++ b/processing/src/test/java/org/apache/druid/data/input/impl/JavaScriptParseSpecTest.java @@ -22,7 +22,7 @@ package org.apache.druid.data.input.impl; import com.fasterxml.jackson.databind.InjectableValues; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableMap; -import org.apache.druid.TestObjectMapper; +import org.apache.druid.jackson.DefaultObjectMapper; import org.apache.druid.java.util.common.parsers.Parser; import org.apache.druid.js.JavaScriptConfig; import org.junit.Assert; @@ -38,7 +38,7 @@ import java.util.Map; */ public class JavaScriptParseSpecTest { - private final ObjectMapper jsonMapper = new TestObjectMapper(); + private final ObjectMapper jsonMapper = new DefaultObjectMapper(); @Rule public ExpectedException expectedException = ExpectedException.none(); diff --git a/processing/src/test/java/org/apache/druid/data/input/impl/RegexParseSpecTest.java b/processing/src/test/java/org/apache/druid/data/input/impl/RegexParseSpecTest.java index cc3bd75c271..80aac74b12c 100644 --- a/processing/src/test/java/org/apache/druid/data/input/impl/RegexParseSpecTest.java +++ b/processing/src/test/java/org/apache/druid/data/input/impl/RegexParseSpecTest.java @@ -20,7 +20,7 @@ package org.apache.druid.data.input.impl; import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.druid.TestObjectMapper; +import org.apache.druid.jackson.DefaultObjectMapper; import org.junit.Assert; import org.junit.Test; @@ -31,7 +31,7 @@ import java.util.Collections; */ public class RegexParseSpecTest { - private final ObjectMapper jsonMapper = new TestObjectMapper(); + private final ObjectMapper jsonMapper = new DefaultObjectMapper(); @Test public void testSerde() throws IOException diff --git a/processing/src/test/java/org/apache/druid/guice/JsonConfiguratorTest.java b/processing/src/test/java/org/apache/druid/guice/JsonConfiguratorTest.java index c9ec2a77726..85873e09ea0 100644 --- a/processing/src/test/java/org/apache/druid/guice/JsonConfiguratorTest.java +++ b/processing/src/test/java/org/apache/druid/guice/JsonConfiguratorTest.java @@ -24,7 +24,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import org.apache.druid.TestObjectMapper; +import org.apache.druid.jackson.DefaultObjectMapper; import org.junit.Assert; import org.junit.Before; import org.junit.Rule; @@ -43,7 +43,7 @@ import java.util.Set; public class JsonConfiguratorTest { private static final String PROP_PREFIX = "test.property.prefix."; - private final ObjectMapper mapper = new TestObjectMapper(); + private final ObjectMapper jsonMapper = new DefaultObjectMapper(); private final Properties properties = new Properties(); @Rule @@ -55,7 +55,7 @@ public class JsonConfiguratorTest @Before public void setUp() { - mapper.registerSubtypes(MappableObject.class); + jsonMapper.registerSubtypes(MappableObject.class); } final Validator validator = new Validator() @@ -118,7 +118,7 @@ public class JsonConfiguratorTest @Test public void testSimpleConfigurate() { - final JsonConfigurator configurator = new JsonConfigurator(mapper, validator); + final JsonConfigurator configurator = new JsonConfigurator(jsonMapper, validator); properties.setProperty(PROP_PREFIX + "prop1", "prop1"); properties.setProperty(PROP_PREFIX + "prop1List", "[\"prop2\"]"); final MappableObject obj = configurator.configurate(properties, PROP_PREFIX, MappableObject.class); @@ -129,7 +129,7 @@ public class JsonConfiguratorTest @Test public void testMissingConfigList() { - final JsonConfigurator configurator = new JsonConfigurator(mapper, validator); + final JsonConfigurator configurator = new JsonConfigurator(jsonMapper, validator); properties.setProperty(PROP_PREFIX + "prop1", "prop1"); final MappableObject obj = configurator.configurate(properties, PROP_PREFIX, MappableObject.class); Assert.assertEquals("prop1", obj.prop1); @@ -139,7 +139,7 @@ public class JsonConfiguratorTest @Test public void testMissingConfig() { - final JsonConfigurator configurator = new JsonConfigurator(mapper, validator); + final JsonConfigurator configurator = new JsonConfigurator(jsonMapper, validator); properties.setProperty(PROP_PREFIX + "prop1List", "[\"prop2\"]"); final MappableObject obj = configurator.configurate(properties, PROP_PREFIX, MappableObject.class); Assert.assertNull(obj.prop1); @@ -149,7 +149,7 @@ public class JsonConfiguratorTest @Test public void testQuotedConfig() { - final JsonConfigurator configurator = new JsonConfigurator(mapper, validator); + final JsonConfigurator configurator = new JsonConfigurator(jsonMapper, validator); properties.setProperty(PROP_PREFIX + "prop1", "testing \"prop1\""); final MappableObject obj = configurator.configurate(properties, PROP_PREFIX, MappableObject.class); Assert.assertEquals("testing \"prop1\"", obj.prop1); @@ -159,7 +159,7 @@ public class JsonConfiguratorTest @Test public void testPropertyWithDot() { - final JsonConfigurator configurator = new JsonConfigurator(mapper, validator); + final JsonConfigurator configurator = new JsonConfigurator(jsonMapper, validator); properties.setProperty(PROP_PREFIX + "prop2.prop.2", "testing"); properties.setProperty(PROP_PREFIX + "prop1", "prop1"); final MappableObject obj = configurator.configurate(properties, PROP_PREFIX, MappableObject.class); @@ -176,7 +176,7 @@ public class JsonConfiguratorTest List list = ImmutableList.of("list", "of", "strings"); environmentVariables.set("MY_VAR", "value2"); - final JsonConfigurator configurator = new JsonConfigurator(mapper, validator); + final JsonConfigurator configurator = new JsonConfigurator(jsonMapper, validator); properties.setProperty(PROP_PREFIX + "prop1", "${sys:my.property}"); properties.setProperty(PROP_PREFIX + "prop1List", "${file:UTF-8:src/test/resources/list.json}"); properties.setProperty(PROP_PREFIX + "prop2.prop.2", "${env:MY_VAR}"); @@ -197,7 +197,7 @@ public class JsonConfiguratorTest System.setProperty("json.path", "src/test/resources/list.json"); environmentVariables.set("PROP2_NAME", "MY_VAR"); - final JsonConfigurator configurator = new JsonConfigurator(mapper, validator); + final JsonConfigurator configurator = new JsonConfigurator(jsonMapper, validator); properties.setProperty(PROP_PREFIX + "prop1", "${sys:${env:SYS_PROP}}"); properties.setProperty(PROP_PREFIX + "prop1List", "${file:UTF-8:${sys:json.path}}"); properties.setProperty(PROP_PREFIX + "prop2.prop.2", "${env:${env:PROP2_NAME}}"); @@ -212,7 +212,7 @@ public class JsonConfiguratorTest { List list = ImmutableList.of("list", "of", "strings"); - final JsonConfigurator configurator = new JsonConfigurator(mapper, validator); + final JsonConfigurator configurator = new JsonConfigurator(jsonMapper, validator); properties.setProperty(PROP_PREFIX + "prop1", "${sys:my.property:-value1}"); properties.setProperty(PROP_PREFIX + "prop1List", "${unknown:-[\"list\", \"of\", \"strings\"]}"); properties.setProperty(PROP_PREFIX + "prop2.prop.2", "${MY_VAR:-value2}"); @@ -225,7 +225,7 @@ public class JsonConfiguratorTest @Test public void testPropertyInterpolationUndefinedException() { - final JsonConfigurator configurator = new JsonConfigurator(mapper, validator); + final JsonConfigurator configurator = new JsonConfigurator(jsonMapper, validator); properties.setProperty(PROP_PREFIX + "prop1", "${sys:my.property}"); Assert.assertThrows( diff --git a/processing/src/test/java/org/apache/druid/indexer/TaskStatusPlusTest.java b/processing/src/test/java/org/apache/druid/indexer/TaskStatusPlusTest.java index 03a8c6da761..8eddd565df6 100644 --- a/processing/src/test/java/org/apache/druid/indexer/TaskStatusPlusTest.java +++ b/processing/src/test/java/org/apache/druid/indexer/TaskStatusPlusTest.java @@ -19,15 +19,9 @@ package org.apache.druid.indexer; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.deser.std.StdDeserializer; -import com.fasterxml.jackson.databind.module.SimpleModule; -import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import org.apache.druid.jackson.DefaultObjectMapper; import org.apache.druid.java.util.common.DateTimes; -import org.joda.time.DateTime; import org.junit.Assert; import org.junit.Test; @@ -35,15 +29,11 @@ import java.io.IOException; public class TaskStatusPlusTest { + private final ObjectMapper jsonMapper = new DefaultObjectMapper(); + @Test public void testSerde() throws IOException { - final ObjectMapper mapper = new ObjectMapper(); - mapper.registerModule( - new SimpleModule() - .addDeserializer(DateTime.class, new DateTimeDeserializer()) - .addSerializer(DateTime.class, ToStringSerializer.instance) - ); final TaskStatusPlus status = new TaskStatusPlus( "testId", "testGroupId", @@ -57,19 +47,13 @@ public class TaskStatusPlusTest "ds_test", null ); - final String json = mapper.writeValueAsString(status); - Assert.assertEquals(status, mapper.readValue(json, TaskStatusPlus.class)); + final String json = jsonMapper.writeValueAsString(status); + Assert.assertEquals(status, jsonMapper.readValue(json, TaskStatusPlus.class)); } @Test public void testJsonAttributes() throws IOException { - final ObjectMapper mapper = new ObjectMapper(); - mapper.registerModule( - new SimpleModule() - .addDeserializer(DateTime.class, new DateTimeDeserializer()) - .addSerializer(DateTime.class, ToStringSerializer.instance) - ); final String json = "{\n" + "\"id\": \"testId\",\n" + "\"groupId\": \"testGroupId\",\n" @@ -88,43 +72,16 @@ public class TaskStatusPlusTest + "\"dataSource\": \"ds_test\",\n" + "\"errorMsg\": null\n" + "}"; - TaskStatusPlus taskStatusPlus = mapper.readValue(json, TaskStatusPlus.class); + TaskStatusPlus taskStatusPlus = jsonMapper.readValue(json, TaskStatusPlus.class); Assert.assertNotNull(taskStatusPlus); Assert.assertNotNull(taskStatusPlus.getStatusCode()); Assert.assertTrue(taskStatusPlus.getStatusCode().isRunnable()); Assert.assertNotNull(taskStatusPlus.getRunnerStatusCode()); - String serialized = mapper.writeValueAsString(taskStatusPlus); + String serialized = jsonMapper.writeValueAsString(taskStatusPlus); Assert.assertTrue(serialized.contains("\"status\":")); Assert.assertTrue(serialized.contains("\"statusCode\":")); Assert.assertTrue(serialized.contains("\"runnerStatusCode\":")); } - - // Copied from org.apache.druid.jackson.JodaStuff - private static class DateTimeDeserializer extends StdDeserializer - { - public DateTimeDeserializer() - { - super(DateTime.class); - } - - @Override - public DateTime deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException - { - JsonToken t = jp.getCurrentToken(); - if (t == JsonToken.VALUE_NUMBER_INT) { - return DateTimes.utc(jp.getLongValue()); - } - if (t == JsonToken.VALUE_STRING) { - String str = jp.getText().trim(); - if (str.length() == 0) { // [JACKSON-360] - return null; - } - // make sure to preserve time zone information when parsing timestamps - return DateTimes.ISO_DATE_OR_TIME_WITH_OFFSET.parse(str); - } - throw ctxt.mappingException(getValueClass()); - } - } } diff --git a/processing/src/test/java/org/apache/druid/timeline/DataSegmentTest.java b/processing/src/test/java/org/apache/druid/timeline/DataSegmentTest.java index 87ec7b17869..97c3d7a2aaa 100644 --- a/processing/src/test/java/org/apache/druid/timeline/DataSegmentTest.java +++ b/processing/src/test/java/org/apache/druid/timeline/DataSegmentTest.java @@ -24,10 +24,10 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.RangeSet; -import org.apache.druid.TestObjectMapper; import org.apache.druid.data.input.impl.DimensionsSpec; import org.apache.druid.indexer.partitions.DynamicPartitionsSpec; import org.apache.druid.indexer.partitions.HashedPartitionsSpec; +import org.apache.druid.jackson.DefaultObjectMapper; import org.apache.druid.java.util.common.DateTimes; import org.apache.druid.java.util.common.Intervals; import org.apache.druid.java.util.common.jackson.JacksonUtils; @@ -52,7 +52,7 @@ import java.util.Map; */ public class DataSegmentTest { - private static final ObjectMapper MAPPER = new TestObjectMapper(); + private static final ObjectMapper MAPPER = new DefaultObjectMapper(); private static final int TEST_VERSION = 0x9; private static ShardSpec getShardSpec(final int partitionNum) diff --git a/processing/src/test/java/org/apache/druid/timeline/SegmentStatusInClusterTest.java b/processing/src/test/java/org/apache/druid/timeline/SegmentStatusInClusterTest.java index 82b77ddee2b..cc08f72ab02 100644 --- a/processing/src/test/java/org/apache/druid/timeline/SegmentStatusInClusterTest.java +++ b/processing/src/test/java/org/apache/druid/timeline/SegmentStatusInClusterTest.java @@ -25,8 +25,8 @@ import com.fasterxml.jackson.databind.InjectableValues; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.google.common.collect.ImmutableMap; -import org.apache.druid.TestObjectMapper; import org.apache.druid.jackson.CommaListJoinDeserializer; +import org.apache.druid.jackson.DefaultObjectMapper; import org.apache.druid.java.util.common.Intervals; import org.apache.druid.java.util.common.jackson.JacksonUtils; import org.apache.druid.timeline.DataSegment.PruneSpecsHolder; @@ -56,7 +56,7 @@ public class SegmentStatusInClusterTest private static ObjectMapper createObjectMapper() { - ObjectMapper objectMapper = new TestObjectMapper(); + ObjectMapper objectMapper = new DefaultObjectMapper(); InjectableValues.Std injectableValues = new InjectableValues.Std(); injectableValues.addValue(PruneSpecsHolder.class, PruneSpecsHolder.DEFAULT); objectMapper.setInjectableValues(injectableValues); diff --git a/processing/src/test/java/org/apache/druid/timeline/partition/NoneShardSpecTest.java b/processing/src/test/java/org/apache/druid/timeline/partition/NoneShardSpecTest.java index 65f17b7062d..6fb09aa4416 100644 --- a/processing/src/test/java/org/apache/druid/timeline/partition/NoneShardSpecTest.java +++ b/processing/src/test/java/org/apache/druid/timeline/partition/NoneShardSpecTest.java @@ -20,7 +20,7 @@ package org.apache.druid.timeline.partition; import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.druid.TestObjectMapper; +import org.apache.druid.jackson.DefaultObjectMapper; import org.junit.Assert; import org.junit.Test; @@ -28,6 +28,8 @@ import java.io.IOException; public class NoneShardSpecTest { + private final ObjectMapper jsonMapper = new DefaultObjectMapper(); + @Test public void testEqualsAndHashCode() { @@ -41,9 +43,8 @@ public class NoneShardSpecTest public void testSerde() throws Exception { final NoneShardSpec one = NoneShardSpec.instance(); - ObjectMapper mapper = new TestObjectMapper(); - NoneShardSpec serde1 = mapper.readValue(mapper.writeValueAsString(one), NoneShardSpec.class); - NoneShardSpec serde2 = mapper.readValue(mapper.writeValueAsString(one), NoneShardSpec.class); + NoneShardSpec serde1 = jsonMapper.readValue(jsonMapper.writeValueAsString(one), NoneShardSpec.class); + NoneShardSpec serde2 = jsonMapper.readValue(jsonMapper.writeValueAsString(one), NoneShardSpec.class); // Serde should return same object instead of creating new one every time. Assert.assertTrue(serde1 == serde2); @@ -55,8 +56,7 @@ public class NoneShardSpecTest public void testPartitionFieldIgnored() throws IOException { final String jsonStr = "{\"type\": \"none\",\"partitionNum\": 2}"; - ObjectMapper mapper = new TestObjectMapper(); - final ShardSpec noneShardSpec = mapper.readValue(jsonStr, ShardSpec.class); + final ShardSpec noneShardSpec = jsonMapper.readValue(jsonStr, ShardSpec.class); Assert.assertEquals(NoneShardSpec.instance(), noneShardSpec); } }