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-24627][tests] add some Junit5 extensions to replace the existed Junit4 rules #17556
Conversation
Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community Automated ChecksLast check on commit 389f0b4 (Mon Oct 25 07:24:57 UTC 2021) 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:
|
All the new files are missing the apache license header. |
Thanks, I will fix it. |
ce08ce6
to
974ba5b
Compare
flink-runtime/src/test/java/org/apache/flink/runtime/testutils/MiniClusterExtension.java
Outdated
Show resolved
Hide resolved
@flinkbot run azure |
974ba5b
to
7560273
Compare
...link-test-utils-junit/src/main/java/org/apache/flink/core/testutils/EachCallbackWrapper.java
Outdated
Show resolved
Hide resolved
...flink-test-utils-junit/src/main/java/org/apache/flink/core/testutils/AllCallbackWrapper.java
Outdated
Show resolved
Hide resolved
flink-runtime/src/test/java/org/apache/flink/runtime/zookeeper/ZooKeeperExtension.java
Outdated
Show resolved
Hide resolved
...flink-test-utils-junit/src/main/java/org/apache/flink/core/testutils/AllCallbackWrapper.java
Outdated
Show resolved
Hide resolved
...-utils-junit/src/main/java/org/apache/flink/testutils/junit/RetryTestExecutionExtension.java
Outdated
Show resolved
Hide resolved
...s-parent/flink-test-utils-junit/src/main/java/org/apache/flink/util/TestLoggerExtension.java
Show resolved
Hide resolved
...-test-utils-junit/src/main/java/org/apache/flink/testutils/junit/SharedObjectsExtension.java
Show resolved
Hide resolved
...-test-utils-junit/src/main/java/org/apache/flink/testutils/junit/SharedObjectsExtension.java
Show resolved
Hide resolved
...ils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/util/LogLevelExtension.java
Show resolved
Hide resolved
...link-test-utils-junit/src/main/java/org/apache/flink/core/testutils/EachCallbackWrapper.java
Outdated
Show resolved
Hide resolved
...-utils-junit/src/main/java/org/apache/flink/testutils/junit/RetryTestExecutionExtension.java
Outdated
Show resolved
Hide resolved
public void handleTestExecutionException(ExtensionContext context, Throwable throwable) | ||
throws Throwable { | ||
String method = getTestMethodKey(context); | ||
if (repeatableException != null) { |
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.
are there any limitation as to what we can add to the ExtensionContext store? It would be quite neat if we could just encapsulate the 2 restart mechanisms in 2 implementations of a sort of restart strategy, and we just store one such instance in the store.
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.
I'll try to refactor it , it seems not to have this limit.
"Retry test %s[%d/%d] failed with repeatable exception, continue retrying.", | ||
method, retryIndex, totalTimes); | ||
LOG.error(retryMsg, throwable); | ||
throw new TestAbortedException(retryMsg); |
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.
why does this result in a retry? 😕
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.
Because I do not find a way to control the execution of test cases except ExecutionCondition
, the behavior of RetryExtension
is different from RetryRule
.
When use the RetryExtension
, the test case will be planned to execute fixed times as the times
in RetryOnException
and RetryOnFailure
. We could control which attempt to skip by ExecutionCondition
. When we throw TestAbortedException
for a test case, this test case execution will not be marked as failed, but as ignored.
Compare the test result of RetryOnExceptionExtensionTest
(RetryExtension) and RetryOnExceptionTest
(RetryRule), the difference could be seen more clearly.
...-utils-junit/src/main/java/org/apache/flink/testutils/junit/RetryTestExecutionExtension.java
Outdated
Show resolved
Hide resolved
...-utils-junit/src/main/java/org/apache/flink/testutils/junit/RetryTestExecutionExtension.java
Outdated
Show resolved
Hide resolved
There's a compile issue:
|
@zentol I have fixed it, thanks for reminding. |
import org.apache.flink.testutils.junit.RetryRule; | ||
import org.apache.flink.testutils.junit.extensions.retry.annotation.RetryOnException; |
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.
I'm wondering if we should revert this change. It can just easily lead to issues during rebases/backports.
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.
These annotations are used by Junit4 and Junit5 tests before we totally migrate to Junit5. Should I put them back to the package they used to be?
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.
yes; that's what I meant.
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.
+1; once CI is green I'll merge it!
7580de0
to
47abcfe
Compare
@flinkbot run azure |
Hello -- I've been looking at FLINK-29198. Is there any reason in this PR why the behaviour of Aborted tests are noted as skipped, and CI will pass without drawing attention to them. |
What is the purpose of the change
This pull request provides some junit5 extensions to replace the existed junit4 rules.
Brief change log
xxxxExtension.java
, and replace the word Resource to Extension if the rule's filename is likexxxResource.java
, e.g.MiniClusterResource.java
corresponds toMiniClusterExtension.java
.CustomExtension
,AllCallbackWrapper
andEachCallbackWrapper
for the rules that is both used as@Rule
and@ClassRule
.RetryRule
.TestLoggerExtension
to replaceTestLogger
Verifying this change
This change is already covered by existing tests.
Does this pull request potentially affect one of the following parts:
@Public(Evolving)
: (no)Documentation
Change Details
1. How to change junit4 rules to junit5 extension
A
TestRule
could be used as a@Rule
or a@ClassRule
in Junit4. We could make use ofBeforeEachCallback
andAfterEachCallback
to rewrite@Rule
, and useBeforeAllCallback
andAfterAllCallback
to rewrite@ClassRule
.So if the TestRule is only used as a
@Rule
, the new extension class will implementBeforeEachCallback
andAfterEachCallback
. if the TestRule is only used as a@ClassRule
, the new extension class will implementBeforeAllCallback
andAfterAllCallback
.There are some rules used both as a
@Rule
and a@ClassRule
in flink. But a extension in junit5 can not implement both afterCallback and eachCallback, which will lead to some odd behaviors.So if a TestRule is used both as a
@Rule
and a@ClassRule
, the new extension should implement the providedCustomExtension
interface. And it should be used with aAllCallbackWrapper
orEachCallbackWrapper
, and annotated with@RegisterExtension
. A use case has already provided inflink-runtime/src/test/java/org/apache/flink/runtime/taskmanager/TaskCancelAsyncProducerConsumerITCase.java
.2. The changed behavior in
RetryExtension
compared toRetryRule
If we want to execute a test multiple times in Junit5, we need implement
TestTemplateInvocationContextProvider
and annotate a test by@TestTemplate
. And use aTestExecutionExceptionHandler
to decide a test whether should be executed.In this way, the number of retry tests in Junit5 is different from junit4. Because retry tests in Junit5 will plan to do test multiple times at the beginning, it will skip the following tests if has reached some condition, like succeed or throwing some unexpected exception.