dajac commented on a change in pull request #9902: URL: https://github.com/apache/kafka/pull/9902#discussion_r569998233
########## File path: clients/src/main/java/org/apache/kafka/clients/HostResolver.java ########## @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.kafka.clients; + +import java.net.InetAddress; +import java.net.UnknownHostException; + +public interface HostResolver { + + InetAddress[] resolve(String host) throws UnknownHostException; +} Review comment: nit: Could we add an empty line here? ########## File path: clients/src/main/java/org/apache/kafka/clients/DefaultHostResolver.java ########## @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.kafka.clients; + +import java.net.InetAddress; +import java.net.UnknownHostException; + +public class DefaultHostResolver implements HostResolver { + + @Override + public InetAddress[] resolve(String host) throws UnknownHostException { + return InetAddress.getAllByName(host); + } +} Review comment: nit: Could we add an empty line here? ########## File path: clients/src/test/java/org/apache/kafka/clients/NetworkClientTest.java ########## @@ -960,4 +1112,29 @@ public KafkaException getAndClearFailure() { return failure; } } + + private class AddressChangeHostResolver implements HostResolver { + private boolean useNewAddresses; + private InetAddress[] initialAddressArray = initialAddresses.toArray(new InetAddress[0]); + private InetAddress[] newAddressArray = newAddresses.toArray(new InetAddress[0]); Review comment: nit: I wonder if it would be better to pass these two in a constructor? It makes reading the tests a bit more easy. ########## File path: clients/src/test/java/org/apache/kafka/clients/NetworkClientTest.java ########## @@ -81,6 +85,19 @@ private final NetworkClient clientWithNoExponentialBackoff = createNetworkClient(reconnectBackoffMsTest); private final NetworkClient clientWithStaticNodes = createNetworkClientWithStaticNodes(); private final NetworkClient clientWithNoVersionDiscovery = createNetworkClientWithNoVersionDiscovery(); + private ArrayList<InetAddress> initialAddresses = new ArrayList<>(Arrays.asList( Review comment: nit: Should we make these two static? ########## File path: clients/src/main/java/org/apache/kafka/clients/ClientUtils.java ########## @@ -106,8 +106,9 @@ public static ChannelBuilder createChannelBuilder(AbstractConfig config, Time ti clientSaslMechanism, time, true, logContext); } - static List<InetAddress> resolve(String host, ClientDnsLookup clientDnsLookup) throws UnknownHostException { - InetAddress[] addresses = InetAddress.getAllByName(host); + static List<InetAddress> resolve(String host, ClientDnsLookup clientDnsLookup, + HostResolver hostResolver) throws UnknownHostException { Review comment: Thanks @bob-barrett. I do agree with your point. Let's keep it as you suggested. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org