Keep trying ports until you get one lower than 55535 (#83)
* Keep trying ports until you get one lower than 55535 * Rename method and change to do...while * Limit attempts to 11,000 to find an open redis cluster port
This commit is contained in:
parent
42c797ee97
commit
0ee7a66033
|
@ -42,7 +42,7 @@ public abstract class AbstractRedisClusterTest {
|
||||||
clusterNodes = new RedisServer[NODE_COUNT];
|
clusterNodes = new RedisServer[NODE_COUNT];
|
||||||
|
|
||||||
for (int i = 0; i < NODE_COUNT; i++) {
|
for (int i = 0; i < NODE_COUNT; i++) {
|
||||||
clusterNodes[i] = buildClusterNode(getNextPort());
|
clusterNodes[i] = buildClusterNode(getNextRedisClusterPort());
|
||||||
clusterNodes[i].start();
|
clusterNodes[i].start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,10 +143,18 @@ public abstract class AbstractRedisClusterTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getNextPort() throws IOException {
|
private static int getNextRedisClusterPort() throws IOException {
|
||||||
try (ServerSocket socket = new ServerSocket(0)) {
|
final int MAX_ITERATIONS = 11_000;
|
||||||
socket.setReuseAddress(false);
|
int port;
|
||||||
return socket.getLocalPort();
|
for (int i = 0; i < MAX_ITERATIONS; i++) {
|
||||||
|
try (ServerSocket socket = new ServerSocket(0)) {
|
||||||
|
socket.setReuseAddress(false);
|
||||||
|
port = socket.getLocalPort();
|
||||||
|
}
|
||||||
|
if (port < 55535) {
|
||||||
|
return port;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
throw new IOException("Couldn't find an open port below 55,535 in " + MAX_ITERATIONS + " tries");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue