Skip to content

Commit

Permalink
[FLINK-25537] [JUnit5 Migration] Migrate the api package of flink-cor…
Browse files Browse the repository at this point in the history
…e module to JUnit5
  • Loading branch information
GOODBOY008 authored May 7, 2024
1 parent afe4c79 commit ffa3869
Show file tree
Hide file tree
Showing 98 changed files with 2,364 additions and 2,671 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@

import org.apache.flink.FlinkVersion;
import org.apache.flink.api.common.typeutils.TypeSerializer;
import org.apache.flink.api.common.typeutils.TypeSerializerMatchers;
import org.apache.flink.api.common.typeutils.TypeSerializerConditions;
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.hadoop.io.Writable;
import org.hamcrest.Matcher;
import org.assertj.core.api.Condition;

import java.io.DataInput;
import java.io.DataOutput;
Expand All @@ -35,8 +35,6 @@
import java.util.Collection;
import java.util.Objects;

import static org.hamcrest.Matchers.is;

/** A {@link TypeSerializerUpgradeTestBase} for {@link WritableSerializer}. */
class WritableSerializerUpgradeTest
extends TypeSerializerUpgradeTestBase<WritableName, WritableName> {
Expand Down Expand Up @@ -129,16 +127,16 @@ public TypeSerializer<WritableName> createUpgradedSerializer() {
}

@Override
public Matcher<WritableName> testDataMatcher() {
public Condition<WritableName> testDataCondition() {
WritableName writable = new WritableName();
writable.setName("flink");
return is(writable);
return new Condition<>(writable::equals, "writable is " + writable);
}

@Override
public Matcher<TypeSerializerSchemaCompatibility<WritableName>> schemaCompatibilityMatcher(
FlinkVersion version) {
return TypeSerializerMatchers.isCompatibleAsIs();
public Condition<TypeSerializerSchemaCompatibility<WritableName>>
schemaCompatibilityCondition(FlinkVersion version) {
return TypeSerializerConditions.isCompatibleAsIs();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private void testLoadingSchedulerTypeFromConfiguration(
configFromConfiguration.configure(
configuration, Thread.currentThread().getContextClassLoader());

assertThat(configFromConfiguration.getSchedulerType()).contains(schedulerType);
assertThat(configFromConfiguration.getSchedulerType()).hasValue(schedulerType);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Fail.fail;

public class DelimitedInputFormatSamplingTest {
class DelimitedInputFormatSamplingTest {

private static final String TEST_DATA1 =
"123456789\n"
Expand Down Expand Up @@ -77,7 +77,7 @@ public class DelimitedInputFormatSamplingTest {
// ========================================================================

@BeforeAll
public static void initialize() {
static void initialize() {
try {
testTempFolder = TempDirUtils.newFolder(tempDir);
// make sure we do 4 samples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ class DelimitedInputFormatTest {
// --------------------------------------------------------------------------------------------

@BeforeEach
public void setup() {
void setup() {
format = new MyTextInputFormat();
this.format.setFilePath(new Path("file:///some/file/that/will/not/be/read"));
}

@AfterEach
public void shutdown() throws Exception {
void shutdown() throws Exception {
if (this.format != null) {
this.format.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ class EnumerateNestedFilesTest {
private DummyFileInputFormat format;

@BeforeEach
public void setup() {
void setup() {
this.config = new Configuration();
format = new DummyFileInputFormat();
}

@AfterEach
public void setdown() throws Exception {
void setdown() throws Exception {
if (this.format != null) {
this.format.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ class GenericCsvInputFormatTest {
// --------------------------------------------------------------------------------------------

@BeforeEach
public void setup() {
void setup() {
format = new TestCsvInputFormat();
format.setFilePath("file:///some/file/that/will/not/be/read");
}

@AfterEach
public void setdown() throws Exception {
void setdown() throws Exception {
if (this.format != null) {
this.format.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;

@SuppressWarnings("unused")
public class ExpressionKeysTest {
class ExpressionKeysTest {

@Test
void testBasicType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import static org.assertj.core.api.Assertions.assertThat;

public class OrderingTest {
class OrderingTest {

@Test
void testNewOrdering() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ void testMerge() {
ResourceSpec rs3 = rs1.merge(rs2);
assertThat(rs3.getCpuCores()).isEqualTo(new CPUResource(2.0));
assertThat(rs3.getTaskHeapMemory().getMebiBytes()).isEqualTo(200);
assertThat(rs3.getExtendedResource(EXTERNAL_RESOURCE_NAME).get())
.isEqualTo(new ExternalResource(EXTERNAL_RESOURCE_NAME, 1.1));
assertThat(rs3.getExtendedResource(EXTERNAL_RESOURCE_NAME))
.hasValue(new ExternalResource(EXTERNAL_RESOURCE_NAME, 1.1));

ResourceSpec rs4 = rs1.merge(rs3);
assertThat(rs4.getExtendedResource(EXTERNAL_RESOURCE_NAME).get())
.isEqualTo(new ExternalResource(EXTERNAL_RESOURCE_NAME, 2.2));
assertThat(rs4.getExtendedResource(EXTERNAL_RESOURCE_NAME))
.hasValue(new ExternalResource(EXTERNAL_RESOURCE_NAME, 2.2));
}

@Test
Expand Down Expand Up @@ -228,8 +228,8 @@ void testSubtract() {
final ResourceSpec subtracted = rs1.subtract(rs2);
assertThat(subtracted.getCpuCores()).isEqualTo(new CPUResource(0.8));
assertThat(subtracted.getTaskHeapMemory().getMebiBytes()).isZero();
assertThat(subtracted.getExtendedResource(EXTERNAL_RESOURCE_NAME).get())
.isEqualTo(new ExternalResource(EXTERNAL_RESOURCE_NAME, 0.6));
assertThat(subtracted.getExtendedResource(EXTERNAL_RESOURCE_NAME))
.contains(new ExternalResource(EXTERNAL_RESOURCE_NAME, 0.6));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ void testBuildSlotSharingGroupWithSpecificResource() {
.build();

assertThat(slotSharingGroup.getName()).isEqualTo(name);
assertThat(slotSharingGroup.getCpuCores()).contains(1.0);
assertThat(slotSharingGroup.getTaskHeapMemory()).contains(heap);
assertThat(slotSharingGroup.getTaskOffHeapMemory()).contains(offHeap);
assertThat(slotSharingGroup.getManagedMemory()).contains(managed);
assertThat(slotSharingGroup.getCpuCores()).hasValue(1.0);
assertThat(slotSharingGroup.getTaskHeapMemory()).hasValue(heap);
assertThat(slotSharingGroup.getTaskOffHeapMemory()).hasValue(offHeap);
assertThat(slotSharingGroup.getManagedMemory()).hasValue(managed);
assertThat(slotSharingGroup.getExternalResources())
.isEqualTo(Collections.singletonMap("gpu", 1.0));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import static org.assertj.core.api.Assertions.assertThat;

/** The test for flat map operator. */
public class FlatMapOperatorCollectionTest implements Serializable {
class FlatMapOperatorCollectionTest implements Serializable {

@Test
void testExecuteOnCollection() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import static org.assertj.core.api.Assertions.assertThat;

/** The test for inner join operator. */
public class InnerJoinOperatorBaseTest implements Serializable {
class InnerJoinOperatorBaseTest implements Serializable {

@Test
void testJoinPlain() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import static org.assertj.core.api.Assertions.assertThat;

/** The test for map operator. */
public class MapOperatorTest implements java.io.Serializable {
class MapOperatorTest implements java.io.Serializable {

@Test
void testMapPlain() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;

/** The test for outer join operator. */
public class OuterJoinOperatorBaseTest implements Serializable {
class OuterJoinOperatorBaseTest implements Serializable {

private MockRichFlatJoinFunction joiner;

Expand All @@ -61,7 +61,7 @@ public class OuterJoinOperatorBaseTest implements Serializable {

@SuppressWarnings({"rawtypes", "unchecked"})
@BeforeEach
public void setup() {
void setup() {
joiner = new MockRichFlatJoinFunction();

baseOperator =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import static org.assertj.core.api.Assertions.assertThat;

/** The test for partition map operator. */
public class PartitionMapOperatorTest implements java.io.Serializable {
class PartitionMapOperatorTest implements java.io.Serializable {

@Test
void testMapPartitionWithRuntimeContext() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import static org.assertj.core.api.Assertions.assertThat;

/** Tests for {@link SlotSharingGroupUtils}. */
public class SlotSharingGroupUtilsTest {
class SlotSharingGroupUtilsTest {
@Test
void testCovertToResourceSpec() {
final ExternalResource gpu = new ExternalResource("gpu", 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ void testReadingDefaultConfig() {
@Test
void testDoubleTypeRegistration() {
SerializerConfig config = new SerializerConfigImpl();
List<Class<?>> types = Arrays.<Class<?>>asList(Double.class, Integer.class, Double.class);
List<Class<?>> expectedTypes = Arrays.<Class<?>>asList(Double.class, Integer.class);
List<Class<?>> types = Arrays.asList(Double.class, Integer.class, Double.class);
List<Class<?>> expectedTypes = Arrays.asList(Double.class, Integer.class);

for (Class<?> tpe : types) {
config.registerKryoType(tpe);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import static org.assertj.core.api.Assertions.assertThat;

/** Tests for the {@link ValueStateDescriptor}. */
public class ValueStateDescriptorTest {
class ValueStateDescriptorTest {

@Test
void testHashCodeEquals() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
import org.apache.flink.api.java.typeutils.runtime.EitherSerializer;
import org.apache.flink.types.Either;

import org.hamcrest.Matcher;
import org.assertj.core.api.Condition;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
import static org.hamcrest.Matchers.is;
import static org.assertj.core.api.Assertions.assertThat;

/** A {@link TypeSerializerUpgradeTestBase} for {@link GenericArraySerializer}. */
class CompositeTypeSerializerUpgradeTest extends TypeSerializerUpgradeTestBase<Object, Object> {
Expand Down Expand Up @@ -90,14 +90,16 @@ public TypeSerializer<Either<String, Integer>> createUpgradedSerializer() {
}

@Override
public Matcher<Either<String, Integer>> testDataMatcher() {
return is(new Either.Left<>("ApacheFlink"));
public Condition<Either<String, Integer>> testDataCondition() {
return new Condition<>(
value -> new Either.Left<>("ApacheFlink").equals(value),
"value is Either.Left(\"ApacheFlink\")");
}

@Override
public Matcher<TypeSerializerSchemaCompatibility<Either<String, Integer>>>
schemaCompatibilityMatcher(FlinkVersion version) {
return TypeSerializerMatchers.isCompatibleAsIs();
public Condition<TypeSerializerSchemaCompatibility<Either<String, Integer>>>
schemaCompatibilityCondition(FlinkVersion version) {
return TypeSerializerConditions.isCompatibleAsIs();
}
}

Expand Down Expand Up @@ -134,15 +136,16 @@ public TypeSerializer<String[]> createUpgradedSerializer() {
}

@Override
public Matcher<String[]> testDataMatcher() {
public Condition<String[]> testDataCondition() {
String[] data = {"Apache", "Flink"};
return is(data);
return new Condition<>(
value -> Arrays.equals(data, value), "data is " + Arrays.toString(data));
}

@Override
public Matcher<TypeSerializerSchemaCompatibility<String[]>> schemaCompatibilityMatcher(
public Condition<TypeSerializerSchemaCompatibility<String[]>> schemaCompatibilityCondition(
FlinkVersion version) {
return TypeSerializerMatchers.isCompatibleAsIs();
return TypeSerializerConditions.isCompatibleAsIs();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;

/** Tests for the {@link CompositeTypeSerializerUtil}. */
class CompositeTypeSerializerUtilTest {
Expand Down Expand Up @@ -62,11 +61,11 @@ void testCompatibleAsIsIntermediateCompatibilityResult() {

assertThat(intermediateCompatibilityResult.isCompatibleAsIs()).isTrue();
assertThat(intermediateCompatibilityResult.getFinalResult().isCompatibleAsIs()).isTrue();
assertArrayEquals(
Arrays.stream(newSerializerSnapshots)
.map(TypeSerializerSnapshot::restoreSerializer)
.toArray(),
intermediateCompatibilityResult.getNestedSerializers());
assertThat(intermediateCompatibilityResult.getNestedSerializers())
.containsExactly(
Arrays.stream(newSerializerSnapshots)
.map(TypeSerializerSnapshot::restoreSerializer)
.toArray(TypeSerializer[]::new));
}

@Test
Expand Down
Loading

0 comments on commit ffa3869

Please sign in to comment.