You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-issues@hadoop.apache.org by "slfan1989 (via GitHub)" <gi...@apache.org> on 2025/03/01 01:37:02 UTC
Re: [PR] YARN-11258. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-yarn-server-common. [hadoop]
slfan1989 commented on code in PR #7437:
URL: https://github.com/apache/hadoop/pull/7437#discussion_r1976207144
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/impl/ZKFederationStateStoreOpDurations.java:
##########
@@ -236,4 +237,9 @@ public void removeStoredTokenDuration(long startTime, long endTime) {
public void getTokenByRouterStoreTokenDuration(long startTime, long endTime) {
getTokenByRouterStoreToken.add(endTime - startTime);
}
+
+ @VisibleForTesting
+ protected ZKFederationStateStoreOpDurations resetOpDurations() {
Review Comment:
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org