[FLINK-5442] [streaming] Ensure order of enum elements in StateDescriptor.Type through a test
This closes #3091 Project: http://git-wip-us.apache.org/repos/asf/flink/repo Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/758ea79a Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/758ea79a Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/758ea79a Branch: refs/heads/release-1.2 Commit: 758ea79a1cda1dec58d43266487ce663f7205f86 Parents: 8d3ad45 Author: Stefan Richter <[email protected]> Authored: Tue Jan 10 22:52:58 2017 +0100 Committer: Stephan Ewen <[email protected]> Committed: Wed Jan 11 19:06:10 2017 +0100 ---------------------------------------------------------------------- .../flink/api/common/state/StateDescriptor.java | 3 ++- .../runtime/state/SerializationProxiesTest.java | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flink/blob/758ea79a/flink-core/src/main/java/org/apache/flink/api/common/state/StateDescriptor.java ---------------------------------------------------------------------- diff --git a/flink-core/src/main/java/org/apache/flink/api/common/state/StateDescriptor.java b/flink-core/src/main/java/org/apache/flink/api/common/state/StateDescriptor.java index de3cd4e..ad9d417 100644 --- a/flink-core/src/main/java/org/apache/flink/api/common/state/StateDescriptor.java +++ b/flink-core/src/main/java/org/apache/flink/api/common/state/StateDescriptor.java @@ -49,8 +49,9 @@ import static java.util.Objects.requireNonNull; @PublicEvolving public abstract class StateDescriptor<S extends State, T> implements Serializable { + // Do not change the order of the elements in this enum, ordinal is used in serialization public enum Type { - VALUE, LIST, REDUCING, FOLDING, @Deprecated UNKNOWN + @Deprecated UNKNOWN, VALUE, LIST, REDUCING, FOLDING } private static final long serialVersionUID = 1L; http://git-wip-us.apache.org/repos/asf/flink/blob/758ea79a/flink-runtime/src/test/java/org/apache/flink/runtime/state/SerializationProxiesTest.java ---------------------------------------------------------------------- diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/state/SerializationProxiesTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/state/SerializationProxiesTest.java index 9211e92..832b022 100644 --- a/flink-runtime/src/test/java/org/apache/flink/runtime/state/SerializationProxiesTest.java +++ b/flink-runtime/src/test/java/org/apache/flink/runtime/state/SerializationProxiesTest.java @@ -96,4 +96,20 @@ public class SerializationProxiesTest { Assert.assertEquals(name, metaInfo.getStateName()); } + + /** + * This test fixes the order of elements in the enum which is important for serialization. Do not modify this test + * except if you are entirely sure what you are doing. + */ + @Test + public void testFixTypeOrder() { + // ensure all elements are covered + Assert.assertEquals(5, StateDescriptor.Type.values().length); + // fix the order of elements to keep serialization format stable + Assert.assertEquals(0, StateDescriptor.Type.UNKNOWN.ordinal()); + Assert.assertEquals(1, StateDescriptor.Type.VALUE.ordinal()); + Assert.assertEquals(2, StateDescriptor.Type.LIST.ordinal()); + Assert.assertEquals(3, StateDescriptor.Type.REDUCING.ordinal()); + Assert.assertEquals(4, StateDescriptor.Type.FOLDING.ordinal()); + } } \ No newline at end of file
