This is an automated email from the ASF dual-hosted git repository.

aljoscha pushed a commit to branch release-1.11
in repository https://gitbox.apache.org/repos/asf/flink.git

commit a38cbb0bc548f2b41f7b5b7c26fdcfdd41a9df04
Author: Aljoscha Krettek <aljos...@apache.org>
AuthorDate: Fri Jan 17 16:17:51 2020 +0100

    [FLINK-13632] Port TtlSerializer upgrade test to 
TypeSerializerUpgradeTestBase
---
 .../avro/typeutils/AvroSerializerUpgradeTest.java  |   2 +-
 .../state/ttl/TtlSerializerStateMigrationTest.java |  60 ------------
 .../state/ttl/TtlSerializerUpgradeTest.java        | 105 +++++++++++++++++++++
 .../flink/runtime/state/ttl/TtlValueMatchers.java  |  67 +++++++++++++
 .../test/resources/flink-1.6-ttl-serializer-data   | Bin 230 -> 0 bytes
 .../resources/flink-1.6-ttl-serializer-snapshot    | Bin 1753 -> 0 bytes
 .../test/resources/flink-1.7-ttl-serializer-data   | Bin 230 -> 0 bytes
 .../resources/flink-1.7-ttl-serializer-snapshot    | Bin 1763 -> 0 bytes
 8 files changed, 173 insertions(+), 61 deletions(-)

diff --git 
a/flink-formats/flink-avro/src/test/java/org/apache/flink/formats/avro/typeutils/AvroSerializerUpgradeTest.java
 
b/flink-formats/flink-avro/src/test/java/org/apache/flink/formats/avro/typeutils/AvroSerializerUpgradeTest.java
index f647c92..e897e8a 100644
--- 
a/flink-formats/flink-avro/src/test/java/org/apache/flink/formats/avro/typeutils/AvroSerializerUpgradeTest.java
+++ 
b/flink-formats/flink-avro/src/test/java/org/apache/flink/formats/avro/typeutils/AvroSerializerUpgradeTest.java
@@ -49,7 +49,7 @@ public class AvroSerializerUpgradeTest extends 
TypeSerializerUpgradeTestBase<Obj
        @Parameterized.Parameters(name = "Test Specification = {0}")
        public static Collection<TestSpecification<?, ?>> testSpecifications() 
throws Exception {
                ArrayList<TestSpecification<?, ?>> testSpecifications = new 
ArrayList<>();
-               for (MigrationVersion migrationVersion : migrationVersions) {
+               for (MigrationVersion migrationVersion : MIGRATION_VERSIONS) {
                        testSpecifications.add(
                                        new TestSpecification<>(
                                                        
"generic-avro-serializer",
diff --git 
a/flink-runtime/src/test/java/org/apache/flink/runtime/state/ttl/TtlSerializerStateMigrationTest.java
 
b/flink-runtime/src/test/java/org/apache/flink/runtime/state/ttl/TtlSerializerStateMigrationTest.java
deleted file mode 100644
index 87ab396..0000000
--- 
a/flink-runtime/src/test/java/org/apache/flink/runtime/state/ttl/TtlSerializerStateMigrationTest.java
+++ /dev/null
@@ -1,60 +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.flink.runtime.state.ttl;
-
-import 
org.apache.flink.api.common.typeutils.TypeSerializerSnapshotMigrationTestBase;
-import org.apache.flink.api.common.typeutils.base.LongSerializer;
-import org.apache.flink.api.common.typeutils.base.StringSerializer;
-import org.apache.flink.runtime.state.ttl.TtlStateFactory.TtlSerializer;
-import 
org.apache.flink.runtime.state.ttl.TtlStateFactory.TtlSerializerSnapshot;
-import org.apache.flink.testutils.migration.MigrationVersion;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-import java.util.Collection;
-
-/**
- * State migration test for {@link TtlSerializerStateMigrationTest}.
- */
-@RunWith(Parameterized.class)
-public class TtlSerializerStateMigrationTest extends 
TypeSerializerSnapshotMigrationTestBase<TtlValue<String>> {
-
-       private static final String SPEC_NAME = "ttl-serializer";
-
-       public 
TtlSerializerStateMigrationTest(TestSpecification<TtlValue<String>> 
testSpecification) {
-               super(testSpecification);
-       }
-
-       @SuppressWarnings("unchecked")
-       @Parameterized.Parameters(name = "Test Specification = {0}")
-       public static Collection<TestSpecification<?>> testSpecifications() {
-
-               final TestSpecifications testSpecifications = new 
TestSpecifications(MigrationVersion.v1_6, MigrationVersion.v1_7);
-
-               testSpecifications.add(
-                       SPEC_NAME,
-                       TtlSerializer.class,
-                       TtlSerializerSnapshot.class,
-                       () -> new TtlSerializer<>(LongSerializer.INSTANCE, 
StringSerializer.INSTANCE));
-
-               return testSpecifications.get();
-       }
-}
-
diff --git 
a/flink-runtime/src/test/java/org/apache/flink/runtime/state/ttl/TtlSerializerUpgradeTest.java
 
b/flink-runtime/src/test/java/org/apache/flink/runtime/state/ttl/TtlSerializerUpgradeTest.java
new file mode 100644
index 0000000..edcf8be
--- /dev/null
+++ 
b/flink-runtime/src/test/java/org/apache/flink/runtime/state/ttl/TtlSerializerUpgradeTest.java
@@ -0,0 +1,105 @@
+/*
+ * 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.flink.runtime.state.ttl;
+
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.api.common.typeutils.TypeSerializerMatchers;
+import org.apache.flink.api.common.typeutils.TypeSerializerSchemaCompatibility;
+import org.apache.flink.api.common.typeutils.TypeSerializerUpgradeTestBase;
+import org.apache.flink.api.common.typeutils.base.LongSerializer;
+import org.apache.flink.api.common.typeutils.base.StringSerializer;
+import org.apache.flink.runtime.state.ttl.TtlStateFactory.TtlSerializer;
+import org.apache.flink.testutils.migration.MigrationVersion;
+
+import org.hamcrest.Matcher;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import static org.apache.flink.runtime.state.ttl.TtlValueMatchers.ttlValue;
+import static org.hamcrest.Matchers.is;
+
+/**
+ * State migration test for {@link TtlSerializer}.
+ */
+@RunWith(Parameterized.class)
+public class TtlSerializerUpgradeTest
+               extends TypeSerializerUpgradeTestBase<TtlValue<String>, 
TtlValue<String>> {
+
+       public TtlSerializerUpgradeTest(
+                       TestSpecification<TtlValue<String>, TtlValue<String>> 
testSpecification) {
+               super(testSpecification);
+       }
+
+       @Parameterized.Parameters(name = "Test Specification = {0}")
+       public static Collection<TestSpecification<?, ?>> testSpecifications() 
throws Exception {
+
+               ArrayList<TestSpecification<?, ?>> testSpecifications = new 
ArrayList<>();
+               for (MigrationVersion migrationVersion : MIGRATION_VERSIONS) {
+                       testSpecifications.add(
+                                       new TestSpecification<>(
+                                                       "ttl-serializer",
+                                                       migrationVersion,
+                                                       
TtlSerializerSetup.class,
+                                                       
TtlSerializerVerifier.class));
+               }
+
+               return testSpecifications;
+       }
+
+       // 
----------------------------------------------------------------------------------------------
+       //  Specification for "ttl-serializer"
+       // 
----------------------------------------------------------------------------------------------
+
+       public static final class TtlSerializerSetup
+                       implements 
TypeSerializerUpgradeTestBase.PreUpgradeSetup<TtlValue<String>> {
+
+               @Override
+               public TypeSerializer<TtlValue<String>> createPriorSerializer() 
{
+                       return new TtlSerializer<>(LongSerializer.INSTANCE, 
StringSerializer.INSTANCE);
+               }
+
+               @Override
+               public TtlValue<String> createTestData() {
+                       return new TtlValue<>("hello Gordon", 13);
+               }
+       }
+
+       public static final class TtlSerializerVerifier
+                       implements 
TypeSerializerUpgradeTestBase.UpgradeVerifier<TtlValue<String>> {
+
+               @Override
+               public TypeSerializer<TtlValue<String>> 
createUpgradedSerializer() {
+                       return new TtlSerializer<>(LongSerializer.INSTANCE, 
StringSerializer.INSTANCE);
+               }
+
+               @Override
+               public Matcher<TtlValue<String>> testDataMatcher() {
+                       return ttlValue(is("hello Gordon"), is(13L));
+               }
+
+               @Override
+               public 
Matcher<TypeSerializerSchemaCompatibility<TtlValue<String>>> 
schemaCompatibilityMatcher(MigrationVersion version) {
+                       return TypeSerializerMatchers.isCompatibleAsIs();
+               }
+       }
+}
+
diff --git 
a/flink-runtime/src/test/java/org/apache/flink/runtime/state/ttl/TtlValueMatchers.java
 
b/flink-runtime/src/test/java/org/apache/flink/runtime/state/ttl/TtlValueMatchers.java
new file mode 100644
index 0000000..d1d1269
--- /dev/null
+++ 
b/flink-runtime/src/test/java/org/apache/flink/runtime/state/ttl/TtlValueMatchers.java
@@ -0,0 +1,67 @@
+/*
+ * 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.flink.runtime.state.ttl;
+
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
+
+/**
+ * {@link Matcher Matchers} for {@link TtlValue}.
+ */
+public class TtlValueMatchers {
+
+       /**
+        * Creates a matcher that matches when the given value and timestamp 
matchers match the value
+        * and timestamp in a {@link TtlValue};
+        */
+       public static <T> Matcher<TtlValue<T>> ttlValue(
+                       Matcher<T> valueMatcher,
+                       Matcher<Long> timestampMatcher) {
+               return new IsTtlValue<>(valueMatcher, timestampMatcher);
+       }
+
+       static class IsTtlValue<T> extends 
TypeSafeDiagnosingMatcher<TtlValue<T>> {
+               private final Matcher<T> valueMatcher;
+               private final Matcher<Long> timestampMatcher;
+
+               public IsTtlValue(Matcher<T> valueMatcher, Matcher<Long> 
timestampMatcher) {
+                       this.valueMatcher = valueMatcher;
+                       this.timestampMatcher = timestampMatcher;
+               }
+
+               @Override
+               protected boolean matchesSafely(TtlValue<T> item, Description 
mismatchDescription) {
+                       mismatchDescription.appendText("TtlValue with value ");
+                       mismatchDescription.appendValue(item.getUserValue());
+                       mismatchDescription.appendText(" with timestamp ");
+                       
mismatchDescription.appendValue(item.getLastAccessTimestamp());
+                       return valueMatcher.matches(item.getUserValue()) &&
+                                       
timestampMatcher.matches(item.getLastAccessTimestamp());
+               }
+
+               @Override
+               public void describeTo(Description description) {
+                       description.appendText("TtlValue with value ");
+                       valueMatcher.describeTo(description);
+                       description.appendText(" with timestamp ");
+                       timestampMatcher.describeTo(description);
+               }
+       }
+}
diff --git a/flink-runtime/src/test/resources/flink-1.6-ttl-serializer-data 
b/flink-runtime/src/test/resources/flink-1.6-ttl-serializer-data
deleted file mode 100644
index 9d156ca..0000000
Binary files a/flink-runtime/src/test/resources/flink-1.6-ttl-serializer-data 
and /dev/null differ
diff --git a/flink-runtime/src/test/resources/flink-1.6-ttl-serializer-snapshot 
b/flink-runtime/src/test/resources/flink-1.6-ttl-serializer-snapshot
deleted file mode 100644
index 0d3a8a0..0000000
Binary files 
a/flink-runtime/src/test/resources/flink-1.6-ttl-serializer-snapshot and 
/dev/null differ
diff --git a/flink-runtime/src/test/resources/flink-1.7-ttl-serializer-data 
b/flink-runtime/src/test/resources/flink-1.7-ttl-serializer-data
deleted file mode 100644
index 16c2bda..0000000
Binary files a/flink-runtime/src/test/resources/flink-1.7-ttl-serializer-data 
and /dev/null differ
diff --git a/flink-runtime/src/test/resources/flink-1.7-ttl-serializer-snapshot 
b/flink-runtime/src/test/resources/flink-1.7-ttl-serializer-snapshot
deleted file mode 100644
index 74aca45..0000000
Binary files 
a/flink-runtime/src/test/resources/flink-1.7-ttl-serializer-snapshot and 
/dev/null differ

Reply via email to