You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by ch...@apache.org on 2025/02/05 08:59:31 UTC

(kafka) branch 3.8 updated: KAFKA-18675 Add unit test to verify space separated brokers won't cause exception for 3.8 and 3.9 (#18767)

This is an automated email from the ASF dual-hosted git repository.

chia7712 pushed a commit to branch 3.8
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/3.8 by this push:
     new 44cf3e60a1a KAFKA-18675 Add unit test to verify space separated brokers won't cause exception for 3.8 and 3.9 (#18767)
44cf3e60a1a is described below

commit 44cf3e60a1a23b53f9c6f4892ee393694061b394
Author: Ming-Yen Chung <mi...@gmail.com>
AuthorDate: Wed Feb 5 16:55:10 2025 +0800

    KAFKA-18675 Add unit test to verify space separated brokers won't cause exception for 3.8 and 3.9 (#18767)
    
    Reviewers: Ken Huang <s7...@gmail.com>, TengYao Chi <ki...@gmail.com>, Chia-Ping Tsai <ch...@gmail.com>
---
 .../org/apache/kafka/clients/ClientUtilsTest.java  | 26 ++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/clients/src/test/java/org/apache/kafka/clients/ClientUtilsTest.java b/clients/src/test/java/org/apache/kafka/clients/ClientUtilsTest.java
index 1dc968b0061..67cb42f1454 100644
--- a/clients/src/test/java/org/apache/kafka/clients/ClientUtilsTest.java
+++ b/clients/src/test/java/org/apache/kafka/clients/ClientUtilsTest.java
@@ -19,6 +19,8 @@ package org.apache.kafka.clients;
 import org.apache.kafka.common.config.ConfigException;
 
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
 import org.mockito.MockedConstruction;
 import org.mockito.MockedStatic;
 
@@ -28,8 +30,10 @@ import java.net.UnknownHostException;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
+import java.util.stream.Stream;
 
 import static java.util.Arrays.asList;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -96,6 +100,28 @@ public class ClientUtilsTest {
         }
     }
 
+    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));
+    }
+
+    @Test
+    public void testInvalidBrokerAddress() {
+        List<String> invalidBrokerAddress = Collections.singletonList("localhost:9997\nlocalhost:9998\nlocalhost:9999");
+        assertThrows(ConfigException.class,
+            () -> ClientUtils.parseAndValidateAddresses(invalidBrokerAddress, ClientDnsLookup.USE_ALL_DNS_IPS));
+    }
+
     @Test
     public void testInvalidConfig() {
         assertThrows(IllegalArgumentException.class,