diff --git a/server/src/test/java/org/apache/druid/timeline/partition/HashBasedNumberedShardSpecTest.java b/core/src/test/java/org/apache/druid/timeline/partition/HashBasedNumberedShardSpecTest.java similarity index 92% rename from server/src/test/java/org/apache/druid/timeline/partition/HashBasedNumberedShardSpecTest.java rename to core/src/test/java/org/apache/druid/timeline/partition/HashBasedNumberedShardSpecTest.java index be24fe5c25a..624f3d34f16 100644 --- a/server/src/test/java/org/apache/druid/timeline/partition/HashBasedNumberedShardSpecTest.java +++ b/core/src/test/java/org/apache/druid/timeline/partition/HashBasedNumberedShardSpecTest.java @@ -30,7 +30,6 @@ import org.apache.druid.data.input.MapBasedInputRow; import org.apache.druid.data.input.Row; import org.apache.druid.java.util.common.DateTimes; import org.apache.druid.java.util.common.ISE; -import org.apache.druid.server.ServerTestHelper; import org.joda.time.DateTime; import org.junit.Assert; import org.junit.Test; @@ -43,6 +42,8 @@ import java.util.stream.IntStream; public class HashBasedNumberedShardSpecTest { + private final ObjectMapper objectMapper = ShardSpecTestUtils.initObjectMapper(); + @Test public void testEquals() { @@ -56,16 +57,15 @@ public class HashBasedNumberedShardSpecTest @Test public void testSerdeRoundTrip() throws Exception { - - final ShardSpec spec = ServerTestHelper.MAPPER.readValue( - ServerTestHelper.MAPPER.writeValueAsBytes( + final ShardSpec spec = objectMapper.readValue( + objectMapper.writeValueAsBytes( new HashBasedNumberedShardSpec( 1, 2, 1, 3, ImmutableList.of("visitor_id"), - ServerTestHelper.MAPPER + objectMapper ) ), ShardSpec.class @@ -80,14 +80,14 @@ public class HashBasedNumberedShardSpecTest @Test public void testSerdeBackwardsCompat() throws Exception { - final ShardSpec spec = ServerTestHelper.MAPPER.readValue( + final ShardSpec spec = objectMapper.readValue( "{\"type\": \"hashed\", \"partitions\": 2, \"partitionNum\": 1}", ShardSpec.class ); Assert.assertEquals(1, spec.getPartitionNum()); Assert.assertEquals(2, spec.getNumCorePartitions()); - final ShardSpec specWithPartitionDimensions = ServerTestHelper.MAPPER.readValue( + final ShardSpec specWithPartitionDimensions = objectMapper.readValue( "{\"type\": \"hashed\", \"partitions\": 2, \"partitionNum\": 1, \"partitionDimensions\":[\"visitor_id\"]}", ShardSpec.class ); @@ -104,9 +104,9 @@ public class HashBasedNumberedShardSpecTest public void testPartitionChunks() { final List specs = ImmutableList.of( - new HashBasedNumberedShardSpec(0, 3, 0, 3, null, ServerTestHelper.MAPPER), - new HashBasedNumberedShardSpec(1, 3, 1, 3, null, ServerTestHelper.MAPPER), - new HashBasedNumberedShardSpec(2, 3, 2, 3, null, ServerTestHelper.MAPPER) + new HashBasedNumberedShardSpec(0, 3, 0, 3, null, objectMapper), + new HashBasedNumberedShardSpec(1, 3, 1, 3, null, objectMapper), + new HashBasedNumberedShardSpec(2, 3, 2, 3, null, objectMapper) ); final List> chunks = Lists.transform( @@ -208,7 +208,7 @@ public class HashBasedNumberedShardSpecTest 1, 3, ImmutableList.of("visitor_id"), - ServerTestHelper.MAPPER + objectMapper ); Assert.assertTrue(shardSpec.sharePartitionSpace(NumberedPartialShardSpec.instance())); Assert.assertTrue(shardSpec.sharePartitionSpace(new HashBasedNumberedPartialShardSpec(null, 0, 1))); @@ -226,11 +226,11 @@ public class HashBasedNumberedShardSpecTest throw new ISE("None of the partition matches"); } - public static class HashOverridenShardSpec extends HashBasedNumberedShardSpec + public class HashOverridenShardSpec extends HashBasedNumberedShardSpec { public HashOverridenShardSpec(int partitionNum, int partitions) { - super(partitionNum, partitions, partitionNum, partitions, null, ServerTestHelper.MAPPER); + super(partitionNum, partitions, partitionNum, partitions, null, objectMapper); } @Override diff --git a/server/src/test/java/org/apache/druid/server/shard/NumberedShardSpecTest.java b/core/src/test/java/org/apache/druid/timeline/partition/NumberedShardSpecTest.java similarity index 92% rename from server/src/test/java/org/apache/druid/server/shard/NumberedShardSpecTest.java rename to core/src/test/java/org/apache/druid/timeline/partition/NumberedShardSpecTest.java index 04c0c553bcf..8b8d5da1b2c 100644 --- a/server/src/test/java/org/apache/druid/server/shard/NumberedShardSpecTest.java +++ b/core/src/test/java/org/apache/druid/timeline/partition/NumberedShardSpecTest.java @@ -17,8 +17,9 @@ * under the License. */ -package org.apache.druid.server.shard; +package org.apache.druid.timeline.partition; +import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Function; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -26,17 +27,9 @@ import com.google.common.collect.Lists; import com.google.common.collect.Ordering; import nl.jqno.equalsverifier.EqualsVerifier; import org.apache.druid.java.util.common.Intervals; -import org.apache.druid.server.ServerTestHelper; import org.apache.druid.timeline.Overshadowable; import org.apache.druid.timeline.TimelineObjectHolder; import org.apache.druid.timeline.VersionedIntervalTimeline; -import org.apache.druid.timeline.partition.HashBasedNumberedPartialShardSpec; -import org.apache.druid.timeline.partition.NumberedOverwritePartialShardSpec; -import org.apache.druid.timeline.partition.NumberedPartialShardSpec; -import org.apache.druid.timeline.partition.NumberedShardSpec; -import org.apache.druid.timeline.partition.PartitionChunk; -import org.apache.druid.timeline.partition.ShardSpec; -import org.apache.druid.timeline.partition.SingleDimensionPartialShardSpec; import org.joda.time.Interval; import org.junit.Assert; import org.junit.Test; @@ -58,8 +51,9 @@ public class NumberedShardSpecTest @Test public void testSerdeRoundTrip() throws Exception { - final ShardSpec spec = ServerTestHelper.MAPPER.readValue( - ServerTestHelper.MAPPER.writeValueAsBytes(new NumberedShardSpec(1, 2)), + final ObjectMapper objectMapper = ShardSpecTestUtils.initObjectMapper(); + final ShardSpec spec = objectMapper.readValue( + objectMapper.writeValueAsBytes(new NumberedShardSpec(1, 2)), ShardSpec.class ); Assert.assertEquals(1, spec.getPartitionNum()); @@ -69,7 +63,8 @@ public class NumberedShardSpecTest @Test public void testSerdeBackwardsCompat() throws Exception { - final ShardSpec spec = ServerTestHelper.MAPPER.readValue( + final ObjectMapper objectMapper = ShardSpecTestUtils.initObjectMapper(); + final ShardSpec spec = objectMapper.readValue( "{\"type\": \"numbered\", \"partitions\": 2, \"partitionNum\": 1}", ShardSpec.class ); diff --git a/core/src/test/java/org/apache/druid/timeline/partition/ShardSpecTestUtils.java b/core/src/test/java/org/apache/druid/timeline/partition/ShardSpecTestUtils.java index 2f153651513..dd613afbc76 100644 --- a/core/src/test/java/org/apache/druid/timeline/partition/ShardSpecTestUtils.java +++ b/core/src/test/java/org/apache/druid/timeline/partition/ShardSpecTestUtils.java @@ -20,6 +20,7 @@ package org.apache.druid.timeline.partition; import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.InjectableValues.Std; import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; @@ -30,6 +31,7 @@ public class ShardSpecTestUtils { // Copied configurations from org.apache.druid.jackson.DefaultObjectMapper final ObjectMapper mapper = new ObjectMapper(); + mapper.setInjectableValues(new Std().addValue(ObjectMapper.class, mapper)); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(MapperFeature.AUTO_DETECT_GETTERS, false); // See https://github.com/FasterXML/jackson-databind/issues/170 diff --git a/server/src/test/java/org/apache/druid/server/shard/SingleDimensionShardSpecTest.java b/core/src/test/java/org/apache/druid/timeline/partition/SingleDimensionShardSpecTest.java similarity index 93% rename from server/src/test/java/org/apache/druid/server/shard/SingleDimensionShardSpecTest.java rename to core/src/test/java/org/apache/druid/timeline/partition/SingleDimensionShardSpecTest.java index 6928dfa735e..a8f1aa9d33e 100644 --- a/server/src/test/java/org/apache/druid/server/shard/SingleDimensionShardSpecTest.java +++ b/core/src/test/java/org/apache/druid/timeline/partition/SingleDimensionShardSpecTest.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.druid.server.shard; +package org.apache.druid.timeline.partition; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -30,12 +30,6 @@ import org.apache.druid.data.input.InputRow; import org.apache.druid.data.input.MapBasedInputRow; import org.apache.druid.java.util.common.Pair; import org.apache.druid.java.util.common.StringUtils; -import org.apache.druid.timeline.partition.HashBasedNumberedPartialShardSpec; -import org.apache.druid.timeline.partition.NumberedOverwritePartialShardSpec; -import org.apache.druid.timeline.partition.NumberedPartialShardSpec; -import org.apache.druid.timeline.partition.ShardSpec; -import org.apache.druid.timeline.partition.SingleDimensionPartialShardSpec; -import org.apache.druid.timeline.partition.SingleDimensionShardSpec; import org.junit.Assert; import org.junit.Test;