Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KAFKA-18675: Add tests for valid and invalid broker addresses #18781

Open
wants to merge 8 commits into
base: trunk
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
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;

Expand All @@ -27,8 +29,10 @@
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;
Expand Down Expand Up @@ -95,10 +99,38 @@ public void testParseAndValidateAddressesWithReverseLookup() {
}
}

static Stream<List<String>> provideValidBrokerAddressTestCases() {
return Stream.of(
List.of("localhost:9997", "localhost:9998", "localhost:9999")

);
}

@ParameterizedTest
@MethodSource("provideValidBrokerAddressTestCases")
public void testValidBrokerAddress(List<String> addresses) {
assertDoesNotThrow(() -> ClientUtils.parseAndValidateAddresses(addresses, ClientDnsLookup.USE_ALL_DNS_IPS));
}
mingyen066 marked this conversation as resolved.
Show resolved Hide resolved

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,
() -> ClientUtils.parseAndValidateAddresses(Collections.singletonList("localhost:10000"), "random.value"));
assertThrows(ConfigException.class, () -> checkWithoutLookup("localhost:10000", "localhost:10001"));
mingyen066 marked this conversation as resolved.
Show resolved Hide resolved
}

@Test
Expand Down
Loading