MINOR: Fix ClusterConnectionStatesTest.testSingleIP (#14741)

This test fails because `localhost` resolved to more than one IP on the Ci. This patch updates the ClusterConnectionStatesTest.testSingleIP test to use a static resolver.

Reviewers: Luke Chen <showuon@gmail.com>
This commit is contained in:
David Jacot 2023-11-13 10:15:35 +01:00 committed by GitHub
parent 7c562a776d
commit 49d3122d42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 1 deletions

View File

@ -32,6 +32,8 @@ import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
import org.apache.kafka.common.errors.AuthenticationException;
import org.apache.kafka.common.utils.LogContext;
import org.apache.kafka.common.utils.MockTime;
@ -264,7 +266,14 @@ public class ClusterConnectionStatesTest {
@Test
public void testSingleIP() throws UnknownHostException {
assertEquals(1, ClientUtils.resolve("localhost", singleIPHostResolver).size());
InetAddress[] localhostIps = Stream.of(InetAddress.getByName("127.0.0.1")).toArray(InetAddress[]::new);
HostResolver hostResolver = host -> {
assertEquals("localhost", host);
return localhostIps;
};
connectionStates = new ClusterConnectionStates(reconnectBackoffMs, reconnectBackoffMax,
connectionSetupTimeoutMs, connectionSetupTimeoutMaxMs, new LogContext(), hostResolver);
connectionStates.connecting(nodeId1, time.milliseconds(), "localhost");
InetAddress currAddress = connectionStates.currentAddress(nodeId1);