You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by dh...@apache.org on 2021/05/14 15:46:08 UTC

[geode] branch develop updated: GEODE-8772: Assign TCP Server test ports in test JVM (#6472)

This is an automated email from the ASF dual-hosted git repository.

dhemery pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new b8aef02  GEODE-8772: Assign TCP Server test ports in test JVM (#6472)
b8aef02 is described below

commit b8aef025bac80f52729aa0201d8fe1c905862038
Author: Dale Emery <de...@vmware.com>
AuthorDate: Fri May 14 08:45:18 2021 -0700

    GEODE-8772: Assign TCP Server test ports in test JVM (#6472)
    
    * GEODE-8772: Assign TCP Server test ports in test JVM
    
    Make TcpServerProductVersionDUnitTest assign the locator port in the
    test JVM rather than in child VMs.
    
    An upcoming change to AvailablePortHelper will improve how it assigns
    ports to better support tests running in parallel outside of docker.  A
    child VM running an older version of Geode (as happens in this test)
    will have an out-of-date implementation of AvailablePortHelper, and so
    may assign a port that is in use by another test running in parallel.
    
    * Move func per review suggestion
---
 .../TcpServerProductVersionDUnitTest.java          | 40 ++++++++++------------
 1 file changed, 19 insertions(+), 21 deletions(-)

diff --git a/geode-tcp-server/src/distributedTest/java/org/apache/geode/distributed/internal/tcpserver/TcpServerProductVersionDUnitTest.java b/geode-tcp-server/src/distributedTest/java/org/apache/geode/distributed/internal/tcpserver/TcpServerProductVersionDUnitTest.java
index 01ed555..14a470c 100644
--- a/geode-tcp-server/src/distributedTest/java/org/apache/geode/distributed/internal/tcpserver/TcpServerProductVersionDUnitTest.java
+++ b/geode-tcp-server/src/distributedTest/java/org/apache/geode/distributed/internal/tcpserver/TcpServerProductVersionDUnitTest.java
@@ -159,7 +159,7 @@ public class TcpServerProductVersionDUnitTest implements Serializable {
     VM clientVM = Host.getHost(0).getVM(versions.clientProductVersion.toString(), clientVMNumber);
     VM locatorVM =
         Host.getHost(0).getVM(versions.locatorProductVersion.toString(), locatorVMNumber);
-    int locatorPort = createLocator(locatorVM, true);
+    int locatorPort = createLocator(locatorVM);
 
     clientVM.invoke("issue version request",
         createRequestResponseFunction(locatorPort, VersionRequest.class.getName(),
@@ -177,6 +177,23 @@ public class TcpServerProductVersionDUnitTest implements Serializable {
     });
   }
 
+  private int createLocator(VM memberVM) {
+    final int port = AvailablePortHelper.getRandomAvailableTCPPort();
+
+    return memberVM.invoke("create locator", () -> {
+      System.setProperty(GMSJoinLeave.BYPASS_DISCOVERY_PROPERTY, "true");
+      try {
+        // for stress-tests make sure that an older-version locator doesn't try
+        // to read state persisted by another run's newer-version locator
+        DistributedTestUtils.deleteLocatorStateFile(port);
+        return Locator.startLocatorAndDS(port, new File(""), getDistributedSystemProperties())
+            .getPort();
+      } finally {
+        System.clearProperty(GMSJoinLeave.BYPASS_DISCOVERY_PROPERTY);
+      }
+    });
+  }
+
   @SuppressWarnings("deprecation")
   private void testDeprecatedMessageTypes(VM clientVM, int locatorPort) {
     clientVM.invoke("issue info request",
@@ -224,12 +241,12 @@ public class TcpServerProductVersionDUnitTest implements Serializable {
     };
 
   }
-
   /*
    * The TcpClient class changed in version FIRST_NEW_VERSION. That version (and later)
    * no longer has the old constructor TcpClient(final Properties), so we have to access
    * that constructor via reflection.
    */
+
   private TcpClient getLegacyTcpClient()
       throws NoSuchMethodException, IllegalAccessException, InvocationTargetException,
       InstantiationException {
@@ -251,25 +268,6 @@ public class TcpServerProductVersionDUnitTest implements Serializable {
         TcpSocketFactory.DEFAULT);
   }
 
-  private int createLocator(VM memberVM, boolean usingOldVersion) {
-    return memberVM.invoke("create locator", () -> {
-      System.setProperty(GMSJoinLeave.BYPASS_DISCOVERY_PROPERTY, "true");
-      try {
-        int port = 0;
-        // for stress-tests make sure that an older-version locator doesn't try
-        // to read state persisted by another run's newer-version locator
-        if (usingOldVersion) {
-          port = AvailablePortHelper.getRandomAvailableTCPPort();
-          DistributedTestUtils.deleteLocatorStateFile(port);
-        }
-        return Locator.startLocatorAndDS(port, new File(""), getDistributedSystemProperties())
-            .getPort();
-      } finally {
-        System.clearProperty(GMSJoinLeave.BYPASS_DISCOVERY_PROPERTY);
-      }
-    });
-  }
-
   public Properties getDistributedSystemProperties() {
     Properties properties = new Properties();
     properties.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");