-
Notifications
You must be signed in to change notification settings - Fork 4.5k
This PR fixes a critical JUnit 5 compatibility issue where TestPipeline.run() would throw an IllegalStateException about missing @Rule annotation even when using the proper TestPipelineExtension for JUnit 5.
#36254
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
This PR fixes a critical JUnit 5 compatibility issue where TestPipeline.run() would throw an IllegalStateException about missing @Rule annotation even when using the proper TestPipelineExtension for JUnit 5.
#36254
Conversation
- Fix TestPipeline to detect JUnit 5 context and set default enforcement - Fix TestPipelineExtension to avoid duplicate enforcement creation - Add comprehensive JUnit 5 compatibility and interoperability tests - Update CHANGELOG.md with bugfix entry Resolves IllegalStateException about missing @rule annotation when using TestPipelineExtension with JUnit 5. Maintains full backward compatibility with existing JUnit 4 usage patterns. Fixes: TestPipeline.run() now works seamlessly with JUnit 5 TestPipelineExtension
Summary of ChangesHello @chennu2020, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a long-standing compatibility issue preventing Apache Beam's "TestPipeline" from working seamlessly with JUnit 5's "TestPipelineExtension". The core problem stemmed from "TestPipeline"'s internal validation expecting JUnit 4's "@rule" annotation even in a JUnit 5 context. The solution involves enhancing "TestPipeline" to intelligently detect its execution environment and adapt its enforcement logic, while also refining "TestPipelineExtension" to better coordinate with "TestPipeline"'s internal mechanisms. This ensures that developers can now use "TestPipeline" with JUnit 5 without encountering "IllegalStateException"s, maintaining full backward compatibility with JUnit 4, and significantly improving the testing experience for Beam users. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment |
| * TestPipelineExtension. This is used to provide JUnit 5 compatibility without breaking JUnit 4 | ||
| * behavior. | ||
| */ | ||
| private boolean isJUnit5Context() { |
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.
This looks like an ad-hoc fix. There should be a cleaner way to do this (than bump stack trace and check class name). Let me also do some experiments.
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.
opened #36258
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.
Thank you
Issue
When using Apache Beam's
TestPipelineExtensionwith JUnit 5, tests would fail with:Root Cause Analysis
TestPipeline Internal Validation: The
TestPipelineclass had internal validation logic that expected the@Ruleannotation to be present, even when used in JUnit 5 context throughTestPipelineExtension.Enforcement Coordination Issue: The
TestPipelineExtensionwas creating duplicate enforcement mechanisms that conflicted withTestPipeline's internal enforcement, leading to coordination problems.JUnit 5 Context Detection:
TestPipelinelacked proper detection of JUnit 5 execution context, causing it to apply JUnit 4-specific validation rules inappropriately.Solution Implementation
1. Enhanced TestPipeline.java
File:
sdks/java/core/src/main/java/org/apache/beam/sdk/testing/TestPipeline.javaKey Changes:
run()method to set default enforcement when running in JUnit 5 context2. Improved TestPipelineExtension.java
File:
sdks/java/testing/junit/src/main/java/org/apache/beam/sdk/testing/TestPipelineExtension.javaKey Changes:
enableAbandonedNodeEnforcement(true)setDeducedEnforcementLevel()to prevent conflictsTestPipelinehandle its own enforcement mechanism instead of creating separate extension enforcement3. Comprehensive Test Coverage
Files:
TestPipelineJUnit5CompatibilityTest.java- New comprehensive JUnit 5 compatibility testsTestPipelineJUnit4And5InteroperabilityTest.java- Interoperability validation testsTest Coverage:
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, commentfixes #<ISSUE NUMBER>instead.CHANGES.mdwith noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.
To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md
GitHub Actions Tests Status (on master branch)
See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.