From db451b8f5bf55d8f49cd82aa33b5eaae2e5eab34 Mon Sep 17 00:00:00 2001 From: Santhosh Date: Thu, 21 May 2026 22:13:35 +0530 Subject: [PATCH 1/2] Apply suggested fix to netty-socketio-core/src/test/java/com/socketio4j/socketio/integration/DistributedRedissonClusterSuite.java from Copilot Autofix Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> --- .../integration/DistributedRedissonClusterSuite.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/netty-socketio-core/src/test/java/com/socketio4j/socketio/integration/DistributedRedissonClusterSuite.java b/netty-socketio-core/src/test/java/com/socketio4j/socketio/integration/DistributedRedissonClusterSuite.java index 3b486c0f..88b53d22 100644 --- a/netty-socketio-core/src/test/java/com/socketio4j/socketio/integration/DistributedRedissonClusterSuite.java +++ b/netty-socketio-core/src/test/java/com/socketio4j/socketio/integration/DistributedRedissonClusterSuite.java @@ -16,8 +16,6 @@ */ package com.socketio4j.socketio.integration; -import java.net.ServerSocket; - import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Nested; @@ -43,12 +41,6 @@ public class DistributedRedissonClusterSuite { @SuppressWarnings("resource") static final CustomizedRedisContainer REDIS = new CustomizedRedisContainer().withReuse(false); - private static int findAvailablePort() throws Exception { - try (ServerSocket socket = new ServerSocket(0)) { - return socket.getLocalPort(); - } - } - @BeforeAll static void startRedis() { REDIS.start(); @@ -77,7 +69,7 @@ void setupNodes() throws Exception { Configuration cfg1 = new Configuration(); DistributedClusterIntegrationSupport.applyReuseListenAddress(cfg1); cfg1.setHostname("127.0.0.1"); - cfg1.setPort(findAvailablePort()); + cfg1.setPort(DistributedClusterIntegrationSupport.findAvailablePort()); cfg1.setStoreFactory(new RedisStoreFactory(redisClient1, new RedisPubSubEventStore.Builder(redisClient1).eventStoreMode(EventStoreMode.SINGLE_CHANNEL).build())); node1 = new SocketIOServer(cfg1); @@ -87,7 +79,7 @@ void setupNodes() throws Exception { Configuration cfg2 = new Configuration(); DistributedClusterIntegrationSupport.applyReuseListenAddress(cfg2); cfg2.setHostname("127.0.0.1"); - cfg2.setPort(findAvailablePort()); + cfg2.setPort(DistributedClusterIntegrationSupport.findAvailablePort()); cfg2.setStoreFactory(new RedisStoreFactory(redisClient2, new RedisPubSubEventStore.Builder(redisClient2).eventStoreMode(EventStoreMode.SINGLE_CHANNEL).build())); node2 = new SocketIOServer(cfg2); From 2a311cbb203004ffcdb5f2cc2cf0824f5bacbae3 Mon Sep 17 00:00:00 2001 From: sanjomo Date: Thu, 21 May 2026 22:18:00 +0530 Subject: [PATCH 2/2] Add findAvailablePort utility for tests Introduce a findAvailablePort() helper in DistributedClusterIntegrationSupport that opens a ServerSocket(0) to obtain an ephemeral free port (using try-with-resources). Add the java.net.ServerSocket import and statically import the helper in DistributedRedissonClusterSuite, replacing fully-qualified calls with the static method. This ensures test nodes bind to available ports and reduces port collision issues during integration tests. --- .../integration/DistributedClusterIntegrationSupport.java | 7 ++++++- .../integration/DistributedRedissonClusterSuite.java | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/netty-socketio-core/src/test/java/com/socketio4j/socketio/integration/DistributedClusterIntegrationSupport.java b/netty-socketio-core/src/test/java/com/socketio4j/socketio/integration/DistributedClusterIntegrationSupport.java index 647635a8..ca97445a 100644 --- a/netty-socketio-core/src/test/java/com/socketio4j/socketio/integration/DistributedClusterIntegrationSupport.java +++ b/netty-socketio-core/src/test/java/com/socketio4j/socketio/integration/DistributedClusterIntegrationSupport.java @@ -16,6 +16,7 @@ */ package com.socketio4j.socketio.integration; +import java.net.ServerSocket; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -35,7 +36,11 @@ final class DistributedClusterIntegrationSupport { private DistributedClusterIntegrationSupport() { } - + static int findAvailablePort() throws Exception { + try (ServerSocket socket = new ServerSocket(0)) { + return socket.getLocalPort(); + } + } static void applyReuseListenAddress(Configuration configuration) { configuration.getSocketConfig().setReuseAddress(true); } diff --git a/netty-socketio-core/src/test/java/com/socketio4j/socketio/integration/DistributedRedissonClusterSuite.java b/netty-socketio-core/src/test/java/com/socketio4j/socketio/integration/DistributedRedissonClusterSuite.java index 88b53d22..7c01d5e9 100644 --- a/netty-socketio-core/src/test/java/com/socketio4j/socketio/integration/DistributedRedissonClusterSuite.java +++ b/netty-socketio-core/src/test/java/com/socketio4j/socketio/integration/DistributedRedissonClusterSuite.java @@ -32,6 +32,8 @@ import com.socketio4j.socketio.store.redis_reliable.RedisPubSubReliableEventStore; import com.socketio4j.socketio.store.redis_stream.RedisStreamEventStore; +import static com.socketio4j.socketio.integration.DistributedClusterIntegrationSupport.findAvailablePort; + /** * Runs {@link DistributedCommonTest} against all Redisson-backed cluster variants while sharing * one Redis Testcontainer. @@ -69,7 +71,7 @@ void setupNodes() throws Exception { Configuration cfg1 = new Configuration(); DistributedClusterIntegrationSupport.applyReuseListenAddress(cfg1); cfg1.setHostname("127.0.0.1"); - cfg1.setPort(DistributedClusterIntegrationSupport.findAvailablePort()); + cfg1.setPort(findAvailablePort()); cfg1.setStoreFactory(new RedisStoreFactory(redisClient1, new RedisPubSubEventStore.Builder(redisClient1).eventStoreMode(EventStoreMode.SINGLE_CHANNEL).build())); node1 = new SocketIOServer(cfg1); @@ -79,7 +81,7 @@ void setupNodes() throws Exception { Configuration cfg2 = new Configuration(); DistributedClusterIntegrationSupport.applyReuseListenAddress(cfg2); cfg2.setHostname("127.0.0.1"); - cfg2.setPort(DistributedClusterIntegrationSupport.findAvailablePort()); + cfg2.setPort(findAvailablePort()); cfg2.setStoreFactory(new RedisStoreFactory(redisClient2, new RedisPubSubEventStore.Builder(redisClient2).eventStoreMode(EventStoreMode.SINGLE_CHANNEL).build())); node2 = new SocketIOServer(cfg2);