New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FLINK-26232][tests][JUnit5 migration] Module:flink-avro #18871
[FLINK-26232][tests][JUnit5 migration] Module:flink-avro #18871
Conversation
[FLINK-26232][tests][JUnit5 migration] Module:flink-avro AvroTypeExtractionTest
Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community Automated ChecksLast check on commit 6a31168 (Tue Feb 22 09:23:13 UTC 2022) Warnings:
Mention the bot in a comment to re-run the automated checks. Review Progress
Please see the Pull Request Review Guide for a full explanation of the review process. The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required Bot commandsThe @flinkbot bot supports the following commands:
|
…ng public. Extra assertJ cleanup on some tests.
@@ -46,6 +45,8 @@ | |||
import java.util.List; | |||
import java.util.Objects; | |||
|
|||
import static org.assertj.core.api.Assertions.assertThat; | |||
|
|||
/** IT cases for the {@link AvroOutputFormat}. */ | |||
@SuppressWarnings("serial") | |||
public class AvroOutputFormatITCase extends JavaProgramTestBase { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an example of a class that moved to AssertJ matchers while leaving the base class still uses JUnit 4 to run. The public
modifiers are still necessary, but fortunately there's nothing else JUnit4 to change here.
flink-formats/flink-avro/src/test/java/org/apache/flink/formats/avro/AvroOutputFormatTest.java
Outdated
Show resolved
Hide resolved
flink-formats/flink-avro/src/test/java/org/apache/flink/formats/avro/AvroOutputFormatTest.java
Outdated
Show resolved
Hide resolved
@@ -99,8 +100,7 @@ protected void postSubmit() throws Exception { | |||
output1 = file1.listFiles(); | |||
// check for avro ext in dir. | |||
for (File avroOutput : Objects.requireNonNull(output1)) { | |||
Assert.assertTrue( | |||
"Expect extension '.avro'", avroOutput.toString().endsWith(".avro")); | |||
assertThat(avroOutput.toString()).endsWith(".avro"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AssertJ does nice enough descriptions, so I removed a few throughout the code. This, for example, produces:
Expecting actual:
"/tmp/junit5763721249197813393/junit1392834020197511051/avro_output1/4.avrox"
to end with:
".avro"
flink-formats/flink-avro/src/test/java/org/apache/flink/formats/avro/AvroOutputFormatTest.java
Outdated
Show resolved
Hide resolved
serializationSchema.serialize(rowData); | ||
fail("expecting exception message: " + errorMessage); | ||
} catch (Throwable t) { | ||
assertThat(t, FlinkMatchers.containsMessage(errorMessage)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooooh, found a bug here: rowData
is actually serialized correctly , but the fail
call afterwards throws an assertion exception (containing the expected error message by definition). I suspect that the setField(1, 2)
is what was intended, actually testing a type mismatch.
The withStackTraceContaining
looks like a nice AssertJ replacement for finding messages in the cause exceptions.
...k-avro/src/test/java/org/apache/flink/formats/avro/typeutils/AvroSerializerSnapshotTest.java
Show resolved
Hide resolved
public AvroTypeExtractionTest(TestExecutionMode mode) { | ||
super(mode); | ||
/** Tests for the {@link AvroInputFormat} reading Pojos. */ | ||
class AvroTypeExtractionTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the most "complicated" test in the module (that I attempted):
- Removed base class to provide 2
ExecutionEnvironment
instance through a JUnit 5 parameterization, and a MiniClusterExtension directly in the class. - The call to teardown in the base class no longer occurs.
- It looks like there's no impact: since the ExecutionEvironment isn't set as context, it doesn't need to be unset?
...ts/flink-avro/src/test/java/org/apache/flink/formats/avro/AvroSplittableInputFormatTest.java
Outdated
Show resolved
Hide resolved
...ts/flink-avro/src/test/java/org/apache/flink/formats/avro/AvroSplittableInputFormatTest.java
Outdated
Show resolved
Hide resolved
...ts/flink-avro/src/test/java/org/apache/flink/formats/avro/AvroSplittableInputFormatTest.java
Outdated
Show resolved
Hide resolved
...ts/flink-avro/src/test/java/org/apache/flink/formats/avro/AvroSplittableInputFormatTest.java
Outdated
Show resolved
Hide resolved
...ts/flink-avro/src/test/java/org/apache/flink/formats/avro/AvroSplittableInputFormatTest.java
Outdated
Show resolved
Hide resolved
...ormats/flink-avro/src/test/java/org/apache/flink/formats/avro/AvroRecordInputFormatTest.java
Outdated
Show resolved
Hide resolved
...ormats/flink-avro/src/test/java/org/apache/flink/formats/avro/AvroRecordInputFormatTest.java
Outdated
Show resolved
Hide resolved
...ormats/flink-avro/src/test/java/org/apache/flink/formats/avro/AvroRecordInputFormatTest.java
Outdated
Show resolved
Hide resolved
...k-avro/src/test/java/org/apache/flink/formats/avro/typeutils/AvroSerializerSnapshotTest.java
Show resolved
Hide resolved
...flink-avro/src/test/java/org/apache/flink/formats/avro/typeutils/AvroTypeExtractionTest.java
Outdated
Show resolved
Hide resolved
Moved to assertThatThrownBy for exception testing Some additional cleanup for best AssertJ practices Use containsOnly for Maps
Thanks for the review, let me know if you have any advice for the next step: would it be better to start migrating the base classes so in order to "finish" |
@RyanSkraba I'd focus on low-hanging fruits for now (i.e., where we can migrate an entire module at once); the core modules such as flink-runtime will likely have to migrated piece-by-piece. |
@flinkbot run azure In my local environment, failed to compile |
What is the purpose of the change
Update the
flink-formats/flink-avro
module to AssertJ and JUnit 5 following the JUnit 5 Migration GuideThe migration of this module isn't fully finished -- notably those that depend on test base classes outside this module, which I either left untouched or just did the AssertJ changes if they could be done independently.
Brief change log
Verifying this change
This change is a code cleanup without any test coverage.
Does this pull request potentially affect one of the following parts:
@Public(Evolving)
: noDocumentation