You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by al...@apache.org on 2020/05/28 11:51:46 UTC

[flink] 20/42: [FLINK-13632] Port MapViewSerializer upgrade test to TypeSerializerUpgradeTestBase

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 dcaa1072e6e0150b137d49c4606571d6ce8023fe
Author: klion26 <qc...@gmail.com>
AuthorDate: Sat Feb 15 21:04:57 2020 +0800

    [FLINK-13632] Port MapViewSerializer upgrade test to TypeSerializerUpgradeTestBase
---
 .../MapViewSerializerSnapshotMigrationTest.java    |  59 -----------
 .../dataview/MapViewSerializerUpgradeTest.java     | 115 +++++++++++++++++++++
 .../resources/flink-1.6-map-view-serializer-data   | Bin 440 -> 0 bytes
 .../flink-1.6-map-view-serializer-snapshot         | Bin 1503 -> 0 bytes
 .../resources/flink-1.7-map-view-serializer-data   | Bin 390 -> 0 bytes
 .../flink-1.7-map-view-serializer-snapshot         | Bin 454 -> 0 bytes
 6 files changed, 115 insertions(+), 59 deletions(-)

diff --git a/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/dataview/MapViewSerializerSnapshotMigrationTest.java b/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/dataview/MapViewSerializerSnapshotMigrationTest.java
deleted file mode 100644
index 2679f6a..0000000
--- a/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/dataview/MapViewSerializerSnapshotMigrationTest.java
+++ /dev/null
@@ -1,59 +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.table.dataview;
-
-import org.apache.flink.api.common.typeutils.TypeSerializerSnapshotMigrationTestBase;
-import org.apache.flink.api.common.typeutils.base.IntSerializer;
-import org.apache.flink.api.common.typeutils.base.MapSerializer;
-import org.apache.flink.api.common.typeutils.base.StringSerializer;
-import org.apache.flink.table.api.dataview.MapView;
-import org.apache.flink.testutils.migration.MigrationVersion;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-import java.util.Collection;
-
-/**
- * Migration test for the {@link MapViewSerializerSnapshot}.
- */
-@RunWith(Parameterized.class)
-public class MapViewSerializerSnapshotMigrationTest extends TypeSerializerSnapshotMigrationTestBase<MapView<Integer, String>> {
-
-	private static final String SPEC_NAME = "map-view-serializer";
-
-	public MapViewSerializerSnapshotMigrationTest(TestSpecification<MapView<Integer, 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,
-			MapViewSerializer.class,
-			MapViewSerializerSnapshot.class,
-			() -> new MapViewSerializer<>(new MapSerializer<>(IntSerializer.INSTANCE, StringSerializer.INSTANCE)));
-
-		return testSpecifications.get();
-	}
-}
diff --git a/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/dataview/MapViewSerializerUpgradeTest.java b/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/dataview/MapViewSerializerUpgradeTest.java
new file mode 100644
index 0000000..a9f72c1
--- /dev/null
+++ b/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/dataview/MapViewSerializerUpgradeTest.java
@@ -0,0 +1,115 @@
+/*
+ * 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.table.dataview;
+
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+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.IntSerializer;
+import org.apache.flink.api.common.typeutils.base.MapSerializer;
+import org.apache.flink.api.common.typeutils.base.StringSerializer;
+import org.apache.flink.table.api.dataview.MapView;
+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.hamcrest.Matchers.is;
+
+/**
+ * A {@link TypeSerializerUpgradeTestBase} for {@link MapViewSerializer}.
+ */
+@RunWith(Parameterized.class)
+public class MapViewSerializerUpgradeTest extends TypeSerializerUpgradeTestBase<MapView<Integer, String>, MapView<Integer, String>> {
+
+	private static final String SPEC_NAME = "map-view-serializer";
+
+	public MapViewSerializerUpgradeTest(TestSpecification<MapView<Integer, String>, MapView<Integer, 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<>(
+					SPEC_NAME,
+					migrationVersion,
+					MapViewSerializerSetup.class,
+					MapViewSerializerVerifier.class));
+		}
+		return testSpecifications;
+	}
+
+	// ----------------------------------------------------------------------------------------------
+	//  Specification for "map-view-serializer"
+	// ----------------------------------------------------------------------------------------------
+
+	/**
+	 * This class is only public to work with {@link org.apache.flink.api.common.typeutils.ClassRelocator}.
+	 */
+	public static final class MapViewSerializerSetup implements TypeSerializerUpgradeTestBase.PreUpgradeSetup<MapView<Integer, String>> {
+		@Override
+		public TypeSerializer<MapView<Integer, String>> createPriorSerializer() {
+			return new MapViewSerializer<>(new MapSerializer<>(IntSerializer.INSTANCE, StringSerializer.INSTANCE));
+		}
+
+		@Override
+		public MapView<Integer, String> createTestData() {
+			return mockTestData();
+		}
+	}
+
+	/**
+	 * This class is only public to work with {@link org.apache.flink.api.common.typeutils.ClassRelocator}.
+	 */
+	public static final class MapViewSerializerVerifier implements TypeSerializerUpgradeTestBase.UpgradeVerifier<MapView<Integer, String>> {
+		@Override
+		public TypeSerializer<MapView<Integer, String>> createUpgradedSerializer() {
+			return new MapViewSerializer<>(new MapSerializer<>(IntSerializer.INSTANCE, StringSerializer.INSTANCE));
+		}
+
+		@Override
+		public Matcher<MapView<Integer, String>> testDataMatcher() {
+			return is(mockTestData());
+		}
+
+		@Override
+		public Matcher<TypeSerializerSchemaCompatibility<MapView<Integer, String>>> schemaCompatibilityMatcher(MigrationVersion version) {
+			return TypeSerializerMatchers.isCompatibleAsIs();
+		}
+	}
+
+	public static MapView<Integer, String> mockTestData() {
+		MapView<Integer, String> view = new MapView<>(TypeInformation.of(Integer.class), TypeInformation.of(String.class));
+		try {
+			view.put(1, "1");
+		} catch (Exception e) {
+			throw new RuntimeException(e);
+		}
+		return view;
+	}
+}
diff --git a/flink-table/flink-table-planner/src/test/resources/flink-1.6-map-view-serializer-data b/flink-table/flink-table-planner/src/test/resources/flink-1.6-map-view-serializer-data
deleted file mode 100644
index 6d68f19..0000000
Binary files a/flink-table/flink-table-planner/src/test/resources/flink-1.6-map-view-serializer-data and /dev/null differ
diff --git a/flink-table/flink-table-planner/src/test/resources/flink-1.6-map-view-serializer-snapshot b/flink-table/flink-table-planner/src/test/resources/flink-1.6-map-view-serializer-snapshot
deleted file mode 100644
index 9546a16..0000000
Binary files a/flink-table/flink-table-planner/src/test/resources/flink-1.6-map-view-serializer-snapshot and /dev/null differ
diff --git a/flink-table/flink-table-planner/src/test/resources/flink-1.7-map-view-serializer-data b/flink-table/flink-table-planner/src/test/resources/flink-1.7-map-view-serializer-data
deleted file mode 100644
index 4d7334a..0000000
Binary files a/flink-table/flink-table-planner/src/test/resources/flink-1.7-map-view-serializer-data and /dev/null differ
diff --git a/flink-table/flink-table-planner/src/test/resources/flink-1.7-map-view-serializer-snapshot b/flink-table/flink-table-planner/src/test/resources/flink-1.7-map-view-serializer-snapshot
deleted file mode 100644
index 19003a0..0000000
Binary files a/flink-table/flink-table-planner/src/test/resources/flink-1.7-map-view-serializer-snapshot and /dev/null differ