You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2020/11/28 05:06:13 UTC

[GitHub] [kafka] chia7712 commented on a change in pull request #9659: KAFKA-10770: Remove duplicate defination of Metrics#getTags

chia7712 commented on a change in pull request #9659:
URL: https://github.com/apache/kafka/pull/9659#discussion_r531876293



##########
File path: clients/src/main/java/org/apache/kafka/common/metrics/internals/MetricsUtils.java
##########
@@ -43,4 +47,20 @@ public static double convert(long timeMs, TimeUnit unit) {
                 throw new IllegalStateException("Unknown unit: " + unit);
         }
     }
+
+    /**
+     * Create a set of tags using the supplied key and value pairs. The order of the tags will be kept.
+     *
+     * @param keyValue the key and value pairs for the tags; must be an even number
+     * @return the map of tags that can be supplied to the {@link Metrics} methods; never null
+     */
+    public static Map<String, String> getTags(String... keyValue) {
+        if ((keyValue.length % 2) != 0)
+            throw new IllegalArgumentException("keyValue needs to be specified in pairs");
+        Map<String, String> tags = new LinkedHashMap<>();

Review comment:
       Could you set the initial capability?

##########
File path: clients/src/test/java/org/apache/kafka/common/metrics/internals/MetricsUtilsTest.java
##########
@@ -0,0 +1,39 @@
+/*
+ * 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.common.metrics.internals;
+
+import org.junit.Test;
+
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+
+public class MetricsUtilsTest {
+
+    @Test
+    public void testCreatingTags() {
+        Map<String, String> tags = MetricsUtils.getTags("k1", "v1", "k2", "v2");
+        assertEquals("v1", tags.get("k1"));
+        assertEquals("v2", tags.get("k2"));
+        assertEquals(2, tags.size());
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testCreatingTagsWithOddNumberOfTags() {
+        MetricsUtils.getTags("k1", "v1", "k2", "v2", "extra");

Review comment:
       Could you use ```assertThrows```?




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

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