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-23255][test] Introduce JUnit 5 dependencies #16551

Merged
merged 2 commits into from
Aug 10, 2021

Conversation

PatrickRen
Copy link
Contributor

What is the purpose of the change

This pull request introduces JUnit 5 dependencies into Flink project so that developers can write JUnit 5 style test cases.

Brief change log

  • Add junit-jupiter dependency in root pom
  • Add junit-vintage-engine and junit-jupiter-migrationsupport dependency for supporting existing JUnit 4 test cases.

Verifying this change

This change is already covered by all existing tests.

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

  • Dependencies (does it add or upgrade a dependency): (yes)
  • 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)
  • If yes, how is the feature documented? (not applicable)

@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 58f4488 (Wed Jul 21 07:34:46 UTC 2021)

Warnings:

  • 11 pom.xml files were touched: Check for build and licensing issues.
  • No documentation files were touched! Remember to keep the Flink docs up to date!
  • This pull request references an unassigned Jira ticket. According to the code contribution guide, tickets need to be assigned before starting with the implementation work.

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 Jul 21, 2021

CI report:

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

@@ -1578,7 +1591,7 @@ under the License.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<version>2.22.2</version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this being bumped?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review @zentol! 2.22.2 fixed a bug related to junit-vintage-engine, so I bumped the version.

Copy link
Contributor

@AHeise AHeise left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have verified that the test count is plausible, however from the AZP run, I could not assess if JUnit5 is actually used. The easiest way would be to temporarily add a test that fails and look at the stack trace.


<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-migrationsupport</artifactId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we even need this? Afaik this is for using JUnit4 rules in JUnit5 tests.
I had expected instead to see the vintage runner.

Same comment for the other modules.

@PatrickRen
Copy link
Contributor Author

Thanks for the review @AHeise !

Sorry for misunderstanding the usage of junit-jupiter-migrationsupport. I have removed them in the latest commit.

About validating whether Jupiter engine is truly used, I tried to check the stack trace but found that the stack is different under different execution environments. For example Intellij IDEA has its own engine so I can't capture keyword "jupiter" in the stack trace. Instead I added a temp test class JUnitJupiterTest with JUnit5 unique features. I think this case can prove that Jupiter engine truly works in the project.

@AHeise
Copy link
Contributor

AHeise commented Aug 4, 2021

Sorry for misunderstanding the usage of junit-jupiter-migrationsupport. I have removed them in the latest commit.

Yes but I think you need to add vintage at some of those places (migrationsupport has it as a transitive dependency afaik) and now JUnit4 classes are missing.

About validating whether Jupiter engine is truly used, I tried to check the stack trace but found that the stack is different under different execution environments. For example Intellij IDEA has its own engine so I can't capture keyword "jupiter" in the stack trace. Instead I added a temp test class JUnitJupiterTest with JUnit5 unique features. I think this case can prove that Jupiter engine truly works in the project.

Sounds good to me and is a neat idea. We can double-check if the test count is the same and your new test appears on AZP and then this PR is good to go.

@PatrickRen
Copy link
Contributor Author

@AHeise Thanks again for the review! I made a rebase to sync with the latest master.

I manually ran CI twice in my own AZP project, one with the JUnit 5 dependencies[1] and another without[2]. Number of tests are almost identical to each other (59,186 vs 59,189) only with slight diffs.

Missing tests with JUnit5 dependencies:

  • org.apache.flink.testutils.junit.RetryRuleTest$TestClassWithAnnotation
  • org.apache.flink.testutils.junit.RetryRuleTest$TestClassWithAnnotationOnMethod
  • org.apache.flink.testutils.junit.RetryRuleTest$TestClassWithTestExpectingRuntimeException
  • org.apache.flink.testutils.junit.RetryRuleTest$TestClassWithoutAnnotation
  • org.apache.flink.test.checkpointing.LocalRecoveryITCase$EventTimeWindowCheckpointingITCaseInstance
  • org.apache.flink.api.common.typeutils.CompositeSerializerTest$CompositeSerializerTestInstance
  • org.apache.flink.api.java.typeutils.runtime.AbstractGenericTypeComparatorTest$ComparatorTestInstance
  • org.apache.flink.api.java.typeutils.runtime.EitherSerializerTest$EitherSerializerTestInstance
  • org.apache.flink.api.java.typeutils.runtime.LegacyRowSerializerTest$RowSerializerTestInstance
  • org.apache.flink.api.java.typeutils.runtime.RowSerializerTest$RowSerializerTestInstance

Interesting thing is that all these tests are annotated with @Ignore. Not sure why these cases are run in JUnit4.

Additional tests with JUnit5 dependencies:

  • org.apache.flink.test.junit5.JUnitJupiterTest * 6 (Intentionally added for testing Jupiter engine)
  • org.apache.flink.connector.jdbc.xa.JdbcXaSinkMigrationTest#testCommitFromSnapshot (Not sure why this case is not run in JUnit4)

In general, I think all test cases are covered with by vintage engine, and new Jupiter engine is validated by JUnitJupiterTest.

[1] With JUnit 5: https://dev.azure.com/renqs/Apache%20Flink/_build/results?buildId=42&view=ms.vss-test-web.build-test-results-tab
[2] Without JUnit 5: https://dev.azure.com/renqs/Apache%20Flink/_build/results?buildId=43&view=ms.vss-test-web.build-test-results-tab

Copy link
Contributor

@AHeise AHeise left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
I'm assuming that one additional test was ignored on master or whatever you compared with.
Let me know if I should merge. It would be best to do it at a time when you can also check if it causes issues with subsequent builds.

@AHeise AHeise merged commit f8ce4d7 into apache:master Aug 10, 2021
hhkkxxx133 pushed a commit to hhkkxxx133/flink that referenced this pull request Aug 25, 2021
[FLINK-23255][test] Introduce JUnit 5 dependencies.

All existing JUnit4 tests are run through the vintage runner of JUnit5.
gddezero pushed a commit to gddezero/flink that referenced this pull request Feb 17, 2023
[FLINK-23255][test] Introduce JUnit 5 dependencies.

All existing JUnit4 tests are run through the vintage runner of JUnit5.
gddezero added a commit to gddezero/flink that referenced this pull request Feb 17, 2023
jnh5y pushed a commit to jnh5y/flink that referenced this pull request Dec 18, 2023
[FLINK-23255][test] Introduce JUnit 5 dependencies.

All existing JUnit4 tests are run through the vintage runner of JUnit5.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants