Skip to content
Permalink
Browse files
[FLINK-27501][tests] Migrate SerializerTestBase to JUnit5
  • Loading branch information
zentol committed May 17, 2022
1 parent 46c6d78 commit bf38c1273ff32fdad5714fcee458075e2e8f5fd7
Showing 110 changed files with 761 additions and 807 deletions.
@@ -21,7 +21,7 @@
import org.apache.flink.api.common.typeutils.TypeSerializer;

/** XaSerializersTest. */
public class CheckpointAndXidSerializersTest extends SerializerTestBase<CheckpointAndXid> {
class CheckpointAndXidSerializersTest extends SerializerTestBase<CheckpointAndXid> {
private static final CheckpointAndXid CHECKPOINT_AND_XID =
CheckpointAndXid.createRestored(1L, 1, XidImplTest.XID);

@@ -23,7 +23,7 @@
import javax.transaction.xa.Xid;

/** XaSerializersTest. */
public class XidSerializersTest extends SerializerTestBase<Xid> {
class XidSerializersTest extends SerializerTestBase<Xid> {

@Override
protected TypeSerializer<Xid> createSerializer() {
@@ -26,7 +26,7 @@
import java.util.Optional;

/** A test for the {@link TypeSerializer TypeSerializers} used for the Kafka producer state. */
public class FlinkKafkaProducerStateSerializerTest
class FlinkKafkaProducerStateSerializerTest
extends SerializerTestBase<
TwoPhaseCommitSinkFunction.State<
FlinkKafkaProducer.KafkaTransactionState,
@@ -24,7 +24,7 @@
* A test for the {@link TypeSerializer TypeSerializers} used for {@link
* FlinkKafkaProducer.NextTransactionalIdHint}.
*/
public class NextTransactionalIdHintSerializerTest
class NextTransactionalIdHintSerializerTest
extends SerializerTestBase<FlinkKafkaProducer.NextTransactionalIdHint> {

@Override
@@ -51,7 +51,7 @@ public void testStringArrayWritable() {

SerializerTestInstance<StringArrayWritable> testInstance =
new SerializerTestInstance<StringArrayWritable>(
writableSerializer, writableTypeInfo.getTypeClass(), -1, data);
writableSerializer, writableTypeInfo.getTypeClass(), -1, data) {};

testInstance.testAll();
}
@@ -24,7 +24,7 @@
import java.util.UUID;

/** Tests for the {@link WritableSerializer} with {@link WritableID}. */
public class WritableSerializerUUIDTest extends SerializerTestBase<WritableID> {
class WritableSerializerUUIDTest extends SerializerTestBase<WritableID> {
@Override
protected TypeSerializer<WritableID> createSerializer() {
return new WritableSerializer<>(WritableID.class);
@@ -28,9 +28,7 @@
import org.apache.flink.core.memory.DataInputView;
import org.apache.flink.core.memory.DataOutputView;

import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import javax.annotation.Nonnull;

@@ -42,7 +40,7 @@
import java.util.stream.IntStream;

/** Test suite for {@link CompositeSerializer}. */
public class CompositeSerializerTest {
class CompositeSerializerTest {
private static final ExecutionConfig execConf = new ExecutionConfig();

private static final List<Tuple2<TypeSerializer<?>, Object[]>> TEST_FIELD_SERIALIZERS =
@@ -58,7 +56,7 @@ public class CompositeSerializerTest {
}));

@Test
public void testSingleFieldSerializer() {
void testSingleFieldSerializer() {
TEST_FIELD_SERIALIZERS.forEach(
t -> {
@SuppressWarnings("unchecked")
@@ -72,7 +70,7 @@ public void testSingleFieldSerializer() {
}

@Test
public void testPairFieldSerializer() {
void testPairFieldSerializer() {
TEST_FIELD_SERIALIZERS.forEach(
t1 ->
TEST_FIELD_SERIALIZERS.forEach(
@@ -95,7 +93,7 @@ public void testPairFieldSerializer() {
}

@Test
public void testAllFieldSerializer() {
void testAllFieldSerializer() {
@SuppressWarnings("unchecked")
TypeSerializer<Object>[] fieldSerializers =
TEST_FIELD_SERIALIZERS.stream()
@@ -123,18 +121,12 @@ private static int getLength(TypeSerializer<Object>[] fieldSerializers) {
@SuppressWarnings("unchecked")
private void runTests(
int length, TypeSerializer<Object>[] fieldSerializers, List<Object>... instances) {
try {
for (boolean immutability : Arrays.asList(true, false)) {
TypeSerializer<List<Object>> serializer =
new TestListCompositeSerializer(immutability, fieldSerializers);
CompositeSerializerTestInstance test =
new CompositeSerializerTestInstance(serializer, length, instances);
test.testAll();
}
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
Assert.fail(e.getMessage());
for (boolean immutability : Arrays.asList(true, false)) {
TypeSerializer<List<Object>> serializer =
new TestListCompositeSerializer(immutability, fieldSerializers);
CompositeSerializerTestInstance test =
new CompositeSerializerTestInstance(serializer, length, instances);
test.testAll();
}
}

@@ -263,7 +255,6 @@ protected TestListCompositeSerializer createOuterSerializerWithNestedSerializers
}
}

@Ignore("Prevents this class from being considered a test class by JUnit.")
private static class CompositeSerializerTestInstance
extends SerializerTestInstance<List<Object>> {
@SuppressWarnings("unchecked")
@@ -29,12 +29,13 @@
import org.apache.flink.testutils.CustomEqualityMatcher;
import org.apache.flink.testutils.DeeplyEqualsChecker;
import org.apache.flink.util.InstantiationUtil;
import org.apache.flink.util.TestLogger;
import org.apache.flink.util.TestLoggerExtension;

import org.apache.commons.lang3.SerializationException;
import org.apache.commons.lang3.SerializationUtils;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -59,7 +60,8 @@
* to pass this test but the internal state would be corrupt, which becomes evident when toString is
* called.
*/
public abstract class SerializerTestBase<T> extends TestLogger {
@ExtendWith(TestLoggerExtension.class)
public abstract class SerializerTestBase<T> {

private final DeeplyEqualsChecker checker;

@@ -97,7 +99,7 @@ protected boolean allowNullInstances(TypeSerializer<T> serializer) {
// --------------------------------------------------------------------------------------------

@Test
public void testInstantiate() {
protected void testInstantiate() {
try {
TypeSerializer<T> serializer = getSerializer();
T instance = serializer.createInstance();
@@ -125,14 +127,14 @@ public void testInstantiate() {
}

@Test
public void testConfigSnapshotInstantiation() {
protected void testConfigSnapshotInstantiation() {
TypeSerializerSnapshot<T> configSnapshot = getSerializer().snapshotConfiguration();

InstantiationUtil.instantiate(configSnapshot.getClass());
}

@Test
public void testSnapshotConfigurationAndReconfigure() throws Exception {
protected void testSnapshotConfigurationAndReconfigure() throws Exception {
final TypeSerializer<T> serializer = getSerializer();
final TypeSerializerSnapshot<T> configSnapshot = serializer.snapshotConfiguration();

@@ -166,7 +168,7 @@ public void testSnapshotConfigurationAndReconfigure() throws Exception {
}

@Test
public void testGetLength() {
void testGetLength() {
final int len = getLength();

if (len == 0) {
@@ -184,7 +186,7 @@ public void testGetLength() {
}

@Test
public void testCopy() {
protected void testCopy() {
try {
TypeSerializer<T> serializer = getSerializer();
T[] testData = getData();
@@ -202,7 +204,7 @@ public void testCopy() {
}

@Test
public void testCopyIntoNewElements() {
void testCopyIntoNewElements() {
try {
TypeSerializer<T> serializer = getSerializer();
T[] testData = getData();
@@ -220,7 +222,7 @@ public void testCopyIntoNewElements() {
}

@Test
public void testCopyIntoReusedElements() {
void testCopyIntoReusedElements() {
try {
TypeSerializer<T> serializer = getSerializer();
T[] testData = getData();
@@ -241,7 +243,7 @@ public void testCopyIntoReusedElements() {
}

@Test
public void testSerializeIndividually() {
void testSerializeIndividually() {
try {
TypeSerializer<T> serializer = getSerializer();
T[] testData = getData();
@@ -268,7 +270,7 @@ public void testSerializeIndividually() {
}

@Test
public void testSerializeIndividuallyReusingValues() {
void testSerializeIndividuallyReusingValues() {
try {
TypeSerializer<T> serializer = getSerializer();
T[] testData = getData();
@@ -299,7 +301,7 @@ public void testSerializeIndividuallyReusingValues() {
}

@Test
public void testSerializeAsSequenceNoReuse() {
void testSerializeAsSequenceNoReuse() {
try {
TypeSerializer<T> serializer = getSerializer();
T[] testData = getData();
@@ -329,7 +331,7 @@ public void testSerializeAsSequenceNoReuse() {
}

@Test
public void testSerializeAsSequenceReusingValues() {
void testSerializeAsSequenceReusingValues() {
try {
TypeSerializer<T> serializer = getSerializer();
T[] testData = getData();
@@ -361,7 +363,7 @@ public void testSerializeAsSequenceReusingValues() {
}

@Test
public void testSerializedCopyIndividually() {
void testSerializedCopyIndividually() {
try {
TypeSerializer<T> serializer = getSerializer();
T[] testData = getData();
@@ -395,7 +397,7 @@ public void testSerializedCopyIndividually() {
}

@Test
public void testSerializedCopyAsSequence() {
void testSerializedCopyAsSequence() {
try {
TypeSerializer<T> serializer = getSerializer();
T[] testData = getData();
@@ -431,7 +433,7 @@ public void testSerializedCopyAsSequence() {
}

@Test
public void testSerializabilityAndEquals() {
void testSerializabilityAndEquals() {
try {
TypeSerializer<T> ser1 = getSerializer();
TypeSerializer<T> ser2;
@@ -452,7 +454,7 @@ public void testSerializabilityAndEquals() {
}

@Test
public void testNullability() {
void testNullability() {
TypeSerializer<T> serializer = getSerializer();
try {
NullableSerializer.checkIfNullSupported(serializer);
@@ -464,7 +466,7 @@ public void testNullability() {
}

@Test
public void testDuplicate() throws Exception {
void testDuplicate() throws Exception {
final int numThreads = 10;
final TypeSerializer<T> serializer = getSerializer();
final CyclicBarrier startLatch = new CyclicBarrier(numThreads);
@@ -20,14 +20,12 @@

import org.apache.flink.testutils.DeeplyEqualsChecker;

import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

@Ignore
public class SerializerTestInstance<T> extends SerializerTestBase<T> {
public abstract class SerializerTestInstance<T> extends SerializerTestBase<T> {

private final TypeSerializer<T> serializer;

@@ -25,7 +25,7 @@
import java.util.Random;

/** A test for the {@link BigDecSerializer}. */
public class BigDecSerializerTest extends SerializerTestBase<BigDecimal> {
class BigDecSerializerTest extends SerializerTestBase<BigDecimal> {

@Override
protected TypeSerializer<BigDecimal> createSerializer() {
@@ -25,7 +25,7 @@
import java.util.Random;

/** A test for the {@link BigIntSerializer}. */
public class BigIntSerializerTest extends SerializerTestBase<BigInteger> {
class BigIntSerializerTest extends SerializerTestBase<BigInteger> {

@Override
protected TypeSerializer<BigInteger> createSerializer() {
@@ -24,7 +24,7 @@
import java.util.Random;

/** A test for the {@link org.apache.flink.api.common.typeutils.base.BooleanSerializer}. */
public class BooleanSerializerTest extends SerializerTestBase<Boolean> {
class BooleanSerializerTest extends SerializerTestBase<Boolean> {

@Override
protected TypeSerializer<Boolean> createSerializer() {
@@ -25,7 +25,7 @@
import java.util.Random;

/** A test for the {@link BooleanValueSerializer}. */
public class BooleanValueSerializerTest extends SerializerTestBase<BooleanValue> {
class BooleanValueSerializerTest extends SerializerTestBase<BooleanValue> {

@Override
protected TypeSerializer<BooleanValue> createSerializer() {
@@ -24,7 +24,7 @@
import java.util.Random;

/** A test for the {@link org.apache.flink.api.common.typeutils.base.ByteSerializer}. */
public class ByteSerializerTest extends SerializerTestBase<Byte> {
class ByteSerializerTest extends SerializerTestBase<Byte> {

@Override
protected TypeSerializer<Byte> createSerializer() {
@@ -25,7 +25,7 @@
import java.util.Random;

/** A test for the {@link ByteValueSerializer}. */
public class ByteValueSerializerTest extends SerializerTestBase<ByteValue> {
class ByteValueSerializerTest extends SerializerTestBase<ByteValue> {

@Override
protected TypeSerializer<ByteValue> createSerializer() {
@@ -24,7 +24,7 @@
import java.util.Random;

/** A test for the {@link org.apache.flink.api.common.typeutils.base.CharSerializer}. */
public class CharSerializerTest extends SerializerTestBase<Character> {
class CharSerializerTest extends SerializerTestBase<Character> {

@Override
protected TypeSerializer<Character> createSerializer() {
@@ -25,7 +25,7 @@
import java.util.Random;

/** A test for the {@link CharValueSerializer}. */
public class CharValueSerializerTest extends SerializerTestBase<CharValue> {
class CharValueSerializerTest extends SerializerTestBase<CharValue> {

@Override
protected TypeSerializer<CharValue> createSerializer() {

0 comments on commit bf38c12

Please sign in to comment.