igalshilman commented on a change in pull request #7759: [FLINK-11485][FLINK-10897] POJO state schema evolution / migrate PojoSerializer to use new compatibility APIs URL: https://github.com/apache/flink/pull/7759#discussion_r258827742
########## File path: flink-core/src/test/java/org/apache/flink/api/common/typeutils/CompositeTypeSerializerUtilTest.java ########## @@ -0,0 +1,149 @@ +/* + * 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.common.typeutils; + +import org.apache.flink.api.common.typeutils.CompositeTypeSerializerUtil.IntermediateCompatibilityResult; +import org.apache.flink.testutils.migration.SchemaCompatibilityTestingSerializer; +import org.junit.Test; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Tests for the {@link CompositeTypeSerializerUtil}. + */ +public class CompositeTypeSerializerUtilTest { + + // ------------------------------------------------------------------------------------------------ + // Tests for CompositeTypeSerializerUtil#constructIntermediateCompatibilityResult + // ------------------------------------------------------------------------------------------------ + + @Test + public void testCompatibleAsIsIntermediateCompatibilityResult() { + final TypeSerializerSnapshot<?>[] testSerializerSnapshots = new TypeSerializerSnapshot<?>[] { + new SchemaCompatibilityTestingSerializer.InitialSerializer().snapshotConfiguration(), + new SchemaCompatibilityTestingSerializer.InitialSerializer().snapshotConfiguration(), + new SchemaCompatibilityTestingSerializer.InitialSerializer().snapshotConfiguration(), + new SchemaCompatibilityTestingSerializer.InitialSerializer().snapshotConfiguration(), + }; + + final TypeSerializer<?>[] testNewSerializers = new TypeSerializer<?>[] { + new SchemaCompatibilityTestingSerializer.InitialSerializer(), + new SchemaCompatibilityTestingSerializer.InitialSerializer(), + new SchemaCompatibilityTestingSerializer.InitialSerializer(), + new SchemaCompatibilityTestingSerializer.InitialSerializer(), + }; + + IntermediateCompatibilityResult<?> intermediateCompatibilityResult = + CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(testNewSerializers, testSerializerSnapshots); + + assertTrue(intermediateCompatibilityResult.isCompatibleAsIs()); + assertTrue(intermediateCompatibilityResult.getFinalResult().isCompatibleAsIs()); + assertArrayEquals(testNewSerializers, intermediateCompatibilityResult.getNestedSerializers()); + } + + @Test + public void testCompatibleWithReconfiguredSerializerIntermediateCompatibilityResult() { + final TypeSerializerSnapshot<?>[] testSerializerSnapshots = new TypeSerializerSnapshot<?>[] { + new SchemaCompatibilityTestingSerializer.InitialSerializer().snapshotConfiguration(), + new SchemaCompatibilityTestingSerializer.InitialSerializer().snapshotConfiguration(), + new SchemaCompatibilityTestingSerializer.InitialSerializer().snapshotConfiguration(), + new SchemaCompatibilityTestingSerializer.InitialSerializer().snapshotConfiguration(), + }; + + final TypeSerializer<?>[] testNewSerializers = new TypeSerializer<?>[] { + new SchemaCompatibilityTestingSerializer.InitialSerializer(), + new SchemaCompatibilityTestingSerializer.ReconfigurationRequiringSerializer<>(), + new SchemaCompatibilityTestingSerializer.InitialSerializer(), + new SchemaCompatibilityTestingSerializer.InitialSerializer() + }; + + IntermediateCompatibilityResult<?> intermediateCompatibilityResult = + CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(testNewSerializers, testSerializerSnapshots); + + assertTrue(intermediateCompatibilityResult.isCompatibleWithReconfiguredSerializer()); + assertThatExceptionIsThrown(intermediateCompatibilityResult::getFinalResult); + + final TypeSerializer<?>[] expectedReconfiguredNestedSerializers = new TypeSerializer<?>[] { + new SchemaCompatibilityTestingSerializer.InitialSerializer(), + new SchemaCompatibilityTestingSerializer.InitialSerializer(), + new SchemaCompatibilityTestingSerializer.InitialSerializer(), + new SchemaCompatibilityTestingSerializer.InitialSerializer() + }; + assertArrayEquals(expectedReconfiguredNestedSerializers, intermediateCompatibilityResult.getNestedSerializers()); + } + + @Test + public void testCompatibleAfterMigrationIntermediateCompatibilityResult() { + final TypeSerializerSnapshot<?>[] testSerializerSnapshots = new TypeSerializerSnapshot<?>[] { + new SchemaCompatibilityTestingSerializer.InitialSerializer().snapshotConfiguration(), + new SchemaCompatibilityTestingSerializer.InitialSerializer().snapshotConfiguration(), + new SchemaCompatibilityTestingSerializer.InitialSerializer().snapshotConfiguration(), + new SchemaCompatibilityTestingSerializer.InitialSerializer().snapshotConfiguration(), + }; + + final TypeSerializer<?>[] testNewSerializers = new TypeSerializer<?>[] { + new SchemaCompatibilityTestingSerializer.InitialSerializer(), + new SchemaCompatibilityTestingSerializer.ReconfigurationRequiringSerializer<>(), + new SchemaCompatibilityTestingSerializer.UpgradedSchemaSerializer<>(), + new SchemaCompatibilityTestingSerializer.InitialSerializer() + }; + + IntermediateCompatibilityResult<?> intermediateCompatibilityResult = + CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(testNewSerializers, testSerializerSnapshots); + + assertTrue(intermediateCompatibilityResult.isCompatibleAfterMigration()); + assertTrue(intermediateCompatibilityResult.getFinalResult().isCompatibleAfterMigration()); + assertThatExceptionIsThrown(intermediateCompatibilityResult::getNestedSerializers); + } + + @Test + public void testIncompatibleIntermediateCompatibilityResult() { + final TypeSerializerSnapshot<?>[] testSerializerSnapshots = new TypeSerializerSnapshot<?>[] { + new SchemaCompatibilityTestingSerializer.InitialSerializer().snapshotConfiguration(), + new SchemaCompatibilityTestingSerializer.InitialSerializer().snapshotConfiguration(), + new SchemaCompatibilityTestingSerializer.InitialSerializer().snapshotConfiguration(), + new SchemaCompatibilityTestingSerializer.InitialSerializer().snapshotConfiguration(), + }; + + final TypeSerializer<?>[] testNewSerializers = new TypeSerializer<?>[] { + new SchemaCompatibilityTestingSerializer.InitialSerializer(), + new SchemaCompatibilityTestingSerializer.IncompatibleSerializer<>(), + new SchemaCompatibilityTestingSerializer.ReconfigurationRequiringSerializer<>(), + new SchemaCompatibilityTestingSerializer.UpgradedSchemaSerializer() + }; + + IntermediateCompatibilityResult<?> intermediateCompatibilityResult = + CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(testNewSerializers, testSerializerSnapshots); + + assertTrue(intermediateCompatibilityResult.isIncompatible()); + assertTrue(intermediateCompatibilityResult.getFinalResult().isIncompatible()); + assertThatExceptionIsThrown(intermediateCompatibilityResult::getNestedSerializers); Review comment: I would split it to another test, and decelerate it on `@Test(expected = ..)` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
