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:41 UTC

[flink] 15/42: [FLINK-13632] Port NullableSerializer 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 5a730d4633db4665b12eda5d783eb035905b28b8
Author: klion26 <qc...@gmail.com>
AuthorDate: Thu Jan 30 17:00:54 2020 +0800

    [FLINK-13632] Port NullableSerializer test to TypeSerializerUpgradeTestBase
---
 .../runtime/NullableSerializerMigrationTest.java   |  83 ------------
 .../runtime/NullableSerializerUpgradeTest.java     | 146 +++++++++++++++++++++
 .../flink-1.6-nullable-not-padded-serializer-data  | Bin 58 -> 0 bytes
 ...ink-1.6-nullable-not-padded-serializer-snapshot | Bin 944 -> 0 bytes
 .../flink-1.6-nullable-padded-serializer-data      | Bin 90 -> 0 bytes
 .../flink-1.6-nullable-padded-serializer-snapshot  | Bin 952 -> 0 bytes
 .../flink-1.7-nullable-not-padded-serializer-data  | Bin 58 -> 0 bytes
 ...ink-1.7-nullable-not-padded-serializer-snapshot | Bin 941 -> 0 bytes
 .../flink-1.7-nullable-padded-serializer-data      | Bin 90 -> 0 bytes
 .../flink-1.7-nullable-padded-serializer-snapshot  | Bin 949 -> 0 bytes
 10 files changed, 146 insertions(+), 83 deletions(-)

diff --git a/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/NullableSerializerMigrationTest.java b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/NullableSerializerMigrationTest.java
deleted file mode 100644
index 1da7da7..0000000
--- a/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/NullableSerializerMigrationTest.java
+++ /dev/null
@@ -1,83 +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.common.typeutils.base.LongSerializer;
-import org.apache.flink.api.java.typeutils.runtime.NullableSerializer.NullableSerializerSnapshot;
-import org.apache.flink.testutils.migration.MigrationVersion;
-
-import org.hamcrest.BaseMatcher;
-import org.hamcrest.Description;
-import org.hamcrest.Matcher;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-import java.util.Collection;
-
-/**
- * {@link NullableSerializer} migration test.
- */
-@RunWith(Parameterized.class)
-public class NullableSerializerMigrationTest extends TypeSerializerSnapshotMigrationTestBase<Long> {
-
-	public NullableSerializerMigrationTest(TestSpecification<Long> 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(
-			"nullable-padded-serializer",
-			NullableSerializer.class,
-			NullableSerializerSnapshot.class,
-			() -> NullableSerializer.wrap(LongSerializer.INSTANCE, true),
-			NULL_OR_LONG);
-
-		testSpecifications.add(
-			"nullable-not-padded-serializer",
-			NullableSerializer.class,
-			NullableSerializerSnapshot.class,
-			() -> NullableSerializer.wrap(LongSerializer.INSTANCE, false),
-			NULL_OR_LONG);
-
-		return testSpecifications.get();
-	}
-
-	@SuppressWarnings("unchecked")
-	private static final Matcher<Long> NULL_OR_LONG = new NullableMatcher();
-
-	private static final class NullableMatcher extends BaseMatcher<Long> {
-
-		@Override
-		public boolean matches(Object item) {
-			return item == null || item instanceof Long;
-		}
-
-		@Override
-		public void describeTo(Description description) {
-			description.appendText("a null or a long");
-		}
-	}
-
-}
diff --git a/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/NullableSerializerUpgradeTest.java b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/NullableSerializerUpgradeTest.java
new file mode 100644
index 0000000..af1eca95
--- /dev/null
+++ b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/NullableSerializerUpgradeTest.java
@@ -0,0 +1,146 @@
+/*
+ * 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.common.typeutils.base.LongSerializer;
+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.CoreMatchers.is;
+
+/**
+ * A {@link TypeSerializerUpgradeTestBase} for {@link NullableSerializer}.
+ */
+@RunWith(Parameterized.class)
+public class NullableSerializerUpgradeTest extends TypeSerializerUpgradeTestBase<Long, Long> {
+
+	public NullableSerializerUpgradeTest(TestSpecification<Long, Long> 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<>(
+					"nullable-padded-serializer",
+					migrationVersion,
+					NullablePaddedSerializerSetup.class,
+					NullablePaddedSerializerVerifier.class));
+
+			testSpecifications.add(
+				new TestSpecification<>(
+					"nullable-not-padded-serializer",
+					migrationVersion,
+					NullableNotPaddedSerializerSetup.class,
+					NullableNotPaddedSerializerVerifier.class));
+		}
+		return testSpecifications;
+	}
+
+	// ----------------------------------------------------------------------------------------------
+	//  Specification for "nullable-padded-serializer"
+	// ----------------------------------------------------------------------------------------------
+
+	/**
+	 * This class is only public to work with {@link org.apache.flink.api.common.typeutils.ClassRelocator}.
+	 */
+	public static final class NullablePaddedSerializerSetup implements TypeSerializerUpgradeTestBase.PreUpgradeSetup<Long> {
+		@Override
+		public TypeSerializer<Long> createPriorSerializer() {
+			return NullableSerializer.wrap(LongSerializer.INSTANCE, true);
+		}
+
+		@Override
+		public Long createTestData() {
+			return null;
+		}
+	}
+
+	/**
+	 * This class is only public to work with {@link org.apache.flink.api.common.typeutils.ClassRelocator}.
+	 */
+	public static final class NullablePaddedSerializerVerifier implements TypeSerializerUpgradeTestBase.UpgradeVerifier<Long> {
+		@Override
+		public TypeSerializer<Long> createUpgradedSerializer() {
+			return NullableSerializer.wrap(LongSerializer.INSTANCE, true);
+		}
+
+		@Override
+		public Matcher<Long> testDataMatcher() {
+			return is((Long) null);
+		}
+
+		@Override
+		public Matcher<TypeSerializerSchemaCompatibility<Long>> schemaCompatibilityMatcher(MigrationVersion version) {
+			return TypeSerializerMatchers.isCompatibleAsIs();
+		}
+	}
+
+	// ----------------------------------------------------------------------------------------------
+	//  Specification for "nullable-not-padded-serializer"
+	// ----------------------------------------------------------------------------------------------
+
+	/**
+	 * This class is only public to work with {@link org.apache.flink.api.common.typeutils.ClassRelocator}.
+	 */
+	public static final class NullableNotPaddedSerializerSetup implements TypeSerializerUpgradeTestBase.PreUpgradeSetup<Long> {
+		@Override
+		public TypeSerializer<Long> createPriorSerializer() {
+			return NullableSerializer.wrap(LongSerializer.INSTANCE, false);
+		}
+
+		@Override
+		public Long createTestData() {
+			return null;
+		}
+	}
+
+	/**
+	 * This class is only public to work with {@link org.apache.flink.api.common.typeutils.ClassRelocator}.
+	 */
+	public static final class NullableNotPaddedSerializerVerifier implements TypeSerializerUpgradeTestBase.UpgradeVerifier<Long> {
+		@Override
+		public TypeSerializer<Long> createUpgradedSerializer() {
+			return NullableSerializer.wrap(LongSerializer.INSTANCE, false);
+		}
+
+		@Override
+		public Matcher<Long> testDataMatcher() {
+			return is((Long) null);
+		}
+
+		@Override
+		public Matcher<TypeSerializerSchemaCompatibility<Long>> schemaCompatibilityMatcher(MigrationVersion version) {
+			return TypeSerializerMatchers.isCompatibleAsIs();
+		}
+	}
+}
diff --git a/flink-core/src/test/resources/flink-1.6-nullable-not-padded-serializer-data b/flink-core/src/test/resources/flink-1.6-nullable-not-padded-serializer-data
deleted file mode 100644
index ca6d29f..0000000
Binary files a/flink-core/src/test/resources/flink-1.6-nullable-not-padded-serializer-data and /dev/null differ
diff --git a/flink-core/src/test/resources/flink-1.6-nullable-not-padded-serializer-snapshot b/flink-core/src/test/resources/flink-1.6-nullable-not-padded-serializer-snapshot
deleted file mode 100644
index 8c8b27f..0000000
Binary files a/flink-core/src/test/resources/flink-1.6-nullable-not-padded-serializer-snapshot and /dev/null differ
diff --git a/flink-core/src/test/resources/flink-1.6-nullable-padded-serializer-data b/flink-core/src/test/resources/flink-1.6-nullable-padded-serializer-data
deleted file mode 100644
index 42439f7..0000000
Binary files a/flink-core/src/test/resources/flink-1.6-nullable-padded-serializer-data and /dev/null differ
diff --git a/flink-core/src/test/resources/flink-1.6-nullable-padded-serializer-snapshot b/flink-core/src/test/resources/flink-1.6-nullable-padded-serializer-snapshot
deleted file mode 100644
index 9bd3af7..0000000
Binary files a/flink-core/src/test/resources/flink-1.6-nullable-padded-serializer-snapshot and /dev/null differ
diff --git a/flink-core/src/test/resources/flink-1.7-nullable-not-padded-serializer-data b/flink-core/src/test/resources/flink-1.7-nullable-not-padded-serializer-data
deleted file mode 100644
index aecf5b8..0000000
Binary files a/flink-core/src/test/resources/flink-1.7-nullable-not-padded-serializer-data and /dev/null differ
diff --git a/flink-core/src/test/resources/flink-1.7-nullable-not-padded-serializer-snapshot b/flink-core/src/test/resources/flink-1.7-nullable-not-padded-serializer-snapshot
deleted file mode 100644
index a2e0807..0000000
Binary files a/flink-core/src/test/resources/flink-1.7-nullable-not-padded-serializer-snapshot and /dev/null differ
diff --git a/flink-core/src/test/resources/flink-1.7-nullable-padded-serializer-data b/flink-core/src/test/resources/flink-1.7-nullable-padded-serializer-data
deleted file mode 100644
index 426221e..0000000
Binary files a/flink-core/src/test/resources/flink-1.7-nullable-padded-serializer-data and /dev/null differ
diff --git a/flink-core/src/test/resources/flink-1.7-nullable-padded-serializer-snapshot b/flink-core/src/test/resources/flink-1.7-nullable-padded-serializer-snapshot
deleted file mode 100644
index 685f8dd..0000000
Binary files a/flink-core/src/test/resources/flink-1.7-nullable-padded-serializer-snapshot and /dev/null differ