You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "mimaison (via GitHub)" <gi...@apache.org> on 2023/02/01 15:53:05 UTC

[GitHub] [kafka] mimaison commented on a diff in pull request #13136: KAFKA-14582: Move JmxTool to tools

mimaison commented on code in PR #13136:
URL: https://github.com/apache/kafka/pull/13136#discussion_r1093412947


##########
tools/src/test/java/org/apache/kafka/tools/JmxToolTest.java:
##########
@@ -0,0 +1,282 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.tools;
+
+import org.apache.kafka.common.utils.AppInfoParser;
+import org.apache.kafka.common.utils.Exit;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.remote.JMXConnectorServer;
+import javax.management.remote.JMXConnectorServerFactory;
+import javax.management.remote.JMXServiceURL;
+
+import java.lang.management.ManagementFactory;
+import java.net.ServerSocket;
+import java.rmi.registry.LocateRegistry;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class JmxToolTest {
+    private final ToolsTestUtils.MockExitProcedure exitProcedure = new ToolsTestUtils.MockExitProcedure();
+
+    private static JMXConnectorServer jmxAgent;
+    private static String jmxUrl;
+
+    @BeforeAll
+    public static void beforeAll() throws Exception {
+        int port = findRandomOpenPortOnAllLocalInterfaces();
+        jmxAgent = startJmxAgent(port);
+        jmxUrl = String.format("service:jmx:rmi:///jndi/rmi://:%d/jmxrmi", port);
+    }
+
+    @AfterAll
+    public static void afterAll() throws Exception {
+        jmxAgent.stop();
+    }
+
+    @BeforeEach
+    public void beforeEach() {
+        Exit.setExitProcedure(exitProcedure);
+    }
+
+    @AfterEach
+    public void afterEach() {
+        Exit.resetExitProcedure();
+    }
+
+    @Test
+    public void kafkaVersion() {
+        String out = executeAndGetOut("--version");
+        assertNormalExit();
+        assertEquals(AppInfoParser.getVersion(), out);

Review Comment:
   This fails when running in Intellij. The output is:
   ```
   [2023-02-01 16:49:33,671] WARN Error while loading kafka-version.properties: inStream parameter is null (org.apache.kafka.common.utils.AppInfoParser:46)
   unknown
   ```
   I guess all we could simply do `assertTrue(out.contains(AppInfoParser.getVersion()));`



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org