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-26252][runtime][test-utils] Refactor MiniClusterExtension to support JUnit 5 parallel tests #18847
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 7f3404d (Fri Feb 18 14:02:12 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:
|
...flink-test-utils-junit/src/main/java/org/apache/flink/core/testutils/AllCallbackWrapper.java
Outdated
Show resolved
Hide resolved
...s-parent/flink-test-utils/src/main/java/org/apache/flink/test/util/MiniClusterExtension.java
Outdated
Show resolved
Hide resolved
...s-parent/flink-test-utils/src/main/java/org/apache/flink/test/util/MiniClusterExtension.java
Outdated
Show resolved
Hide resolved
...k-runtime/src/test/java/org/apache/flink/runtime/testutils/InternalMiniClusterExtension.java
Outdated
Show resolved
Hide resolved
...s-parent/flink-test-utils/src/main/java/org/apache/flink/test/util/MiniClusterExtension.java
Outdated
Show resolved
Hide resolved
The architecture tests are complaining because they don't recognize the MiniClusterExtension as a mini cluster without the CallbackWrappers. |
...ase/src/test/java/org/apache/flink/connector/base/source/reader/AlignedWatermarksITCase.java
Outdated
Show resolved
Hide resolved
...-connector-pulsar/src/test/java/org/apache/flink/connector/pulsar/sink/PulsarSinkITCase.java
Outdated
Show resolved
Hide resolved
...k-architecture-tests-test/src/main/java/org/apache/flink/architecture/rules/ITCaseRules.java
Outdated
Show resolved
Hide resolved
b1d7e49
to
3ce599b
Compare
@JingGe can you please check this out? |
3ce599b
to
6dc0997
Compare
...k-connectors/flink-connector-aws-kinesis-data-streams/src/test/resources/archunit.properties
Outdated
Show resolved
Hide resolved
9ce87b8
to
1cfeaa7
Compare
@slinkydeveloper , Thanks for your work. The To be honest, I don't understand why the |
Exactly my point on why I didn't added this feature here. It doesn't seem there are much tests doing that, and probably most of the ones that are doing it, are doing it by mistake. I would rather not add the capability in this PR. If it's really needed, we add it in future, but now as default this extension always starts only one cluster per class. Another aspect is that if you really need to create a cluster per method, then just manually instantiating |
There are use-cases where it can make sense to run dedicated clusters for each test, for example when you add a taskmanager to the cluster within a test (test scale-up of a job), doing something destructive like killing a taskmanager (scala-down / recovery) or creating an intentional resource leak. However, I'd consider these as niche use-cases that we shouldn't don't have to focus on (at this time). There are multiple ways to workaround this (spread tests across classes / wrap extension / manual life-cycling) in any case. |
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.
Running CI in the background; will update PR and merge once it's green.
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.
Thanks @slinkydeveloper for driving this PR. It looks overall good. I just left some comments.
|
||
``` | ||
rm -rf `find . -type d -name archunit-violations` | ||
mvn test -Dtest="*TestCodeArchitectureTest*" -DfailIfNoTests=false -Darchunit.freeze.refreeze=true -Darchunit.freeze.store.default.allowStoreCreation=true -Dfast |
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.
NIT: -Dskip.npm=true
* <p>2. For JUnit 5 test, use {@link ExtendWith}: | ||
* | ||
* <pre>{@code | ||
* @ExtendWith(MiniClusterExtension.class) |
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.
Where to use it? at class level?
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
@@ -135,14 +140,46 @@ | |||
MiniClusterWithClientResource.class, Rule.class)); | |||
} | |||
|
|||
private static DescribedPredicate<JavaClass> inFlinkRuntimePackages() { | |||
return JavaClass.Predicates.resideInAPackage("org.apache.flink.runtime.*"); |
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.
import static?
/** | ||
* An extension which starts a {@link MiniCluster} for testing purposes. | ||
* | ||
* <p>This should only be used by tests within the flink-runtime module. Other modules should use |
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.
Could you add more description to tell why a different MiniClusterExtension is required explicitly for flink-runtime and the same MiniClusterExtension can not be used by other modules? I think the idea of using @InjectMiniCluster is excellent and could be very useful for tests in other modules beyond flink-runtime too.
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.
MiniClusterExtension requires flink-clients. InjectMiniCluster can also be used with the MiniClusterExtension.
Certain configuration parameters (e.g., ports) are inferred from other extensions. As extensions commonly only really start up resources in before*() methods the current approach of determining the configuration up-front imposes limitations as to whether a MiniClusterExtension can be static or not. With this change the configuration can also be passed in with a Supplier that is evaluated right before the cluster is started.
Refactors the test to make use of a static MiniClusterExtension, in preperation FLINK-26252.
What is the purpose of the change
The goal of this PR is to fix
MiniClusterWithClientExtension
(renamed toMiniClusterExtension
) to properly support parallel tests, to be used with theExtendWith
annotation and to correctly tie to the lifecycle when creating one cluster per class.Brief change log
MiniClusterExtension
to add support for parallel tests and injection of client as test parametersMiniClusterExtension
in flink-runtime to avoid confusion and misusages