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

[fix][test] Fix flaky test ConnectionPoolTest.testSetProxyToTargetBrokerAddress #20293

Merged
merged 1 commit into from
May 11, 2023
Merged
Changes from all 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 @@ -154,7 +154,7 @@ public void testEnableConnectionPool() throws Exception {
@Test
public void testSetProxyToTargetBrokerAddress() throws Exception {
ClientConfigurationData conf = new ClientConfigurationData();
conf.setConnectionsPerBroker(5);
conf.setConnectionsPerBroker(1);


EventLoopGroup eventLoop =
Expand All @@ -176,19 +176,24 @@ protected void doResolve(SocketAddress socketAddress, Promise promise) throws Ex
@Override
protected void doResolveAll(SocketAddress socketAddress, Promise promise) throws Exception {
final InetSocketAddress socketAddress1 = (InetSocketAddress) socketAddress;
final boolean isProxy = socketAddress1.getHostName().equals("proxy");
final boolean isBroker = socketAddress1.getHostName().equals("broker");
String hostName = socketAddress1.getHostName();
final boolean isProxy = hostName.equals("proxy");
final boolean isBroker = hostName.startsWith("broker");
if (!isProxy && !isBroker) {
promise.setFailure(new IllegalStateException());
throw new IllegalStateException();
}
List<InetSocketAddress> result = new ArrayList<>();
// All 127.0.0.0/8 addresses are valid local loopback addresses
if (isProxy) {
result.add(new InetSocketAddress("localhost", brokerPort));
result.add(InetSocketAddress.createUnresolved("proxy", brokerPort));
} else {
result.add(new InetSocketAddress("127.0.0.1", brokerPort));
result.add(InetSocketAddress.createUnresolved("broker", brokerPort));
result.add(new InetSocketAddress("127.0.0.101", brokerPort));
result.add(new InetSocketAddress("127.0.0.102", brokerPort));
} else if (hostName.equals("broker1")){
result.add(new InetSocketAddress("127.0.0.103", brokerPort));
result.add(new InetSocketAddress("127.0.0.104", brokerPort));
} else if (hostName.equals("broker2")){
result.add(new InetSocketAddress("127.0.0.105", brokerPort));
result.add(new InetSocketAddress("127.0.0.106", brokerPort));
}
promise.setSuccess(result);
}
Expand All @@ -203,23 +208,19 @@ protected void doResolveAll(SocketAddress socketAddress, Promise promise) throws
InetSocketAddress.createUnresolved("proxy", 9999)).get();
Assert.assertEquals(cnx.remoteHostName, "proxy");
Assert.assertNull(cnx.proxyToTargetBrokerAddress);
cnx.close();

cnx = pool.getConnection(
InetSocketAddress.createUnresolved("broker", 9999),
InetSocketAddress.createUnresolved("broker1", 9999),
InetSocketAddress.createUnresolved("proxy", 9999)).get();
Assert.assertEquals(cnx.remoteHostName, "proxy");
Assert.assertEquals(cnx.proxyToTargetBrokerAddress, "broker:9999");
cnx.close();
Assert.assertEquals(cnx.proxyToTargetBrokerAddress, "broker1:9999");


cnx = pool.getConnection(
InetSocketAddress.createUnresolved("broker", 9999),
InetSocketAddress.createUnresolved("broker", 9999)).get();
Assert.assertEquals(cnx.remoteHostName, "broker");
InetSocketAddress.createUnresolved("broker2", 9999),
InetSocketAddress.createUnresolved("broker2", 9999)).get();
Assert.assertEquals(cnx.remoteHostName, "broker2");
Assert.assertNull(cnx.proxyToTargetBrokerAddress);
cnx.close();


pool.closeAllConnections();
pool.close();
Expand Down