You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "mingyen066 (via GitHub)" <gi...@apache.org> on 2025/01/31 13:49:06 UTC

[PR] KAFKA-18675: Add testValidBrokerList to ClientUtilsTest [kafka]

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

   Based on the discussion https://github.com/apache/kafka/pull/18741#issuecomment-2623740585
   Add unit test to ensure user can provide space-separated broker list
   
   This change need to be backported to 3.8 as well
   
   ### 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] KAFKA-18675: Add unit test to verify space separated brokers won't cause exception for 3.8 and 3.9 [kafka]

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


##########
clients/src/test/java/org/apache/kafka/clients/ClientUtilsTest.java:
##########
@@ -96,6 +100,34 @@ public void testParseAndValidateAddressesWithReverseLookup() {
         }
     }
 
+    static Stream<List<String>> provideValidBrokerAddressTestCases() {
+        return Stream.of(
+            Arrays.asList("localhost:9997", "localhost:9998", "localhost:9999"),
+            Arrays.asList("localhost:9997", "localhost:9998", " localhost:9999"),
+            // Intentionally provide a single string, as users may provide space-separated brokers, which will be parsed as a single string.
+            Arrays.asList("localhost:9997 localhost:9998 localhost:9999")
+        );
+    }
+
+    @ParameterizedTest
+    @MethodSource("provideValidBrokerAddressTestCases")
+    public void testValidBrokerAddress(List<String> addresses) {
+        assertDoesNotThrow(() -> ClientUtils.parseAndValidateAddresses(addresses, ClientDnsLookup.USE_ALL_DNS_IPS));
+    }
+
+    static Stream<List<String>> provideInvalidBrokerAddressTestCases() {
+        return Stream.of(
+            Collections.singletonList("localhost:9997\nlocalhost:9998\nlocalhost:9999")
+        );
+    }
+
+    @ParameterizedTest
+    @MethodSource("provideInvalidBrokerAddressTestCases")
+    public void testInvalidBrokerAddress(List<String> addresses) {
+        assertThrows(ConfigException.class,
+            () -> ClientUtils.parseAndValidateAddresses(addresses, ClientDnsLookup.USE_ALL_DNS_IPS));
+    }

Review Comment:
   Only test one case, why need to use `@ParameterizedTest`



-- 
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] KAFKA-18675: Add unit test to verify space separated brokers won't cause exception for 3.8 and 3.9 [kafka]

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


##########
clients/src/test/java/org/apache/kafka/clients/ClientUtilsTest.java:
##########
@@ -96,6 +100,34 @@ public void testParseAndValidateAddressesWithReverseLookup() {
         }
     }
 
+    static Stream<List<String>> provideValidBrokerAddressTestCases() {
+        return Stream.of(
+            Arrays.asList("localhost:9997", "localhost:9998", "localhost:9999"),
+            Arrays.asList("localhost:9997", "localhost:9998", " localhost:9999"),
+            // Intentionally provide a single string, as users may provide space-separated brokers, which will be parsed as a single string.
+            Arrays.asList("localhost:9997 localhost:9998 localhost:9999")
+        );
+    }
+
+    @ParameterizedTest
+    @MethodSource("provideValidBrokerAddressTestCases")
+    public void testValidBrokerAddress(List<String> addresses) {
+        assertDoesNotThrow(() -> ClientUtils.parseAndValidateAddresses(addresses, ClientDnsLookup.USE_ALL_DNS_IPS));
+    }
+
+    static Stream<List<String>> provideInvalidBrokerAddressTestCases() {
+        return Stream.of(
+            Collections.singletonList("localhost:9997\nlocalhost:9998\nlocalhost:9999")
+        );
+    }
+
+    @ParameterizedTest
+    @MethodSource("provideInvalidBrokerAddressTestCases")
+    public void testInvalidBrokerAddress(List<String> addresses) {
+        assertThrows(ConfigException.class,
+            () -> ClientUtils.parseAndValidateAddresses(addresses, ClientDnsLookup.USE_ALL_DNS_IPS));
+    }

Review Comment:
   I thought I would be convenient to add more cases. But for readibility, I will just eliminate @methodSouce



-- 
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] KAFKA-18675: Add unit test to verify space separated brokers won't cause exception for 3.8 and 3.9 [kafka]

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


##########
clients/src/test/java/org/apache/kafka/clients/ClientUtilsTest.java:
##########
@@ -96,6 +100,20 @@ public void testParseAndValidateAddressesWithReverseLookup() {
         }
     }
 
+    static Stream<List<String>> provideBrokerListTestCases() {
+        return Stream.of(
+            Arrays.asList("localhost:9997", "localhost:9998", "localhost:9999"),
+            // Intentionally provide a single string, as users may provide space-separated brokers, which will be parsed as a single string.
+            Arrays.asList("localhost:9997 localhost:9998 localhost:9999")

Review Comment:
   Unfortunately, List.of is a feature introduced in Java 9, which is not supported by Kafka 3.9 (still built with Java 8).



##########
clients/src/test/java/org/apache/kafka/clients/ClientUtilsTest.java:
##########
@@ -96,6 +100,20 @@ public void testParseAndValidateAddressesWithReverseLookup() {
         }
     }
 
+    static Stream<List<String>> provideBrokerListTestCases() {
+        return Stream.of(
+            Arrays.asList("localhost:9997", "localhost:9998", "localhost:9999"),
+            // Intentionally provide a single string, as users may provide space-separated brokers, which will be parsed as a single string.
+            Arrays.asList("localhost:9997 localhost:9998 localhost:9999")

Review Comment:
   Unfortunately, `List.of` is a feature introduced in Java 9, which is not supported by Kafka 3.9 (still built with Java 8).



-- 
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] KAFKA-18675: Add unit test to verify space separated brokers won't cause exception for 3.8 and 3.9 [kafka]

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


##########
clients/src/test/java/org/apache/kafka/clients/ClientUtilsTest.java:
##########
@@ -96,6 +100,20 @@ public void testParseAndValidateAddressesWithReverseLookup() {
         }
     }
 
+    static Stream<List<String>> provideBrokerListTestCases() {

Review Comment:
   That's a great idea.



-- 
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] KAFKA-18675: Add unit test to verify space separated brokers won't cause exception for 3.8 and 3.9 [kafka]

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


##########
clients/src/test/java/org/apache/kafka/clients/ClientUtilsTest.java:
##########
@@ -96,6 +100,20 @@ public void testParseAndValidateAddressesWithReverseLookup() {
         }
     }
 
+    static Stream<List<String>> provideValidBrokerAddressTestCases() {
+        return Stream.of(

Review Comment:
   Could you please offer a case for new line?



-- 
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] KAFKA-18675: Add unit test to verify space separated brokers won't cause exception for 3.8 and 3.9 [kafka]

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


##########
clients/src/test/java/org/apache/kafka/clients/ClientUtilsTest.java:
##########
@@ -96,6 +100,20 @@ public void testParseAndValidateAddressesWithReverseLookup() {
         }
     }
 
+    static Stream<List<String>> provideValidBrokerAddressTestCases() {
+        return Stream.of(

Review Comment:
   the new line separated addresses seems invalid in 3.9. I have added to invalid tests cases



-- 
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] KAFKA-18675: Add unit test to verify space separated brokers won't cause exception for 3.8 and 3.9 [kafka]

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


##########
clients/src/test/java/org/apache/kafka/clients/ClientUtilsTest.java:
##########
@@ -96,10 +100,32 @@ public void testParseAndValidateAddressesWithReverseLookup() {
         }
     }
 
-    @Test
-    public void testInvalidConfig() {
+    static Stream<List<String>> provideValidBrokerAddressTestCases() {
+        return Stream.of(
+            Arrays.asList("localhost:9997", "localhost:9998", "localhost:9999"),
+            // Intentionally provide a single string, as users may provide space-separated brokers, which will be parsed as a single string.
+            Arrays.asList("localhost:9997 localhost:9998 localhost:9999")
+        );
+    }
+
+    @ParameterizedTest
+    @MethodSource("provideValidBrokerAddressTestCases")
+    public void testValidBrokerAddress(List<String> addresses) {
+        assertDoesNotThrow(() -> ClientUtils.parseAndValidateAddresses(addresses, ClientDnsLookup.USE_ALL_DNS_IPS));
+    }
+
+    static Stream<List<String>> provideInvalidBrokerAddressTestCases() {
+        return Stream.of(
+            Collections.singletonList("localhost:9997\nlocalhost:9998\nlocalhost:9999"),
+            Collections.singletonList("localhost:10000")

Review Comment:
   `localhost:10000` is valid, and the test can cause "expected" error due to "random.value"



##########
clients/src/test/java/org/apache/kafka/clients/ClientUtilsTest.java:
##########
@@ -96,10 +100,32 @@ public void testParseAndValidateAddressesWithReverseLookup() {
         }
     }
 
-    @Test
-    public void testInvalidConfig() {

Review Comment:
   Please keep `testInvalidConfig` as it is used to test `ClientDnsLookup.forConfig` ...



##########
clients/src/test/java/org/apache/kafka/clients/ClientUtilsTest.java:
##########
@@ -96,10 +100,32 @@ public void testParseAndValidateAddressesWithReverseLookup() {
         }
     }
 
-    @Test
-    public void testInvalidConfig() {
+    static Stream<List<String>> provideValidBrokerAddressTestCases() {
+        return Stream.of(
+            Arrays.asList("localhost:9997", "localhost:9998", "localhost:9999"),
+            // Intentionally provide a single string, as users may provide space-separated brokers, which will be parsed as a single string.
+            Arrays.asList("localhost:9997 localhost:9998 localhost:9999")

Review Comment:
   please add test case `Arrays.asList("localhost:9997", " localhost:9998", " localhost:9999")`



-- 
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] KAFKA-18675: Add unit test to verify space separated brokers won't cause exception for 3.8 and 3.9 [kafka]

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


##########
clients/src/test/java/org/apache/kafka/clients/ClientUtilsTest.java:
##########
@@ -96,6 +100,20 @@ public void testParseAndValidateAddressesWithReverseLookup() {
         }
     }
 
+    static Stream<List<String>> provideBrokerListTestCases() {

Review Comment:
   I think the name is not clear. How about providing `provideValidBrokerAddressTestCases` ?



##########
clients/src/test/java/org/apache/kafka/clients/ClientUtilsTest.java:
##########
@@ -96,6 +100,20 @@ public void testParseAndValidateAddressesWithReverseLookup() {
         }
     }
 
+    static Stream<List<String>> provideBrokerListTestCases() {
+        return Stream.of(
+            Arrays.asList("localhost:9997", "localhost:9998", "localhost:9999"),
+            // Intentionally provide a single string, as users may provide space-separated brokers, which will be parsed as a single string.
+            Arrays.asList("localhost:9997 localhost:9998 localhost:9999")

Review Comment:
   Could you use `List.of` instead of `Arrays.asList` ?



##########
clients/src/test/java/org/apache/kafka/clients/ClientUtilsTest.java:
##########
@@ -96,6 +100,20 @@ public void testParseAndValidateAddressesWithReverseLookup() {
         }
     }
 
+    static Stream<List<String>> provideBrokerListTestCases() {
+        return Stream.of(
+            Arrays.asList("localhost:9997", "localhost:9998", "localhost:9999"),
+            // Intentionally provide a single string, as users may provide space-separated brokers, which will be parsed as a single string.
+            Arrays.asList("localhost:9997 localhost:9998 localhost:9999")
+        );
+    }
+
+    @ParameterizedTest
+    @MethodSource("provideBrokerListTestCases")
+    public void testValidBrokerList(List<String> brokerList) {

Review Comment:
   Ditto, naming issue.
   
   One nit: Introduing type to the variable name is not good.



-- 
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] KAFKA-18675: Add unit test to verify space separated brokers won't cause exception for 3.8 and 3.9 [kafka]

Posted by "mingyen066 (via GitHub)" <gi...@apache.org>.
mingyen066 commented on PR #18767:
URL: https://github.com/apache/kafka/pull/18767#issuecomment-2629429514

   The failed test cases `shouldWorkWithRebalance` seems unrelated.


-- 
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] KAFKA-18675: Add unit test to verify space separated brokers won't cause exception for 3.8 and 3.9 [kafka]

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


-- 
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] KAFKA-18675: Add unit test to verify space separated brokers won't cause exception for 3.8 and 3.9 [kafka]

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


##########
clients/src/test/java/org/apache/kafka/clients/ClientUtilsTest.java:
##########
@@ -96,6 +100,20 @@ public void testParseAndValidateAddressesWithReverseLookup() {
         }
     }
 
+    static Stream<List<String>> provideBrokerListTestCases() {
+        return Stream.of(
+            Arrays.asList("localhost:9997", "localhost:9998", "localhost:9999"),
+            // Intentionally provide a single string, as users may provide space-separated brokers, which will be parsed as a single string.
+            Arrays.asList("localhost:9997 localhost:9998 localhost:9999")

Review Comment:
   Yeah, `List.of` is definitely the better choice.



-- 
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] KAFKA-18675: Add unit test to verify space separated brokers won't cause exception for 3.8 and 3.9 [kafka]

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


##########
clients/src/test/java/org/apache/kafka/clients/ClientUtilsTest.java:
##########
@@ -96,6 +100,20 @@ public void testParseAndValidateAddressesWithReverseLookup() {
         }
     }
 
+    static Stream<List<String>> provideBrokerListTestCases() {
+        return Stream.of(
+            Arrays.asList("localhost:9997", "localhost:9998", "localhost:9999"),
+            // Intentionally provide a single string, as users may provide space-separated brokers, which will be parsed as a single string.
+            Arrays.asList("localhost:9997 localhost:9998 localhost:9999")
+        );
+    }
+
+    @ParameterizedTest
+    @MethodSource("provideBrokerListTestCases")
+    public void testValidBrokerList(List<String> brokerList) {

Review Comment:
   How about:
   
   ```suggestion
       public void testValidBrokerAddress(List<String> addresses) {
   ```



-- 
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] KAFKA-18675: Add unit test to verify space separated brokers won't cause exception for 3.8 and 3.9 [kafka]

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


##########
clients/src/test/java/org/apache/kafka/clients/ClientUtilsTest.java:
##########
@@ -96,6 +100,20 @@ public void testParseAndValidateAddressesWithReverseLookup() {
         }
     }
 
+    static Stream<List<String>> provideBrokerListTestCases() {
+        return Stream.of(
+            Arrays.asList("localhost:9997", "localhost:9998", "localhost:9999"),
+            // Intentionally provide a single string, as users may provide space-separated brokers, which will be parsed as a single string.
+            Arrays.asList("localhost:9997 localhost:9998 localhost:9999")
+        );
+    }
+
+    @ParameterizedTest
+    @MethodSource("provideBrokerListTestCases")
+    public void testValidBrokerList(List<String> brokerList) {

Review Comment:
   Changed the method name.



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