GEODE-1600: startLocatorAndDS takes 0 as port number parameter
* Use of getAvailableTCP port led to race conditions which led to
locators being assigned ports in use.
* Use of 0 now assignes a port number to the locator after the server
is started.
* Code modification to accept 0 as a valid port number until a real
port number is assigned after the server is started.
This closes #202
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/8a28f523
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/8a28f523
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/8a28f523
Branch: refs/heads/master
Commit: 8a28f52334ac08183d53b427fa9bb8feaab8f834
Parents: 5b28987
Author: nabarun <[email protected]>
Authored: Mon Jul 11 14:11:38 2016 -0700
Committer: nabarun <[email protected]>
Committed: Thu Jul 14 09:50:05 2016 -0700
----------------------------------------------------------------------
.../internal/AbstractDistributionConfig.java | 5 ++-
.../distributed/internal/InternalLocator.java | 8 +++++
.../test/dunit/standalone/DUnitLauncher.java | 36 +++++++++++++-------
3 files changed, 35 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8a28f523/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/AbstractDistributionConfig.java
----------------------------------------------------------------------
diff --git
a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/AbstractDistributionConfig.java
b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/AbstractDistributionConfig.java
index 531e462..601818e 100644
---
a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/AbstractDistributionConfig.java
+++
b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/AbstractDistributionConfig.java
@@ -322,7 +322,10 @@ public abstract class AbstractDistributionConfig
int portVal = 0;
try {
portVal = Integer.parseInt(port);
- if (portVal < 1 || portVal > 65535) {
+ if(0 == portVal){
+ return "";
+ }
+ else if (portVal < 1 || portVal > 65535) {
throw new
IllegalArgumentException(LocalizedStrings.AbstractDistributionConfig_INVALID_LOCATOR_0_THE_PORT_1_WAS_NOT_GREATER_THAN_ZERO_AND_LESS_THAN_65536.toLocalizedString(new
Object[] {value, Integer.valueOf(portVal)}));
}
} catch (NumberFormatException ex) {
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8a28f523/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 de191e8..1a343dc 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
@@ -603,6 +603,14 @@ public class InternalLocator extends Locator implements
ConnectListener {
this.handler, new DelayedPoolStatHelper(), group, this.toString());
}
+ //Reset the file names with the correct port number if startLocatorAndDS was
called with port number 0
+ public void resetInternalLocatorFileNamesWithCorrectPortNumber(int port){
+ this.stateFile = new File("locator" + port + "view.dat");
+ File productUseFile = new File("locator"+port+"views.log");
+ this.productUseLog = new ProductUseLog(productUseFile);
+ }
+
+
private void startTcpServer() throws IOException {
logger.info(LocalizedMessage.create(LocalizedStrings.InternalLocator_STARTING_0,
this));
server.start();
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8a28f523/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/DUnitLauncher.java
----------------------------------------------------------------------
diff --git
a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/DUnitLauncher.java
b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/DUnitLauncher.java
index b53327d..3335158 100755
---
a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/DUnitLauncher.java
+++
b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/DUnitLauncher.java
@@ -141,8 +141,6 @@ public class DUnitLauncher {
DUNIT_SUSPECT_FILE.delete();
DUNIT_SUSPECT_FILE.deleteOnExit();
- locatorPort = AvailablePortHelper.getRandomAvailableTCPPort();
-
//create an RMI registry and add an object to share our tests config
int namingPort = AvailablePortHelper.getRandomAvailableTCPPort();
Registry registry = LocateRegistry.createRegistry(namingPort);
@@ -184,27 +182,35 @@ public class DUnitLauncher {
processManager.killVMs();
}
});
-
+
+
//Create a VM for the locator
processManager.launchVM(LOCATOR_VM_NUM);
-
+
+ //wait for the VM to start up
+ if(!processManager.waitForVMs(STARTUP_TIMEOUT)) {
+ throw new RuntimeException("VMs did not start up with 30 seconds");
+ }
+
+ locatorPort = startLocator(registry);
+
+ init(master);
+
+
//Launch an initial set of VMs
for(int i=0; i < NUM_VMS; i++) {
processManager.launchVM(i);
}
-
+
//wait for the VMS to start up
if(!processManager.waitForVMs(STARTUP_TIMEOUT)) {
throw new RuntimeException("VMs did not start up with 30 seconds");
}
-
+
//populate the Host class with our stubs. The tests use this host class
DUnitHost host = new
DUnitHost(InetAddress.getLocalHost().getCanonicalHostName(), processManager);
host.init(registry, NUM_VMS);
- init(master);
-
- startLocator(registry);
}
public static Properties getDistributedSystemProperties() {
@@ -241,7 +247,7 @@ public class DUnitLauncher {
loggerConfig.addAppender(fileAppender, Level.INFO, null);
}
- private static void startLocator(Registry registry) throws IOException,
NotBoundException {
+ private static int startLocator(Registry registry) throws IOException,
NotBoundException {
RemoteDUnitVMIF remote = (RemoteDUnitVMIF) registry.lookup("vm" +
LOCATOR_VM_NUM);
final File locatorLogFile =
LOCATOR_LOG_TO_DISK ? new File("locator-" + locatorPort + ".log") :
new File("");
@@ -262,12 +268,15 @@ public class DUnitLauncher {
p.setProperty(DISABLE_AUTO_RECONNECT, "true");
try {
- Locator.startLocatorAndDS(locatorPort, locatorLogFile, p);
+ Locator.startLocatorAndDS(0, locatorLogFile, p);
+ InternalLocator internalLocator = (InternalLocator)
Locator.getLocator();
+ locatorPort = internalLocator.getPort();
+
internalLocator.resetInternalLocatorFileNamesWithCorrectPortNumber(locatorPort);
} finally {
System.getProperties().remove(GMSJoinLeave.BYPASS_DISCOVERY_PROPERTY);
}
-
- return null;
+
+ return locatorPort;
}
}, "call");
if(result.getException() != null) {
@@ -275,6 +284,7 @@ public class DUnitLauncher {
ex.printStackTrace();
throw ex;
}
+ return (Integer) result.getResult();
}
public static void init(MasterRemote master) {