Skip to content

Commit d9f943f

Browse files
jasontedorandyb-elastic
authored andcommitted
Fix Netty 4 multi-port test
This commit fixes an issue with the Netty 4 multi-port test that a transport client can connect. The problem here is that in case the bottom of the random port range was already bound to (for example, by another JVM) then then transport client could not connect to the data node. This is because the transport client was in fact using the bottom of the port range only. Instead, we simply try all the ports that the data node might be bound to. This commit is cherry picked from 049e641 but adapted to preserve the use of InetSocketTransportAddress Closes #24441
1 parent ab76fae commit d9f943f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

modules/transport-netty4/src/test/java/org/elasticsearch/transport/netty4/Netty4TransportMultiPortIntegrationIT.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class Netty4TransportMultiPortIntegrationIT extends ESNetty4IntegTestCase
5858
protected Settings nodeSettings(int nodeOrdinal) {
5959
if (randomPort == -1) {
6060
randomPort = randomIntBetween(49152, 65525);
61-
randomPortRange = String.format(Locale.ROOT, "%s-%s", randomPort, randomPort+10);
61+
randomPortRange = String.format(Locale.ROOT, "%s-%s", randomPort, randomPort + 10);
6262
}
6363
Settings.Builder builder = Settings.builder()
6464
.put(super.nodeSettings(nodeOrdinal))
@@ -76,8 +76,12 @@ public void testThatTransportClientCanConnect() throws Exception {
7676
.put(NetworkModule.TRANSPORT_TYPE_KEY, Netty4Plugin.NETTY_TRANSPORT_NAME)
7777
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
7878
.build();
79+
// we have to test all the ports that the data node might be bound to
7980
try (TransportClient transportClient = new MockTransportClient(settings, Netty4Plugin.class)) {
8081
transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), randomPort));
82+
for (int i = 0; i <= 10; i++) {
83+
transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), randomPort + i));
84+
}
8185
ClusterHealthResponse response = transportClient.admin().cluster().prepareHealth().get();
8286
assertThat(response.getStatus(), is(ClusterHealthStatus.GREEN));
8387
}

0 commit comments

Comments
 (0)