You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by je...@apache.org on 2016/05/19 13:08:55 UTC

[1/2] incubator-geode git commit: GEODE-1243: Updates to use new CategoryWithParameterizedRunnerFactory

Repository: incubator-geode
Updated Branches:
  refs/heads/develop d14af16ae -> aeb8c01df


GEODE-1243: Updates to use new CategoryWithParameterizedRunnerFactory


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/aeb8c01d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/aeb8c01d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/aeb8c01d

Branch: refs/heads/develop
Commit: aeb8c01df213b8f43a10c6e9bdf1529c5f723ffc
Parents: 6f4a879
Author: Jens Deppe <jd...@pivotal.io>
Authored: Wed May 11 07:42:23 2016 -0700
Committer: Jens Deppe <jd...@pivotal.io>
Committed: Wed May 18 14:39:17 2016 -0700

----------------------------------------------------------------------
 .../java/com/gemstone/gemfire/distributed/LocatorJUnitTest.java | 3 ++-
 .../distributed/LocatorLauncherLocalFileIntegrationTest.java    | 2 ++
 .../distributed/LocatorLauncherLocalIntegrationTest.java        | 2 ++
 .../distributed/LocatorLauncherRemoteFileIntegrationTest.java   | 2 ++
 .../distributed/LocatorLauncherRemoteIntegrationTest.java       | 2 ++
 .../LocatorLauncherRemoteWithCustomLoggingIntegrationTest.java  | 5 +++++
 6 files changed, 15 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/aeb8c01d/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorJUnitTest.java
index 1d7afae..d25427a 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorJUnitTest.java
@@ -31,8 +31,8 @@ import java.util.List;
 import java.util.Properties;
 import java.util.function.IntSupplier;
 
-import com.gemstone.gemfire.distributed.internal.DistributionConfig;
 import com.gemstone.gemfire.internal.AvailablePortHelper;
+import com.gemstone.gemfire.test.junit.runners.CategoryWithParameterizedRunnerFactory;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
@@ -60,6 +60,7 @@ import org.junit.runners.Parameterized;
 
 @Category(IntegrationTest.class)
 @RunWith(Parameterized.class)
+@Parameterized.UseParametersRunnerFactory(CategoryWithParameterizedRunnerFactory.class)
 public class LocatorJUnitTest {
 
   private static final int REQUEST_TIMEOUT = 5 * 1000;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/aeb8c01d/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalFileIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalFileIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalFileIntegrationTest.java
index 422fb7c..6451a67 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalFileIntegrationTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalFileIntegrationTest.java
@@ -18,6 +18,7 @@ package com.gemstone.gemfire.distributed;
 
 import com.gemstone.gemfire.internal.process.ProcessControllerFactory;
 import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+import com.gemstone.gemfire.test.junit.runners.CategoryWithParameterizedRunnerFactory;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -36,6 +37,7 @@ import static org.junit.Assert.assertFalse;
  */
 @Category(IntegrationTest.class)
 @RunWith(Parameterized.class)
+@Parameterized.UseParametersRunnerFactory(CategoryWithParameterizedRunnerFactory.class)
 public class LocatorLauncherLocalFileIntegrationTest extends LocatorLauncherLocalIntegrationTest {
 
   @Before

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/aeb8c01d/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalIntegrationTest.java
index 9137207..a8998f1 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalIntegrationTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalIntegrationTest.java
@@ -23,6 +23,7 @@ import java.lang.management.ManagementFactory;
 import java.net.BindException;
 import java.net.InetAddress;
 
+import com.gemstone.gemfire.test.junit.runners.CategoryWithParameterizedRunnerFactory;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Ignore;
@@ -53,6 +54,7 @@ import org.junit.runners.Parameterized;
  */
 @Category(IntegrationTest.class)
 @RunWith(Parameterized.class)
+@Parameterized.UseParametersRunnerFactory(CategoryWithParameterizedRunnerFactory.class)
 public class LocatorLauncherLocalIntegrationTest extends AbstractLocatorLauncherIntegrationTestCase {
 
   @Before

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/aeb8c01d/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherRemoteFileIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherRemoteFileIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherRemoteFileIntegrationTest.java
index 13e936d..4d8b94b 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherRemoteFileIntegrationTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherRemoteFileIntegrationTest.java
@@ -22,6 +22,7 @@ import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
 
+import com.gemstone.gemfire.test.junit.runners.CategoryWithParameterizedRunnerFactory;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -47,6 +48,7 @@ import org.junit.runners.Parameterized;
  */
 @Category(IntegrationTest.class)
 @RunWith(Parameterized.class)
+@Parameterized.UseParametersRunnerFactory(CategoryWithParameterizedRunnerFactory.class)
 public class LocatorLauncherRemoteFileIntegrationTest extends LocatorLauncherRemoteIntegrationTest {
 
   @Before

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/aeb8c01d/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherRemoteIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherRemoteIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherRemoteIntegrationTest.java
index 508c13c..5cd1fcf 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherRemoteIntegrationTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherRemoteIntegrationTest.java
@@ -29,6 +29,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicBoolean;
 
+import com.gemstone.gemfire.test.junit.runners.CategoryWithParameterizedRunnerFactory;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Ignore;
@@ -60,6 +61,7 @@ import org.junit.runners.Parameterized;
  */
 @Category(IntegrationTest.class)
 @RunWith(Parameterized.class)
+@Parameterized.UseParametersRunnerFactory(CategoryWithParameterizedRunnerFactory.class)
 public class LocatorLauncherRemoteIntegrationTest extends AbstractLocatorLauncherRemoteIntegrationTestCase {
 
   protected volatile Process process;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/aeb8c01d/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherRemoteWithCustomLoggingIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherRemoteWithCustomLoggingIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherRemoteWithCustomLoggingIntegrationTest.java
index 2e84905..5f024c8 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherRemoteWithCustomLoggingIntegrationTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherRemoteWithCustomLoggingIntegrationTest.java
@@ -24,6 +24,7 @@ import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
 
+import com.gemstone.gemfire.test.junit.runners.CategoryWithParameterizedRunnerFactory;
 import org.apache.logging.log4j.core.config.ConfigurationFactory;
 import org.junit.Before;
 import org.junit.Rule;
@@ -36,11 +37,15 @@ import com.gemstone.gemfire.internal.process.ProcessStreamReader;
 import com.gemstone.gemfire.internal.process.ProcessType;
 import com.gemstone.gemfire.internal.process.ProcessUtils;
 import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
 
 /**
  * Integration tests for launching a Locator in a forked process with custom logging configuration
  */
 @Category(IntegrationTest.class)
+@RunWith(Parameterized.class)
+@Parameterized.UseParametersRunnerFactory(CategoryWithParameterizedRunnerFactory.class)
 public class LocatorLauncherRemoteWithCustomLoggingIntegrationTest extends AbstractLocatorLauncherRemoteIntegrationTestCase {
 
   private File customConfigFile;


[2/2] incubator-geode git commit: GEODE-1243: Locator can start on ephemeral port

Posted by je...@apache.org.
GEODE-1243: Locator can start on ephemeral port


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/6f4a8793
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/6f4a8793
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/6f4a8793

Branch: refs/heads/develop
Commit: 6f4a879304b957696e220e7b806b65cfd09e4636
Parents: d14af16
Author: Jens Deppe <jd...@pivotal.io>
Authored: Wed May 4 13:06:52 2016 -0700
Committer: Jens Deppe <jd...@pivotal.io>
Committed: Wed May 18 14:39:17 2016 -0700

----------------------------------------------------------------------
 .../gemstone/gemfire/distributed/Locator.java   |   9 +-
 .../gemfire/distributed/LocatorLauncher.java    |   4 +
 .../distributed/internal/InternalLocator.java   |  49 +++++----
 .../internal/tcpserver/TcpServer.java           |  41 ++++---
 .../cli/commands/LauncherLifecycleCommands.java |   2 +-
 ...tractLocatorLauncherIntegrationTestCase.java |  21 +++-
 .../distributed/HostedLocatorsDUnitTest.java    | 110 +++++++++++++++++++
 .../gemfire/distributed/LocatorJUnitTest.java   |  65 +++++++----
 ...LocatorLauncherLocalFileIntegrationTest.java |  10 +-
 .../LocatorLauncherLocalIntegrationTest.java    |  24 +++-
 ...ocatorLauncherRemoteFileIntegrationTest.java |   5 +-
 .../LocatorLauncherRemoteIntegrationTest.java   |  29 +++++
 .../InternalDistributedSystemJUnitTest.java     |  30 +----
 .../management/LocatorManagementDUnitTest.java  |  63 ++++++++++-
 14 files changed, 344 insertions(+), 118 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6f4a8793/geode-core/src/main/java/com/gemstone/gemfire/distributed/Locator.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/distributed/Locator.java b/geode-core/src/main/java/com/gemstone/gemfire/distributed/Locator.java
index 80a0248..f089013 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/distributed/Locator.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/distributed/Locator.java
@@ -73,9 +73,6 @@ public abstract class Locator {
   /** The file to which this locator logs */
   protected File logFile;
 
-  /** The port on which this locator listens */
-  protected int port;
-
   /** The bind address for this locator */
   protected InetAddress bindAddress;
 
@@ -423,9 +420,7 @@ public abstract class Locator {
   /**
    * Returns the port on which this locator runs
    */
-  public int getPort() {
-    return this.port;
-  }
+  public abstract Integer getPort();
 
   /**
    * Returns the distributed system started by this locator, if any
@@ -504,7 +499,7 @@ public abstract class Locator {
       }
     }
     StringBuilder locatorString = new StringBuilder(String.valueOf(ba));
-    locatorString.append('[').append(this.port).append(']');
+    locatorString.append('[').append(this.getPort()).append(']');
     return locatorString.toString();
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6f4a8793/geode-core/src/main/java/com/gemstone/gemfire/distributed/LocatorLauncher.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/distributed/LocatorLauncher.java b/geode-core/src/main/java/com/gemstone/gemfire/distributed/LocatorLauncher.java
index 24b859c..b9edb59 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/distributed/LocatorLauncher.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/distributed/LocatorLauncher.java
@@ -408,6 +408,10 @@ public final class LocatorLauncher extends AbstractLauncher<String> {
    * @return an Integer value indicating the port number on which the Locator is listening for client requests.
    */
   public Integer getPort() {
+    if (locator != null) {
+      return locator.getPort();
+    }
+
     return this.port;
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6f4a8793/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/InternalLocator.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/InternalLocator.java b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/InternalLocator.java
index 7ad57ad..cf8d91e 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/InternalLocator.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/InternalLocator.java
@@ -27,13 +27,11 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Properties;
 import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 
-import com.gemstone.gemfire.InternalGemFireException;
 import org.apache.logging.log4j.Logger;
 
 import com.gemstone.gemfire.CancelException;
@@ -186,8 +184,7 @@ public class InternalLocator extends Locator implements ConnectListener {
   private volatile boolean isSharedConfigurationStarted = false; 
   
   private volatile Thread restartThread;
-  
-  
+
   public boolean isSharedConfigurationEnabled() {
     return this.config.getEnableClusterConfiguration();
   }
@@ -528,7 +525,6 @@ public class InternalLocator extends Locator implements ConnectListener {
     InetAddress bindAddress,
     String hostnameForClients,
     java.util.Properties distributedSystemProperties, DistributionConfigImpl cfg, boolean startDistributedSystem) {
-    this.port = port;
     this.logFile = logF;
     this.bindAddress = bindAddress;
     this.hostnameForClients = hostnameForClients;
@@ -551,8 +547,6 @@ public class InternalLocator extends Locator implements ConnectListener {
           bindAddress.getHostAddress());
     }
     
-    
-
     if (distributedSystemProperties != null) {
       env.putAll(distributedSystemProperties);
     }
@@ -607,14 +601,15 @@ public class InternalLocator extends Locator implements ConnectListener {
     
     this.locatorListener = WANServiceProvider.createLocatorMembershipListener();
     if(locatorListener != null) {
-      this.locatorListener.setPort(this.port);
+      // We defer setting the port until the handler is init'd - that way we'll have an actual port in the
+      // case where we're starting with port = 0.
       this.locatorListener.setConfig(this.getConfig());
     }
-    this.handler = new PrimaryHandler(this.port, this, locatorListener);
+    this.handler = new PrimaryHandler(this, locatorListener);
   
     ThreadGroup group = LoggingThreadGroup.createThreadGroup("Distribution locators", logger);
     stats = new LocatorStats();
-    server = new TcpServer(this.port, this.bindAddress, null, this.config,
+    server = new TcpServer(port, this.bindAddress, null, this.config,
         this.handler, new DelayedPoolStatHelper(), group, this.toString());
   }
 
@@ -735,7 +730,7 @@ public class InternalLocator extends Locator implements ConnectListener {
         else {
           sb.append(SocketCreator.getLocalHost().getHostAddress());
         }
-        sb.append('[').append(port).append(']');
+        sb.append('[').append(getPort()).append(']');
         thisLocator = sb.toString();
       }
       
@@ -844,7 +839,7 @@ public class InternalLocator extends Locator implements ConnectListener {
     
     this.locatorDiscoverer = WANServiceProvider.createLocatorDiscoverer();
     if(this.locatorDiscoverer != null) {
-      this.locatorDiscoverer.discover(this.port, config, locatorListener);
+      this.locatorDiscoverer.discover(getPort(), config, locatorListener);
     }
   }
   
@@ -875,7 +870,7 @@ public class InternalLocator extends Locator implements ConnectListener {
 
     this.productUseLog.monitorUse(distributedSystem);
     
-    ServerLocator sl = new ServerLocator(this.port, 
+    ServerLocator sl = new ServerLocator(getPort(),
                                          this.bindAddress,
                                          this.hostnameForClients,
                                          this.logFile,
@@ -957,7 +952,7 @@ public class InternalLocator extends Locator implements ConnectListener {
     if (this.server.isAlive()) {
       logger.info(LocalizedMessage.create(LocalizedStrings.InternalLocator_STOPPING__0, this));
       try {
-        stopLocator(this.port, this.bindAddress);
+        stopLocator(getPort(), this.bindAddress);
       } catch ( ConnectException ignore ) {
         // must not be running
       }
@@ -1234,7 +1229,19 @@ public class InternalLocator extends Locator implements ConnectListener {
   public ServerLocator getServerLocatorAdvisee() {
     return this.serverLocator;
   }
-  
+
+  /**
+   * Return the port on which the locator is actually listening. If called before the locator has actually
+   * started, this method will return null.
+   *
+   * @return the port the locator is listening on or null if it has not yet been started
+   */
+  public Integer getPort() {
+    if (server != null) {
+      return server.getPort();
+    }
+    return null;
+  }
   
   /******
    * 
@@ -1290,19 +1297,23 @@ public class InternalLocator extends Locator implements ConnectListener {
     private final LocatorMembershipListener locatorListener;
     //private final List<LocatorJoinMessage> locatorJoinMessages;
     private Object locatorJoinObject = new Object();
-    InternalLocator interalLocator;
+    private InternalLocator internalLocator;
     boolean willHaveServerLocator;  // flag to avoid warning about missing handlers during startup
     
-    public PrimaryHandler(int port, InternalLocator locator,
+    public PrimaryHandler(InternalLocator locator,
         LocatorMembershipListener listener) {
       this.locatorListener = listener;
-      interalLocator = locator;
+      internalLocator = locator;
       //this.locatorJoinMessages = new ArrayList<LocatorJoinMessage>();
     }
 
     // this method is synchronized to make sure that no new handlers are added while
     //initialization is taking place.
     public synchronized void init(TcpServer tcpServer) {
+      if (this.locatorListener != null) {
+        // This is deferred until now as the initial requested port could have been 0
+        this.locatorListener.setPort(internalLocator.getPort());
+      }
       this.tcpServer = tcpServer;
       for(Iterator itr = allHandlers.iterator(); itr.hasNext();) {
         TcpHandler handler = (TcpHandler) itr.next();
@@ -1364,7 +1375,7 @@ public class InternalLocator extends Locator implements ConnectListener {
         handler.shutDown();
       }
       } finally {
-        this.interalLocator.handleShutdown();
+        this.internalLocator.handleShutdown();
       }
     }
     

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6f4a8793/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/tcpserver/TcpServer.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/tcpserver/TcpServer.java b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/tcpserver/TcpServer.java
index c8c6f50..476636a 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/tcpserver/TcpServer.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/tcpserver/TcpServer.java
@@ -182,31 +182,22 @@ public class TcpServer {
   
   public void start() throws IOException {
     this.shuttingDown = false;
-    handler.init(this);
     startServerThread();
+    handler.init(this);
   }
   
   private void startServerThread() throws IOException {
     if (srv_sock == null || srv_sock.isClosed()) {
       if (bind_address == null) {
-        srv_sock = SocketCreator.getDefaultInstance().createServerSocket(port,
-            BACKLOG);
-        // srv_sock=new ServerSocket(port, 20); // backlog of 20 connections
+        srv_sock = SocketCreator.getDefaultInstance().createServerSocket(port, BACKLOG);
         bind_address = srv_sock.getInetAddress();
-      } else
-        srv_sock = SocketCreator.getDefaultInstance().createServerSocket(port,
-            BACKLOG, bind_address);
-
-        // TODO:GEODE-1243: srv_Sock now has a real port even though this.port is still zero -- update it or use a second var
-
-      // srv_sock=new ServerSocket(port, 20, bind_address); // backlog of 20
-      // connections
-      {
-        if (log.isInfoEnabled())
-          log.info("Locator was created at " + new Date());
-        if (log.isInfoEnabled())
-          log.info("Listening on port " + port + " bound on address "
-              + bind_address);
+      } else {
+        srv_sock = SocketCreator.getDefaultInstance().createServerSocket(port, BACKLOG, bind_address);
+      }
+
+      if (log.isInfoEnabled()) {
+        log.info("Locator was created at " + new Date());
+        log.info("Listening on port " + getPort() + " bound on address " + bind_address);
       }
       srv_sock.setReuseAddress(true); // GemStoneAddition
     }
@@ -247,6 +238,20 @@ public class TcpServer {
     return srv_sock.getLocalSocketAddress(); 
   }
 
+  /**
+   * Returns the value of the bound port. If the server was initialized with a port of 0 indicating that any
+   * ephemeral port should be used, this method will return the actual bound port.
+   *
+   * @return the port bound to this socket or 0 if the socket is closed or otherwise not connected
+   */
+  public int getPort() {
+    if (srv_sock != null && !srv_sock.isClosed()) {
+      return srv_sock.getLocalPort();
+    }
+
+    return 0;
+  }
+
   protected void run() {
     Socket sock = null;
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6f4a8793/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/commands/LauncherLifecycleCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/commands/LauncherLifecycleCommands.java b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/commands/LauncherLifecycleCommands.java
index 5b2c872..ceb6cb9 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/commands/LauncherLifecycleCommands.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/commands/LauncherLifecycleCommands.java
@@ -432,7 +432,7 @@ public class LauncherLifecycleCommands extends AbstractCommandsSupport {
         infoResultData.addLine(locatorState.toString());
 
         String locatorHostName = StringUtils.defaultIfBlank(locatorLauncher.getHostnameForClients(), getLocalHost());
-        int locatorPort = locatorLauncher.getPort();
+        int locatorPort = Integer.parseInt(locatorState.getPort());
 
         // AUTO-CONNECT
         // If the connect succeeds add the connected message to the result,

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6f4a8793/geode-core/src/test/java/com/gemstone/gemfire/distributed/AbstractLocatorLauncherIntegrationTestCase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/AbstractLocatorLauncherIntegrationTestCase.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/AbstractLocatorLauncherIntegrationTestCase.java
index 5434a01..d419b61 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/AbstractLocatorLauncherIntegrationTestCase.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/AbstractLocatorLauncherIntegrationTestCase.java
@@ -16,7 +16,10 @@
  */
 package com.gemstone.gemfire.distributed;
 
+import java.util.Arrays;
+import java.util.Collection;
 import java.util.concurrent.Callable;
+import java.util.function.IntSupplier;
 
 import org.junit.After;
 import org.junit.Before;
@@ -30,13 +33,26 @@ import com.gemstone.gemfire.distributed.LocatorLauncher.LocatorState;
 import com.gemstone.gemfire.distributed.internal.SharedConfiguration;
 import com.gemstone.gemfire.internal.AvailablePortHelper;
 import com.gemstone.gemfire.internal.DistributionLocator;
+import org.junit.runners.Parameterized;
 
 /**
  * @since 8.0
  */
 public abstract class AbstractLocatorLauncherIntegrationTestCase extends AbstractLauncherIntegrationTestCase {
 
+  @Parameterized.Parameters
+  public static Collection<Object> data() {
+    return Arrays.asList(new Object[] {
+        (IntSupplier) () -> 0,
+        (IntSupplier) () -> AvailablePortHelper.getRandomAvailableTCPPort()
+    });
+  }
+
+  @Parameterized.Parameter
+  public IntSupplier portSupplier;
+
   protected volatile int locatorPort;
+
   protected volatile LocatorLauncher launcher;
   protected volatile String workingDirectory;
   protected volatile String clusterConfigDirectory;
@@ -49,9 +65,8 @@ public abstract class AbstractLocatorLauncherIntegrationTestCase extends Abstrac
 
   @Before
   public final void setUpAbstractLocatorLauncherIntegrationTestCase() throws Exception {
-    final int port = AvailablePortHelper.getRandomAvailableTCPPort();
-    System.setProperty(DistributionLocator.TEST_OVERRIDE_DEFAULT_PORT_PROPERTY, String.valueOf(port));
-    this.locatorPort = port;
+    this.locatorPort = portSupplier.getAsInt();
+    System.setProperty(DistributionLocator.TEST_OVERRIDE_DEFAULT_PORT_PROPERTY, String.valueOf(this.locatorPort));
     this.workingDirectory = this.temporaryFolder.getRoot().getCanonicalPath();
     this.clusterConfigDirectory = this.temporaryFolder.newFolder(SharedConfiguration.CLUSTER_CONFIG_DISK_DIR_PREFIX + getUniqueName()).getCanonicalPath();
   }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6f4a8793/geode-core/src/test/java/com/gemstone/gemfire/distributed/HostedLocatorsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/HostedLocatorsDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/HostedLocatorsDUnitTest.java
index 042e896..fe8c204 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/HostedLocatorsDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/HostedLocatorsDUnitTest.java
@@ -27,6 +27,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.Callable;
 
+import com.gemstone.gemfire.test.dunit.Host;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
@@ -174,6 +175,115 @@ public class HostedLocatorsDUnitTest extends JUnit4DistributedTestCase {
     }
   }
 
+  @Test
+  public void testGetAllHostedLocatorsUsingPortZero() throws Exception {
+    final InternalDistributedSystem system = getSystem();
+    final String dunitLocator = system.getConfig().getLocators();
+    assertNotNull(dunitLocator);
+    assertFalse(dunitLocator.isEmpty());
+
+    // This will eventually contain the ports used by locators
+    final int[] ports = new int[] {0, 0, 0, 0};
+
+    final String uniqueName = getUniqueName();
+    for (int i = 0 ; i < 4; i++) {
+      final int whichvm = i;
+      Integer port = (Integer) Host.getHost(0).getVM(whichvm).invoke(new SerializableCallable() {
+        @Override
+        public Object call() throws Exception {
+          try {
+            System.setProperty("gemfire.locators", dunitLocator);
+            System.setProperty("gemfire.mcast-port", "0");
+
+            final String name = uniqueName + "-" + whichvm;
+            final File subdir = new File(name);
+            subdir.mkdir();
+            assertTrue(subdir.exists() && subdir.isDirectory());
+
+            final Builder builder = new Builder()
+                .setMemberName(name)
+                .setPort(ports[whichvm])
+                .setRedirectOutput(true)
+                .setWorkingDirectory(name);
+
+            launcher = builder.build();
+            assertEquals(Status.ONLINE, launcher.start().getStatus());
+            waitForLocatorToStart(launcher, TIMEOUT_MILLISECONDS, 10, true);
+            return launcher.getPort();
+          } finally {
+            System.clearProperty("gemfire.locators");
+            System.clearProperty("gemfire.mcast-port");
+          }
+        }
+      });
+      ports[i] = port;
+    }
+
+    final String host = SocketCreator.getLocalHost().getHostAddress();
+
+    final Set<String> locators = new HashSet<String>();
+    locators.add(host + "[" + dunitLocator.substring(dunitLocator.indexOf("[")+1, dunitLocator.indexOf("]")) + "]");
+    for (int port : ports) {
+      locators.add(host +"[" + port + "]");
+    }
+
+    // validation within non-locator
+    final DistributionManager dm = (DistributionManager)system.getDistributionManager();
+
+    final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
+    assertEquals(5, locatorIds.size());
+
+    final Map<InternalDistributedMember, Collection<String>> hostedLocators = dm.getAllHostedLocators();
+    assertTrue(!hostedLocators.isEmpty());
+    assertEquals(5, hostedLocators.size());
+
+    for (InternalDistributedMember member : hostedLocators.keySet()) {
+      assertEquals(1, hostedLocators.get(member).size());
+      final String hostedLocator = hostedLocators.get(member).iterator().next();
+      assertTrue(locators + " does not contain " + hostedLocator, locators.contains(hostedLocator));
+    }
+
+    // validate fix for #46324
+    for (int whichvm = 0 ; whichvm < 4; whichvm++) {
+      Host.getHost(0).getVM(whichvm).invoke(new SerializableRunnable() {
+        @Override
+        public void run() {
+          final DistributionManager dm = (DistributionManager)InternalDistributedSystem.getAnyInstance().getDistributionManager();
+          final InternalDistributedMember self = dm.getDistributionManagerId();
+
+          final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
+          assertTrue(locatorIds.contains(self));
+
+          final Map<InternalDistributedMember, Collection<String>> hostedLocators = dm.getAllHostedLocators();
+          assertTrue("hit bug #46324: " + hostedLocators + " is missing " + InternalLocator.getLocatorStrings() + " for " + self, hostedLocators.containsKey(self));
+        }
+      });
+    }
+
+    // validation with locators
+    for (int whichvm = 0 ; whichvm < 4; whichvm++) {
+      Host.getHost(0).getVM(whichvm).invoke(new SerializableRunnable() {
+        @Override
+        public void run() {
+          final DistributionManager dm = (DistributionManager)InternalDistributedSystem.getAnyInstance().getDistributionManager();
+
+          final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
+          assertEquals(5, locatorIds.size());
+
+          final Map<InternalDistributedMember, Collection<String>> hostedLocators = dm.getAllHostedLocators();
+          assertTrue(!hostedLocators.isEmpty());
+          assertEquals(5, hostedLocators.size());
+
+          for (InternalDistributedMember member : hostedLocators.keySet()) {
+            assertEquals(1, hostedLocators.get(member).size());
+            final String hostedLocator = hostedLocators.get(member).iterator().next();
+            assertTrue(locators + " does not contain " + hostedLocator, locators.contains(hostedLocator));
+          }
+        }
+      });
+    }
+  }
+
   protected void waitForLocatorToStart(final LocatorLauncher launcher, int timeout, int interval, boolean throwOnTimeout) throws Exception {
     assertEventuallyTrue("waiting for process to start: " + launcher.status(), new Callable<Boolean>() {
       @Override

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6f4a8793/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorJUnitTest.java
index 7ee4694..1d7afae 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorJUnitTest.java
@@ -24,10 +24,15 @@ import java.io.File;
 import java.io.IOException;
 import java.net.InetAddress;
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 import java.util.Properties;
+import java.util.function.IntSupplier;
 
+import com.gemstone.gemfire.distributed.internal.DistributionConfig;
+import com.gemstone.gemfire.internal.AvailablePortHelper;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
@@ -50,15 +55,29 @@ import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
 import com.gemstone.gemfire.internal.cache.tier.sockets.ClientProxyMembershipID;
 import com.gemstone.gemfire.management.internal.JmxManagerAdvisor.JmxManagerProfile;
 import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
 
 @Category(IntegrationTest.class)
+@RunWith(Parameterized.class)
 public class LocatorJUnitTest {
 
   private static final int REQUEST_TIMEOUT = 5 * 1000;
 
   private Locator locator;
-  private int port;
   private File tmpFile;
+  private int port;
+
+  @Parameterized.Parameters
+  public static Collection<Object> data() {
+    return Arrays.asList(new Object[] {
+        (IntSupplier) () -> 0,
+        (IntSupplier) () -> AvailablePortHelper.getRandomAvailableTCPPort()
+    });
+  }
+
+  @Parameterized.Parameter
+  public IntSupplier portSupplier;
 
   @Rule
   public TemporaryFolder temporaryFolder = new TemporaryFolder();
@@ -66,8 +85,8 @@ public class LocatorJUnitTest {
   @Before
   public void setUp() throws IOException {
     tmpFile = File.createTempFile("locator", ".log");
-    port = getRandomAvailablePort(SOCKET);
-    File locatorFile = new File("locator"+port+".dat");
+    this.port = portSupplier.getAsInt();
+    File locatorFile = new File("locator" + this.port + ".dat");
     if (locatorFile.exists()) {
       locatorFile.delete();
     }
@@ -89,7 +108,6 @@ public class LocatorJUnitTest {
     Properties dsprops = new Properties();
     int jmxPort = getRandomAvailablePort(SOCKET);
     dsprops.setProperty("mcast-port", "0");
-    dsprops.setProperty("locators", "localhost[" + port + "]");
     dsprops.setProperty("jmx-manager-port", ""+jmxPort);
     dsprops.setProperty("jmx-manager-start", "true");
     dsprops.setProperty("jmx-manager-http-port", "0");
@@ -108,18 +126,18 @@ public class LocatorJUnitTest {
   @Test
   public void testBasicInfo() throws Exception {
     locator = Locator.startLocator(port, tmpFile);
-   assertTrue(locator.isPeerLocator());
-   assertFalse(locator.isServerLocator());
-    String[] info = InternalLocator.getLocatorInfo(InetAddress.getLocalHost(), port);
-   assertNotNull(info);
-   assertTrue(info.length > 1);
+    assertTrue(locator.isPeerLocator());
+    assertFalse(locator.isServerLocator());
+    int boundPort = (port == 0) ? locator.getPort() : port;
+    String[] info = InternalLocator.getLocatorInfo(InetAddress.getLocalHost(), boundPort);
+    assertNotNull(info);
+    assertTrue(info.length > 1);
   }
 
   @Test
   public void testNoThreadLeftBehind() throws Exception {
     Properties dsprops = new Properties();
     dsprops.setProperty("mcast-port", "0");
-    dsprops.setProperty("locators", "localhost[" + port + "]");
     dsprops.setProperty("jmx-manager-start", "false");
     dsprops.setProperty(ENABLE_CLUSTER_CONFIGURATION_NAME, "false");
 
@@ -137,9 +155,9 @@ public class LocatorJUnitTest {
         }
       }
       if (threadCount < Thread.activeCount()) {
-          OSProcess.printStacks(0);
-          fail("expected " + threadCount + " threads or fewer but found " + Thread.activeCount()
-              +".  Check log file for a thread dump.");
+        OSProcess.printStacks(0);
+        fail("expected " + threadCount + " threads or fewer but found " + Thread.activeCount()
+            +".  Check log file for a thread dump.");
         }
     }
   }
@@ -153,7 +171,7 @@ public class LocatorJUnitTest {
    assertFalse(locator.isPeerLocator());
    assertTrue(locator.isServerLocator());
     Thread.sleep(1000);
-    doServerLocation();
+    doServerLocation(locator.getPort());
   }
 
   @Test
@@ -163,10 +181,10 @@ public class LocatorJUnitTest {
     props.setProperty(ENABLE_CLUSTER_CONFIGURATION_NAME, "false");
 
     locator = Locator.startLocatorAndDS(port, tmpFile, null, props);
-   assertTrue(locator.isPeerLocator());
-   assertTrue(locator.isServerLocator());
+    assertTrue(locator.isPeerLocator());
+    assertTrue(locator.isServerLocator());
     Thread.sleep(1000);
-    doServerLocation();
+    doServerLocation(locator.getPort());
     locator.stop();
   }
 
@@ -185,19 +203,18 @@ public class LocatorJUnitTest {
     }
   }
 
-  private void doServerLocation() throws Exception {
+  private void doServerLocation(int realPort) throws Exception {
     {
       ClientConnectionRequest request = new ClientConnectionRequest(Collections.EMPTY_SET, "group1");
-      ClientConnectionResponse response = (ClientConnectionResponse) TcpClient.requestToServer(InetAddress.getLocalHost(), port, request, REQUEST_TIMEOUT);
-     assertEquals(null, response.getServer());
+      ClientConnectionResponse response = (ClientConnectionResponse) TcpClient.requestToServer(InetAddress.getLocalHost(), realPort, request, REQUEST_TIMEOUT);
+      assertEquals(null, response.getServer());
     }
 
     {
       QueueConnectionRequest request = new QueueConnectionRequest(ClientProxyMembershipID.getNewProxyMembership(InternalDistributedSystem.getAnyInstance()), 3, Collections.EMPTY_SET, "group1",true);
-      QueueConnectionResponse response = (QueueConnectionResponse) TcpClient.requestToServer(InetAddress.getLocalHost(), port, request, REQUEST_TIMEOUT);
-     assertEquals(new ArrayList(), response.getServers());
-     assertFalse(response.isDurableQueueFound());
+      QueueConnectionResponse response = (QueueConnectionResponse) TcpClient.requestToServer(InetAddress.getLocalHost(), realPort, request, REQUEST_TIMEOUT);
+      assertEquals(new ArrayList(), response.getServers());
+      assertFalse(response.isDurableQueueFound());
     }
   }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6f4a8793/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalFileIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalFileIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalFileIntegrationTest.java
index c695b07..422fb7c 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalFileIntegrationTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalFileIntegrationTest.java
@@ -16,15 +16,16 @@
  */
 package com.gemstone.gemfire.distributed;
 
-import static org.junit.Assert.*;
-
+import com.gemstone.gemfire.internal.process.ProcessControllerFactory;
+import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
 
-import com.gemstone.gemfire.internal.process.ProcessControllerFactory;
-import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+import static org.junit.Assert.assertFalse;
 
 /**
  * Subclass of LocatorLauncherLocalDUnitTest which forces the code to not find 
@@ -34,6 +35,7 @@ import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
  * @since 8.0
  */
 @Category(IntegrationTest.class)
+@RunWith(Parameterized.class)
 public class LocatorLauncherLocalFileIntegrationTest extends LocatorLauncherLocalIntegrationTest {
 
   @Before

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6f4a8793/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalIntegrationTest.java
index 897d0fa..9137207 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalIntegrationTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalIntegrationTest.java
@@ -43,6 +43,8 @@ import com.gemstone.gemfire.internal.process.ProcessControllerFactory;
 import com.gemstone.gemfire.internal.process.ProcessType;
 import com.gemstone.gemfire.internal.process.ProcessUtils;
 import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
 
 /**
  * Tests usage of LocatorLauncher as a local API in existing JVM.
@@ -50,8 +52,9 @@ import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
  * @since 8.0
  */
 @Category(IntegrationTest.class)
+@RunWith(Parameterized.class)
 public class LocatorLauncherLocalIntegrationTest extends AbstractLocatorLauncherIntegrationTestCase {
-  
+
   @Before
   public final void setUpLocatorLauncherLocalIntegrationTest() throws Exception {
     disconnectFromDS();
@@ -320,6 +323,11 @@ public class LocatorLauncherLocalIntegrationTest extends AbstractLocatorLauncher
   
   @Test
   public void testStartWithDefaultPortInUseFails() throws Throwable {
+    // Test makes no sense in this case
+    if (this.locatorPort == 0) {
+      return;
+    }
+
     this.socket = SocketCreator.getDefaultInstance().createServerSocket(this.locatorPort, 50, null, -1);
     assertTrue(this.socket.isBound());
     assertFalse(this.socket.isClosed());
@@ -480,13 +488,13 @@ public class LocatorLauncherLocalIntegrationTest extends AbstractLocatorLauncher
     }
   } // testStartWithExistingPidFileFails
   */
-  
+
   @Test
   public void testStartUsingPort() throws Throwable {
     // generate one free port and then use it instead of default
     final int freeTCPPort = AvailablePortHelper.getRandomAvailableTCPPort();
     assertTrue(AvailablePort.isPortAvailable(freeTCPPort, AvailablePort.SOCKET));
-    
+
     this.launcher = new Builder()
         .setMemberName(getUniqueName())
         .setPort(freeTCPPort)
@@ -531,13 +539,17 @@ public class LocatorLauncherLocalIntegrationTest extends AbstractLocatorLauncher
   
   @Test
   public void testStartUsingPortInUseFails() throws Throwable {
+    // Test makes no sense in this case
+    if (this.locatorPort == 0) {
+      return;
+    }
+
     // generate one free port and then use it instead of default
-    final int freeTCPPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
-    this.socket = SocketCreator.getDefaultInstance().createServerSocket(freeTCPPort, 50, null, -1);
+    this.socket = SocketCreator.getDefaultInstance().createServerSocket(this.locatorPort, 50, null, -1);
     
     this.launcher = new Builder()
         .setMemberName(getUniqueName())
-        .setPort(freeTCPPort)
+        .setPort(this.locatorPort)
         .setRedirectOutput(true)
         .setWorkingDirectory(this.workingDirectory)
         .set(DistributionConfig.CLUSTER_CONFIGURATION_DIR, this.clusterConfigDirectory)

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6f4a8793/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherRemoteFileIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherRemoteFileIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherRemoteFileIntegrationTest.java
index 63f7312..13e936d 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherRemoteFileIntegrationTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherRemoteFileIntegrationTest.java
@@ -35,6 +35,8 @@ import com.gemstone.gemfire.internal.process.ProcessType;
 import com.gemstone.gemfire.internal.process.ProcessUtils;
 import com.gemstone.gemfire.lang.AttachAPINotFoundException;
 import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
 
 /**
  * Subclass of LocatorLauncherRemoteDUnitTest which forces the code to not find 
@@ -44,8 +46,9 @@ import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
  * @since 8.0
  */
 @Category(IntegrationTest.class)
+@RunWith(Parameterized.class)
 public class LocatorLauncherRemoteFileIntegrationTest extends LocatorLauncherRemoteIntegrationTest {
-  
+
   @Before
   public final void setUpLocatorLauncherRemoteFileIntegrationTest() throws Exception {
     System.setProperty(ProcessControllerFactory.PROPERTY_DISABLE_ATTACH_API, "true");

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6f4a8793/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherRemoteIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherRemoteIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherRemoteIntegrationTest.java
index a5b8831..508c13c 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherRemoteIntegrationTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherRemoteIntegrationTest.java
@@ -29,6 +29,8 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicBoolean;
 
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
@@ -48,6 +50,8 @@ import com.gemstone.gemfire.internal.process.ProcessType;
 import com.gemstone.gemfire.internal.process.ProcessUtils;
 import com.gemstone.gemfire.test.junit.categories.FlakyTest;
 import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
 
 /**
  * Integration tests for launching a Locator in a forked process.
@@ -55,8 +59,31 @@ import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
  * @since 8.0
  */
 @Category(IntegrationTest.class)
+@RunWith(Parameterized.class)
 public class LocatorLauncherRemoteIntegrationTest extends AbstractLocatorLauncherRemoteIntegrationTestCase {
+
+  protected volatile Process process;
+  protected volatile ProcessStreamReader processOutReader;
+  protected volatile ProcessStreamReader processErrReader;
   
+  @Before
+  public final void setUpLocatorLauncherRemoteTest() throws Exception {
+  }
+
+  @After
+  public final void tearDownLocatorLauncherRemoteTest() throws Exception {
+    if (this.process != null) {
+      this.process.destroy();
+      this.process = null;
+    }
+    if (this.processOutReader != null && this.processOutReader.isRunning()) {
+      this.processOutReader.stop();
+    }
+    if (this.processErrReader != null && this.processErrReader.isRunning()) {
+      this.processErrReader.stop();
+    }
+  }
+
   @Test
   public void testIsAttachAPIFound() throws Exception {
     final ProcessControllerFactory factory = new ProcessControllerFactory();
@@ -368,6 +395,7 @@ public class LocatorLauncherRemoteIntegrationTest extends AbstractLocatorLaunche
   @Test
   public void testStartUsingPortInUseFails() throws Throwable {
     this.socket = SocketCreator.getDefaultInstance().createServerSocket(this.locatorPort, 50, null, -1);
+    this.locatorPort = this.socket.getLocalPort();
     
     final List<String> jvmArguments = getJvmArguments();
     
@@ -437,6 +465,7 @@ public class LocatorLauncherRemoteIntegrationTest extends AbstractLocatorLaunche
     AtomicBoolean outputContainedExpectedString = new AtomicBoolean();
 
     this.socket = SocketCreator.getDefaultInstance().createServerSocket(this.locatorPort, 50, null, -1);
+    this.locatorPort = this.socket.getLocalPort();
     
     assertFalse(AvailablePort.isPortAvailable(this.locatorPort, AvailablePort.SOCKET));
     assertTrue(this.socket.isBound());

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6f4a8793/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/InternalDistributedSystemJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/InternalDistributedSystemJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/InternalDistributedSystemJUnitTest.java
index 8832459..827091f 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/InternalDistributedSystemJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/InternalDistributedSystemJUnitTest.java
@@ -108,8 +108,6 @@ public class InternalDistributedSystemJUnitTest
   @Test
   public void testDefaultProperties() {
     Properties props = new Properties();
-//     int unusedPort = AvailablePort.getRandomAvailablePort(AvailablePort.JGROUPS);
-//     props.setProperty("mcast-port", String.valueOf(unusedPort));
     // a loner is all this test needs
     props.setProperty("mcast-port", "0");
     props.setProperty("locators", "");
@@ -165,8 +163,6 @@ public class InternalDistributedSystemJUnitTest
 
     Properties props = new Properties();
     props.put(DistributionConfig.NAME_NAME, name);
-//     int unusedPort = AvailablePort.getRandomAvailablePort(AvailablePort.JGROUPS);
-//     props.setProperty("mcast-port", String.valueOf(unusedPort));
     // a loner is all this test needs
     props.setProperty("mcast-port", "0");
     props.setProperty("locators", "");
@@ -309,8 +305,6 @@ public class InternalDistributedSystemJUnitTest
   public void testGetLogLevel() {
     Level logLevel = Level.FINER;
     Properties props = new Properties();
-//     int unusedPort = AvailablePort.getRandomAvailablePort(AvailablePort.JGROUPS);
-//     props.setProperty("mcast-port", String.valueOf(unusedPort));
     // a loner is all this test needs
     props.setProperty("mcast-port", "0");
     props.setProperty("locators", "");
@@ -336,8 +330,6 @@ public class InternalDistributedSystemJUnitTest
   @Test
   public void testGetStatisticSamplingEnabled() {
     Properties props = new Properties();
-//     int unusedPort = AvailablePort.getRandomAvailablePort(AvailablePort.JGROUPS);
-//     props.setProperty("mcast-port", String.valueOf(unusedPort));
     // a loner is all this test needs
     props.setProperty("mcast-port", "0");
     props.setProperty("locators", "");
@@ -350,8 +342,6 @@ public class InternalDistributedSystemJUnitTest
   public void testGetStatisticSampleRate() {
     String rate = String.valueOf(DistributionConfig.MIN_STATISTIC_SAMPLE_RATE);
     Properties props = new Properties();
-//     int unusedPort = AvailablePort.getRandomAvailablePort(AvailablePort.JGROUPS);
-//     props.setProperty("mcast-port", String.valueOf(unusedPort));
     // a loner is all this test needs
     props.setProperty("mcast-port", "0");
     props.setProperty("locators", "");
@@ -391,8 +381,6 @@ public class InternalDistributedSystemJUnitTest
   public void testGetStatisticArchiveFile() {
     String fileName = "testGetStatisticArchiveFile";
     Properties props = new Properties();
-//     int unusedPort = AvailablePort.getRandomAvailablePort(AvailablePort.JGROUPS);
-//     props.setProperty("mcast-port", String.valueOf(unusedPort));
     // a loner is all this test needs
     props.setProperty("mcast-port", "0");
     props.setProperty("locators", "");
@@ -409,8 +397,6 @@ public class InternalDistributedSystemJUnitTest
   public void _testGetAckWaitThreshold() {
     String time = String.valueOf(DistributionConfig.MIN_ACK_WAIT_THRESHOLD);
     Properties props = new Properties();
-//     int unusedPort = AvailablePort.getRandomAvailablePort(AvailablePort.JGROUPS);
-//     props.setProperty("mcast-port", String.valueOf(unusedPort));
     // a loner is all this test needs
     props.setProperty("mcast-port", "0");
     props.setProperty("locators", "");
@@ -440,8 +426,6 @@ public class InternalDistributedSystemJUnitTest
   public void testGetCacheXmlFile() {
     String fileName = "blah";
     Properties props = new Properties();
-//     int unusedPort = AvailablePort.getRandomAvailablePort(AvailablePort.JGROUPS);
-//     props.setProperty("mcast-port", String.valueOf(unusedPort));
     // a loner is all this test needs
     props.setProperty("mcast-port", "0");
     props.setProperty("locators", "");
@@ -454,8 +438,6 @@ public class InternalDistributedSystemJUnitTest
   public void testGetArchiveDiskSpaceLimit() {
     String value = String.valueOf(DistributionConfig.MIN_ARCHIVE_DISK_SPACE_LIMIT);
     Properties props = new Properties();
-//     int unusedPort = AvailablePort.getRandomAvailablePort(AvailablePort.JGROUPS);
-//     props.setProperty("mcast-port", String.valueOf(unusedPort));
     // a loner is all this test needs
     props.setProperty("mcast-port", "0");
     props.setProperty("locators", "");
@@ -481,8 +463,6 @@ public class InternalDistributedSystemJUnitTest
   public void testGetArchiveFileSizeLimit() {
     String value = String.valueOf(DistributionConfig.MIN_ARCHIVE_FILE_SIZE_LIMIT);
     Properties props = new Properties();
-//     int unusedPort = AvailablePort.getRandomAvailablePort(AvailablePort.JGROUPS);
-//     props.setProperty("mcast-port", String.valueOf(unusedPort));
     // a loner is all this test needs
     props.setProperty("mcast-port", "0");
     props.setProperty("locators", "");
@@ -508,8 +488,6 @@ public class InternalDistributedSystemJUnitTest
   public void testGetLogDiskSpaceLimit() {
     String value = String.valueOf(DistributionConfig.MIN_LOG_DISK_SPACE_LIMIT);
     Properties props = new Properties();
-//     int unusedPort = AvailablePort.getRandomAvailablePort(AvailablePort.JGROUPS);
-//     props.setProperty("mcast-port", String.valueOf(unusedPort));
     // a loner is all this test needs
     props.setProperty("mcast-port", "0");
     props.setProperty("locators", "");
@@ -535,8 +513,6 @@ public class InternalDistributedSystemJUnitTest
   public void testGetLogFileSizeLimit() {
     String value = String.valueOf(DistributionConfig.MIN_LOG_FILE_SIZE_LIMIT);
     Properties props = new Properties();
-//     int unusedPort = AvailablePort.getRandomAvailablePort(AvailablePort.JGROUPS);
-//     props.setProperty("mcast-port", String.valueOf(unusedPort));
     // a loner is all this test needs
     props.setProperty("mcast-port", "0");
     props.setProperty("locators", "");
@@ -562,8 +538,6 @@ public class InternalDistributedSystemJUnitTest
   public void testAccessingClosedDistributedSystem() {
     Properties props = new Properties();
 
-//     int unusedPort = AvailablePort.getRandomAvailablePort(AvailablePort.JGROUPS);
-//     props.setProperty("mcast-port", String.valueOf(unusedPort));
     // a loner is all this test needs
     props.setProperty("mcast-port", "0");
     props.setProperty("locators", "");
@@ -659,8 +633,6 @@ public class InternalDistributedSystemJUnitTest
     Level level = Level.FINE;
 
     Properties props = new Properties();
-//     int unusedPort = AvailablePort.getRandomAvailablePort(AvailablePort.JGROUPS);
-//     props.setProperty("mcast-port", String.valueOf(unusedPort));
     // a loner is all this test needs
     props.setProperty("mcast-port", "0");
     props.setProperty("locators", "");
@@ -684,7 +656,7 @@ public class InternalDistributedSystemJUnitTest
     Assert.assertTrue(locator.isPeerLocator());
 //    Assert.assertFalse(locator.isServerLocator()); server location is forced on while licensing is disabled in GemFire
 //    Assert.assertIndexDetailsEquals("127.0.0.1", locator.getBindAddress().getHostAddress());  removed this check for ipv6 testing
-    Assert.assertEquals(unusedPort, locator.getPort());
+    Assert.assertEquals(unusedPort, locator.getPort().intValue());
     deleteStateFile(unusedPort);
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6f4a8793/geode-core/src/test/java/com/gemstone/gemfire/management/LocatorManagementDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/LocatorManagementDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/LocatorManagementDUnitTest.java
index 7399ef8..fb8ae7d 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/LocatorManagementDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/LocatorManagementDUnitTest.java
@@ -105,6 +105,28 @@ public class LocatorManagementDUnitTest extends ManagementTestBase {
 
   }
 
+  public void testPeerLocationWithPortZero() throws Exception {
+    // Start the locator with port=0
+    int locPort = startLocator(locator, true, 0);
+    locatorMBeanExist(locator, locPort, true);
+
+    Host host = Host.getHost(0);
+    String host0 = getServerHostName(host);
+    Properties props = new Properties();
+    props.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
+    props.setProperty(DistributionConfig.LOCATORS_NAME, host0 + "[" + locPort
+        + "]");
+    props.setProperty(DistributionConfig.JMX_MANAGER_NAME, "true");
+    props.setProperty(DistributionConfig.JMX_MANAGER_START_NAME, "false");
+    props.setProperty(DistributionConfig.JMX_MANAGER_PORT_NAME, "0");
+    props.setProperty(DistributionConfig.JMX_MANAGER_HTTP_PORT_NAME, "0");
+    createCache(managingNode, props);
+    startManagingNode(managingNode);
+    DistributedMember locatorMember = getMember(locator);
+    remoteLocatorMBeanExist(managingNode,locatorMember);
+
+  }
+
   /**
    * Tests a locator which is co-located with already existing cache
    * 
@@ -118,6 +140,13 @@ public class LocatorManagementDUnitTest extends ManagementTestBase {
 
   }
 
+  public void testColocatedLocatorWithPortZero() throws Exception {
+    initManagement(false);
+    int locPort = startLocator(locator, false, 0);
+    locatorMBeanExist(locator, locPort, false);
+
+  }
+
   public void testListManagers() throws Exception {
     initManagement(false);
     int locPort = AvailablePortHelper.getRandomAvailableTCPPort();
@@ -125,6 +154,12 @@ public class LocatorManagementDUnitTest extends ManagementTestBase {
     listManagers(locator, locPort, false);
   }
 
+  public void testListManagersWithPortZero() throws Exception {
+    initManagement(false);
+    int locPort = startLocator(locator, false, 0);
+    listManagers(locator, locPort, false);
+  }
+
   public void testWillingManagers() throws Exception {
     int locPort = AvailablePortHelper.getRandomAvailableTCPPort();
     startLocator(locator, true, locPort);
@@ -144,6 +179,23 @@ public class LocatorManagementDUnitTest extends ManagementTestBase {
     listWillingManagers(locator, locPort, false);
   }
 
+  public void testWillingManagersWithPortZero() throws Exception {
+    int locPort = startLocator(locator, true, 0);
+
+    Host host = Host.getHost(0);
+    String host0 = getServerHostName(host);
+
+    Properties props = new Properties();
+    props.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
+    props.setProperty(DistributionConfig.LOCATORS_NAME, host0 + "[" + locPort
+        + "]");
+    props.setProperty(DistributionConfig.JMX_MANAGER_NAME, "true");
+
+    createCache(managedNode2, props);
+    createCache(managedNode3, props);
+
+    listWillingManagers(locator, locPort, false);
+  }
 
   /**
    * Starts a locator with given configuration.
@@ -152,10 +204,9 @@ public class LocatorManagementDUnitTest extends ManagementTestBase {
    * @param vm
    *          reference to VM
    */
-  protected String startLocator(final VM vm, final boolean isPeer,
-      final int port) {
+  protected Integer startLocator(final VM vm, final boolean isPeer, final int port) {
 
-    return (String) vm.invoke(new SerializableCallable("Start Locator In VM") {
+    return (Integer) vm.invoke(new SerializableCallable("Start Locator In VM") {
 
       public Object call() throws Exception {
 
@@ -174,16 +225,16 @@ public class LocatorManagementDUnitTest extends ManagementTestBase {
           Assert.fail("While resolving bind address ", uhe);
         }
 
+        Locator locator = null;
         try {
           File logFile = new File(getTestMethodName() + "-locator" + port + ".log");
-          Locator locator = Locator.startLocatorAndDS(port, logFile, bindAddr,
-              props, isPeer, true, null);
+          locator = Locator.startLocatorAndDS(port, logFile, bindAddr, props, isPeer, true, null);
         } catch (IOException ex) {
           Assert.fail("While starting locator on port " + port, ex);
         }
 
         assertTrue(InternalLocator.hasLocator());
-        return null;
+        return locator.getPort();
       }
     });
   }