KAFKA-12173 Migrate streams:streams-scala module to JUnit 5#9858
KAFKA-12173 Migrate streams:streams-scala module to JUnit 5#9858chia7712 merged 8 commits intoapache:trunkfrom
Conversation
|
This PR is huge and contains a lot of reformatting. Is this required? Very tedious to review. Why are there so many Java class changes -- this PR does not migrate Java tests to JUnit5? Could this PR be split into multiple smaller ones to make it easier to review? |
vvcephei
left a comment
There was a problem hiding this comment.
Woah, thanks for all this work, @chia7712 !
I agree it's a little on the large side for a PR, but it looks like it was necessary, since changing EmbeddedKafkaCluster dragged in all the integration tests.
I'm assuming we had to ditch Scalatest stuff like Flatspec because the JUnitRunner isn't compatible with JUnit5? It's fine with me either way. We were writing those Scala tests in exactly the same way we write the Java ones, might as well use the same testing framework, too.
All in all, these changes look good to me. Please feel free to merge whenever you're satisfied with the test results, and thanks again, @chia7712 !
|
@mjsax Sorry for lazy response. I did not notice your feedback until @vvcephei touch this PR :(
We are migrate code to Junit 5 by module in order to avoid huge patch (although this patch is still big ...). The root cause of making this tedious patch is that |
|
@vvcephei Thanks for your feedback. I will fix conflicting files. |
) 1. replace org.junit.Assert by org.junit.jupiter.api.Assertions 2. replace org.junit by org.junit.jupiter.api 3. replace Before by BeforeEach 4. replace After by AfterEach 5. remove ExternalResource from all scala modules 6. add explicit AfterClass/BeforeClass to stop/start EmbeddedKafkaCluster Noted that this PR does not migrate stream module to junit 5 so it does not introduce callback of junit 5 to deal with beforeAll/afterAll. The next PR of migrating stream module can replace explicit beforeAll/afterAll by junit 5 extension. Or we can keep the beforeAll/afterAll if it make code more readable. Reviewers: John Roesler <vvcephei@apache.org>
|
|
||
| @AfterClass | ||
| public static void closeCluster() { | ||
| CLUSTER.stop(); |
There was a problem hiding this comment.
Hey @chia7712 , sorry for never bothering to take a look at this PR until just now, but I had a question about this. I know it was necessary to remove the ExternalResource feature that used to be responsible for calling start() and stop() for us in the integration tests since @ClassRule was removed in JUnit5, but that was really quite a loss since this now leaves us vulnerable to
- resource leaks due to forgetting to clean up the EmbeddedKafkaCluster in an integration test, or doing so in an incorrect way (eg such that a test failure might skip the cleanup stage, a mistake that we've certainly encountered in our tests in the past)
- breaking compatibility of integration tests across older branches, so that if we ever need to backport a fix that includes an integration test -- which many will/should do -- we can easily break the build of older branches by accident. See for example #11257: aka the reason I started digging into this 🙂 . Even if we remember to fix this during the backport, it's just an extra hassle.
Now I'm certainly not an expert in all things JUnit, but a cursory glance suggests we can replicate the old behavior in which the EmbeddedKafkaCluster is automatically started/stopped without the need for this @Before/AfterClass boilerplate code in every integration test. I believe it's possible to do so using the @Extension/ExtendWith annotations. Can we try to port the EmbeddedKafkaCluster back to an automated lifecycle with these so we can clean up the Streams integration tests?
cc @ijuma @vvcephei who may be more familiar with these constructs and how/when/why to use them
There was a problem hiding this comment.
cc also @showuon -- would you be interested in taking a shot at this?
There was a problem hiding this comment.
https://issues.apache.org/jira/browse/KAFKA-13230 is created for this issue. Need more discussion to make sure what we really want.
issue: https://issues.apache.org/jira/browse/KAFKA-12173
org.junit.Assertbyorg.junit.jupiter.api.Assertionsorg.junitbyorg.junit.jupiter.apiBeforebyBeforeEachAfterbyAfterEachExternalResourcefrom all scala modulesAfterClass/BeforeClassto stop/startEmbeddedKafkaClusterNoted that this PR does not migrate stream module to junit 5 so it does not introduce callback of junit 5 to deal with beforeAll/afterAll. The next PR of migrating stream module can replace explicit beforeAll/afterAll by junit 5 extension. Or we can keep the beforeAll/afterAll if it make code more readable.
Committer Checklist (excluded from commit message)