Skip to content
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

Merged

Conversation

RyanSkraba
Copy link
Contributor

What is the purpose of the change

Update the flink-formats/flink-avro module to AssertJ and JUnit 5 following the JUnit 5 Migration Guide

The 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

  • Removed dependences on JUnit 4, JUnit 5 Assertions and Hamcrest where possible.

Verifying this change

This change is a code cleanup without any test coverage.

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): no
  • The public API, i.e., is any changed class annotated with @Public(Evolving): no
  • The serializers: no
  • The runtime per-record code paths (performance sensitive):no
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
  • The S3 file system connector: no

Documentation

  • Does this pull request introduce a new feature? no

[FLINK-26232][tests][JUnit5 migration] Module:flink-avro AvroTypeExtractionTest
@flinkbot
Copy link
Collaborator

Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community
to review your pull request. We will use this comment to track the progress of the review.

Automated Checks

Last check on commit 6a31168 (Tue Feb 22 09:23:13 UTC 2022)

Warnings:

  • No documentation files were touched! Remember to keep the Flink docs up to date!

Mention the bot in a comment to re-run the automated checks.

Review Progress

  • ❓ 1. The [description] looks good.
  • ❓ 2. There is [consensus] that the contribution should go into to Flink.
  • ❓ 3. Needs [attention] from.
  • ❓ 4. The change fits into the overall [architecture].
  • ❓ 5. Overall code [quality] is good.

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 commands
The @flinkbot bot supports the following commands:

  • @flinkbot approve description to approve one or more aspects (aspects: description, consensus, architecture and quality)
  • @flinkbot approve all to approve all aspects
  • @flinkbot approve-until architecture to approve everything until architecture
  • @flinkbot attention @username1 [@username2 ..] to require somebody's attention
  • @flinkbot disapprove architecture to remove an approval you gave earlier

@flinkbot
Copy link
Collaborator

flinkbot commented Feb 22, 2022

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run azure re-run the last Azure build

…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 {
Copy link
Contributor Author

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.

@@ -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");
Copy link
Contributor Author

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"

serializationSchema.serialize(rowData);
fail("expecting exception message: " + errorMessage);
} catch (Throwable t) {
assertThat(t, FlinkMatchers.containsMessage(errorMessage));
Copy link
Contributor Author

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.

public AvroTypeExtractionTest(TestExecutionMode mode) {
super(mode);
/** Tests for the {@link AvroInputFormat} reading Pojos. */
class AvroTypeExtractionTest {
Copy link
Contributor Author

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?

Moved to assertThatThrownBy for exception testing
Some additional cleanup for best AssertJ practices
Use containsOnly for Maps
@RyanSkraba
Copy link
Contributor Author

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" flink-avro, or to attack the "low-hanging" fruit in other modules?

@zentol zentol merged commit a3dff68 into apache:master Mar 9, 2022
@zentol
Copy link
Contributor

zentol commented Mar 9, 2022

@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.

@RyanSkraba RyanSkraba deleted the rskraba/FLINK-26232-flink-avro-junit branch March 9, 2022 12:36
@RyanSkraba RyanSkraba restored the rskraba/FLINK-26232-flink-avro-junit branch March 9, 2022 17:12
@fsk119
Copy link
Member

fsk119 commented Mar 10, 2022

@flinkbot run azure

In my local environment, failed to compile AvroTypeExractionTest.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants