You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "m1a2st (via GitHub)" <gi...@apache.org> on 2026/04/11 16:42:18 UTC

[PR] MINOR: Move KafkaMetricsGroupTest from Scala to Java [kafka]

m1a2st opened a new pull request, #22028:
URL: https://github.com/apache/kafka/pull/22028

   Rewrite by Java
   


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


Re: [PR] MINOR: Move KafkaMetricsGroupTest from Scala to Java [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison merged PR #22028:
URL: https://github.com/apache/kafka/pull/22028


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


Re: [PR] MINOR: Move KafkaMetricsGroupTest from Scala to Java [kafka]

Posted by "m1a2st (via GitHub)" <gi...@apache.org>.
m1a2st commented on code in PR #22028:
URL: https://github.com/apache/kafka/pull/22028#discussion_r3068288649


##########
server-common/src/test/java/org/apache/kafka/server/metrics/KafkaMetricsGroupTest.java:
##########
@@ -20,18 +20,59 @@
 
 import org.junit.jupiter.api.Test;
 
+import java.util.LinkedHashMap;
 import java.util.Map;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
 
 public class KafkaMetricsGroupTest {
+
+    @Test
+    public void testUntaggedMetricName() {
+        KafkaMetricsGroup metricsGroup = new KafkaMetricsGroup("kafka.metrics", "TestMetrics");
+        MetricName metricName = metricsGroup.metricName("TaggedMetric", Map.of());
+
+        assertEquals("kafka.metrics", metricName.getGroup());
+        assertEquals("TestMetrics", metricName.getType());
+        assertEquals("TaggedMetric", metricName.getName());
+        assertEquals("kafka.metrics:type=TestMetrics,name=TaggedMetric", metricName.getMBeanName());
+        assertNull(metricName.getScope());
+    }
+
+    @Test
+    public void testTaggedMetricName() {
+        LinkedHashMap<String, String> tags = new LinkedHashMap<>();
+        tags.put("foo", "bar");
+        tags.put("bar", "baz");
+        tags.put("baz", "raz.taz");
+
+        KafkaMetricsGroup metricsGroup = new KafkaMetricsGroup("kafka.metrics", "TestMetrics");
+        MetricName metricName = metricsGroup.metricName("TaggedMetric", tags);
+
+        assertEquals("kafka.metrics", metricName.getGroup());
+        assertEquals("TestMetrics", metricName.getType());
+        assertEquals("TaggedMetric", metricName.getName());
+        assertEquals("kafka.metrics:type=TestMetrics,name=TaggedMetric,foo=bar,bar=baz,baz=raz.taz",
+                metricName.getMBeanName());
+        assertEquals("bar.baz.baz.raz_taz.foo.bar", metricName.getScope());
+    }
+
     @Test
-    public void testConstructorWithPackageAndSimpleName() {
-        String packageName = "testPackage";
-        String simpleName = "testSimple";
-        KafkaMetricsGroup group = new KafkaMetricsGroup(packageName, simpleName);
-        MetricName metricName = group.metricName("metric-name", Map.of());
-        assertEquals(packageName, metricName.getGroup());
-        assertEquals(simpleName, metricName.getType());

Review Comment:
   Since this test is covered by `testUntaggedMetricName`, removed it



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