KAFKA-14108: Ensure both JUnit 4 and JUnit 5 tests run#12441
KAFKA-14108: Ensure both JUnit 4 and JUnit 5 tests run#12441cadonna merged 5 commits intoapache:trunkfrom
Conversation
as well?
|
|
Thanks for the PR, @clolov ! The builds have errors: |
build.gradle
Outdated
| // KAFKA-14109 | ||
| // Both engines are needed to run JUnit 4 tests alongside JUnit 5 tests. | ||
| // junit-vintage (JUnit 4) can be removed once the JUnit 4 migration is complete. | ||
| includeEngines "junit-vintage", "junit-jupiter" |
There was a problem hiding this comment.
We don't want to do this for all modules since most of them have already been converted.
There was a problem hiding this comment.
Is there a disadvantage/side-effect if we do it for all the modules?
From what I understand (please correct me if I am wrong), loading the vintage engine for JUnit5 tests won't have any side effects since they would be run with jupiter engine anyways. Vintage engine only runs Junit4 tests in a Junit5 platform. It does not impact already converted Junit5 tests running on Junit5 platform.
I am advocating for this because it keeps the changes minimal and simplified here. Given that it is a temporary transient stage (we already have PRs out for most of the test conversion to JUnit5), I would preferr minimal changes so that reverting them is easier.
|
@clolov I also found a mistake in #12285: instead of otherwise the test does not run wince the topic name contains illegal characters. |
build.gradle
Outdated
| if (shouldUseJUnit5) { | ||
| useJUnitPlatform { | ||
| includeTags "integration" | ||
| // KAFKA-14109 |
There was a problem hiding this comment.
We don't typically include jira references in the code like this (it pollutes the code and goes stale typically).
There was a problem hiding this comment.
Addressed the comment in the latest revision.
gradle/dependencies.gradle
Outdated
| // KAFKA-14109 | ||
| // The below dependency is needed for compiling JUnit 4 tests. | ||
| // It can be safely removed once all of streams has moved to JUnit 5. | ||
| junit4: "junit:junit:$versions.junit4", |
There was a problem hiding this comment.
This explanation is odd - compilation works currently and we don't have this dependency.
There was a problem hiding this comment.
I did some tests and discovered that junitVintageEngine pulls in JUnit 4. That means if we move junitVintageEngine back to the testImplementation dependencies compilation of JUnit4 tests works.
There was a problem hiding this comment.
That makes sense. There should be no need for depending on the old junit4 jars directly.
There was a problem hiding this comment.
Removed the dependency in latest revision.
build.gradle
Outdated
| if (shouldUseJUnit5) { | ||
| useJUnitPlatform { | ||
| includeTags "integration" | ||
| // KAFKA-14109 |
build.gradle
Outdated
| useJUnitPlatform { | ||
| includeTags "integration" | ||
| // KAFKA-14109 | ||
| // Both engines are needed to run JUnit 4 tests alongside JUnit 5 tests. | ||
| // junit-vintage (JUnit 4) can be removed once the JUnit 4 migration is complete. | ||
| includeEngines "junit-vintage", "junit-jupiter" | ||
| } |
There was a problem hiding this comment.
I experimented a bit and found the following solution.
| useJUnitPlatform { | |
| includeTags "integration" | |
| // KAFKA-14109 | |
| // Both engines are needed to run JUnit 4 tests alongside JUnit 5 tests. | |
| // junit-vintage (JUnit 4) can be removed once the JUnit 4 migration is complete. | |
| includeEngines "junit-vintage", "junit-jupiter" | |
| } | |
| if (project.name.equals('streams')) { | |
| useJUnitPlatform { | |
| includeTags "integration" | |
| includeTags 'org.apache.kafka.test.IntegrationTest' | |
| includeEngines "junit-vintage", "junit-jupiter" | |
| } | |
| } else { | |
| useJUnitPlatform { | |
| includeTags "integration" | |
| } | |
| } |
In this way, we can limit the change to Streams.
The caveat is that we need to replace @Category({IntegrationTest.class}) with @Tag{"integration"} in the integration tests that have already been migrated to JUnit 5.
There was a problem hiding this comment.
Made the changes as suggested. Please see latest revision.
build.gradle
Outdated
| useJUnitPlatform { | ||
| excludeTags "integration" | ||
| // KAFKA-14109 | ||
| // Both engines are needed to run JUnit 4 tests alongside JUnit 5 tests. | ||
| // junit-vintage (JUnit 4) can be removed once the JUnit 4 migration is complete. | ||
| includeEngines "junit-vintage", "junit-jupiter" | ||
| } |
There was a problem hiding this comment.
Here we can do similar as above but excluding the tags.
| useJUnitPlatform { | |
| excludeTags "integration" | |
| // KAFKA-14109 | |
| // Both engines are needed to run JUnit 4 tests alongside JUnit 5 tests. | |
| // junit-vintage (JUnit 4) can be removed once the JUnit 4 migration is complete. | |
| includeEngines "junit-vintage", "junit-jupiter" | |
| } | |
| if (project.name.equals('streams')) { | |
| useJUnitPlatform { | |
| excludeTags "integration" | |
| excludeTags 'org.apache.kafka.test.IntegrationTest' | |
| includeEngines "junit-vintage", "junit-jupiter" | |
| } | |
| } else { | |
| useJUnitPlatform { | |
| excludeTags "integration" | |
| } | |
| } |
build.gradle
Outdated
| // KAFKA-14109 | ||
| // The below compileOnly dependency is needed for JUnit 4 tests. | ||
| // It can be safely removed once all of streams has moved to JUnit 5. | ||
| testCompileOnly libs.junit4 | ||
|
|
There was a problem hiding this comment.
As we said below this is not needed if you move libs.junitVintageEngine back to testImplementation.
build.gradle
Outdated
| testImplementation libs.junitJupiterApi | ||
| testImplementation libs.junitVintageEngine | ||
| testImplementation libs.junitJupiter | ||
| testImplementation libs.junitJupiterParams // needed for parameterized tests |
There was a problem hiding this comment.
I would prefer to add this when we need it during the migration of the parametrized tests. But I am also fine if it stays.
The inline comment is not needed.
There was a problem hiding this comment.
I have removed this right now to keep this PR simple. Will add when needed.
|
@divijvaidya That would be great, because I start feeling uncomfortable having some integration tests not running on the builds. |
|
@divijvaidya Regarding your question
Yes, we need. |
Changes
ResultsResult of executing BeforeAfterNote
CommentsAddressed concerns from @ijuma:
Addressed concerns from @cadonna
Next steps (separate PRs, in order)
|
|
@divijvaidya Thank you for the updates! I am afraid you did a mistake when generating the test reports to test the changes. You changed task In my tests yesterday, I experienced that you cannot use |
This reverts commit e5faaf9.
| @BeforeEach | ||
| public void before(final TestInfo testInfo) throws Exception { | ||
| sourceTopic = SOURCE_TOPIC + "-" + testInfo.getTestMethod().map(Method::getName); | ||
| sourceTopic = SOURCE_TOPIC + "-" + IntegrationTestUtils.safeUniqueTestName(getClass(), testInfo); |
There was a problem hiding this comment.
Note that the test fails without this change.
There was a problem hiding this comment.
Yeah, thank you! That is known. See #12441 (comment)
|
Updated the code. @cadonna should be ready for your review once the test run is complete. Result for
|
|
@divijvaidya Thanks a lot for the update! This looks good! However, there are some checkstyle issues due to some unused imports. Could you fix those? |
There was a problem hiding this comment.
Thanks @divijvaidya and @clolov !
LGTM!
Once the builds are acceptable and I verified that they run the tests written in JUnit 5, I will merge this PR.
|
I verified that all Streams' tests are run in the builds and I also verified that the tests of other modules are run in the builds. |
|
Build failures are unrelated. |
…(5 August 2022) Version related conflicts: * Jenkinsfile * gradle.properties * streams/quickstart/java/pom.xml * streams/quickstart/java/src/main/resources/archetype-resources/pom.xml * streams/quickstart/pom.xml * tests/kafkatest/__init__.py * tests/kafkatest/version.py * commit 'add7cd85baa61cd0e1430': (66 commits) KAFKA-14136 Generate ConfigRecord for brokers even if the value is unchanged (apache#12483) HOTFIX / KAFKA-14130: Reduce RackAwarenesssTest to unit Test (apache#12476) MINOR: Remove ARM/PowerPC builds from Jenkinsfile (apache#12380) KAFKA-14111 Fix sensitive dynamic broker configs in KRaft (apache#12455) KAFKA-13877: Fix flakiness in RackAwarenessIntegrationTest (apache#12468) KAFKA-14129: KRaft must check manual assignments for createTopics are contiguous (apache#12467) KAFKA-13546: Do not fail connector validation if default topic creation group is explicitly specified (apache#11615) KAFKA-14122: Fix flaky test DynamicBrokerReconfigurationTest#testKeyStoreAlter (apache#12452) MINOR; Use right enum value for broker registration change (apache#12236) MINOR; Synchronize access to snapshots' TreeMap (apache#12464) MINOR; Bump trunk to 3.4.0-SNAPSHOT (apache#12463) MINOR: Stop logging 404s at ERROR level in Connect KAFKA-14095: Improve handling of sync offset failures in MirrorMaker (apache#12432) Minor: enable index for emit final sliding window (apache#12461) MINOR: convert some more junit tests to support KRaft (apache#12456) KAFKA-14108: Ensure both JUnit 4 and JUnit 5 tests run (apache#12441) MINOR: Remove code of removed metric (apache#12453) MINOR: Update comment on verifyTaskGenerationAndOwnership method in DistributedHerder KAFKA-14012: Add warning to closeQuietly documentation about method references of null objects (apache#12321) MINOR: Fix static mock usage in ThreadMetricsTest (apache#12454) ...






This pull request addresses the problem reported in #12285 and tracked in https://issues.apache.org/jira/browse/KAFKA-14108