forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-11485] [core] Refactor multiple nested serializer compatibilit…
…y resolution logic to CompositeTypeSerializerUtil This commit refactors the logic of resolving overall compatibility results across multiple nested serializers of a composite serializer out of the CompositeTypeSerializerSnapshot class. This allows us to reuse this functionality when implementing the compatibility check for the PojoSerializerSnapshot
- Loading branch information
Showing
4 changed files
with
597 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
.../src/test/java/org/apache/flink/api/common/typeutils/CompositeTypeSerializerUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.api.common.typeutils.base.IntSerializer; | ||
import org.apache.flink.testutils.migration.SchemaCompatibilityTestingSerializer; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertArrayEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* 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(), | ||
}; | ||
|
||
final TypeSerializer<?>[] testNewSerializers = new TypeSerializer<?>[] { | ||
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(), | ||
}; | ||
|
||
final TypeSerializer<?>[] testNewSerializers = new TypeSerializer<?>[] { | ||
new SchemaCompatibilityTestingSerializer.InitialSerializer(), | ||
new SchemaCompatibilityTestingSerializer.ReconfigurationRequiringSerializer<>(), | ||
}; | ||
|
||
IntermediateCompatibilityResult<?> intermediateCompatibilityResult = | ||
CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(testNewSerializers, testSerializerSnapshots); | ||
|
||
assertTrue(intermediateCompatibilityResult.isCompatibleWithReconfiguredSerializer()); | ||
|
||
final TypeSerializer<?>[] expectedReconfiguredNestedSerializers = new TypeSerializer<?>[] { | ||
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(), | ||
}; | ||
|
||
final TypeSerializer<?>[] testNewSerializers = new TypeSerializer<?>[] { | ||
new SchemaCompatibilityTestingSerializer.ReconfigurationRequiringSerializer<>(), | ||
new SchemaCompatibilityTestingSerializer.UpgradedSchemaSerializer<>(), | ||
new SchemaCompatibilityTestingSerializer.InitialSerializer() | ||
}; | ||
|
||
IntermediateCompatibilityResult<?> intermediateCompatibilityResult = | ||
CompositeTypeSerializerUtil.constructIntermediateCompatibilityResult(testNewSerializers, testSerializerSnapshots); | ||
|
||
assertTrue(intermediateCompatibilityResult.isCompatibleAfterMigration()); | ||
assertTrue(intermediateCompatibilityResult.getFinalResult().isCompatibleAfterMigration()); | ||
} | ||
|
||
@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()); | ||
} | ||
|
||
@Test(expected = IllegalStateException.class) | ||
public void testGetFinalResultOnUndefinedReconfigureIntermediateCompatibilityResultFails() { | ||
IntermediateCompatibilityResult<Integer> intermediateCompatibilityResult = | ||
IntermediateCompatibilityResult.undefinedReconfigureResult(new TypeSerializer[]{ IntSerializer.INSTANCE }); | ||
|
||
intermediateCompatibilityResult.getFinalResult(); | ||
} | ||
|
||
@Test(expected = IllegalStateException.class) | ||
public void testGetNestedSerializersOnCompatibleAfterMigrationIntermediateCompatibilityResultFails() { | ||
IntermediateCompatibilityResult<Integer> intermediateCompatibilityResult = | ||
IntermediateCompatibilityResult.definedCompatibleAfterMigrationResult(); | ||
|
||
intermediateCompatibilityResult.getNestedSerializers(); | ||
} | ||
|
||
@Test(expected = IllegalStateException.class) | ||
public void testGetNestedSerializersOnIncompatibleIntermediateCompatibilityResultFails() { | ||
IntermediateCompatibilityResult<Integer> intermediateCompatibilityResult = | ||
IntermediateCompatibilityResult.definedIncompatibleResult(); | ||
|
||
intermediateCompatibilityResult.getNestedSerializers(); | ||
} | ||
} |
Oops, something went wrong.