Move shardSpec tests to core (#10079)

* Move shardSpec tests to core

* checkstyle

* inject object mapper for testing

* unused import
This commit is contained in:
Jihoon Son 2020-06-29 17:31:37 -07:00 committed by GitHub
parent 15a0b4ffe2
commit 8ef3598c05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 32 deletions

View File

@ -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<ShardSpec> 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<PartitionChunk<String>> 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

View File

@ -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
);

View File

@ -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

View File

@ -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;