chia7712 commented on code in PR #23561:
URL: https://github.com/apache/kafka/pull/23561#discussion_r4588801188


##########
tools/src/test/java/org/apache/kafka/tools/JmxToolTest.java:
##########
@@ -65,15 +79,16 @@ public static void beforeAll() throws Exception {
         env.put("com.sun.management.jmxremote.ssl", "false");
         JMXServiceURL url = new JMXServiceURL(jmxUrl);
         MBeanServer server = ManagementFactory.getPlatformMBeanServer();
-        server.registerMBean(new Metrics(),
+        jmxFixture = new JmxFixture(server,
             new 
ObjectName("kafka.server:type=BrokerTopicMetrics,name=MessagesInPerSec"));
-        jmxAgent = JMXConnectorServerFactory.newJMXConnectorServer(url, env, 
server);
-        jmxAgent.start();
+        jmxFixture.start(() -> 
JMXConnectorServerFactory.newJMXConnectorServer(url, env, server));
     }
 
     @AfterAll
     public static void afterAll() throws Exception {
-        jmxAgent.stop();
+        if (jmxFixture != null) {
+            jmxFixture.close();

Review Comment:
   Maybe we could just drop the metrics in this final hook instead of 
introducing the new mechanism?
   
   ```java
       @AfterAll
       public static void afterAll() throws Exception {
           jmxAgent.stop();
           ManagementFactory.getPlatformMBeanServer().unregisterMBean(
                   new 
ObjectName("kafka.server:type=BrokerTopicMetrics,name=MessagesInPerSec"));
       }
   ```



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