From 83e94e8b3198abc43e7c2959123adb20aa9941b6 Mon Sep 17 00:00:00 2001 From: Kevin Conaway Date: Sun, 3 Sep 2017 16:36:18 -0400 Subject: [PATCH] Expose version property for `CustomVersioningPolicy` so that it may serialize/deserialize correctly (#4747) Expose version property for so that it may serialize/deserialize correctly Expose version property for `CustomVersioningPolicy` so that it may serialize/deserialize correctly Expose version property for CustomVersioningPolicy so that it may serialize/deserialize correctly Expose version property for `CustomVersioningPolicy` so that it may serialize/deserialize correctly --- .../plumber/CustomVersioningPolicy.java | 6 +++ .../plumber/CustomVersioningPolicyTest.java | 48 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 server/src/test/java/io/druid/segment/realtime/plumber/CustomVersioningPolicyTest.java diff --git a/server/src/main/java/io/druid/segment/realtime/plumber/CustomVersioningPolicy.java b/server/src/main/java/io/druid/segment/realtime/plumber/CustomVersioningPolicy.java index 331b5ff34a5..1bc6d664811 100644 --- a/server/src/main/java/io/druid/segment/realtime/plumber/CustomVersioningPolicy.java +++ b/server/src/main/java/io/druid/segment/realtime/plumber/CustomVersioningPolicy.java @@ -43,4 +43,10 @@ public class CustomVersioningPolicy implements VersioningPolicy { return version; } + + @JsonProperty("version") + public String getVersion() + { + return version; + } } diff --git a/server/src/test/java/io/druid/segment/realtime/plumber/CustomVersioningPolicyTest.java b/server/src/test/java/io/druid/segment/realtime/plumber/CustomVersioningPolicyTest.java new file mode 100644 index 00000000000..4a909d36a80 --- /dev/null +++ b/server/src/test/java/io/druid/segment/realtime/plumber/CustomVersioningPolicyTest.java @@ -0,0 +1,48 @@ +/* + * Licensed to Metamarkets Group Inc. (Metamarkets) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Metamarkets 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 io.druid.segment.realtime.plumber; + +import io.druid.TestUtil; +import org.joda.time.DateTime; +import org.joda.time.DateTimeZone; +import org.joda.time.Interval; +import org.junit.Assert; +import org.junit.Test; + +public class CustomVersioningPolicyTest +{ + + @Test + public void testSerialization() throws Exception + { + Interval interval = new Interval(DateTime.now(DateTimeZone.UTC), DateTime.now(DateTimeZone.UTC)); + String version = "someversion"; + + CustomVersioningPolicy policy = new CustomVersioningPolicy(version); + + CustomVersioningPolicy serialized = TestUtil.MAPPER.readValue( + TestUtil.MAPPER.writeValueAsBytes(policy), + CustomVersioningPolicy.class + ); + + Assert.assertEquals(version, policy.getVersion(interval)); + Assert.assertEquals(version, serialized.getVersion(interval)); + } +}