You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "xijiu (via GitHub)" <gi...@apache.org> on 2024/07/08 12:35:04 UTC
[PR] MINOR: Increase some unit tests for utils [kafka]
xijiu opened a new pull request, #16549:
URL: https://github.com/apache/kafka/pull/16549
Hello, I noticed that some methods in the `Utils.java` class lack corresponding unit tests when I was reading the code, so added them.
### Committer Checklist (excluded from commit message)
- [ ] Verify design and implementation
- [ ] Verify test coverage and CI build status
- [ ] Verify documentation (including upgrade notes)
--
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: Increase some unit tests for utils [kafka]
Posted by "xijiu (via GitHub)" <gi...@apache.org>.
xijiu commented on PR #16549:
URL: https://github.com/apache/kafka/pull/16549#issuecomment-2216139424
> @xijiu, Thanks for your comments, I leaved some comments
@m1a2st
Thanks for your code review. They are all very helpful. I have fixed all of them, please review again.
--
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: Increase some unit tests for utils [kafka]
Posted by "m1a2st (via GitHub)" <gi...@apache.org>.
m1a2st commented on code in PR #16549:
URL: https://github.com/apache/kafka/pull/16549#discussion_r1669482604
##########
clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java:
##########
@@ -448,6 +449,87 @@ public void testMin() {
assertEquals(1, Utils.min(2, 3, 1));
}
+ @Test
+ public void testMax() {
+ assertEquals(1, Utils.max(1));
+ assertEquals(3, Utils.max(1, 2, 3));
+ assertEquals(3, Utils.max(2, 1, 3, 3));
+ assertEquals(100, Utils.max(0, 2, 2, 100));
+ assertEquals(-1, Utils.max(-1, -2, -2, -10, -100, -1000));
+ assertEquals(0, Utils.max(-1, -2, -2, -10, -150, -1800, 0));
+ }
+
+ @Test
+ public void mkStringTest() {
+ Map<String, String> map = new LinkedHashMap<>();
+ map.put("key1", "val1");
+ map.put("key2", "val2");
+ map.put("key3", "val3");
+ String result = Utils.mkString(map, "__begin__", "__end__", "=", ",");
+ assertEquals("__begin__key1=val1,key2=val2,key3=val3__end__", result);
+
+ String result2 = Utils.mkString(new HashMap<>(), "__begin__", "__end__", "=", ",");
+ assertEquals("__begin____end__", result2);
+
+ String result3 = Utils.mkString(null, "__begin__", "__end__", "=", ",");
+ assertEquals("__begin____end__", result3);
+
+ map.clear();
+ map.put("key4", "val4");
+ map.put("key5", "val5");
+ String result4 = Utils.mkString(map, null, null, " : ", ";");
+ assertEquals("key4 : val4;key5 : val5", result4);
+
+ map.clear();
+ map.put("key6", "val6");
+ String result5 = Utils.mkString(map, null, null, " : ", ";");
+ assertEquals("key6 : val6", result5);
Review Comment:
Could you add a scenario for `keyValueSeparator` or `elementSeparator` is null
##########
clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java:
##########
@@ -448,6 +449,87 @@ public void testMin() {
assertEquals(1, Utils.min(2, 3, 1));
}
+ @Test
+ public void testMax() {
+ assertEquals(1, Utils.max(1));
+ assertEquals(3, Utils.max(1, 2, 3));
+ assertEquals(3, Utils.max(2, 1, 3, 3));
+ assertEquals(100, Utils.max(0, 2, 2, 100));
+ assertEquals(-1, Utils.max(-1, -2, -2, -10, -100, -1000));
+ assertEquals(0, Utils.max(-1, -2, -2, -10, -150, -1800, 0));
+ }
+
+ @Test
+ public void mkStringTest() {
+ Map<String, String> map = new LinkedHashMap<>();
+ map.put("key1", "val1");
+ map.put("key2", "val2");
+ map.put("key3", "val3");
+ String result = Utils.mkString(map, "__begin__", "__end__", "=", ",");
+ assertEquals("__begin__key1=val1,key2=val2,key3=val3__end__", result);
+
+ String result2 = Utils.mkString(new HashMap<>(), "__begin__", "__end__", "=", ",");
+ assertEquals("__begin____end__", result2);
+
+ String result3 = Utils.mkString(null, "__begin__", "__end__", "=", ",");
+ assertEquals("__begin____end__", result3);
+
+ map.clear();
+ map.put("key4", "val4");
+ map.put("key5", "val5");
+ String result4 = Utils.mkString(map, null, null, " : ", ";");
+ assertEquals("key4 : val4;key5 : val5", result4);
+
+ map.clear();
+ map.put("key6", "val6");
+ String result5 = Utils.mkString(map, null, null, " : ", ";");
+ assertEquals("key6 : val6", result5);
+ }
+
+ @Test
+ public void parseMapTest() {
+ Map<String, String> map1 = Utils.parseMap("k1=v1,k2=v2,k3=v3", "=", ",");
+ assertEquals(3, map1.size());
+ assertTrue(map1.containsKey("k1"));
+ assertTrue(map1.containsKey("k2"));
+ assertTrue(map1.containsKey("k3"));
+ assertTrue(map1.containsValue("v1"));
+ assertTrue(map1.containsValue("v2"));
+ assertTrue(map1.containsValue("v3"));
Review Comment:
I think to test `k1` key get value is equals to `v2` is more better, WDTY
##########
clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java:
##########
@@ -448,6 +449,87 @@ public void testMin() {
assertEquals(1, Utils.min(2, 3, 1));
}
+ @Test
+ public void testMax() {
+ assertEquals(1, Utils.max(1));
+ assertEquals(3, Utils.max(1, 2, 3));
+ assertEquals(3, Utils.max(2, 1, 3, 3));
+ assertEquals(100, Utils.max(0, 2, 2, 100));
+ assertEquals(-1, Utils.max(-1, -2, -2, -10, -100, -1000));
+ assertEquals(0, Utils.max(-1, -2, -2, -10, -150, -1800, 0));
+ }
+
+ @Test
+ public void mkStringTest() {
+ Map<String, String> map = new LinkedHashMap<>();
+ map.put("key1", "val1");
+ map.put("key2", "val2");
+ map.put("key3", "val3");
+ String result = Utils.mkString(map, "__begin__", "__end__", "=", ",");
+ assertEquals("__begin__key1=val1,key2=val2,key3=val3__end__", result);
+
+ String result2 = Utils.mkString(new HashMap<>(), "__begin__", "__end__", "=", ",");
Review Comment:
`Collections.emptyMap()` is better
##########
clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java:
##########
@@ -448,6 +449,87 @@ public void testMin() {
assertEquals(1, Utils.min(2, 3, 1));
}
+ @Test
+ public void testMax() {
+ assertEquals(1, Utils.max(1));
+ assertEquals(3, Utils.max(1, 2, 3));
+ assertEquals(3, Utils.max(2, 1, 3, 3));
+ assertEquals(100, Utils.max(0, 2, 2, 100));
+ assertEquals(-1, Utils.max(-1, -2, -2, -10, -100, -1000));
+ assertEquals(0, Utils.max(-1, -2, -2, -10, -150, -1800, 0));
+ }
+
+ @Test
+ public void mkStringTest() {
+ Map<String, String> map = new LinkedHashMap<>();
+ map.put("key1", "val1");
+ map.put("key2", "val2");
+ map.put("key3", "val3");
+ String result = Utils.mkString(map, "__begin__", "__end__", "=", ",");
+ assertEquals("__begin__key1=val1,key2=val2,key3=val3__end__", result);
+
+ String result2 = Utils.mkString(new HashMap<>(), "__begin__", "__end__", "=", ",");
+ assertEquals("__begin____end__", result2);
+
+ String result3 = Utils.mkString(null, "__begin__", "__end__", "=", ",");
+ assertEquals("__begin____end__", result3);
+
+ map.clear();
+ map.put("key4", "val4");
+ map.put("key5", "val5");
+ String result4 = Utils.mkString(map, null, null, " : ", ";");
+ assertEquals("key4 : val4;key5 : val5", result4);
+
+ map.clear();
+ map.put("key6", "val6");
+ String result5 = Utils.mkString(map, null, null, " : ", ";");
+ assertEquals("key6 : val6", result5);
+ }
+
+ @Test
+ public void parseMapTest() {
+ Map<String, String> map1 = Utils.parseMap("k1=v1,k2=v2,k3=v3", "=", ",");
+ assertEquals(3, map1.size());
+ assertTrue(map1.containsKey("k1"));
+ assertTrue(map1.containsKey("k2"));
+ assertTrue(map1.containsKey("k3"));
+ assertTrue(map1.containsValue("v1"));
+ assertTrue(map1.containsValue("v2"));
+ assertTrue(map1.containsValue("v3"));
+
+ Map<String, String> map2 = Utils.parseMap(null, "=", ",");
+ assertEquals(0, map2.size());
+
+ Map<String, String> map3 = Utils.parseMap("k4=v4,k5=v5=vv5=vvv5", "=", ",");
+ assertEquals(2, map3.size());
+ assertTrue(map3.containsKey("k4"));
+ assertTrue(map3.containsKey("k5"));
+ assertTrue(map3.containsValue("v4"));
+ assertTrue(map3.containsValue("v5=vv5=vvv5"));
Review Comment:
I think to test `k5` key get value is equals to`v5=vv5=vvv5` is more better, WDTY
--
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: Increase some unit tests for utils [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 merged PR #16549:
URL: https://github.com/apache/kafka/pull/16549
--
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