- 
                Notifications
    You must be signed in to change notification settings 
- Fork 9.1k
YARN-11258. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-yarn-server-common. #7437
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
Conversation
| 💔 -1 overall 
 
 This message was automatically generated. | 
| 💔 -1 overall 
 
 
 This message was automatically generated. | 
| @cnauroth Could you please help review this PR? Thank you very much! | 
| 💔 -1 overall 
 
 This message was automatically generated. | 
| private FederationStateStoreFacade facade; | ||
|  | ||
| public TestFederationCache(Class cacheClassName) { | ||
| public void initTestFederationCache(Class cacheClassName) | 
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.
Can this be made private?
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 for reviewing this PR! I will work on improving it.
| private Boolean isCachingEnabled; | ||
|  | ||
| public TestFederationStateStoreFacade(Boolean isCachingEnabled) { | ||
| public void initTestFederationStateStoreFacade(Boolean pIsCachingEnabled) | 
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.
Can this be made private?
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 will work on improving it.
| } | ||
|  | ||
| @VisibleForTesting | ||
| protected ZKFederationStateStoreOpDurations resetOpDurations() { | 
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 think I understand why the resetOpDurations changes were made. (There's a singleton instance holding state across test cases.) However, did something about JUnit 5 trigger the need for this? Is it just an unrelated bug?
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 very much for your question! it's a very good one. Apologies for the delayed response, as I've been caught up with some work in the past 1-2 days.
I have noticed a difference in behavior between Junit4 and Junit5 when running unit tests with inheritance. In Junit4, the test methods of the parent and child classes are executed separately, while in Junit5, the test methods of the parent and child classes are coupled together and executed in the child class.
- 
Junit4: The test methods of the parent and child classes are generally executed separately. If we define a test method in the parent class, the child class can inherit these methods and also define its own test methods. During execution, Junit4 will first execute the parent class's test methods, then the child class's test methods. 
- 
Junit5: In Junit5, the test methods in the parent class and the child class are executed together. The inheritance mechanism in Junit5 causes the parent class's test methods to be inherited into the child class, and by default, both the parent and child test methods are executed, with a different execution order compared to Junit4. 
This difference leads to an issue: in the TestZookeeperFederationStateStore#testMetricsInited test, my goal is to check whether the metric accumulation behaves as expected.
In Junit4, ZKFederationStateStoreOpDurations is recreated when executing the child class's tests, so the data it contains is the initial value, which matches the expected result.
However, in Junit5, due to the singleton nature of ZKFederationStateStoreOpDurations, it accumulates metric data from all methods in the unit test, leading to a result that does not meet expectations.
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.
To ensure that the unit test passes in Junit5, I added a reset method here to make the execution result match the expected outcome.
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 understand it now. Thanks for the detailed explanation!
| 🎊 +1 overall 
 
 This message was automatically generated. | 
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. Thank you, @slfan1989 .
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,LGTM @slfan1989
…ommon. (apache#7437) [JDK17] Upgrade JUnit from 4 to 5 in hadoop-yarn-server-common. Co-authored-by: Chris Nauroth <[email protected]> Co-authored-by: Hualong Zhang <[email protected]> Reviewed-by: Chris Nauroth <[email protected]> Reviewed-by: Hualong Zhang <[email protected]> Signed-off-by: Shilun Fan <[email protected]>
Description of PR
JIRA: YARN-11258. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-yarn-server-common.
How was this patch tested?
Junit Test & mvn clean test.
For code changes:
LICENSE,LICENSE-binary,NOTICE-binaryfiles?