Skip to content

Commit 44a66aa

Browse files
committed
GEODE-10490: Fix PortKeeper serialization for DUnit tests
- Made PortKeeper fields transient in MemberStarterRule - Made UniquePortSupplier transient to avoid RMI serialization - Added PortKeeper to HeadlessGfshIntegrationTest for port reservation - Prevents NotSerializableException in distributed tests - Fixes DUnit test failures (RegisterDriverCommandDUnitTest, MemberManagementServiceRestDUnitTest, etc)
1 parent 187e2ae commit 44a66aa

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

geode-dunit/src/main/java/org/apache/geode/test/junit/rules/MemberStarterRule.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ public abstract class MemberStarterRule<T> extends SerializableExternalResource
104104

105105
protected boolean autoStart = false;
106106

107-
// Port keepers for zero-gap port reservation
108-
protected PortKeeper memberPortKeeper;
109-
protected PortKeeper jmxPortKeeper;
110-
protected PortKeeper httpPortKeeper;
111-
private UniquePortSupplier portSupplier;
107+
// Port keepers for zero-gap port reservation (transient to avoid RMI serialization in DUnit)
108+
protected transient PortKeeper memberPortKeeper;
109+
protected transient PortKeeper jmxPortKeeper;
110+
protected transient PortKeeper httpPortKeeper;
111+
private transient UniquePortSupplier portSupplier;
112112

113113
private List<File> firstLevelChildrenFile = new ArrayList<>();
114114
private boolean cleanWorkingDir = true;

geode-gfsh/src/integrationTest/java/org/apache/geode/management/internal/cli/HeadlessGfshIntegrationTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@
4343
import org.apache.geode.management.cli.Result;
4444
import org.apache.geode.management.internal.cli.result.CommandResult;
4545
import org.apache.geode.test.junit.categories.GfshTest;
46+
import org.apache.geode.test.junit.rules.PortKeeper;
4647

4748
/**
4849
* TODO : Add more tests for error-catch, different type of results etc
4950
*/
5051
@Category({GfshTest.class})
5152
public class HeadlessGfshIntegrationTest {
5253
private int port;
54+
private PortKeeper jmxPortKeeper;
5355
private DistributedSystem ds;
5456
private GemFireCacheImpl cache;
5557
private HeadlessGfsh gfsh;
@@ -63,6 +65,7 @@ public class HeadlessGfshIntegrationTest {
6365
@Before
6466
public void setup() throws IOException {
6567
port = getRandomAvailableTCPPort();
68+
jmxPortKeeper = new PortKeeper(port);
6669

6770
Properties properties = new Properties();
6871
properties.put(NAME, testName.getMethodName());
@@ -72,6 +75,7 @@ public void setup() throws IOException {
7275
properties.put(HTTP_SERVICE_PORT, "0");
7376
properties.put(MCAST_PORT, "0");
7477

78+
jmxPortKeeper.close(); // Release port immediately before binding
7579
legacyConnect(properties);
7680

7781
gfsh = new HeadlessGfsh("Test", 25,

0 commit comments

Comments
 (0)