0xffff-zhiyan commented on code in PR #20481:
URL: https://github.com/apache/kafka/pull/20481#discussion_r2438258832


##########
core/src/test/scala/kafka/server/KafkaRequestHandlerTest.scala:
##########
@@ -698,4 +699,94 @@ class KafkaRequestHandlerTest {
     // cleanup
     brokerTopicStats.close()
   }
+
+  @Test
+  def testRequestThreadMetrics(): Unit = {
+    val time = Time.SYSTEM
+    val metricsBroker = new RequestChannelMetrics(java.util.Set.of[ApiKeys])
+    val metricsController = new 
RequestChannelMetrics(java.util.Set.of[ApiKeys])
+    val requestChannelBroker = new RequestChannel(10, time, metricsBroker)
+    val requestChannelController = new RequestChannel(10, time, 
metricsController)
+    val apiHandler = mock(classOf[ApiRequestHandler])
+
+    // Reset global shared counter for test
+    KafkaRequestHandlerPool.aggregateThreads.set(0)
+    
+    // Create broker pool with 4 threads
+    val brokerPool = new KafkaRequestHandlerPool(
+      0,
+      requestChannelBroker,
+      apiHandler,
+      time,
+      4,
+      "broker"
+    )
+
+    // Verify global counter is updated
+    assertEquals(4, KafkaRequestHandlerPool.aggregateThreads.get, "global 
counter should be 4 after broker pool")
+
+    // Create controller pool with 4 threads
+    val controllerPool = new KafkaRequestHandlerPool(
+      0,
+      requestChannelController,
+      apiHandler,
+      time,
+      4,
+      "controller"
+    )
+
+    // Verify global counter is updated to sum of both pools
+    assertEquals(8, KafkaRequestHandlerPool.aggregateThreads.get, "global 
counter should be 8 after both pools")
+
+    try {
+      val aggregateMeterField = 
classOf[KafkaRequestHandlerPool].getDeclaredField("aggregateIdleMeter")
+      aggregateMeterField.setAccessible(true)
+      val aggregateMeter = 
aggregateMeterField.get(brokerPool).asInstanceOf[Meter]
+
+      val perPoolIdleMeterField = 
classOf[KafkaRequestHandlerPool].getDeclaredField("perPoolIdleMeter")
+      perPoolIdleMeterField.setAccessible(true)
+      val brokerPerPoolIdleMeter = 
perPoolIdleMeterField.get(brokerPool).asInstanceOf[Meter]
+      val controllerPerPoolIdleMeter = 
perPoolIdleMeterField.get(controllerPool).asInstanceOf[Meter]
+
+      var aggregateValue = 0.0
+      var brokerPerPoolValue = 0.0
+      var controllerPerPoolValue = 0.0
+
+      Thread.sleep(2000)

Review Comment:
   removed



-- 
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]

Reply via email to