Skip to content

Commit

Permalink
GEODE-6622: WAN rolling upgrade test bind exception (apache#5854)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
demery-pivotal authored Dec 16, 2020
1 parent f4a0c52 commit 82f5df2
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
*/
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.assertj.core.api.Assertions;
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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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, ""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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, ""));
Expand Down

0 comments on commit 82f5df2

Please sign in to comment.