This is an automated email from the ASF dual-hosted git repository.
chia7712 pushed a commit to branch 4.0
in repository https://gitbox.apache.org/repos/asf/kafka.git
The following commit(s) were added to refs/heads/4.0 by this push:
new 5d3d7250f6b KAFKA-18675 Add tests for valid and invalid broker
addresses (#18781)
5d3d7250f6b is described below
commit 5d3d7250f6bac93a188bb2a897ae1884138eec2a
Author: Ming-Yen Chung <[email protected]>
AuthorDate: Wed Feb 5 17:01:51 2025 +0800
KAFKA-18675 Add tests for valid and invalid broker addresses (#18781)
Reviewers: Ken Huang <[email protected]>, Chia-Ping Tsai
<[email protected]>
---
.../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 2368a91137f..fac5cd8ee09 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;
@@ -27,8 +29,10 @@ import java.net.InetSocketAddress;
import java.net.UnknownHostException;
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;
@@ -95,6 +99,28 @@ public class ClientUtilsTest {
}
}
+ @Test
+ public void testValidBrokerAddress() {
+ List<String> validBrokerAddress = List.of("localhost:9997",
"localhost:9998", "localhost:9999");
+ assertDoesNotThrow(() ->
ClientUtils.parseAndValidateAddresses(validBrokerAddress,
ClientDnsLookup.USE_ALL_DNS_IPS));
+ }
+
+ static Stream<List<String>> provideInvalidBrokerAddressTestCases() {
+ return Stream.of(
+ List.of("localhost:9997\nlocalhost:9998\nlocalhost:9999"),
+ List.of("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.
+ List.of("localhost:9997 localhost:9998 localhost:9999")
+ );
+ }
+
+ @ParameterizedTest
+ @MethodSource("provideInvalidBrokerAddressTestCases")
+ public void testInvalidBrokerAddress(List<String> addresses) {
+ assertThrows(ConfigException.class,
+ () -> ClientUtils.parseAndValidateAddresses(addresses,
ClientDnsLookup.USE_ALL_DNS_IPS));
+ }
+
@Test
public void testInvalidConfig() {
assertThrows(IllegalArgumentException.class,