architjainjain commented on code in PR #6501:
URL: https://github.com/apache/hive/pull/6501#discussion_r3719077895
##########
ql/src/test/org/apache/hadoop/hive/ql/exec/tez/TestTezSessionState.java:
##########
@@ -133,4 +137,122 @@ void openInternalUnsafe(boolean isAsync,
SessionState.LogHelper console) {
sessionStateForTest.open(resources);
}
+
+ /**
+ * Tests that YarnClient is NOT initialized when queue metrics are disabled
(default: interval=0).
+ * This ensures zero overhead when the feature is disabled.
+ */
+ @Test
+ public void testYarnClientNotInitializedWhenMetricsDisabled() {
+ SessionState ss = createSessionState();
+ HiveConf hiveConf = ss.getConf();
+
+ // Default config: queue metrics disabled (interval = 0)
+ Assert.assertEquals("Default interval should be 0 (disabled)",
+ 0, HiveConf.getTimeVar(hiveConf,
HiveConf.ConfVars.HIVE_TEZ_QUEUE_METRICS_REFRESH_INTERVAL,
TimeUnit.MILLISECONDS));
+
+ TezSessionState sessionState = new TezSessionState(ss.getSessionId(),
hiveConf);
+
+ // Mock a TezClient and set it
+ TezClient mockTezClient = Mockito.mock(TezClient.class);
+ sessionState.setTezClient(mockTezClient);
+
+ // getYarnClient() should return null when metrics disabled
+ YarnClient yarnClient = sessionState.getYarnClient();
+ Assert.assertNull("YarnClient should not be initialized when queue metrics
are disabled", yarnClient);
+ }
+
+ /**
+ * Tests that YarnClient IS lazily initialized when queue metrics are
enabled.
+ * This ensures the client is created only when needed.
+ */
+ @Test
+ public void testYarnClientLazilyInitializedWhenMetricsEnabled() {
+ SessionState ss = createSessionState();
+ HiveConf hiveConf = ss.getConf();
+
+ // Enable queue metrics with a positive interval
+
hiveConf.setTimeVar(HiveConf.ConfVars.HIVE_TEZ_QUEUE_METRICS_REFRESH_INTERVAL,
10, TimeUnit.SECONDS);
+
+ TezSessionState sessionState = new TezSessionState(ss.getSessionId(),
hiveConf);
+
+ // Mock a TezClient and set it
+ TezClient mockTezClient = Mockito.mock(TezClient.class);
+ sessionState.setTezClient(mockTezClient);
Review Comment:
done
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]