From 82f5df25df2603e2f5fefb82ea890edac9a98f15 Mon Sep 17 00:00:00 2001 From: Dale Emery Date: Wed, 16 Dec 2020 12:04:17 -0800 Subject: [PATCH] GEODE-6622: WAN rolling upgrade test bind exception (#5854) Before: Several WAN rolling upgrade tests allocated ports for two locators by making two separate calls to AvailablePort. AvailablePort randomly samples ports with replacement, and so two calls can return the same port if the port is not put into use between the calls. From time to time, a test would get the same port for both locators, and the second would fail to start because its port was already in use. Now: The tests allocate both ports at the same time, ensuring that the two ports differ. And they get their ports from AvailablePortHelper, which allocates ports round robin instead of sampling with replacement, further reducing the chance of collisions. --- ...radeCreateGatewaySenderMixedSiteOneCurrentSiteTwo.java | 7 ++++--- ...gUpgradeEventProcessingMixedSiteOneCurrentSiteTwo.java | 7 ++++--- ...ingUpgradeEventProcessingOldSiteOneCurrentSiteTwo.java | 8 +++++--- ...adeMultipleReceiversDefinedInClusterConfiguration.java | 5 +++-- ...ventsNotReprocessedAfterCurrentSiteMemberFailover.java | 8 +++++--- ...aryEventsNotReprocessedAfterOldSiteMemberFailover.java | 8 +++++--- ...ndRemoveCacheServerProfileToMembersOlderThan1dot5.java | 4 ++-- .../wan/WANRollingUpgradeVerifyGatewaySenderProfile.java | 4 ++-- 8 files changed, 30 insertions(+), 21 deletions(-) diff --git a/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeCreateGatewaySenderMixedSiteOneCurrentSiteTwo.java b/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeCreateGatewaySenderMixedSiteOneCurrentSiteTwo.java index c948414b7771..2e688070063a 100644 --- a/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeCreateGatewaySenderMixedSiteOneCurrentSiteTwo.java +++ b/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeCreateGatewaySenderMixedSiteOneCurrentSiteTwo.java @@ -14,6 +14,7 @@ */ package org.apache.geode.cache.wan; +import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPorts; import static org.apache.geode.test.awaitility.GeodeAwaitility.await; import static org.junit.Assert.assertTrue; @@ -21,7 +22,6 @@ import org.junit.Test; import org.apache.geode.distributed.internal.InternalLocator; -import org.apache.geode.internal.AvailablePort; import org.apache.geode.internal.serialization.KnownVersion; import org.apache.geode.management.internal.i18n.CliStrings; import org.apache.geode.test.dunit.DistributedTestUtils; @@ -49,15 +49,16 @@ public void CreateGatewaySenderMixedSiteOneCurrentSiteTwo() throws Exception { VM site2Server1 = host.getVM(VersionManager.CURRENT_VERSION, 5); VM site2Server2 = host.getVM(VersionManager.CURRENT_VERSION, 6); + int[] locatorPorts = getRandomAvailableTCPPorts(2); // Get mixed site locator properties String hostName = NetworkUtils.getServerHostName(host); - final int site1LocatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); + final int site1LocatorPort = locatorPorts[0]; site1Locator.invoke(() -> DistributedTestUtils.deleteLocatorStateFile(site1LocatorPort)); final String site1Locators = hostName + "[" + site1LocatorPort + "]"; final int site1DistributedSystemId = 0; // Get current site locator properties - final int site2LocatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); + final int site2LocatorPort = locatorPorts[1]; site2Locator.invoke(() -> DistributedTestUtils.deleteLocatorStateFile(site2LocatorPort)); final String site2Locators = hostName + "[" + site2LocatorPort + "]"; final int site2DistributedSystemId = 1; diff --git a/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeEventProcessingMixedSiteOneCurrentSiteTwo.java b/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeEventProcessingMixedSiteOneCurrentSiteTwo.java index 8bdbc3e105c8..952917fed048 100644 --- a/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeEventProcessingMixedSiteOneCurrentSiteTwo.java +++ b/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeEventProcessingMixedSiteOneCurrentSiteTwo.java @@ -14,13 +14,13 @@ */ package org.apache.geode.cache.wan; +import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPorts; import static org.apache.geode.test.awaitility.GeodeAwaitility.await; import static org.junit.Assert.assertTrue; import org.junit.Test; import org.apache.geode.distributed.internal.InternalLocator; -import org.apache.geode.internal.AvailablePort; import org.apache.geode.internal.cache.wan.parallel.ParallelGatewaySenderQueue; import org.apache.geode.test.dunit.DistributedTestUtils; import org.apache.geode.test.dunit.Host; @@ -46,14 +46,15 @@ public void EventProcessingMixedSiteOneCurrentSiteTwo() { VM site2Server1 = host.getVM(VersionManager.CURRENT_VERSION, 5); VM site2Server2 = host.getVM(VersionManager.CURRENT_VERSION, 6); + int[] locatorPorts = getRandomAvailableTCPPorts(2); // Get mixed site locator properties String hostName = NetworkUtils.getServerHostName(host); - final int site1LocatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); + final int site1LocatorPort = locatorPorts[0]; final String site1Locators = hostName + "[" + site1LocatorPort + "]"; final int site1DistributedSystemId = 0; // Get current site locator properties - final int site2LocatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); + final int site2LocatorPort = locatorPorts[1]; final String site2Locators = hostName + "[" + site2LocatorPort + "]"; final int site2DistributedSystemId = 1; diff --git a/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeEventProcessingOldSiteOneCurrentSiteTwo.java b/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeEventProcessingOldSiteOneCurrentSiteTwo.java index 7796ead6a3f6..200c65be1c2c 100644 --- a/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeEventProcessingOldSiteOneCurrentSiteTwo.java +++ b/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeEventProcessingOldSiteOneCurrentSiteTwo.java @@ -14,13 +14,13 @@ */ package org.apache.geode.cache.wan; +import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPorts; import static org.apache.geode.test.awaitility.GeodeAwaitility.await; import static org.junit.Assert.assertTrue; import org.junit.Test; import org.apache.geode.distributed.internal.InternalLocator; -import org.apache.geode.internal.AvailablePort; import org.apache.geode.internal.cache.wan.parallel.ParallelGatewaySenderQueue; import org.apache.geode.test.dunit.DistributedTestUtils; import org.apache.geode.test.dunit.Host; @@ -47,15 +47,17 @@ public void testEventProcessingOldSiteOneCurrentSiteTwo() { VM site2Server2 = host.getVM(VersionManager.CURRENT_VERSION, 6); VM site2Client = host.getVM(VersionManager.CURRENT_VERSION, 7); + int[] locatorPorts = getRandomAvailableTCPPorts(2); + // Get old site locator properties String hostName = NetworkUtils.getServerHostName(host); - final int site1LocatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); + final int site1LocatorPort = locatorPorts[0]; site1Locator.invoke(() -> DistributedTestUtils.deleteLocatorStateFile(site1LocatorPort)); final String site1Locators = hostName + "[" + site1LocatorPort + "]"; final int site1DistributedSystemId = 0; // Get current site locator properties - final int site2LocatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); + final int site2LocatorPort = locatorPorts[1]; site2Locator.invoke(() -> DistributedTestUtils.deleteLocatorStateFile(site2LocatorPort)); final String site2Locators = hostName + "[" + site2LocatorPort + "]"; final int site2DistributedSystemId = 1; diff --git a/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeMultipleReceiversDefinedInClusterConfiguration.java b/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeMultipleReceiversDefinedInClusterConfiguration.java index 130656dc28ae..6d08cea6e23d 100644 --- a/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeMultipleReceiversDefinedInClusterConfiguration.java +++ b/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeMultipleReceiversDefinedInClusterConfiguration.java @@ -15,6 +15,7 @@ package org.apache.geode.cache.wan; +import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPort; import static org.apache.geode.test.awaitility.GeodeAwaitility.await; import static org.assertj.core.api.Assertions.assertThat; @@ -38,7 +39,6 @@ import org.apache.geode.distributed.ConfigurationPersistenceService; import org.apache.geode.distributed.internal.InternalConfigurationPersistenceService; import org.apache.geode.distributed.internal.InternalLocator; -import org.apache.geode.internal.AvailablePort; import org.apache.geode.internal.cache.xmlcache.CacheCreation; import org.apache.geode.internal.cache.xmlcache.CacheXmlGenerator; import org.apache.geode.management.internal.configuration.domain.Configuration; @@ -144,7 +144,8 @@ public void testMultipleReceiversRemovedDuringRoll() { // Get old locator properties VM locator = Host.getHost(0).getVM(oldVersion, 0); String hostName = NetworkUtils.getServerHostName(); - final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); + final int locatorPort = getRandomAvailableTCPPort(); + final String locators = hostName + "[" + locatorPort + "]"; // Start old locator locator.invoke(() -> { diff --git a/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeSecondaryEventsNotReprocessedAfterCurrentSiteMemberFailover.java b/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeSecondaryEventsNotReprocessedAfterCurrentSiteMemberFailover.java index 39d1f831f2c3..4a880c815c1e 100644 --- a/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeSecondaryEventsNotReprocessedAfterCurrentSiteMemberFailover.java +++ b/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeSecondaryEventsNotReprocessedAfterCurrentSiteMemberFailover.java @@ -14,13 +14,13 @@ */ package org.apache.geode.cache.wan; +import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPorts; import static org.apache.geode.test.awaitility.GeodeAwaitility.await; import static org.junit.Assert.assertTrue; import org.junit.Test; import org.apache.geode.distributed.internal.InternalLocator; -import org.apache.geode.internal.AvailablePort; import org.apache.geode.test.dunit.DistributedTestUtils; import org.apache.geode.test.dunit.Host; import org.apache.geode.test.dunit.NetworkUtils; @@ -44,15 +44,17 @@ public void testSecondaryEventsNotReprocessedAfterCurrentSiteMemberFailover() { VM site2Server2 = host.getVM(VersionManager.CURRENT_VERSION, 6); VM site2Client = host.getVM(VersionManager.CURRENT_VERSION, 7); + int[] locatorPorts = getRandomAvailableTCPPorts(2); + // Get old site locator properties String hostName = NetworkUtils.getServerHostName(host); - final int site1LocatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); + final int site1LocatorPort = locatorPorts[0]; site1Locator.invoke(() -> DistributedTestUtils.deleteLocatorStateFile(site1LocatorPort)); final String site1Locators = hostName + "[" + site1LocatorPort + "]"; final int site1DistributedSystemId = 0; // Get current site locator properties - final int site2LocatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); + final int site2LocatorPort = locatorPorts[1]; site2Locator.invoke(() -> DistributedTestUtils.deleteLocatorStateFile(site2LocatorPort)); final String site2Locators = hostName + "[" + site2LocatorPort + "]"; final int site2DistributedSystemId = 1; diff --git a/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeSecondaryEventsNotReprocessedAfterOldSiteMemberFailover.java b/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeSecondaryEventsNotReprocessedAfterOldSiteMemberFailover.java index 4350148a9a3b..f25397806a1d 100644 --- a/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeSecondaryEventsNotReprocessedAfterOldSiteMemberFailover.java +++ b/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeSecondaryEventsNotReprocessedAfterOldSiteMemberFailover.java @@ -14,13 +14,13 @@ */ package org.apache.geode.cache.wan; +import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPorts; import static org.apache.geode.test.awaitility.GeodeAwaitility.await; import static org.junit.Assert.assertTrue; import org.junit.Test; import org.apache.geode.distributed.internal.InternalLocator; -import org.apache.geode.internal.AvailablePort; import org.apache.geode.test.dunit.DistributedTestUtils; import org.apache.geode.test.dunit.Host; import org.apache.geode.test.dunit.NetworkUtils; @@ -44,15 +44,17 @@ public void testSecondaryEventsNotReprocessedAfterOldSiteMemberFailover() { VM site2Server1 = host.getVM(VersionManager.CURRENT_VERSION, 5); VM site2Server2 = host.getVM(VersionManager.CURRENT_VERSION, 6); + int[] locatorPorts = getRandomAvailableTCPPorts(2); + // Get old site locator properties String hostName = NetworkUtils.getServerHostName(host); - final int site1LocatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); + final int site1LocatorPort = locatorPorts[0]; site1Locator.invoke(() -> DistributedTestUtils.deleteLocatorStateFile(site1LocatorPort)); final String site1Locators = hostName + "[" + site1LocatorPort + "]"; final int site1DistributedSystemId = 0; // Get current site locator properties - final int site2LocatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); + final int site2LocatorPort = locatorPorts[1]; site2Locator.invoke(() -> DistributedTestUtils.deleteLocatorStateFile(site2LocatorPort)); final String site2Locators = hostName + "[" + site2LocatorPort + "]"; final int site2DistributedSystemId = 1; diff --git a/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeVerifyGatewayReceiverDoesNotSendRemoveCacheServerProfileToMembersOlderThan1dot5.java b/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeVerifyGatewayReceiverDoesNotSendRemoveCacheServerProfileToMembersOlderThan1dot5.java index d60ec4518cea..432d7f632ea3 100644 --- a/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeVerifyGatewayReceiverDoesNotSendRemoveCacheServerProfileToMembersOlderThan1dot5.java +++ b/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeVerifyGatewayReceiverDoesNotSendRemoveCacheServerProfileToMembersOlderThan1dot5.java @@ -14,13 +14,13 @@ */ package org.apache.geode.cache.wan; +import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPort; import static org.apache.geode.test.awaitility.GeodeAwaitility.await; import static org.junit.Assert.assertTrue; import org.junit.Test; import org.apache.geode.distributed.internal.InternalLocator; -import org.apache.geode.internal.AvailablePort; import org.apache.geode.test.dunit.DistributedTestUtils; import org.apache.geode.test.dunit.Host; import org.apache.geode.test.dunit.IgnoredException; @@ -39,7 +39,7 @@ public void VerifyGatewayReceiverDoesNotSendRemoveCacheServerProfileToMembersOld VM currentServer = host.getVM(VersionManager.CURRENT_VERSION, 2); // Start locator - final int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); + final int port = getRandomAvailableTCPPort(); oldLocator.invoke(() -> DistributedTestUtils.deleteLocatorStateFile(port)); final String locators = NetworkUtils.getServerHostName(host) + "[" + port + "]"; oldLocator.invoke(() -> startLocator(port, 0, locators, "")); diff --git a/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeVerifyGatewaySenderProfile.java b/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeVerifyGatewaySenderProfile.java index 1fdb9e65c6e2..8d70ec729c79 100644 --- a/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeVerifyGatewaySenderProfile.java +++ b/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeVerifyGatewaySenderProfile.java @@ -14,13 +14,13 @@ */ package org.apache.geode.cache.wan; +import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPort; import static org.apache.geode.test.awaitility.GeodeAwaitility.await; import static org.junit.Assert.assertTrue; import org.junit.Test; import org.apache.geode.distributed.internal.InternalLocator; -import org.apache.geode.internal.AvailablePort; import org.apache.geode.internal.cache.wan.parallel.ParallelGatewaySenderQueue; import org.apache.geode.test.dunit.DistributedTestUtils; import org.apache.geode.test.dunit.Host; @@ -39,7 +39,7 @@ public void testVerifyGatewaySenderProfile() { VM currentServer = host.getVM(VersionManager.CURRENT_VERSION, 2); // Start locator - final int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); + final int port = getRandomAvailableTCPPort(); oldLocator.invoke(() -> DistributedTestUtils.deleteLocatorStateFile(port)); final String locators = NetworkUtils.getServerHostName(host) + "[" + port + "]"; oldLocator.invoke(() -> startLocator(port, 0, locators, ""));