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:57 UTC
[flink] 31/42: [FLINK-13632] Port WritableSerializer 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 47d535d6372ec34279f47fde41fb0661073aeaba
Author: klion26 <qc...@gmail.com>
AuthorDate: Sat Feb 15 20:41:30 2020 +0800
[FLINK-13632] Port WritableSerializer upgrade test to TypeSerializerUpgradeTestBase
---
.../runtime/WritableSerializerMigrationTest.java | 88 ------------
.../runtime/WritableSerializerUpgradeTest.java | 151 +++++++++++++++++++++
.../resources/flink-1.6-writeable-serializer-data | Bin 150 -> 0 bytes
.../flink-1.6-writeable-serializer-snapshot | Bin 506 -> 0 bytes
.../resources/flink-1.7-writeable-serializer-data | Bin 150 -> 0 bytes
.../flink-1.7-writeable-serializer-snapshot | Bin 494 -> 0 bytes
6 files changed, 151 insertions(+), 88 deletions(-)
diff --git a/flink-connectors/flink-hadoop-compatibility/src/test/java/org/apache/flink/api/java/typeutils/runtime/WritableSerializerMigrationTest.java b/flink-connectors/flink-hadoop-compatibility/src/test/java/org/apache/flink/api/java/typeutils/runtime/WritableSerializerMigrationTest.java
deleted file mode 100644
index 8dc7e89..0000000
--- a/flink-connectors/flink-hadoop-compatibility/src/test/java/org/apache/flink/api/java/typeutils/runtime/WritableSerializerMigrationTest.java
+++ /dev/null
@@ -1,88 +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.api.java.typeutils.runtime;
-
-import org.apache.flink.api.common.typeutils.TypeSerializerSnapshotMigrationTestBase;
-import org.apache.flink.api.java.typeutils.runtime.WritableSerializer.WritableSerializerSnapshot;
-import org.apache.flink.api.java.typeutils.runtime.WritableSerializerMigrationTest.WritableName;
-import org.apache.flink.testutils.migration.MigrationVersion;
-
-import org.apache.hadoop.io.Writable;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.util.Collection;
-
-/**
- * State migration test for {@link RowSerializer}.
- */
-@RunWith(Parameterized.class)
-public class WritableSerializerMigrationTest extends TypeSerializerSnapshotMigrationTestBase<WritableName> {
-
- public WritableSerializerMigrationTest(TestSpecification<WritableName> testSpecification) {
- super(testSpecification);
- }
-
- @SuppressWarnings("unchecked")
- @Parameterized.Parameters(name = "Test Specification = {0}")
- public static Collection<TestSpecification<?>> testSpecifications() {
-
- TestSpecifications testSpecifications = new TestSpecifications(MigrationVersion.v1_6, MigrationVersion.v1_7);
-
- testSpecifications.add(
- "writeable-serializer",
- WritableSerializer.class,
- WritableSerializerSnapshot.class,
- () -> new WritableSerializer<>(WritableName.class));
-
- return testSpecifications.get();
- }
-
- /**
- * A dummy class that is used in this test.
- */
- public static final class WritableName implements Writable {
-
- public static final long serialVersionUID = 1L;
-
- private String name;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- @Override
- public void write(DataOutput out) throws IOException {
- out.writeUTF(name);
- }
-
- @Override
- public void readFields(DataInput in) throws IOException {
- name = in.readUTF();
- }
- }
-
-}
diff --git a/flink-connectors/flink-hadoop-compatibility/src/test/java/org/apache/flink/api/java/typeutils/runtime/WritableSerializerUpgradeTest.java b/flink-connectors/flink-hadoop-compatibility/src/test/java/org/apache/flink/api/java/typeutils/runtime/WritableSerializerUpgradeTest.java
new file mode 100644
index 0000000..b79cbc9
--- /dev/null
+++ b/flink-connectors/flink-hadoop-compatibility/src/test/java/org/apache/flink/api/java/typeutils/runtime/WritableSerializerUpgradeTest.java
@@ -0,0 +1,151 @@
+/*
+ * 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.api.java.typeutils.runtime;
+
+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.java.typeutils.runtime.WritableSerializerUpgradeTest.WritableName;
+import org.apache.flink.testutils.migration.MigrationVersion;
+
+import org.apache.hadoop.io.Writable;
+import org.hamcrest.Matcher;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Objects;
+
+import static org.hamcrest.Matchers.is;
+
+/**
+ * A {@link TypeSerializerUpgradeTestBase} for {@link WritableSerializer}.
+ */
+@RunWith(Parameterized.class)
+public class WritableSerializerUpgradeTest extends TypeSerializerUpgradeTestBase<WritableName, WritableName> {
+
+ public WritableSerializerUpgradeTest(TestSpecification<WritableName, WritableName> 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<>(
+ "writeable-serializer",
+ migrationVersion,
+ WritableSerializerSetup.class,
+ WritableSerializerVerifier.class));
+ }
+ return testSpecifications;
+ }
+
+ /**
+ * A dummy class that is used in this test.
+ */
+ public static final class WritableName implements Writable {
+
+ public static final long serialVersionUID = 1L;
+
+ private String name;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public void write(DataOutput out) throws IOException {
+ out.writeUTF(name);
+ }
+
+ @Override
+ public void readFields(DataInput in) throws IOException {
+ name = in.readUTF();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+
+ if (!(obj instanceof WritableName)) {
+ return false;
+ }
+
+ WritableName other = (WritableName) obj;
+ return Objects.equals(name, other.name);
+ }
+ }
+
+ // ----------------------------------------------------------------------------------------------
+ // Specification for "writeable-serializer"
+ // ----------------------------------------------------------------------------------------------
+
+ /**
+ * This class is only public to work with {@link org.apache.flink.api.common.typeutils.ClassRelocator}.
+ */
+ public static final class WritableSerializerSetup implements TypeSerializerUpgradeTestBase.PreUpgradeSetup<WritableName> {
+ @Override
+ public TypeSerializer<WritableName> createPriorSerializer() {
+ return new WritableSerializer<>(WritableName.class);
+ }
+
+ @Override
+ public WritableName createTestData() {
+ WritableName writable = new WritableName();
+ writable.setName("flink");
+ return writable;
+ }
+ }
+
+ /**
+ * This class is only public to work with {@link org.apache.flink.api.common.typeutils.ClassRelocator}.
+ */
+ public static final class WritableSerializerVerifier implements TypeSerializerUpgradeTestBase.UpgradeVerifier<WritableName> {
+ @Override
+ public TypeSerializer<WritableName> createUpgradedSerializer() {
+ return new WritableSerializer<>(WritableName.class);
+ }
+
+ @Override
+ public Matcher<WritableName> testDataMatcher() {
+ WritableName writable = new WritableName();
+ writable.setName("flink");
+ return is(writable);
+ }
+
+ @Override
+ public Matcher<TypeSerializerSchemaCompatibility<WritableName>> schemaCompatibilityMatcher(MigrationVersion version) {
+ return TypeSerializerMatchers.isCompatibleAsIs();
+ }
+ }
+}
diff --git a/flink-connectors/flink-hadoop-compatibility/src/test/resources/flink-1.6-writeable-serializer-data b/flink-connectors/flink-hadoop-compatibility/src/test/resources/flink-1.6-writeable-serializer-data
deleted file mode 100644
index c6bd30c..0000000
Binary files a/flink-connectors/flink-hadoop-compatibility/src/test/resources/flink-1.6-writeable-serializer-data and /dev/null differ
diff --git a/flink-connectors/flink-hadoop-compatibility/src/test/resources/flink-1.6-writeable-serializer-snapshot b/flink-connectors/flink-hadoop-compatibility/src/test/resources/flink-1.6-writeable-serializer-snapshot
deleted file mode 100644
index 268534f..0000000
Binary files a/flink-connectors/flink-hadoop-compatibility/src/test/resources/flink-1.6-writeable-serializer-snapshot and /dev/null differ
diff --git a/flink-connectors/flink-hadoop-compatibility/src/test/resources/flink-1.7-writeable-serializer-data b/flink-connectors/flink-hadoop-compatibility/src/test/resources/flink-1.7-writeable-serializer-data
deleted file mode 100644
index e857bed..0000000
Binary files a/flink-connectors/flink-hadoop-compatibility/src/test/resources/flink-1.7-writeable-serializer-data and /dev/null differ
diff --git a/flink-connectors/flink-hadoop-compatibility/src/test/resources/flink-1.7-writeable-serializer-snapshot b/flink-connectors/flink-hadoop-compatibility/src/test/resources/flink-1.7-writeable-serializer-snapshot
deleted file mode 100644
index b54029b..0000000
Binary files a/flink-connectors/flink-hadoop-compatibility/src/test/resources/flink-1.7-writeable-serializer-snapshot and /dev/null differ