You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2017/08/11 22:25:30 UTC
[1/2] geode git commit: GEODE-3337: Refactoring
LauncherLifecycleCommandsDUnitTest
Repository: geode
Updated Branches:
refs/heads/develop 63169699e -> 210ff9f15
http://git-wip-us.apache.org/repos/asf/geode/blob/210ff9f1/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartServerCommand.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartServerCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartServerCommand.java
index 8080e3f..035a8c1 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartServerCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartServerCommand.java
@@ -48,7 +48,7 @@ import org.apache.geode.management.internal.cli.result.ResultBuilder;
import org.apache.geode.management.internal.cli.shell.Gfsh;
import org.apache.geode.management.internal.security.ResourceConstants;
-public class StartServerCommand implements GfshCommand {
+public class StartServerCommand extends StartMemberCommand implements GfshCommand {
private static final String SERVER_TERM_NAME = "Server";
@CliCommand(value = CliStrings.START_SERVER, help = CliStrings.START_SERVER__HELP)
@@ -181,7 +181,7 @@ public class StartServerCommand implements GfshCommand {
try {
if (StringUtils.isBlank(memberName)) {
// when the user doesn't give us a name, we make one up!
- memberName = StartMemberUtils.getNameGenerator().generate('-');
+ memberName = getNameGenerator().generate('-');
}
// prompt for password is username is specified in the command
@@ -195,7 +195,7 @@ public class StartServerCommand implements GfshCommand {
}
}
- workingDirectory = StartMemberUtils.resolveWorkingDir(workingDirectory, memberName);
+ workingDirectory = resolveWorkingDir(workingDirectory, memberName);
cacheXmlPathname = CliUtil.resolvePathname(cacheXmlPathname);
@@ -219,56 +219,49 @@ public class StartServerCommand implements GfshCommand {
File serverPidFile = new File(workingDirectory, ProcessType.SERVER.getPidFileName());
- final int oldPid = StartMemberUtils.readPid(serverPidFile);
+ readPid(serverPidFile);
Properties gemfireProperties = new Properties();
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.BIND_ADDRESS,
- bindAddress);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties,
- ConfigurationProperties.CACHE_XML_FILE, cacheXmlPathname);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties,
- ConfigurationProperties.ENABLE_TIME_STATISTICS, enableTimeStatistics);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.GROUPS,
- group);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties,
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.BIND_ADDRESS, bindAddress);
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.CACHE_XML_FILE,
+ cacheXmlPathname);
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.ENABLE_TIME_STATISTICS,
+ enableTimeStatistics);
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.GROUPS, group);
+ setPropertyIfNotNull(gemfireProperties,
ConfigurationProperties.JMX_MANAGER_HOSTNAME_FOR_CLIENTS, jmxManagerHostnameForClients);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.LOCATORS,
- locators);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties,
- ConfigurationProperties.LOCATOR_WAIT_TIME, locatorWaitTime);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.LOG_LEVEL,
- logLevel);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties,
- ConfigurationProperties.MCAST_ADDRESS, mcastBindAddress);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.MCAST_PORT,
- mcastPort);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties,
- ConfigurationProperties.MEMCACHED_PORT, memcachedPort);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties,
- ConfigurationProperties.MEMCACHED_PROTOCOL, memcachedProtocol);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties,
- ConfigurationProperties.MEMCACHED_BIND_ADDRESS, memcachedBindAddress);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.REDIS_PORT,
- redisPort);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties,
- ConfigurationProperties.REDIS_BIND_ADDRESS, redisBindAddress);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties,
- ConfigurationProperties.REDIS_PASSWORD, redisPassword);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties,
- ConfigurationProperties.STATISTIC_ARCHIVE_FILE, statisticsArchivePathname);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties,
- ConfigurationProperties.USE_CLUSTER_CONFIGURATION, requestSharedConfiguration);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.LOCK_MEMORY,
- lockMemory);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties,
- ConfigurationProperties.OFF_HEAP_MEMORY_SIZE, offHeapMemorySize);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties,
- ConfigurationProperties.START_DEV_REST_API, startRestApi);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties,
- ConfigurationProperties.HTTP_SERVICE_PORT, httpServicePort);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties,
- ConfigurationProperties.HTTP_SERVICE_BIND_ADDRESS, httpServiceBindAddress);
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.LOCATORS, locators);
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.LOCATOR_WAIT_TIME,
+ locatorWaitTime);
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.LOG_LEVEL, logLevel);
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.MCAST_ADDRESS,
+ mcastBindAddress);
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.MCAST_PORT, mcastPort);
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.MEMCACHED_PORT,
+ memcachedPort);
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.MEMCACHED_PROTOCOL,
+ memcachedProtocol);
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.MEMCACHED_BIND_ADDRESS,
+ memcachedBindAddress);
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.REDIS_PORT, redisPort);
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.REDIS_BIND_ADDRESS,
+ redisBindAddress);
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.REDIS_PASSWORD,
+ redisPassword);
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.STATISTIC_ARCHIVE_FILE,
+ statisticsArchivePathname);
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.USE_CLUSTER_CONFIGURATION,
+ requestSharedConfiguration);
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.LOCK_MEMORY, lockMemory);
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.OFF_HEAP_MEMORY_SIZE,
+ offHeapMemorySize);
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.START_DEV_REST_API,
+ startRestApi);
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.HTTP_SERVICE_PORT,
+ httpServicePort);
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.HTTP_SERVICE_BIND_ADDRESS,
+ httpServiceBindAddress);
// if username is specified in the command line, it will overwrite what's set in the
// properties file
if (StringUtils.isNotBlank(userName)) {
@@ -377,9 +370,9 @@ public class StartServerCommand implements GfshCommand {
} while (!(registeredServerSignalListener && serverSignalListener.isSignaled())
&& serverState.isStartingOrNotResponding());
} finally {
- stderrReader.stopAsync(StartMemberUtils.PROCESS_STREAM_READER_ASYNC_STOP_TIMEOUT_MILLIS); // stop
- // will
- // close
+ stderrReader.stopAsync(PROCESS_STREAM_READER_ASYNC_STOP_TIMEOUT_MILLIS); // stop
+ // will
+ // close
// ErrorStream
getGfsh().getSignalHandler().unregisterListener(serverSignalListener);
}
@@ -424,16 +417,16 @@ public class StartServerCommand implements GfshCommand {
throws MalformedObjectNameException {
List<String> commandLine = new ArrayList<>();
- commandLine.add(StartMemberUtils.getJavaPath());
+ commandLine.add(getJavaPath());
commandLine.add("-server");
commandLine.add("-classpath");
commandLine.add(getServerClasspath(Boolean.TRUE.equals(includeSystemClasspath), userClasspath));
- StartMemberUtils.addCurrentLocators(this, commandLine, gemfireProperties);
- StartMemberUtils.addGemFirePropertyFile(commandLine, gemfirePropertiesFile);
- StartMemberUtils.addGemFireSecurityPropertyFile(commandLine, gemfireSecurityPropertiesFile);
- StartMemberUtils.addGemFireSystemProperties(commandLine, gemfireProperties);
- StartMemberUtils.addJvmArgumentsAndOptions(commandLine, jvmArgsOpts);
+ addCurrentLocators(this, commandLine, gemfireProperties);
+ addGemFirePropertyFile(commandLine, gemfirePropertiesFile);
+ addGemFireSecurityPropertyFile(commandLine, gemfireSecurityPropertiesFile);
+ addGemFireSystemProperties(commandLine, gemfireProperties);
+ addJvmArgumentsAndOptions(commandLine, jvmArgsOpts);
// NOTE asserting not equal to true rather than equal to false handles the null case and ensures
// the user
@@ -442,8 +435,8 @@ public class StartServerCommand implements GfshCommand {
addJvmOptionsForOutOfMemoryErrors(commandLine);
}
- StartMemberUtils.addInitialHeap(commandLine, initialHeap);
- StartMemberUtils.addMaxHeap(commandLine, maxHeap);
+ addInitialHeap(commandLine, initialHeap);
+ addMaxHeap(commandLine, maxHeap);
commandLine.add(
"-D".concat(AbstractLauncher.SIGNAL_HANDLER_REGISTRATION_SYSTEM_PROPERTY.concat("=true")));
@@ -551,9 +544,9 @@ public class StartServerCommand implements GfshCommand {
String getServerClasspath(final boolean includeSystemClasspath, final String userClasspath) {
List<String> jarFilePathnames = new ArrayList<>();
- jarFilePathnames.add(StartMemberUtils.CORE_DEPENDENCIES_JAR_PATHNAME);
+ jarFilePathnames.add(CORE_DEPENDENCIES_JAR_PATHNAME);
- return StartMemberUtils.toClasspath(includeSystemClasspath,
+ return toClasspath(includeSystemClasspath,
jarFilePathnames.toArray(new String[jarFilePathnames.size()]), userClasspath);
}
http://git-wip-us.apache.org/repos/asf/geode/blob/210ff9f1/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/lifecycle/StopLocatorCommand.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/lifecycle/StopLocatorCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/lifecycle/StopLocatorCommand.java
index 5dfb54e..da50912 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/lifecycle/StopLocatorCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/lifecycle/StopLocatorCommand.java
@@ -15,7 +15,12 @@
package org.apache.geode.management.internal.cli.commands.lifecycle;
import static org.apache.geode.management.internal.cli.i18n.CliStrings.LOCATOR_TERM_NAME;
-import static org.apache.geode.management.internal.cli.shell.MXBeanProvider.getMemberMXBean;
+
+import java.io.IOException;
+import java.util.concurrent.TimeUnit;
+
+import org.springframework.shell.core.annotation.CliCommand;
+import org.springframework.shell.core.annotation.CliOption;
import org.apache.geode.SystemFailure;
import org.apache.geode.distributed.AbstractLauncher;
@@ -30,10 +35,7 @@ import org.apache.geode.management.internal.cli.commands.GfshCommand;
import org.apache.geode.management.internal.cli.i18n.CliStrings;
import org.apache.geode.management.internal.cli.result.ResultBuilder;
import org.apache.geode.management.internal.cli.shell.Gfsh;
-import org.springframework.shell.core.annotation.CliCommand;
-import org.springframework.shell.core.annotation.CliOption;
-
-import java.util.concurrent.TimeUnit;
+import org.apache.geode.management.internal.cli.shell.MXBeanProvider;
public class StopLocatorCommand implements GfshCommand {
private static final long WAITING_FOR_STOP_TO_MAKE_PID_GO_AWAY_TIMEOUT_MILLIS = 30 * 1000;
@@ -121,4 +123,8 @@ public class StopLocatorCommand implements GfshCommand {
Gfsh.redirectInternalJavaLoggers();
}
}
+
+ MemberMXBean getMemberMXBean(String member) throws IOException {
+ return MXBeanProvider.getMemberMXBean(member);
+ }
}
http://git-wip-us.apache.org/repos/asf/geode/blob/210ff9f1/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/GfshCommandJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/GfshCommandJUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/GfshCommandJUnitTest.java
index da60c7a..e3b6ad4 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/GfshCommandJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/GfshCommandJUnitTest.java
@@ -14,14 +14,6 @@
*/
package org.apache.geode.management.internal.cli.commands;
-import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_BIND_ADDRESS;
-import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_PORT;
-import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
-import static org.apache.geode.distributed.ConfigurationProperties.LOG_FILE;
-import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
-import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
-import static org.apache.geode.distributed.ConfigurationProperties.NAME;
-import static org.apache.geode.distributed.ConfigurationProperties.START_DEV_REST_API;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -35,7 +27,6 @@ import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import java.util.Properties;
import java.util.Set;
import org.jmock.Expectations;
@@ -51,7 +42,6 @@ import org.apache.geode.cache.execute.Function;
import org.apache.geode.cache.execute.FunctionService;
import org.apache.geode.distributed.DistributedMember;
import org.apache.geode.distributed.DistributedSystem;
-import org.apache.geode.distributed.internal.DistributionConfig;
import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.internal.lang.StringUtils;
import org.apache.geode.internal.util.CollectionUtils;
@@ -409,216 +399,15 @@ public class GfshCommandJUnitTest {
@Test
public void testAddGemFirePropertyFileToCommandLine() {
- final List<String> commandLine = new ArrayList<>();
- assertTrue(commandLine.isEmpty());
- StartMemberUtils.addGemFirePropertyFile(commandLine, null);
- assertTrue(commandLine.isEmpty());
- StartMemberUtils.addGemFirePropertyFile(commandLine, new File("/path/to/gemfire.properties"));
- assertFalse(commandLine.isEmpty());
- assertTrue(commandLine.contains("-DgemfirePropertyFile=/path/to/gemfire.properties"));
- }
-
- @Test
- public void testAddGemFireSystemPropertiesToCommandLine() {
- final List<String> commandLine = new ArrayList<>();
- assertTrue(commandLine.isEmpty());
- StartMemberUtils.addGemFireSystemProperties(commandLine, new Properties());
- assertTrue(commandLine.isEmpty());
-
- final Properties gemfireProperties = new Properties();
- gemfireProperties.setProperty(LOCATORS, "localhost[11235]");
- gemfireProperties.setProperty(LOG_LEVEL, "config");
- gemfireProperties.setProperty(LOG_FILE, org.apache.commons.lang.StringUtils.EMPTY);
- gemfireProperties.setProperty(MCAST_PORT, "0");
- gemfireProperties.setProperty(NAME, "machine");
- StartMemberUtils.addGemFireSystemProperties(commandLine, gemfireProperties);
-
- assertFalse(commandLine.isEmpty());
- assertEquals(4, commandLine.size());
-
- for (final String propertyName : gemfireProperties.stringPropertyNames()) {
- final String propertyValue = gemfireProperties.getProperty(propertyName);
- if (org.apache.commons.lang.StringUtils.isBlank(propertyValue)) {
- for (final String systemProperty : commandLine) {
- assertFalse(systemProperty.startsWith(
- "-D" + DistributionConfig.GEMFIRE_PREFIX + "".concat(propertyName).concat("=")));
- }
- } else {
- assertTrue(commandLine.contains("-D" + DistributionConfig.GEMFIRE_PREFIX
- + "".concat(propertyName).concat("=").concat(propertyValue)));
- }
- }
- }
+ StartMemberCommand startMemberCommand = new StartMemberCommand();
- @Test
- public void testAddGemFireSystemPropertiesToCommandLineWithRestAPI() {
- final List<String> commandLine = new ArrayList<>();
- assertTrue(commandLine.isEmpty());
- StartMemberUtils.addGemFireSystemProperties(commandLine, new Properties());
- assertTrue(commandLine.isEmpty());
- final Properties gemfireProperties = new Properties();
- gemfireProperties.setProperty(LOCATORS, "localhost[11235]");
- gemfireProperties.setProperty(LOG_LEVEL, "config");
- gemfireProperties.setProperty(LOG_FILE, StringUtils.EMPTY);
- gemfireProperties.setProperty(MCAST_PORT, "0");
- gemfireProperties.setProperty(NAME, "machine");
- gemfireProperties.setProperty(START_DEV_REST_API, "true");
- gemfireProperties.setProperty(HTTP_SERVICE_PORT, "8080");
- gemfireProperties.setProperty(HTTP_SERVICE_BIND_ADDRESS, "localhost");
-
- StartMemberUtils.addGemFireSystemProperties(commandLine, gemfireProperties);
-
- assertFalse(commandLine.isEmpty());
- assertEquals(7, commandLine.size());
-
- for (final String propertyName : gemfireProperties.stringPropertyNames()) {
- final String propertyValue = gemfireProperties.getProperty(propertyName);
- if (StringUtils.isBlank(propertyValue)) {
- for (final String systemProperty : commandLine) {
- assertFalse(systemProperty.startsWith(
- "-D" + DistributionConfig.GEMFIRE_PREFIX + "".concat(propertyName).concat("=")));
- }
- } else {
- assertTrue(commandLine.contains("-D" + DistributionConfig.GEMFIRE_PREFIX
- + "".concat(propertyName).concat("=").concat(propertyValue)));
- }
- }
- }
-
- @Test
- public void testAddInitialHeapToCommandLine() {
final List<String> commandLine = new ArrayList<>();
assertTrue(commandLine.isEmpty());
- StartMemberUtils.addInitialHeap(commandLine, null);
- assertTrue(commandLine.isEmpty());
- StartMemberUtils.addInitialHeap(commandLine, org.apache.commons.lang.StringUtils.EMPTY);
- assertTrue(commandLine.isEmpty());
- StartMemberUtils.addInitialHeap(commandLine, " ");
+ startMemberCommand.addGemFirePropertyFile(commandLine, null);
assertTrue(commandLine.isEmpty());
- StartMemberUtils.addInitialHeap(commandLine, "512M");
+ startMemberCommand.addGemFirePropertyFile(commandLine, new File("/path/to/gemfire.properties"));
assertFalse(commandLine.isEmpty());
- assertEquals("-Xms512M", commandLine.get(0));
- }
-
- @Test
- public void testAddJvmArgumentsAndOptionsToCommandLine() {
- final List<String> commandLine = new ArrayList<>();
- assertTrue(commandLine.isEmpty());
- StartMemberUtils.addJvmArgumentsAndOptions(commandLine, null);
- assertTrue(commandLine.isEmpty());
- StartMemberUtils.addJvmArgumentsAndOptions(commandLine, new String[] {});
- assertTrue(commandLine.isEmpty());
- StartMemberUtils.addJvmArgumentsAndOptions(commandLine,
- new String[] {"-DmyProp=myVal", "-d64", "-server", "-Xprof"});
- assertFalse(commandLine.isEmpty());
- assertEquals(4, commandLine.size());
- assertEquals("-DmyProp=myVal", commandLine.get(0));
- assertEquals("-d64", commandLine.get(1));
- assertEquals("-server", commandLine.get(2));
- assertEquals("-Xprof", commandLine.get(3));
- }
-
- @Test
- public void testAddMaxHeapToCommandLine() {
- final List<String> commandLine = new ArrayList<>();
- assertTrue(commandLine.isEmpty());
- StartMemberUtils.addMaxHeap(commandLine, null);
- assertTrue(commandLine.isEmpty());
- StartMemberUtils.addMaxHeap(commandLine, org.apache.commons.lang.StringUtils.EMPTY);
- assertTrue(commandLine.isEmpty());
- StartMemberUtils.addMaxHeap(commandLine, " ");
- assertTrue(commandLine.isEmpty());
- StartMemberUtils.addMaxHeap(commandLine, "1024M");
- assertFalse(commandLine.isEmpty());
- assertEquals(3, commandLine.size());
- assertEquals("-Xmx1024M", commandLine.get(0));
- assertEquals("-XX:+UseConcMarkSweepGC", commandLine.get(1));
- assertEquals(
- "-XX:CMSInitiatingOccupancyFraction=" + StartMemberUtils.CMS_INITIAL_OCCUPANCY_FRACTION,
- commandLine.get(2));
- }
-
- @Test(expected = AssertionError.class)
- public void testReadPidWithNull() {
- try {
- StartMemberUtils.readPid(null);
- } catch (AssertionError expected) {
- assertEquals("The file from which to read the process ID (pid) cannot be null!",
- expected.getMessage());
- throw expected;
- }
- }
-
- @Test
- public void testReadPidWithNonExistingFile() {
- assertEquals(StartMemberUtils.INVALID_PID,
- StartMemberUtils.readPid(new File("/path/to/non_existing/pid.file")));
- }
-
- @Test
- public void testGetSystemClasspath() {
- assertEquals(System.getProperty("java.class.path"), StartMemberUtils.getSystemClasspath());
- }
-
- @Test
- public void testToClasspath() {
- final boolean EXCLUDE_SYSTEM_CLASSPATH = false;
- final boolean INCLUDE_SYSTEM_CLASSPATH = true;
- String[] jarFilePathnames =
- {"/path/to/user/libs/A.jar", "/path/to/user/libs/B.jar", "/path/to/user/libs/C.jar"};
- String[] userClasspaths = {"/path/to/classes:/path/to/libs/1.jar:/path/to/libs/2.jar",
- "/path/to/ext/libs/1.jar:/path/to/ext/classes:/path/to/ext/lib/10.jar"};
- String expectedClasspath = StartMemberUtils.GEODE_JAR_PATHNAME.concat(File.pathSeparator)
- .concat(toClasspath(userClasspaths)).concat(File.pathSeparator)
- .concat(toClasspath(jarFilePathnames));
- assertEquals(expectedClasspath,
- StartMemberUtils.toClasspath(EXCLUDE_SYSTEM_CLASSPATH, jarFilePathnames, userClasspaths));
- expectedClasspath = StartMemberUtils.GEODE_JAR_PATHNAME.concat(File.pathSeparator)
- .concat(toClasspath(userClasspaths)).concat(File.pathSeparator)
- .concat(System.getProperty("java.class.path")).concat(File.pathSeparator)
- .concat(toClasspath(jarFilePathnames));
- assertEquals(expectedClasspath,
- StartMemberUtils.toClasspath(INCLUDE_SYSTEM_CLASSPATH, jarFilePathnames, userClasspaths));
- expectedClasspath = StartMemberUtils.GEODE_JAR_PATHNAME.concat(File.pathSeparator)
- .concat(System.getProperty("java.class.path"));
- assertEquals(expectedClasspath,
- StartMemberUtils.toClasspath(INCLUDE_SYSTEM_CLASSPATH, null, (String[]) null));
- assertEquals(StartMemberUtils.GEODE_JAR_PATHNAME,
- StartMemberUtils.toClasspath(EXCLUDE_SYSTEM_CLASSPATH, null, (String[]) null));
- assertEquals(StartMemberUtils.GEODE_JAR_PATHNAME,
- StartMemberUtils.toClasspath(EXCLUDE_SYSTEM_CLASSPATH, new String[0], ""));
- }
-
- @Test
- public void testToClassPathOrder() {
- String userClasspathOne = "/path/to/user/lib/a.jar:/path/to/user/classes";
- String userClasspathTwo =
- "/path/to/user/lib/x.jar:/path/to/user/lib/y.jar:/path/to/user/lib/z.jar";
-
- String expectedClasspath = StartMemberUtils.getGemFireJarPath().concat(File.pathSeparator)
- .concat(userClasspathOne).concat(File.pathSeparator).concat(userClasspathTwo)
- .concat(File.pathSeparator).concat(System.getProperty("java.class.path"))
- .concat(File.pathSeparator).concat(StartMemberUtils.CORE_DEPENDENCIES_JAR_PATHNAME)
- .concat(File.pathSeparator).concat(StartMemberUtils.CORE_DEPENDENCIES_JAR_PATHNAME);
-
- String actualClasspath =
- StartMemberUtils.toClasspath(true,
- new String[] {StartMemberUtils.CORE_DEPENDENCIES_JAR_PATHNAME,
- StartMemberUtils.CORE_DEPENDENCIES_JAR_PATHNAME},
- userClasspathOne, userClasspathTwo);
-
- assertEquals(expectedClasspath, actualClasspath);
+ assertTrue(commandLine.contains("-DgemfirePropertyFile=/path/to/gemfire.properties"));
}
- private String toClasspath(final String... jarFilePathnames) {
- String classpath = org.apache.commons.lang.StringUtils.EMPTY;
- if (jarFilePathnames != null) {
- for (final String jarFilePathname : jarFilePathnames) {
- classpath +=
- (classpath.isEmpty() ? org.apache.commons.lang.StringUtils.EMPTY : File.pathSeparator);
- classpath += jarFilePathname;
- }
- }
- return classpath;
- }
}
http://git-wip-us.apache.org/repos/asf/geode/blob/210ff9f1/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommandUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommandUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommandUnitTest.java
new file mode 100644
index 0000000..3550638
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommandUnitTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.geode.management.internal.cli.commands;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.spy;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.management.cli.Result;
+import org.apache.geode.management.internal.cli.result.CommandResult;
+import org.apache.geode.test.dunit.rules.GfshParserRule;
+import org.apache.geode.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class StartLocatorCommandUnitTest {
+ @Rule
+ public GfshParserRule gfshRule = new GfshParserRule();
+
+ private StartLocatorCommand command;
+ private CommandResult result;
+
+ @Before
+ public void before() throws Exception {
+ command = spy(StartLocatorCommand.class);
+ }
+
+ @Test
+ public void failsOnMissingGemFirePropertiesFile() throws Exception {
+ result =
+ gfshRule.executeCommandWithInstance(command, "start locator --properties-file=notExist");
+ assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR);
+ assertThat(result.toString()).contains("notExist could not be found");
+ }
+
+ @Test
+ public void failsOnMissingGemFireSecurityPropertiesFile() throws Exception {
+ result = gfshRule.executeCommandWithInstance(command,
+ "start locator --security-properties-file=notExist");
+ assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR);
+ assertThat(result.toString()).contains("notExist could not be found");
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/210ff9f1/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/StartMemberCommandTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/StartMemberCommandTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/StartMemberCommandTest.java
new file mode 100644
index 0000000..911e752
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/StartMemberCommandTest.java
@@ -0,0 +1,335 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.geode.management.internal.cli.commands;
+
+import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_BIND_ADDRESS;
+import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.LOG_FILE;
+import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.NAME;
+import static org.apache.geode.distributed.ConfigurationProperties.START_DEV_REST_API;
+import static org.assertj.core.api.Java6Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.StringUtils;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TemporaryFolder;
+import org.junit.rules.TestName;
+
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.internal.util.IOUtils;
+import org.apache.geode.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class StartMemberCommandTest {
+ private StartMemberCommand startMemberCommand;
+
+ @Rule
+ public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+ @Rule
+ public TestName testName = new TestName();
+
+ @Before
+ public void before() {
+ startMemberCommand = new StartMemberCommand();
+ }
+
+ @Test
+ public void testAddGemFirePropertyFileToCommandLine() {
+ final List<String> commandLine = new ArrayList<>();
+ assertTrue(commandLine.isEmpty());
+ startMemberCommand.addGemFirePropertyFile(commandLine, null);
+ assertTrue(commandLine.isEmpty());
+ startMemberCommand.addGemFirePropertyFile(commandLine, null);
+ assertTrue(commandLine.isEmpty());
+ startMemberCommand.addGemFirePropertyFile(commandLine, null);
+ assertTrue(commandLine.isEmpty());
+ startMemberCommand.addGemFirePropertyFile(commandLine, new File("/path/to/gemfire.properties"));
+ assertFalse(commandLine.isEmpty());
+ assertTrue(commandLine.contains("-DgemfirePropertyFile=/path/to/gemfire.properties"));
+ }
+
+ @Test
+ public void testAddGemFireSystemPropertiesToCommandLine() {
+ final List<String> commandLine = new ArrayList<>();
+ assertTrue(commandLine.isEmpty());
+ startMemberCommand.addGemFireSystemProperties(commandLine, new Properties());
+ assertTrue(commandLine.isEmpty());
+
+ final Properties gemfireProperties = new Properties();
+ gemfireProperties.setProperty(LOCATORS, "localhost[11235]");
+ gemfireProperties.setProperty(LOG_LEVEL, "config");
+ gemfireProperties.setProperty(LOG_FILE, org.apache.commons.lang.StringUtils.EMPTY);
+ gemfireProperties.setProperty(MCAST_PORT, "0");
+ gemfireProperties.setProperty(NAME, "machine");
+ startMemberCommand.addGemFireSystemProperties(commandLine, gemfireProperties);
+
+ assertFalse(commandLine.isEmpty());
+ assertEquals(4, commandLine.size());
+
+ for (final String propertyName : gemfireProperties.stringPropertyNames()) {
+ final String propertyValue = gemfireProperties.getProperty(propertyName);
+ if (org.apache.commons.lang.StringUtils.isBlank(propertyValue)) {
+ for (final String systemProperty : commandLine) {
+ assertFalse(systemProperty.startsWith(
+ "-D" + DistributionConfig.GEMFIRE_PREFIX + "".concat(propertyName).concat("=")));
+ }
+ } else {
+ assertTrue(commandLine.contains("-D" + DistributionConfig.GEMFIRE_PREFIX
+ + "".concat(propertyName).concat("=").concat(propertyValue)));
+ }
+ }
+ }
+
+ @Test
+ public void testAddGemFireSystemPropertiesToCommandLineWithRestAPI() {
+ final List<String> commandLine = new ArrayList<>();
+ assertTrue(commandLine.isEmpty());
+ startMemberCommand.addGemFireSystemProperties(commandLine, new Properties());
+ assertTrue(commandLine.isEmpty());
+ final Properties gemfireProperties = new Properties();
+ gemfireProperties.setProperty(LOCATORS, "localhost[11235]");
+ gemfireProperties.setProperty(LOG_LEVEL, "config");
+ gemfireProperties.setProperty(LOG_FILE, "");
+ gemfireProperties.setProperty(MCAST_PORT, "0");
+ gemfireProperties.setProperty(NAME, "machine");
+ gemfireProperties.setProperty(START_DEV_REST_API, "true");
+ gemfireProperties.setProperty(HTTP_SERVICE_PORT, "8080");
+ gemfireProperties.setProperty(HTTP_SERVICE_BIND_ADDRESS, "localhost");
+
+ startMemberCommand.addGemFireSystemProperties(commandLine, gemfireProperties);
+
+ assertFalse(commandLine.isEmpty());
+ assertEquals(7, commandLine.size());
+
+ for (final String propertyName : gemfireProperties.stringPropertyNames()) {
+ final String propertyValue = gemfireProperties.getProperty(propertyName);
+ if (StringUtils.isBlank(propertyValue)) {
+ for (final String systemProperty : commandLine) {
+ assertFalse(systemProperty.startsWith(
+ "-D" + DistributionConfig.GEMFIRE_PREFIX + "".concat(propertyName).concat("=")));
+ }
+ } else {
+ assertTrue(commandLine.contains("-D" + DistributionConfig.GEMFIRE_PREFIX
+ + "".concat(propertyName).concat("=").concat(propertyValue)));
+ }
+ }
+ }
+
+ @Test
+ public void testAddInitialHeapToCommandLine() {
+ final List<String> commandLine = new ArrayList<>();
+ assertTrue(commandLine.isEmpty());
+ startMemberCommand.addInitialHeap(commandLine, null);
+ assertTrue(commandLine.isEmpty());
+ startMemberCommand.addInitialHeap(commandLine, org.apache.commons.lang.StringUtils.EMPTY);
+ assertTrue(commandLine.isEmpty());
+ startMemberCommand.addInitialHeap(commandLine, " ");
+ assertTrue(commandLine.isEmpty());
+ startMemberCommand.addInitialHeap(commandLine, "512M");
+ assertFalse(commandLine.isEmpty());
+ assertEquals("-Xms512M", commandLine.get(0));
+ }
+
+ @Test
+ public void testAddJvmArgumentsAndOptionsToCommandLine() {
+ final List<String> commandLine = new ArrayList<>();
+ assertTrue(commandLine.isEmpty());
+ startMemberCommand.addJvmArgumentsAndOptions(commandLine, null);
+ assertTrue(commandLine.isEmpty());
+ startMemberCommand.addJvmArgumentsAndOptions(commandLine, new String[] {});
+ assertTrue(commandLine.isEmpty());
+ startMemberCommand.addJvmArgumentsAndOptions(commandLine,
+ new String[] {"-DmyProp=myVal", "-d64", "-server", "-Xprof"});
+ assertFalse(commandLine.isEmpty());
+ assertEquals(4, commandLine.size());
+ assertEquals("-DmyProp=myVal", commandLine.get(0));
+ assertEquals("-d64", commandLine.get(1));
+ assertEquals("-server", commandLine.get(2));
+ assertEquals("-Xprof", commandLine.get(3));
+ }
+
+ @Test
+ public void testAddMaxHeapToCommandLine() {
+ final List<String> commandLine = new ArrayList<>();
+ assertTrue(commandLine.isEmpty());
+ startMemberCommand.addMaxHeap(commandLine, null);
+ assertTrue(commandLine.isEmpty());
+ startMemberCommand.addMaxHeap(commandLine, org.apache.commons.lang.StringUtils.EMPTY);
+ assertTrue(commandLine.isEmpty());
+ startMemberCommand.addMaxHeap(commandLine, " ");
+ assertTrue(commandLine.isEmpty());
+ startMemberCommand.addMaxHeap(commandLine, "1024M");
+ assertFalse(commandLine.isEmpty());
+ assertEquals(3, commandLine.size());
+ assertEquals("-Xmx1024M", commandLine.get(0));
+ assertEquals("-XX:+UseConcMarkSweepGC", commandLine.get(1));
+ assertEquals(
+ "-XX:CMSInitiatingOccupancyFraction=" + StartMemberCommand.CMS_INITIAL_OCCUPANCY_FRACTION,
+ commandLine.get(2));
+ }
+
+ @Test(expected = AssertionError.class)
+ public void testReadPidWithNull() {
+ try {
+ startMemberCommand.readPid(null);
+ } catch (AssertionError expected) {
+ assertEquals("The file from which to read the process ID (pid) cannot be null!",
+ expected.getMessage());
+ throw expected;
+ }
+ }
+
+ @Test
+ public void testReadPidWithNonExistingFile() {
+ assertEquals(StartMemberCommand.INVALID_PID,
+ startMemberCommand.readPid(new File("/path/to/non_existing/pid.file")));
+ }
+
+ @Test
+ public void testGetSystemClasspath() {
+ assertEquals(System.getProperty("java.class.path"), startMemberCommand.getSystemClasspath());
+ }
+
+ @Test
+ public void testToClasspath() {
+ final boolean EXCLUDE_SYSTEM_CLASSPATH = false;
+ final boolean INCLUDE_SYSTEM_CLASSPATH = true;
+ String[] jarFilePathnames =
+ {"/path/to/user/libs/A.jar", "/path/to/user/libs/B.jar", "/path/to/user/libs/C.jar"};
+ String[] userClasspaths = {"/path/to/classes:/path/to/libs/1.jar:/path/to/libs/2.jar",
+ "/path/to/ext/libs/1.jar:/path/to/ext/classes:/path/to/ext/lib/10.jar"};
+ String expectedClasspath = StartMemberCommand.GEODE_JAR_PATHNAME.concat(File.pathSeparator)
+ .concat(toClasspath(userClasspaths)).concat(File.pathSeparator)
+ .concat(toClasspath(jarFilePathnames));
+ assertEquals(expectedClasspath,
+ startMemberCommand.toClasspath(EXCLUDE_SYSTEM_CLASSPATH, jarFilePathnames, userClasspaths));
+ expectedClasspath = StartMemberCommand.GEODE_JAR_PATHNAME.concat(File.pathSeparator)
+ .concat(toClasspath(userClasspaths)).concat(File.pathSeparator)
+ .concat(System.getProperty("java.class.path")).concat(File.pathSeparator)
+ .concat(toClasspath(jarFilePathnames));
+ assertEquals(expectedClasspath,
+ startMemberCommand.toClasspath(INCLUDE_SYSTEM_CLASSPATH, jarFilePathnames, userClasspaths));
+ expectedClasspath = StartMemberCommand.GEODE_JAR_PATHNAME.concat(File.pathSeparator)
+ .concat(System.getProperty("java.class.path"));
+ assertEquals(expectedClasspath,
+ startMemberCommand.toClasspath(INCLUDE_SYSTEM_CLASSPATH, null, (String[]) null));
+ assertEquals(StartMemberCommand.GEODE_JAR_PATHNAME,
+ startMemberCommand.toClasspath(EXCLUDE_SYSTEM_CLASSPATH, null, (String[]) null));
+ assertEquals(StartMemberCommand.GEODE_JAR_PATHNAME,
+ startMemberCommand.toClasspath(EXCLUDE_SYSTEM_CLASSPATH, new String[0], ""));
+ }
+
+ @Test
+ public void testToClassPathOrder() {
+ String userClasspathOne = "/path/to/user/lib/a.jar:/path/to/user/classes";
+ String userClasspathTwo =
+ "/path/to/user/lib/x.jar:/path/to/user/lib/y.jar:/path/to/user/lib/z.jar";
+
+ String expectedClasspath = startMemberCommand.getGemFireJarPath().concat(File.pathSeparator)
+ .concat(userClasspathOne).concat(File.pathSeparator).concat(userClasspathTwo)
+ .concat(File.pathSeparator).concat(System.getProperty("java.class.path"))
+ .concat(File.pathSeparator).concat(StartMemberCommand.CORE_DEPENDENCIES_JAR_PATHNAME)
+ .concat(File.pathSeparator).concat(StartMemberCommand.CORE_DEPENDENCIES_JAR_PATHNAME);
+
+ String actualClasspath =
+ startMemberCommand.toClasspath(true,
+ new String[] {StartMemberCommand.CORE_DEPENDENCIES_JAR_PATHNAME,
+ StartMemberCommand.CORE_DEPENDENCIES_JAR_PATHNAME},
+ userClasspathOne, userClasspathTwo);
+
+ assertEquals(expectedClasspath, actualClasspath);
+ }
+
+ @Test
+ public void workingDirDefaultsToMemberName() {
+ String workingDir = startMemberCommand.resolveWorkingDir(null, "server1");
+ assertThat(new File(workingDir)).exists();
+ assertThat(workingDir).endsWith("server1");
+ }
+
+ @Test
+ public void workingDirGetsCreatedIfNecessary() throws Exception {
+ File workingDir = temporaryFolder.newFolder("foo");
+ FileUtils.deleteQuietly(workingDir);
+ String workingDirString = workingDir.getAbsolutePath();
+ String resolvedWorkingDir = startMemberCommand.resolveWorkingDir(workingDirString, "server1");
+ assertThat(new File(resolvedWorkingDir)).exists();
+ assertThat(workingDirString).endsWith("foo");
+ }
+
+ @Test
+ public void testWorkingDirWithRelativePath() throws Exception {
+ Path relativePath = Paths.get("some").resolve("relative").resolve("path");
+ assertThat(relativePath.isAbsolute()).isFalse();
+ String resolvedWorkingDir =
+ startMemberCommand.resolveWorkingDir(relativePath.toString(), "server1");
+ assertThat(resolvedWorkingDir).isEqualTo(relativePath.toAbsolutePath().toString());
+ }
+
+
+ @Test
+ public void testReadPid() throws IOException {
+ final int expectedPid = 12345;
+ File folder = temporaryFolder.newFolder();
+ File pidFile =
+ new File(folder, getClass().getSimpleName() + "_" + testName.getMethodName() + ".pid");
+ assertTrue(pidFile.createNewFile());
+ pidFile.deleteOnExit();
+ writePid(pidFile, expectedPid);
+
+ final int actualPid = startMemberCommand.readPid(pidFile);
+
+ assertEquals(expectedPid, actualPid);
+ }
+
+ private String toClasspath(final String... jarFilePathnames) {
+ StringBuilder classpath = new StringBuilder(StringUtils.EMPTY);
+ if (jarFilePathnames != null) {
+ for (final String jarFilePathname : jarFilePathnames) {
+ classpath.append((classpath.length() == 0) ? StringUtils.EMPTY : File.pathSeparator);
+ classpath.append(jarFilePathname);
+ }
+ }
+ return classpath.toString();
+ }
+
+ private void writePid(final File pidFile, final int pid) throws IOException {
+ final FileWriter fileWriter = new FileWriter(pidFile, false);
+ fileWriter.write(String.valueOf(pid));
+ fileWriter.write("\n");
+ fileWriter.flush();
+ IOUtils.close(fileWriter);
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/210ff9f1/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/StartServerCommandUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/StartServerCommandUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/StartServerCommandUnitTest.java
new file mode 100644
index 0000000..41a6eb8
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/StartServerCommandUnitTest.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.geode.management.internal.cli.commands;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.management.cli.Result;
+import org.apache.geode.management.internal.cli.result.CommandResult;
+import org.apache.geode.management.internal.cli.shell.Gfsh;
+import org.apache.geode.test.dunit.rules.GfshParserRule;
+import org.apache.geode.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class StartServerCommandUnitTest {
+ @Rule
+ public GfshParserRule gfshRule = new GfshParserRule();
+
+ private StartServerCommand command;
+ private CommandResult result;
+
+ @Before
+ public void before() throws Exception {
+ command = spy(StartServerCommand.class);
+ Gfsh gfsh = mock(Gfsh.class);
+ when(command.getGfsh()).thenReturn(gfsh);
+ }
+
+ @Test
+ public void failsFastOnMissingCacheXmlFile() throws Exception {
+ result = gfshRule.executeCommandWithInstance(command, "start server --cache-xml-file=notExist");
+ assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR);
+ assertThat(result.toString()).contains("notExist could not be found.");
+ }
+
+ @Test
+ public void failsFastOnMissingGemFirePropertiesFile() throws Exception {
+ result =
+ gfshRule.executeCommandWithInstance(command, "start server --properties-file=notExist");
+ assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR);
+ assertThat(result.toString()).contains("notExist could not be found.");
+ }
+
+ @Test
+ public void failsFastOnMissingGemFireSecurityPropertiesFile() throws Exception {
+ result = gfshRule.executeCommandWithInstance(command,
+ "start server --security-properties-file=notExist");
+ assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR);
+ assertThat(result.toString()).contains("notExist could not be found.");
+ }
+
+ @Test
+ public void failsFastOnMissingPassword() throws Exception {
+ result = gfshRule.executeCommandWithInstance(command, "start server --user=test");
+ assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR);
+ assertThat(result.toString()).contains("password must be specified.");
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/210ff9f1/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/StatusLocatorCommandUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/StatusLocatorCommandUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/StatusLocatorCommandUnitTest.java
new file mode 100644
index 0000000..4c2dbdb
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/StatusLocatorCommandUnitTest.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.geode.management.internal.cli.commands;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.spy;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.management.cli.Result;
+import org.apache.geode.management.internal.cli.commands.lifecycle.StatusLocatorCommand;
+import org.apache.geode.management.internal.cli.i18n.CliStrings;
+import org.apache.geode.management.internal.cli.result.CommandResult;
+import org.apache.geode.test.dunit.rules.GfshParserRule;
+import org.apache.geode.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class StatusLocatorCommandUnitTest {
+ @Rule
+ public GfshParserRule gfshRule = new GfshParserRule();
+
+ private StatusLocatorCommand command;
+
+ @Before
+ public void before() throws Exception {
+ command = spy(StatusLocatorCommand.class);
+ }
+
+ @Test
+ public void usesMemberNameIDWhenGfshIsNotConnected() {
+ CommandResult result =
+ gfshRule.executeCommandWithInstance(command, "status locator --name=myLocator");
+ assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR);
+ assertThat(result.toString()).contains(
+ CliStrings.format(CliStrings.STATUS_SERVICE__GFSH_NOT_CONNECTED_ERROR_MESSAGE, "Locator"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/210ff9f1/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/lifecycle/StopLocatorCommandUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/lifecycle/StopLocatorCommandUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/lifecycle/StopLocatorCommandUnitTest.java
new file mode 100644
index 0000000..8b79444
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/lifecycle/StopLocatorCommandUnitTest.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.geode.management.internal.cli.commands.lifecycle;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.management.cli.Result;
+import org.apache.geode.management.internal.cli.i18n.CliStrings;
+import org.apache.geode.management.internal.cli.result.CommandResult;
+import org.apache.geode.management.internal.cli.shell.Gfsh;
+import org.apache.geode.test.dunit.rules.GfshParserRule;
+import org.apache.geode.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class StopLocatorCommandUnitTest {
+ @Rule
+ public GfshParserRule gfshRule = new GfshParserRule();
+
+ private StopLocatorCommand stopLocatorCommand;
+ private CommandResult result;
+ private Gfsh gfsh;
+
+ @Before
+ public void before() throws Exception {
+ stopLocatorCommand = spy(StopLocatorCommand.class);
+ gfsh = mock(Gfsh.class);
+ }
+
+ @Test
+ public void usesMemberNameIDWhenNotConnected() {
+ when(stopLocatorCommand.isConnectedAndReady()).thenReturn(false);
+ result =
+ gfshRule.executeCommandWithInstance(stopLocatorCommand, "stop locator --name=myLocator");
+ assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR);
+ assertThat(result.toString()).contains(
+ CliStrings.format(CliStrings.STOP_SERVICE__GFSH_NOT_CONNECTED_ERROR_MESSAGE, "Locator"));
+ }
+
+ @Test
+ public void usesMemberNameIDWhenConnected() throws IOException {
+ when(stopLocatorCommand.isConnectedAndReady()).thenReturn(true);
+ when(gfsh.isConnectedAndReady()).thenReturn(true);
+ doReturn(null).when(stopLocatorCommand).getMemberMXBean(anyString());
+ result = gfshRule.executeCommandWithInstance(stopLocatorCommand,
+ "stop locator --name=invalidLocator");
+ assertThat(result.toString()).contains(CliStrings.format(
+ CliStrings.STOP_LOCATOR__NO_LOCATOR_FOUND_FOR_MEMBER_ERROR_MESSAGE, "invalidLocator"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/210ff9f1/geode-junit/src/test/java/org/apache/geode/test/junit/rules/RetryRuleLocalWithErrorTest.java
----------------------------------------------------------------------
diff --git a/geode-junit/src/test/java/org/apache/geode/test/junit/rules/RetryRuleLocalWithErrorTest.java b/geode-junit/src/test/java/org/apache/geode/test/junit/rules/RetryRuleLocalWithErrorTest.java
index b04a6e0..cd18695 100755
--- a/geode-junit/src/test/java/org/apache/geode/test/junit/rules/RetryRuleLocalWithErrorTest.java
+++ b/geode-junit/src/test/java/org/apache/geode/test/junit/rules/RetryRuleLocalWithErrorTest.java
@@ -14,7 +14,7 @@
*/
package org.apache.geode.test.junit.rules;
-import static org.assertj.core.api.Assertions.*;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import java.util.List;
[2/2] geode git commit: GEODE-3337: Refactoring
LauncherLifecycleCommandsDUnitTest
Posted by kl...@apache.org.
GEODE-3337: Refactoring LauncherLifecycleCommandsDUnitTest
This closes #701
Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/210ff9f1
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/210ff9f1
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/210ff9f1
Branch: refs/heads/develop
Commit: 210ff9f15460c993f2bf7fd682d50ee65462cd23
Parents: 6316969
Author: YehEmily <em...@gmail.com>
Authored: Fri Aug 11 10:22:33 2017 -0700
Committer: Kirk Lund <kl...@apache.org>
Committed: Fri Aug 11 15:10:52 2017 -0700
----------------------------------------------------------------------
.../commands/GfshCommandIntegrationTest.java | 69 +-
.../LauncherLifecycleCommandsDUnitTest.java | 1115 ------------------
.../cli/commands/StartLocatorCommandTest.java | 4 +-
.../cli/commands/StartServerCommandTest.java | 4 +-
.../test/dunit/rules/gfsh/ProcessLogger.java | 10 +-
.../cli/commands/StartLocatorCommand.java | 67 +-
.../cli/commands/StartMemberCommand.java | 248 ++++
.../internal/cli/commands/StartMemberUtils.java | 251 ----
.../cli/commands/StartServerCommand.java | 117 +-
.../commands/lifecycle/StopLocatorCommand.java | 16 +-
.../cli/commands/GfshCommandJUnitTest.java | 219 +---
.../commands/StartLocatorCommandUnitTest.java | 59 +
.../cli/commands/StartMemberCommandTest.java | 335 ++++++
.../commands/StartServerCommandUnitTest.java | 78 ++
.../commands/StatusLocatorCommandUnitTest.java | 53 +
.../lifecycle/StopLocatorCommandUnitTest.java | 74 ++
.../rules/RetryRuleLocalWithErrorTest.java | 2 +-
17 files changed, 961 insertions(+), 1760 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode/blob/210ff9f1/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/GfshCommandIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/GfshCommandIntegrationTest.java b/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/GfshCommandIntegrationTest.java
index 263b12c..a191905 100644
--- a/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/GfshCommandIntegrationTest.java
+++ b/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/GfshCommandIntegrationTest.java
@@ -15,16 +15,11 @@
package org.apache.geode.management.internal.cli.commands;
-import static org.assertj.core.api.Java6Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
-import java.io.FileWriter;
import java.io.IOException;
-import java.nio.file.Path;
-import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -33,14 +28,12 @@ import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
-import org.apache.commons.io.FileUtils;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestName;
-import org.apache.geode.internal.util.IOUtils;
import org.apache.geode.test.junit.categories.IntegrationTest;
@Category(IntegrationTest.class)
@@ -52,60 +45,8 @@ public class GfshCommandIntegrationTest {
public TestName testName = new TestName();
@Test
- public void workingDirDefaultsToMemberName() {
- StartServerCommand startServer = new StartServerCommand();
- String workingDir = StartMemberUtils.resolveWorkingDir(null, "server1");
- assertThat(new File(workingDir)).exists();
- assertThat(workingDir).endsWith("server1");
- }
-
- @Test
- public void workingDirGetsCreatedIfNecessary() throws Exception {
- File workingDir = temporaryFolder.newFolder("foo");
- FileUtils.deleteQuietly(workingDir);
- String workingDirString = workingDir.getAbsolutePath();
-
- StartServerCommand startServer = new StartServerCommand();
-
- String resolvedWorkingDir = StartMemberUtils.resolveWorkingDir(workingDirString, "server1");
- assertThat(new File(resolvedWorkingDir)).exists();
- assertThat(workingDirString).endsWith("foo");
- }
-
- @Test
- public void testWorkingDirWithRelativePath() throws Exception {
- Path relativePath = Paths.get("some").resolve("relative").resolve("path");
- assertThat(relativePath.isAbsolute()).isFalse();
-
- StartServerCommand startServer = new StartServerCommand();
-
- String resolvedWorkingDir =
- StartMemberUtils.resolveWorkingDir(relativePath.toString(), "server1");
-
- assertThat(resolvedWorkingDir).isEqualTo(relativePath.toAbsolutePath().toString());
- }
-
- @Test
- public void testReadPid() throws IOException {
- final int expectedPid = 12345;
-
- File folder = temporaryFolder.newFolder();
- File pidFile =
- new File(folder, getClass().getSimpleName() + "_" + testName.getMethodName() + ".pid");
-
- assertTrue(pidFile.createNewFile());
-
- pidFile.deleteOnExit();
- writePid(pidFile, expectedPid);
-
- final int actualPid = StartMemberUtils.readPid(pidFile);
-
- assertEquals(expectedPid, actualPid);
- }
-
- @Test
public void testGemFireCoreClasspath() throws IOException {
- File coreDependenciesJar = new File(StartMemberUtils.CORE_DEPENDENCIES_JAR_PATHNAME);
+ File coreDependenciesJar = new File(StartMemberCommand.CORE_DEPENDENCIES_JAR_PATHNAME);
assertNotNull(coreDependenciesJar);
assertTrue(coreDependenciesJar + " is not a file", coreDependenciesJar.isFile());
Collection<String> expectedJarDependencies =
@@ -167,11 +108,5 @@ public class GfshCommandIntegrationTest {
missingExpectedJarDependenciesList.isEmpty());
}
- private void writePid(final File pidFile, final int pid) throws IOException {
- final FileWriter fileWriter = new FileWriter(pidFile, false);
- fileWriter.write(String.valueOf(pid));
- fileWriter.write("\n");
- fileWriter.flush();
- IOUtils.close(fileWriter);
- }
+
}
http://git-wip-us.apache.org/repos/asf/geode/blob/210ff9f1/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommandsDUnitTest.java b/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommandsDUnitTest.java
deleted file mode 100644
index 6e5d17c..0000000
--- a/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommandsDUnitTest.java
+++ /dev/null
@@ -1,1115 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.apache.geode.management.internal.cli.commands;
-
-import static org.apache.geode.distributed.ConfigurationProperties.DURABLE_CLIENT_ID;
-import static org.apache.geode.distributed.ConfigurationProperties.START_LOCATOR;
-import static org.apache.geode.test.dunit.Assert.assertEquals;
-import static org.apache.geode.test.dunit.Assert.assertFalse;
-import static org.apache.geode.test.dunit.Assert.assertNotNull;
-import static org.apache.geode.test.dunit.Assert.assertTrue;
-import static org.apache.geode.test.dunit.Wait.waitForCriterion;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.lang.management.ManagementFactory;
-import java.net.InetAddress;
-import java.nio.charset.Charset;
-import java.text.DateFormat;
-import java.text.MessageFormat;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Queue;
-import java.util.Set;
-import java.util.concurrent.ConcurrentLinkedDeque;
-import java.util.concurrent.TimeUnit;
-
-import javax.management.MBeanServerConnection;
-import javax.management.ObjectName;
-import javax.management.Query;
-import javax.management.QueryExp;
-import javax.management.remote.JMXConnector;
-import javax.management.remote.JMXConnectorFactory;
-import javax.management.remote.JMXServiceURL;
-
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runners.MethodSorters;
-
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.client.ClientCache;
-import org.apache.geode.cache.client.ClientCacheFactory;
-import org.apache.geode.cache.client.ClientRegionFactory;
-import org.apache.geode.cache.client.ClientRegionShortcut;
-import org.apache.geode.cache.client.Pool;
-import org.apache.geode.cache.client.PoolFactory;
-import org.apache.geode.cache.client.PoolManager;
-import org.apache.geode.distributed.AbstractLauncher.ServiceState;
-import org.apache.geode.distributed.AbstractLauncher.Status;
-import org.apache.geode.distributed.LocatorLauncher;
-import org.apache.geode.distributed.LocatorLauncher.Builder;
-import org.apache.geode.distributed.LocatorLauncher.Command;
-import org.apache.geode.distributed.LocatorLauncher.LocatorState;
-import org.apache.geode.distributed.ServerLauncher;
-import org.apache.geode.distributed.ServerLauncher.ServerState;
-import org.apache.geode.distributed.internal.DistributionConfig;
-import org.apache.geode.internal.AvailablePortHelper;
-import org.apache.geode.internal.lang.ObjectUtils;
-import org.apache.geode.internal.lang.StringUtils;
-import org.apache.geode.internal.lang.SystemUtils;
-import org.apache.geode.internal.process.ProcessType;
-import org.apache.geode.internal.process.ProcessUtils;
-import org.apache.geode.internal.util.IOUtils;
-import org.apache.geode.management.cli.Result;
-import org.apache.geode.management.internal.cli.i18n.CliStrings;
-import org.apache.geode.management.internal.cli.result.CommandResult;
-import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
-import org.apache.geode.test.dunit.WaitCriterion;
-import org.apache.geode.test.junit.categories.DistributedTest;
-
-/**
- * The LauncherLifecycleCommandsDUnitTest class is a test suite of integration tests testing the
- * contract and functionality of the GemFire launcher lifecycle commands inside Gfsh.
- *
- * @see javax.management.MBeanServerConnection
- * @see javax.management.remote.JMXConnector
- * @see org.apache.geode.distributed.AbstractLauncher
- * @see org.apache.geode.distributed.LocatorLauncher
- * @see org.apache.geode.distributed.ServerLauncher
- * @see org.apache.geode.internal.AvailablePortHelper
- * @see org.apache.geode.management.internal.cli.shell.Gfsh
- * @see org.apache.geode.management.internal.cli.commands.CliCommandTestBase
- * @see org.apache.geode.management.internal.cli.util.CommandStringBuilder
- * @since GemFire 7.0
- */
-@Category(DistributedTest.class)
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class LauncherLifecycleCommandsDUnitTest extends CliCommandTestBase {
-
- protected static final DateFormat TIMESTAMP = new SimpleDateFormat("yyyyMMddHHmmssSSS");
-
- private final Queue<Integer> processIds = new ConcurrentLinkedDeque<>();
-
- protected static String getMemberId(final int jmxManagerPort, final String memberName)
- throws Exception {
- return getMemberId(InetAddress.getLocalHost().getHostName(), jmxManagerPort, memberName);
- }
-
- protected static String getMemberId(final String jmxManagerHost, final int jmxManagerPort,
- final String memberName) throws Exception {
- JMXConnector connector = null;
-
- try {
- connector = JMXConnectorFactory.connect(new JMXServiceURL(String.format(
- "service:jmx:rmi://%1$s/jndi/rmi://%1$s:%2$d/jmxrmi", jmxManagerHost, jmxManagerPort)));
-
- MBeanServerConnection connection = connector.getMBeanServerConnection();
-
- ObjectName objectNamePattern = ObjectName.getInstance("GemFire:type=Member,*");
-
- QueryExp query = Query.eq(Query.attr("Name"), Query.value(memberName));
-
- Set<ObjectName> objectNames = connection.queryNames(objectNamePattern, query);
-
- assertNotNull(objectNames);
- assertFalse(objectNames.isEmpty());
- assertEquals(1, objectNames.size());
-
- // final ObjectName objectName = ObjectName.getInstance("GemFire:type=Member,Name=" +
- // memberName);
- ObjectName objectName = objectNames.iterator().next();
-
- // System.err.printf("ObjectName for Member with Name (%1$s) is %2$s%n", memberName,
- // objectName);
-
- return ObjectUtils.toString(connection.getAttribute(objectName, "Id"));
- } finally {
- IOUtils.close(connector);
- }
- }
-
- @Override
- public final void postTearDown() throws Exception {
- Integer pid;
-
- while ((pid = processIds.poll()) != null) {
- if (ProcessUtils.isProcessAlive(pid)) {
- try {
- String killCommand = String.format("%1$s %2$d",
- SystemUtils.isWindows() ? "taskkill /F /PID" : "kill -9", pid);
- Runtime.getRuntime().exec(killCommand);
- } catch (Throwable ignore) {
- }
- }
- }
- }
-
- @SuppressWarnings("unused")
- protected void assertStatus(final LocatorState expectedStatus, final LocatorState actualStatus) {
- assertEquals(expectedStatus.getStatus(), actualStatus.getStatus());
- assertEquals(expectedStatus.getTimestamp(), actualStatus.getTimestamp());
- assertEquals(expectedStatus.getServiceLocation(), actualStatus.getServiceLocation());
- assertTrue(ObjectUtils.equalsIgnoreNull(expectedStatus.getPid(), actualStatus.getPid()));
- assertEquals(expectedStatus.getUptime(), actualStatus.getUptime());
- assertEquals(expectedStatus.getWorkingDirectory(), actualStatus.getWorkingDirectory());
- assertEquals(expectedStatus.getJvmArguments(), actualStatus.getJvmArguments());
- assertEquals(expectedStatus.getClasspath(), actualStatus.getClasspath());
- assertEquals(expectedStatus.getGemFireVersion(), actualStatus.getGemFireVersion());
- assertEquals(expectedStatus.getJavaVersion(), actualStatus.getJavaVersion());
- }
-
- protected Integer readPid(final File workingDirectory) throws IOException {
- assertTrue(String.format("The working directory (%1$s) must exist!", workingDirectory),
- workingDirectory != null && workingDirectory.isDirectory());
-
- File[] files = workingDirectory.listFiles(pathname -> (pathname != null && pathname.isFile()
- && pathname.getAbsolutePath().endsWith(".pid")));
-
- assertNotNull(files);
- assertTrue(files.length > 0);
-
- File pidFile = files[0];
-
- BufferedReader fileReader = null;
-
- try {
- fileReader = new BufferedReader(new FileReader(pidFile), 1024);
- return Integer.parseInt(fileReader.readLine().trim());
- } catch (Exception ignore) {
- return null;
- } finally {
- IOUtils.close(fileReader);
- }
- }
-
- protected String serviceStateStatusStringNormalized(final ServiceState serviceState) {
- return serviceStateStatusStringNormalized(serviceState.toString());
- }
-
- protected String serviceStateStatusStringNormalized(final String serviceStateStatus) {
- assertNotNull(serviceStateStatus);
- assertTrue("serviceStateStatus is missing 'Uptime': " + serviceStateStatus,
- serviceStateStatus.contains("Uptime"));
- assertTrue("serviceStateStatus is missing 'JVM Arguments': " + serviceStateStatus,
- serviceStateStatus.contains("JVM Arguments"));
-
- return serviceStateStatus.substring(0, serviceStateStatus.indexOf("Uptime"))
- .concat(serviceStateStatus.substring(serviceStateStatus.indexOf("JVM Arguments")));
- }
-
- protected Status stopLocator(final File workingDirectory) {
- return stopLocator(IOUtils.tryGetCanonicalPathElseGetAbsolutePath(workingDirectory));
- }
-
- protected Status stopLocator(final String workingDirectory) {
- return waitForGemFireProcessToStop(
- new Builder().setCommand(Command.STOP).setWorkingDirectory(workingDirectory).build().stop(),
- workingDirectory);
- }
-
- protected Status stopServer(final String workingDirectory) {
- return waitForGemFireProcessToStop(
- new ServerLauncher.Builder().setCommand(ServerLauncher.Command.STOP)
- .setWorkingDirectory(workingDirectory).build().stop(),
- workingDirectory);
- }
-
- protected String toString(final Result result) {
- assert result != null : "The Result object from the command execution cannot be null!";
-
- StringBuilder buffer = new StringBuilder(StringUtils.LINE_SEPARATOR);
-
- while (result.hasNextLine()) {
- buffer.append(result.nextLine());
- buffer.append(StringUtils.LINE_SEPARATOR);
- }
-
- return buffer.toString();
- }
-
- protected Status waitForGemFireProcessToStop(final ServiceState serviceState,
- final String workingDirectory) {
- if (!Status.STOPPED.equals(serviceState.getStatus())) {
- try {
- final Integer pid = readPid(new File(workingDirectory));
-
- if (pid != null) {
- WaitCriterion waitCriteria = new WaitCriterion() {
- @Override
- public boolean done() {
- return !ProcessUtils.isProcessAlive(pid);
- }
-
- @Override
- public String description() {
- return String.format("Waiting for GemFire Process with PID (%1$d) to stop.", pid);
- }
- };
-
- waitForCriterion(waitCriteria, TimeUnit.SECONDS.toMillis(15),
- TimeUnit.SECONDS.toMillis(5), false);
-
- if (!waitCriteria.done()) {
- processIds.offer(pid);
- }
- }
- } catch (IOException ignore) {
- }
- }
-
- return serviceState.getStatus();
- }
-
- protected void writePid(final File pidFile, final int pid) throws IOException {
- assertTrue("The PID file must actually exist!", pidFile != null && pidFile.isFile());
-
- FileWriter writer = null;
-
- try {
- writer = new FileWriter(pidFile, false);
- writer.write(String.valueOf(pid));
- writer.write(System.getProperty("line.separator"));
- writer.flush();
- } finally {
- IOUtils.close(writer);
- }
- }
-
- @Test
- public void test000StartLocatorCapturesOutputOnError() throws IOException {
- final int locatorPort = AvailablePortHelper.getRandomAvailableTCPPort();
-
- String pathname = (getClass().getSimpleName() + "_" + getTestMethodName());
- File workingDirectory = temporaryFolder.newFolder(pathname);
-
- assertTrue(workingDirectory.isDirectory() || workingDirectory.mkdir());
-
- File pidFile = new File(workingDirectory, ProcessType.LOCATOR.getPidFileName());
-
- assertTrue(pidFile.createNewFile());
-
- writePid(pidFile, getPidOrOne());
- pidFile.deleteOnExit();
-
- assertTrue(pidFile.isFile());
-
- CommandStringBuilder command = new CommandStringBuilder(CliStrings.START_LOCATOR);
-
- command.addOption(CliStrings.START_LOCATOR__MEMBER_NAME, pathname);
- command.addOption(CliStrings.START_LOCATOR__DIR, workingDirectory.getCanonicalPath());
- command.addOption(CliStrings.START_LOCATOR__PORT, String.valueOf(locatorPort));
- command.addOption(CliStrings.START_LOCATOR__ENABLE__SHARED__CONFIGURATION,
- Boolean.FALSE.toString());
- command.addOption(CliStrings.START_LOCATOR__J,
- "-D" + DistributionConfig.GEMFIRE_PREFIX + "http-service-port=0");
- command.addOption(CliStrings.START_LOCATOR__J, "-D" + DistributionConfig.GEMFIRE_PREFIX
- + "jmx-manager-port=" + AvailablePortHelper.getRandomAvailableTCPPort());
-
- CommandResult result = executeCommand(command.toString());
-
- assertNotNull(result);
- assertEquals(Result.Status.ERROR, result.getStatus());
-
- String resultString = toString(result);
-
- assertTrue(resultString,
- resultString.contains(
- "Exception in thread \"main\" java.lang.RuntimeException: A PID file already exists and a Locator may be running in "
- + IOUtils.tryGetCanonicalFileElseGetAbsoluteFile(workingDirectory)));
- assertTrue(resultString,
- resultString.contains(
- "Caused by: org.apache.geode.internal.process.FileAlreadyExistsException: Pid file already exists: "
- + IOUtils.tryGetCanonicalFileElseGetAbsoluteFile(pidFile)));
- }
-
- /*
- * This method makes an effort to get the PID of the running process. If it is unable to determine
- * accurately, it simply returns 1.
- */
- private int getPidOrOne() {
- int pid = 1;
- String[] name = ManagementFactory.getRuntimeMXBean().getName().split("@");
- if (name.length > 1) {
- try {
- pid = Integer.parseInt(name[0]);
- } catch (NumberFormatException nex) {
- // Ignored
- }
- }
-
- return pid;
- }
-
- @Test
- public void test001StartLocatorFailsFastOnMissingGemFirePropertiesFile() throws IOException {
- String gemfirePropertiesPathname = "/path/to/missing/gemfire.properties";
-
- CommandStringBuilder command = new CommandStringBuilder(CliStrings.START_LOCATOR);
- String pathName = getClass().getSimpleName().concat("_").concat(getTestMethodName());
- final File workingDirectory = temporaryFolder.newFolder(pathName);
-
- command.addOption(CliStrings.START_LOCATOR__MEMBER_NAME, pathName);
- command.addOption(CliStrings.START_LOCATOR__DIR, workingDirectory.getCanonicalPath());
- command.addOption(CliStrings.START_LOCATOR__PORT, "0");
- command.addOption(CliStrings.START_LOCATOR__PROPERTIES, gemfirePropertiesPathname);
- command.addOption(CliStrings.START_LOCATOR__J,
- "-D" + DistributionConfig.GEMFIRE_PREFIX + "http-service-port=0");
- command.addOption(CliStrings.START_LOCATOR__J,
- "-D" + DistributionConfig.GEMFIRE_PREFIX + "jmx-manager=false");
- command.addOption(CliStrings.START_LOCATOR__J,
- "-D" + DistributionConfig.GEMFIRE_PREFIX + "jmx-manager-port=0");
- command.addOption(CliStrings.START_LOCATOR__J,
- "-D" + DistributionConfig.GEMFIRE_PREFIX + "jmx-manager-start=false");
-
- CommandResult result = executeCommand(command.toString());
-
- assertNotNull(result);
- assertEquals(Result.Status.ERROR, result.getStatus());
-
- String resultString = toString(result);
-
- assertTrue(resultString,
- resultString
- .contains(MessageFormat.format(CliStrings.GEODE_0_PROPERTIES_1_NOT_FOUND_MESSAGE,
- StringUtils.EMPTY, gemfirePropertiesPathname)));
- }
-
- /**
- * Test to verify GEODE-2138
- *
- * @throws IOException
- */
- @Test
- public void testVersionTitleForStartServerAndLocator() throws IOException {
- final int locatorPort = AvailablePortHelper.getRandomAvailableTCPPort();
-
- String pathname = (getClass().getSimpleName() + "_" + getTestMethodName());
- String pathnameLoc = pathname + "_loc";
- String pathnameSer = pathname + "_ser";
-
- File workingDirectoryLoc = temporaryFolder.newFolder(pathnameLoc);
- File workingDirectorySer = temporaryFolder.newFolder(pathnameSer);
-
- assertTrue(workingDirectoryLoc.isDirectory() || workingDirectoryLoc.mkdir());
- assertTrue(workingDirectorySer.isDirectory() || workingDirectorySer.mkdir());
-
- try {
- // verify the start locator output does not contain string "gemfire"
- CommandStringBuilder locCommand = new CommandStringBuilder(CliStrings.START_LOCATOR);
- locCommand.addOption(CliStrings.START_LOCATOR__MEMBER_NAME, pathnameLoc);
- locCommand.addOption(CliStrings.START_LOCATOR__CONNECT, Boolean.FALSE.toString());
- locCommand.addOption(CliStrings.START_LOCATOR__DIR, workingDirectoryLoc.getCanonicalPath());
- locCommand.addOption(CliStrings.START_LOCATOR__PORT, String.valueOf(locatorPort));
-
- CommandResult locResult = executeCommand(locCommand.toString());
- assertNotNull(locResult);
- assertEquals(Result.Status.OK, locResult.getStatus());
- String locatorOutput = toString(locResult);
- assertNotNull(locatorOutput);
- assertTrue("Locator output was: " + locatorOutput, !locatorOutput.contains("Gemfire"));
-
- // verify the start server output does not contain string "gemfire"
- CommandStringBuilder serCommand = new CommandStringBuilder(CliStrings.START_SERVER);
- serCommand.addOption(CliStrings.START_SERVER__NAME, pathnameSer);
- serCommand.addOption(CliStrings.START_SERVER__DIR, workingDirectorySer.getCanonicalPath());
-
- CommandResult serResult = executeCommand(serCommand.toString());
- assertNotNull(serResult);
- assertEquals(Result.Status.OK, serResult.getStatus());
- String serverOutput = toString(serResult);
-
- assertTrue("Server start output was: " + serverOutput, !serverOutput.contains("Gemfire"));
- } finally {
- stopLocator(workingDirectoryLoc);
- stopServer(IOUtils.tryGetCanonicalPathElseGetAbsolutePath(workingDirectorySer));
- }
- }
-
- @Test
- public void test002StartLocatorFailsFastOnMissingGemFireSecurityPropertiesFile()
- throws IOException {
- String gemfireSecurityPropertiesPathname = "/path/to/missing/gemfire-security.properties";
- String pathName = getClass().getSimpleName().concat("_").concat(getTestMethodName());
- final File workingDirectory = temporaryFolder.newFolder(pathName);
-
- CommandStringBuilder command = new CommandStringBuilder(CliStrings.START_LOCATOR);
-
- command.addOption(CliStrings.START_LOCATOR__MEMBER_NAME, pathName);
- command.addOption(CliStrings.START_LOCATOR__DIR, workingDirectory.getCanonicalPath());
- command.addOption(CliStrings.START_LOCATOR__PORT, "0");
- command.addOption(CliStrings.START_LOCATOR__SECURITY_PROPERTIES,
- gemfireSecurityPropertiesPathname);
- command.addOption(CliStrings.START_LOCATOR__J,
- "-D" + DistributionConfig.GEMFIRE_PREFIX + "http-service-port=0");
- command.addOption(CliStrings.START_LOCATOR__J,
- "-D" + DistributionConfig.GEMFIRE_PREFIX + "jmx-manager=false");
- command.addOption(CliStrings.START_LOCATOR__J,
- "-D" + DistributionConfig.GEMFIRE_PREFIX + "jmx-manager-port=0");
- command.addOption(CliStrings.START_LOCATOR__J,
- "-D" + DistributionConfig.GEMFIRE_PREFIX + "jmx-manager-start=false");
-
- CommandResult result = executeCommand(command.toString());
-
- assertNotNull(result);
- assertEquals(Result.Status.ERROR, result.getStatus());
-
- String resultString = toString(result);
-
- assertTrue(resultString,
- resultString
- .contains(MessageFormat.format(CliStrings.GEODE_0_PROPERTIES_1_NOT_FOUND_MESSAGE,
- "Security ", gemfireSecurityPropertiesPathname)));
- }
-
- @Test
- public void test003StartServerFailsFastOnMissingCacheXmlFile() throws IOException {
- String cacheXmlPathname = "/path/to/missing/cache.xml";
-
- CommandStringBuilder command = new CommandStringBuilder(CliStrings.START_SERVER);
- String pathName = getClass().getSimpleName().concat("_").concat(getTestMethodName());
- final File workingDirectory = temporaryFolder.newFolder(pathName);
-
- command.addOption(CliStrings.START_SERVER__NAME, pathName);
- command.addOption(CliStrings.START_SERVER__DIR, workingDirectory.getCanonicalPath());
- command.addOption(CliStrings.START_SERVER__CACHE_XML_FILE, cacheXmlPathname);
-
- CommandResult result = executeCommand(command.toString());
-
- assertNotNull(result);
- assertEquals(Result.Status.ERROR, result.getStatus());
-
- String resultString = toString(result);
-
- assertTrue(resultString, resultString
- .contains(MessageFormat.format(CliStrings.CACHE_XML_NOT_FOUND_MESSAGE, cacheXmlPathname)));
- }
-
- @Test
- public void test004StartServerFailsFastOnMissingGemFirePropertiesFile() throws IOException {
- String gemfirePropertiesFile = "/path/to/missing/gemfire.properties";
-
- CommandStringBuilder command = new CommandStringBuilder(CliStrings.START_SERVER);
-
- String pathName = getClass().getSimpleName().concat("_").concat(getTestMethodName());
- final File workingDirectory = temporaryFolder.newFolder(pathName);
-
- command.addOption(CliStrings.START_SERVER__NAME, pathName);
- command.addOption(CliStrings.START_SERVER__DIR, workingDirectory.getCanonicalPath());
- command.addOption(CliStrings.START_SERVER__PROPERTIES, gemfirePropertiesFile);
-
- CommandResult result = executeCommand(command.toString());
-
- assertNotNull(result);
- assertEquals(Result.Status.ERROR, result.getStatus());
-
- String resultString = toString(result);
-
- assertTrue(resultString,
- resultString
- .contains(MessageFormat.format(CliStrings.GEODE_0_PROPERTIES_1_NOT_FOUND_MESSAGE,
- StringUtils.EMPTY, gemfirePropertiesFile)));
- }
-
- @Test
- public void testStartServerFailsFastOnMissingPassword() throws IOException {
-
- CommandStringBuilder command = new CommandStringBuilder(CliStrings.START_SERVER);
-
- String pathName = getClass().getSimpleName().concat("_").concat(getTestMethodName());
- final File workingDirectory = temporaryFolder.newFolder(pathName);
-
- command.addOption(CliStrings.START_SERVER__NAME, pathName);
- command.addOption(CliStrings.START_SERVER__DIR, workingDirectory.getCanonicalPath());
- command.addOption(CliStrings.START_SERVER__USERNAME, "test");
-
- CommandResult result = executeCommand(command.toString());
-
- assertNotNull(result);
- assertEquals(Result.Status.ERROR, result.getStatus());
-
- String resultString = toString(result);
-
- assertTrue(resultString, resultString.contains("password must be specified"));
- }
-
- @Test
- public void test005StartServerFailsFastOnMissingGemFireSecurityPropertiesFile()
- throws IOException {
- String gemfireSecuritiesPropertiesFile = "/path/to/missing/gemfire-securities.properties";
-
- CommandStringBuilder command = new CommandStringBuilder(CliStrings.START_SERVER);
-
- String pathName = getClass().getSimpleName().concat("_").concat(getTestMethodName());
- final File workingDirectory = temporaryFolder.newFolder(pathName);
-
- command.addOption(CliStrings.START_SERVER__NAME, pathName);
- command.addOption(CliStrings.START_SERVER__DIR, workingDirectory.getCanonicalPath());
- command.addOption(CliStrings.START_SERVER__SECURITY_PROPERTIES,
- gemfireSecuritiesPropertiesFile);
-
- CommandResult result = executeCommand(command.toString());
-
- assertNotNull(result);
- assertEquals(Result.Status.ERROR, result.getStatus());
-
- String resultString = toString(result);
-
- assertTrue(resultString,
- resultString
- .contains(MessageFormat.format(CliStrings.GEODE_0_PROPERTIES_1_NOT_FOUND_MESSAGE,
- "Security ", gemfireSecuritiesPropertiesFile)));
- }
-
- @Test
- public void test006StartLocatorInRelativeDirectory() {
- final int locatorPort = AvailablePortHelper.getRandomAvailableTCPPort();
-
- String pathname = (getClass().getSimpleName() + "_" + getTestMethodName());
- File workingDirectory = new File(pathname);
-
- assertTrue(workingDirectory.isDirectory() || workingDirectory.mkdir());
-
- try {
- CommandStringBuilder command = new CommandStringBuilder(CliStrings.START_LOCATOR);
-
- command.addOption(CliStrings.START_LOCATOR__MEMBER_NAME, pathname);
- command.addOption(CliStrings.START_LOCATOR__CONNECT, Boolean.FALSE.toString());
- command.addOption(CliStrings.START_LOCATOR__DIR, pathname);
- command.addOption(CliStrings.START_LOCATOR__PORT, String.valueOf(locatorPort));
- command.addOption(CliStrings.START_LOCATOR__ENABLE__SHARED__CONFIGURATION,
- Boolean.FALSE.toString());
- command.addOption(CliStrings.START_LOCATOR__J,
- "-D" + DistributionConfig.GEMFIRE_PREFIX + "http-service-port=0");
- command.addOption(CliStrings.START_LOCATOR__J, "-D" + DistributionConfig.GEMFIRE_PREFIX
- + "jmx-manager-port=" + AvailablePortHelper.getRandomAvailableTCPPort());
-
- CommandResult result = executeCommand(command.toString());
-
- assertNotNull(result);
- assertEquals(Result.Status.OK, result.getStatus());
-
- String locatorOutput = toString(result);
-
- assertNotNull(locatorOutput);
- assertTrue("Locator output was: " + locatorOutput, locatorOutput.contains(
- "Locator in " + IOUtils.tryGetCanonicalFileElseGetAbsoluteFile(workingDirectory)));
- } finally {
- stopLocator(workingDirectory);
- }
- }
-
- @Test
- public void test007StatusLocatorUsingMemberNameIDWhenGfshIsNotConnected() {
- CommandResult result =
- executeCommand(CliStrings.STATUS_LOCATOR + " --name=" + getTestMethodName());
-
- assertNotNull(result);
- assertEquals(Result.Status.ERROR, result.getStatus());
- assertEquals(
- CliStrings.format(CliStrings.STATUS_SERVICE__GFSH_NOT_CONNECTED_ERROR_MESSAGE, "Locator"),
- StringUtils.trim(toString(result)));
- }
-
- @Test
- public void test008StatusLocatorUsingMemberName() throws IOException {
- final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
-
- final int jmxManagerPort = ports[0];
- final int locatorPort = ports[1];
-
- String pathname = (getClass().getSimpleName() + "_" + getTestMethodName());
- File workingDirectory = temporaryFolder.newFolder(pathname);
-
- assertTrue(workingDirectory.isDirectory() || workingDirectory.mkdir());
-
- try {
- CommandStringBuilder command = new CommandStringBuilder(CliStrings.START_LOCATOR);
-
- command.addOption(CliStrings.START_LOCATOR__MEMBER_NAME, pathname);
- command.addOption(CliStrings.START_LOCATOR__CONNECT, Boolean.FALSE.toString());
- command.addOption(CliStrings.START_LOCATOR__DIR, workingDirectory.getCanonicalPath());
- command.addOption(CliStrings.START_LOCATOR__PORT, String.valueOf(locatorPort));
- command.addOption(CliStrings.START_LOCATOR__ENABLE__SHARED__CONFIGURATION,
- Boolean.FALSE.toString());
- command.addOption(CliStrings.START_LOCATOR__FORCE, Boolean.TRUE.toString());
- command.addOption(CliStrings.START_LOCATOR__J,
- "-D" + DistributionConfig.GEMFIRE_PREFIX + "http-service-port=0");
- command.addOption(CliStrings.START_LOCATOR__J,
- "-D" + DistributionConfig.GEMFIRE_PREFIX + "jmx-manager-port=" + jmxManagerPort);
-
- CommandResult result = executeCommand(command.toString());
-
- assertNotNull(result);
- assertEquals(Result.Status.OK, result.getStatus());
-
- LocatorLauncher locatorLauncher = new LocatorLauncher.Builder()
- .setCommand(LocatorLauncher.Command.STATUS).setBindAddress(null).setPort(locatorPort)
- .setWorkingDirectory(workingDirectory.getPath()).build();
-
- assertNotNull(locatorLauncher);
-
- LocatorState expectedLocatorState =
- locatorLauncher.waitOnStatusResponse(60, 10, TimeUnit.SECONDS);
-
- assertNotNull(expectedLocatorState);
- assertEquals(Status.ONLINE, expectedLocatorState.getStatus());
-
- result = executeCommand(
- String.format("%1$s --locator=localhost[%2$d]", CliStrings.CONNECT, locatorPort));
-
- assertNotNull(result);
- assertEquals(Result.Status.OK, result.getStatus());
-
- result = executeCommand(
- String.format("%1$s --name=invalidLocatorMemberName", CliStrings.STATUS_LOCATOR));
-
- assertNotNull(result);
- assertEquals(Result.Status.ERROR, result.getStatus());
- assertEquals(
- CliStrings.format(CliStrings.STATUS_LOCATOR__NO_LOCATOR_FOUND_FOR_MEMBER_ERROR_MESSAGE,
- "invalidLocatorMemberName"),
- StringUtils.trim(toString(result)));
-
- result =
- executeCommand(String.format("%1$s --name=%2$s", CliStrings.STATUS_LOCATOR, pathname));
-
- assertNotNull(result);
- assertEquals(Result.Status.OK, result.getStatus());
- assertTrue(serviceStateStatusStringNormalized(toString(result))
- .contains(serviceStateStatusStringNormalized(expectedLocatorState)));
- } finally {
- stopLocator(workingDirectory);
- }
- }
-
- @Test
- public void test009StatusLocatorUsingMemberId() throws Exception {
- final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
-
- final int jmxManagerPort = ports[0];
- final int locatorPort = ports[1];
-
- String pathname = (getClass().getSimpleName() + "_" + getTestMethodName());
- File workingDirectory = temporaryFolder.newFolder(pathname);
-
- assertTrue(workingDirectory.isDirectory() || workingDirectory.mkdir());
-
- try {
- CommandStringBuilder command = new CommandStringBuilder(CliStrings.START_LOCATOR);
-
- command.addOption(CliStrings.START_LOCATOR__MEMBER_NAME, pathname);
- command.addOption(CliStrings.START_LOCATOR__CONNECT, Boolean.FALSE.toString());
- command.addOption(CliStrings.START_LOCATOR__DIR, workingDirectory.getCanonicalPath());
- command.addOption(CliStrings.START_LOCATOR__PORT, String.valueOf(locatorPort));
- command.addOption(CliStrings.START_LOCATOR__ENABLE__SHARED__CONFIGURATION,
- Boolean.FALSE.toString());
- command.addOption(CliStrings.START_LOCATOR__FORCE, Boolean.TRUE.toString());
- command.addOption(CliStrings.START_LOCATOR__J,
- "-D" + DistributionConfig.GEMFIRE_PREFIX + "http-service-port=0");
- command.addOption(CliStrings.START_LOCATOR__J,
- "-D" + DistributionConfig.GEMFIRE_PREFIX + "jmx-manager-port=" + jmxManagerPort);
-
- CommandResult result = executeCommand(command.toString());
-
- assertNotNull(result);
- assertEquals(Result.Status.OK, result.getStatus());
-
- LocatorLauncher locatorLauncher = new LocatorLauncher.Builder()
- .setCommand(LocatorLauncher.Command.STATUS).setBindAddress(null).setPort(locatorPort)
- .setWorkingDirectory(workingDirectory.getPath()).build();
-
- assertNotNull(locatorLauncher);
-
- LocatorState expectedLocatorState =
- locatorLauncher.waitOnStatusResponse(60, 10, TimeUnit.SECONDS);
-
- assertNotNull(expectedLocatorState);
- assertEquals(Status.ONLINE, expectedLocatorState.getStatus());
-
- result = executeCommand(
- String.format("%1$s --locator=localhost[%2$d]", CliStrings.CONNECT, locatorPort));
-
- assertNotNull(result);
- assertEquals(Result.Status.OK, result.getStatus());
-
- result = executeCommand(String.format("%1$s --name=%2$s", CliStrings.STATUS_LOCATOR,
- getMemberId(jmxManagerPort, pathname)));
-
- assertNotNull(result);
- assertEquals(Result.Status.OK, result.getStatus());
- assertTrue(serviceStateStatusStringNormalized(toString(result))
- .contains(serviceStateStatusStringNormalized(expectedLocatorState)));
- } finally {
- stopLocator(workingDirectory);
- }
- }
-
- @Test
- public void test010StopLocatorUsingMemberNameIDWhenGfshIsNotConnected() {
- CommandResult result =
- executeCommand(CliStrings.STOP_LOCATOR + " --name=" + getTestMethodName());
-
- assertNotNull(result);
- assertEquals(Result.Status.ERROR, result.getStatus());
- assertEquals(
- CliStrings.format(CliStrings.STOP_SERVICE__GFSH_NOT_CONNECTED_ERROR_MESSAGE, "Locator"),
- StringUtils.trim(toString(result)));
- }
-
- @Test
- public void test011StopLocatorUsingMemberName() throws IOException {
- final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
-
- final int jmxManagerPort = ports[0];
- final int locatorPort = ports[1];
-
- String pathname = (getClass().getSimpleName() + "_" + getTestMethodName());
- File workingDirectory = temporaryFolder.newFolder(pathname);
-
- try {
- assertTrue(workingDirectory.isDirectory() || workingDirectory.mkdir());
-
- CommandStringBuilder command = new CommandStringBuilder(CliStrings.START_LOCATOR);
-
- command.addOption(CliStrings.START_LOCATOR__MEMBER_NAME, pathname);
- command.addOption(CliStrings.START_LOCATOR__CONNECT, Boolean.FALSE.toString());
- command.addOption(CliStrings.START_LOCATOR__DIR, workingDirectory.getCanonicalPath());
- command.addOption(CliStrings.START_LOCATOR__PORT, String.valueOf(locatorPort));
- command.addOption(CliStrings.START_LOCATOR__ENABLE__SHARED__CONFIGURATION,
- Boolean.FALSE.toString());
- command.addOption(CliStrings.START_LOCATOR__FORCE, Boolean.TRUE.toString());
- command.addOption(CliStrings.START_LOCATOR__J,
- "-D" + DistributionConfig.GEMFIRE_PREFIX + "http-service-port=0");
- command.addOption(CliStrings.START_LOCATOR__J,
- "-D" + DistributionConfig.GEMFIRE_PREFIX + "jmx-manager-port=" + jmxManagerPort);
-
- CommandResult result = executeCommand(command.toString());
-
- assertNotNull(result);
- assertEquals(Result.Status.OK, result.getStatus());
-
- final LocatorLauncher locatorLauncher =
- new Builder().setCommand(Command.STOP).setBindAddress(null).setPort(locatorPort)
- .setWorkingDirectory(workingDirectory.getPath()).build();
-
- assertNotNull(locatorLauncher);
-
- LocatorState locatorStatus = locatorLauncher.waitOnStatusResponse(60, 10, TimeUnit.SECONDS);
-
- assertNotNull(locatorStatus);
- assertEquals(Status.ONLINE, locatorStatus.getStatus());
-
- result = executeCommand(
- String.format("%1$s --locator=localhost[%2$d]", CliStrings.CONNECT, locatorPort));
-
- assertNotNull(result);
- assertEquals(Result.Status.OK, result.getStatus());
-
- result = executeCommand(
- String.format("%1$s --name=invalidLocatorMemberName", CliStrings.STOP_LOCATOR));
-
- assertNotNull(result);
- assertEquals(Result.Status.ERROR, result.getStatus());
- assertEquals(
- CliStrings.format(CliStrings.STOP_LOCATOR__NO_LOCATOR_FOUND_FOR_MEMBER_ERROR_MESSAGE,
- "invalidLocatorMemberName"),
- StringUtils.trim(toString(result)));
-
- locatorStatus = locatorLauncher.status();
-
- assertNotNull(locatorStatus);
- assertEquals(Status.ONLINE, locatorStatus.getStatus());
-
- result = executeCommand(String.format("%1$s --name=%2$s", CliStrings.STOP_LOCATOR, pathname));
-
- assertNotNull(result);
- assertEquals(Result.Status.OK, result.getStatus());
-
- // TODO figure out what output to assert and validate on now that 'stop locator' uses Gfsh's
- // logger
- // and standard err/out...
- // assertIndexDetailsEquals(CliStrings.format(CliStrings.STOP_LOCATOR__SHUTDOWN_MEMBER_MESSAGE,
- // pathname),
- // StringUtils.trim(toString(result)));
-
- WaitCriterion waitCriteria = new WaitCriterion() {
- @Override
- public boolean done() {
- final LocatorState locatorStatus = locatorLauncher.status();
- return (locatorStatus != null && Status.NOT_RESPONDING.equals(locatorStatus.getStatus()));
- }
-
- @Override
- public String description() {
- return "wait for the Locator to stop; the Locator will no longer respond after it stops";
- }
- };
-
- waitForCriterion(waitCriteria, 15 * 1000, 5000, true);
-
- locatorStatus = locatorLauncher.status();
-
- assertNotNull(locatorStatus);
- assertEquals(Status.NOT_RESPONDING, locatorStatus.getStatus());
- } finally {
- }
-
- }
-
- // @see Trac Bug # 46760
- @Test
- public void test012StopLocatorUsingMemberId() throws Exception {
- final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
-
- final int jmxManagerPort = ports[0];
- final int locatorPort = ports[1];
-
- String pathname = (getClass().getSimpleName() + "_" + getTestMethodName());
- File workingDirectory = temporaryFolder.newFolder(pathname);
-
- try {
- assertTrue(workingDirectory.isDirectory() || workingDirectory.mkdir());
-
- CommandStringBuilder command = new CommandStringBuilder(CliStrings.START_LOCATOR);
-
- command.addOption(CliStrings.START_LOCATOR__MEMBER_NAME, pathname);
- command.addOption(CliStrings.START_LOCATOR__CONNECT, Boolean.FALSE.toString());
- command.addOption(CliStrings.START_LOCATOR__DIR, workingDirectory.getCanonicalPath());
- command.addOption(CliStrings.START_LOCATOR__PORT, String.valueOf(locatorPort));
- command.addOption(CliStrings.START_LOCATOR__ENABLE__SHARED__CONFIGURATION,
- Boolean.FALSE.toString());
- command.addOption(CliStrings.START_LOCATOR__FORCE, Boolean.TRUE.toString());
- command.addOption(CliStrings.START_LOCATOR__J,
- "-D" + DistributionConfig.GEMFIRE_PREFIX + "http-service-port=0");
- command.addOption(CliStrings.START_LOCATOR__J,
- "-D" + DistributionConfig.GEMFIRE_PREFIX + "jmx-manager-port=" + jmxManagerPort);
-
- CommandResult result = executeCommand(command.toString());
-
- assertNotNull(result);
- assertEquals(Result.Status.OK, result.getStatus());
-
- final LocatorLauncher locatorLauncher =
- new Builder().setCommand(Command.STOP).setBindAddress(null).setPort(locatorPort)
- .setWorkingDirectory(workingDirectory.getPath()).build();
-
- assertNotNull(locatorLauncher);
-
- LocatorState locatorState = locatorLauncher.waitOnStatusResponse(60, 10, TimeUnit.SECONDS);
-
- assertNotNull(locatorState);
- assertEquals(Status.ONLINE, locatorState.getStatus());
-
- result = executeCommand(
- String.format("%1$s --locator=localhost[%2$d]", CliStrings.CONNECT, locatorPort));
-
- assertNotNull(result);
- assertEquals(Result.Status.OK, result.getStatus());
-
- String memberId = getMemberId(jmxManagerPort, pathname);
-
- result = executeCommand(String.format("%1$s --name=%2$s", CliStrings.STOP_LOCATOR, memberId));
-
- assertNotNull(result);
- assertEquals(Result.Status.OK, result.getStatus());
-
- // TODO figure out what output to assert and validate on now that 'stop locator' uses Gfsh's
- // logger
- // and standard err/out...
- // assertIndexDetailsEquals(CliStrings.format(CliStrings.STOP_LOCATOR__SHUTDOWN_MEMBER_MESSAGE,
- // memberId),
- // StringUtils.trim(toString(result)));
-
- WaitCriterion waitCriteria = new WaitCriterion() {
- @Override
- public boolean done() {
- LocatorState locatorState = locatorLauncher.status();
- return (locatorState != null && Status.NOT_RESPONDING.equals(locatorState.getStatus()));
- }
-
- @Override
- public String description() {
- return "wait for the Locator to stop; the Locator will no longer respond after it stops";
- }
- };
-
- waitForCriterion(waitCriteria, 15 * 1000, 5000, true);
-
- locatorState = locatorLauncher.status();
-
- assertNotNull(locatorState);
- assertEquals(Status.NOT_RESPONDING, locatorState.getStatus());
- } finally {
- }
- }
-
- @Test
- public void test014GemFireServerJvmProcessTerminatesOnOutOfMemoryError() throws Exception {
- int ports[] = AvailablePortHelper.getRandomAvailableTCPPorts(2);
- final int serverPort = ports[0];
- final int locatorPort = ports[1];
-
- String pathname = getClass().getSimpleName().concat("_").concat(getTestMethodName());
- File workingDirectory = temporaryFolder.newFolder(pathname);
-
- assertTrue(workingDirectory.isDirectory() || workingDirectory.mkdir());
-
- CommandStringBuilder command = new CommandStringBuilder(CliStrings.START_SERVER);
-
- command.addOption(CliStrings.START_SERVER__NAME,
- pathname + TIMESTAMP.format(Calendar.getInstance().getTime()));
- command.addOption(CliStrings.START_SERVER__SERVER_PORT, String.valueOf(serverPort));
- command.addOption(CliStrings.START_SERVER__USE_CLUSTER_CONFIGURATION, Boolean.FALSE.toString());
- command.addOption(CliStrings.START_SERVER__MAXHEAP, "10M");
- command.addOption(CliStrings.START_SERVER__LOG_LEVEL, "config");
- command.addOption(CliStrings.START_SERVER__DIR, workingDirectory.getCanonicalPath());
- command.addOption(CliStrings.START_SERVER__CACHE_XML_FILE,
- IOUtils.tryGetCanonicalPathElseGetAbsolutePath(writeAndGetCacheXmlFile(workingDirectory)));
- command.addOption(CliStrings.START_SERVER__INCLUDE_SYSTEM_CLASSPATH);
- command.addOption(CliStrings.START_SERVER__J, "-D" + DistributionConfig.GEMFIRE_PREFIX + ""
- + START_LOCATOR + "=localhost[" + locatorPort + "]");
-
-
- CommandResult result = executeCommand(command.toString());
- System.out.println("result=" + result);
-
- assertNotNull(result);
- assertEquals(Result.Status.OK, result.getStatus());
-
- ServerLauncher serverLauncher =
- new ServerLauncher.Builder().setCommand(ServerLauncher.Command.STATUS)
- .setWorkingDirectory(IOUtils.tryGetCanonicalPathElseGetAbsolutePath(workingDirectory))
- .build();
-
- assertNotNull(serverLauncher);
-
- ServerState serverState = serverLauncher.status();
-
- assertNotNull(serverState);
- assertEquals(Status.ONLINE, serverState.getStatus());
-
- // Verify our GemFire Server JVM process is running!
- assertTrue(serverState.isVmWithProcessIdRunning());
-
- ClientCache clientCache = setupClientCache(pathname + String.valueOf(serverPort), serverPort);
-
- assertNotNull(clientCache);
-
- try {
- Region<Long, String> exampleRegion = clientCache.getRegion("/Example");
- // run the GemFire Server "out-of-town" with an OutOfMemoryError!
- for (long index = 0; index < Long.MAX_VALUE; index++) {
- exampleRegion.put(index, String.valueOf(index));
- }
- } catch (Exception ignore) {
- System.err.printf("%1$s: %2$s%n", ignore.getClass().getName(), ignore.getMessage());
- } finally {
- clientCache.close();
-
- final int serverPid = serverState.getPid();
-
- WaitCriterion waitCriteria = new WaitCriterion() {
- @Override
- public boolean done() {
- return !ProcessUtils.isProcessAlive(serverPid);
- }
-
- @Override
- public String description() {
- return "Wait for the GemFire Server JVM process that ran out-of-memory to exit.";
- }
- };
-
- waitForCriterion(waitCriteria, TimeUnit.SECONDS.toMillis(30), TimeUnit.SECONDS.toMillis(10),
- true);
-
- // Verify our GemFire Server JVM process is was terminated!
- assertFalse(serverState.isVmWithProcessIdRunning());
-
- serverState = serverLauncher.status();
-
- assertNotNull(serverState);
- assertEquals(Status.NOT_RESPONDING, serverState.getStatus());
- }
- }
-
- private File writeAndGetCacheXmlFile(final File workingDirectory) throws IOException {
- File cacheXml = new File(workingDirectory, "cache.xml");
- StringBuilder buffer = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
-
- buffer.append(StringUtils.LINE_SEPARATOR);
- buffer.append(
- "<!DOCTYPE cache PUBLIC \"-//GemStone Systems, Inc.//GemFire Declarative Caching 7.0//EN\"");
- buffer.append(StringUtils.LINE_SEPARATOR);
- buffer.append(" \"http://www.gemstone.com/dtd/cache7_0.dtd\">");
- buffer.append(StringUtils.LINE_SEPARATOR);
- buffer.append("<cache>");
- buffer.append(StringUtils.LINE_SEPARATOR);
- buffer.append(" <region name=\"Example\" refid=\"REPLICATE\"/>");
- buffer.append(StringUtils.LINE_SEPARATOR);
- buffer.append("</cache>");
-
- BufferedWriter fileWriter = null;
-
- try {
- fileWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(cacheXml, false),
- Charset.forName("UTF-8").newEncoder()));
- fileWriter.write(buffer.toString());
- fileWriter.flush();
- } finally {
- IOUtils.close(fileWriter);
- }
-
- return cacheXml;
- }
-
- private ClientCache setupClientCache(final String durableClientId, final int serverPort) {
- ClientCache clientCache =
- new ClientCacheFactory().set(DURABLE_CLIENT_ID, durableClientId).create();
-
- PoolFactory poolFactory = PoolManager.createFactory();
-
- poolFactory.setMaxConnections(10);
- poolFactory.setMinConnections(1);
- poolFactory.setReadTimeout(5000);
- poolFactory.addServer("localhost", serverPort);
-
- Pool pool = poolFactory.create("serverConnectionPool");
-
- assertNotNull("The 'serverConnectionPool' was not properly configured and initialized!", pool);
-
- ClientRegionFactory<Long, String> regionFactory =
- clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY);
-
- regionFactory.setPoolName(pool.getName());
- regionFactory.setKeyConstraint(Long.class);
- regionFactory.setValueConstraint(String.class);
-
- Region<Long, String> exampleProxy = regionFactory.create("Example");
-
- assertNotNull("The 'Example' Client Region was not properly configured and initialized",
- exampleProxy);
-
- return clientCache;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/210ff9f1/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommandTest.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommandTest.java b/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommandTest.java
index 5a7c11c..e9ca6dc 100644
--- a/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommandTest.java
+++ b/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommandTest.java
@@ -56,9 +56,9 @@ public class StartLocatorCommandTest {
public void testLocatorClasspathOrder() {
String userClasspath = "/path/to/user/lib/app.jar:/path/to/user/classes";
String expectedClasspath =
- StartMemberUtils.getGemFireJarPath().concat(File.pathSeparator).concat(userClasspath)
+ locatorCommands.getGemFireJarPath().concat(File.pathSeparator).concat(userClasspath)
.concat(File.pathSeparator).concat(System.getProperty("java.class.path"))
- .concat(File.pathSeparator).concat(StartMemberUtils.CORE_DEPENDENCIES_JAR_PATHNAME);
+ .concat(File.pathSeparator).concat(StartMemberCommand.CORE_DEPENDENCIES_JAR_PATHNAME);
String actualClasspath = locatorCommands.getLocatorClasspath(true, userClasspath);
assertEquals(expectedClasspath, actualClasspath);
}
http://git-wip-us.apache.org/repos/asf/geode/blob/210ff9f1/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StartServerCommandTest.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StartServerCommandTest.java b/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StartServerCommandTest.java
index e704248..a5012f3 100644
--- a/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StartServerCommandTest.java
+++ b/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StartServerCommandTest.java
@@ -54,8 +54,8 @@ public class StartServerCommandTest {
public void testServerClasspathOrder() {
String userClasspath = "/path/to/user/lib/app.jar:/path/to/user/classes";
String expectedClasspath =
- StartMemberUtils.getGemFireJarPath().concat(File.pathSeparator).concat(userClasspath)
- .concat(File.pathSeparator).concat(StartMemberUtils.CORE_DEPENDENCIES_JAR_PATHNAME);
+ serverCommands.getGemFireJarPath().concat(File.pathSeparator).concat(userClasspath)
+ .concat(File.pathSeparator).concat(StartMemberCommand.CORE_DEPENDENCIES_JAR_PATHNAME);
String actualClasspath = serverCommands.getServerClasspath(false, userClasspath);
assertEquals(expectedClasspath, actualClasspath);
}
http://git-wip-us.apache.org/repos/asf/geode/blob/210ff9f1/geode-assembly/src/test/java/org/apache/geode/test/dunit/rules/gfsh/ProcessLogger.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/test/dunit/rules/gfsh/ProcessLogger.java b/geode-assembly/src/test/java/org/apache/geode/test/dunit/rules/gfsh/ProcessLogger.java
index 47f0304..85a94fa 100644
--- a/geode-assembly/src/test/java/org/apache/geode/test/dunit/rules/gfsh/ProcessLogger.java
+++ b/geode-assembly/src/test/java/org/apache/geode/test/dunit/rules/gfsh/ProcessLogger.java
@@ -36,14 +36,14 @@ public class ProcessLogger {
private final Queue<String> stdOutLines = new ConcurrentLinkedQueue<>();
private final Queue<String> stdErrorLines = new ConcurrentLinkedQueue<>();
- private final StreamGobbler stdOutGobbler;
- private final StreamGobbler stdErrGobbler;
public ProcessLogger(Process process, String name) {
this.logger = LOGGER_CONTEXT.getLogger(name);
- this.stdOutGobbler = new StreamGobbler(process.getInputStream(), this::consumeInfoMessage);
- this.stdErrGobbler = new StreamGobbler(process.getErrorStream(), this::consumeErrorMessage);
+ StreamGobbler stdOutGobbler =
+ new StreamGobbler(process.getInputStream(), this::consumeInfoMessage);
+ StreamGobbler stdErrGobbler =
+ new StreamGobbler(process.getErrorStream(), this::consumeErrorMessage);
stdOutGobbler.startInNewThread();
stdErrGobbler.startInNewThread();
@@ -84,7 +84,7 @@ public class ProcessLogger {
}
public List<String> getStdErrLines() {
- return Lists.newArrayList(stdOutLines.iterator());
+ return Lists.newArrayList(stdErrorLines.iterator());
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/210ff9f1/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommand.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommand.java
index 72ccfbb..5e1df6f 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommand.java
@@ -57,7 +57,7 @@ import org.apache.geode.management.internal.cli.util.HostUtils;
import org.apache.geode.management.internal.configuration.utils.ClusterConfigurationStatusRetriever;
import org.apache.geode.security.AuthenticationFailedException;
-public class StartLocatorCommand implements GfshCommand {
+public class StartLocatorCommand extends StartMemberCommand implements GfshCommand {
@CliCommand(value = CliStrings.START_LOCATOR, help = CliStrings.START_LOCATOR__HELP)
@CliMetaData(shellOnly = true,
relatedTopic = {CliStrings.TOPIC_GEODE_LOCATOR, CliStrings.TOPIC_GEODE_LIFECYCLE})
@@ -123,10 +123,10 @@ public class StartLocatorCommand implements GfshCommand {
try {
if (StringUtils.isBlank(memberName)) {
// when the user doesn't give us a name, we make one up!
- memberName = StartMemberUtils.getNameGenerator().generate('-');
+ memberName = getNameGenerator().generate('-');
}
- workingDirectory = StartMemberUtils.resolveWorkingDir(workingDirectory, memberName);
+ workingDirectory = resolveWorkingDir(workingDirectory, memberName);
if (gemfirePropertiesFile != null && !gemfirePropertiesFile.exists()) {
return ResultBuilder.createUserErrorResult(
@@ -142,32 +142,28 @@ public class StartLocatorCommand implements GfshCommand {
File locatorPidFile = new File(workingDirectory, ProcessType.LOCATOR.getPidFileName());
- final int oldPid = StartMemberUtils.readPid(locatorPidFile);
+ final int oldPid = readPid(locatorPidFile);
Properties gemfireProperties = new Properties();
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.GROUPS,
- group);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.LOCATORS,
- locators);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.LOG_LEVEL,
- logLevel);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties,
- ConfigurationProperties.MCAST_ADDRESS, mcastBindAddress);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.MCAST_PORT,
- mcastPort);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties,
- ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION, enableSharedConfiguration);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties,
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.GROUPS, group);
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.LOCATORS, locators);
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.LOG_LEVEL, logLevel);
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.MCAST_ADDRESS,
+ mcastBindAddress);
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.MCAST_PORT, mcastPort);
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION,
+ enableSharedConfiguration);
+ setPropertyIfNotNull(gemfireProperties,
ConfigurationProperties.LOAD_CLUSTER_CONFIGURATION_FROM_DIR,
loadSharedConfigurationFromDirectory);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties,
- ConfigurationProperties.CLUSTER_CONFIGURATION_DIR, clusterConfigDir);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties,
- ConfigurationProperties.HTTP_SERVICE_PORT, httpServicePort);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties,
- ConfigurationProperties.HTTP_SERVICE_BIND_ADDRESS, httpServiceBindAddress);
- StartMemberUtils.setPropertyIfNotNull(gemfireProperties,
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.CLUSTER_CONFIGURATION_DIR,
+ clusterConfigDir);
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.HTTP_SERVICE_PORT,
+ httpServicePort);
+ setPropertyIfNotNull(gemfireProperties, ConfigurationProperties.HTTP_SERVICE_BIND_ADDRESS,
+ httpServiceBindAddress);
+ setPropertyIfNotNull(gemfireProperties,
ConfigurationProperties.JMX_MANAGER_HOSTNAME_FOR_CLIENTS, jmxManagerHostnameForClients);
// read the OSProcess enable redirect system property here
@@ -258,7 +254,7 @@ public class StartLocatorCommand implements GfshCommand {
&& locatorState.isStartingOrNotResponding());
} finally {
// stop will close
- stderrReader.stopAsync(StartMemberUtils.PROCESS_STREAM_READER_ASYNC_STOP_TIMEOUT_MILLIS);
+ stderrReader.stopAsync(PROCESS_STREAM_READER_ASYNC_STOP_TIMEOUT_MILLIS);
// ErrorStream
getGfsh().getSignalHandler().unregisterListener(locatorSignalListener);
@@ -324,6 +320,7 @@ public class StartLocatorCommand implements GfshCommand {
SystemFailure.initiateFailure(e);
throw e;
} catch (Throwable t) {
+ t.printStackTrace();
SystemFailure.checkFailure();
String errorMessage = String.format(CliStrings.START_LOCATOR__GENERAL_ERROR_MESSAGE,
StringUtils.defaultIfBlank(workingDirectory, memberName),
@@ -439,19 +436,19 @@ public class StartLocatorCommand implements GfshCommand {
final String maxHeap) throws MalformedObjectNameException {
List<String> commandLine = new ArrayList<>();
- commandLine.add(StartMemberUtils.getJavaPath());
+ commandLine.add(getJavaPath());
commandLine.add("-server");
commandLine.add("-classpath");
commandLine
.add(getLocatorClasspath(Boolean.TRUE.equals(includeSystemClasspath), userClasspath));
- StartMemberUtils.addCurrentLocators(this, commandLine, gemfireProperties);
- StartMemberUtils.addGemFirePropertyFile(commandLine, gemfirePropertiesFile);
- StartMemberUtils.addGemFireSecurityPropertyFile(commandLine, gemfireSecurityPropertiesFile);
- StartMemberUtils.addGemFireSystemProperties(commandLine, gemfireProperties);
- StartMemberUtils.addJvmArgumentsAndOptions(commandLine, jvmArgsOpts);
- StartMemberUtils.addInitialHeap(commandLine, initialHeap);
- StartMemberUtils.addMaxHeap(commandLine, maxHeap);
+ addCurrentLocators(this, commandLine, gemfireProperties);
+ addGemFirePropertyFile(commandLine, gemfirePropertiesFile);
+ addGemFireSecurityPropertyFile(commandLine, gemfireSecurityPropertiesFile);
+ addGemFireSystemProperties(commandLine, gemfireProperties);
+ addJvmArgumentsAndOptions(commandLine, jvmArgsOpts);
+ addInitialHeap(commandLine, initialHeap);
+ addMaxHeap(commandLine, maxHeap);
commandLine.add(
"-D".concat(AbstractLauncher.SIGNAL_HANDLER_REGISTRATION_SYSTEM_PROPERTY.concat("=true")));
@@ -492,7 +489,7 @@ public class StartLocatorCommand implements GfshCommand {
}
String getLocatorClasspath(final boolean includeSystemClasspath, final String userClasspath) {
- return StartMemberUtils.toClasspath(includeSystemClasspath,
- new String[] {StartMemberUtils.CORE_DEPENDENCIES_JAR_PATHNAME}, userClasspath);
+ return toClasspath(includeSystemClasspath, new String[] {CORE_DEPENDENCIES_JAR_PATHNAME},
+ userClasspath);
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/210ff9f1/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartMemberCommand.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartMemberCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartMemberCommand.java
new file mode 100644
index 0000000..6bdc25c
--- /dev/null
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartMemberCommand.java
@@ -0,0 +1,248 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.geode.management.internal.cli.commands;
+
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.management.internal.cli.shell.MXBeanProvider.getDistributedSystemMXBean;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+
+import javax.management.MalformedObjectNameException;
+
+import org.apache.commons.lang.ArrayUtils;
+
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.internal.GemFireVersion;
+import org.apache.geode.internal.process.ProcessLauncherContext;
+import org.apache.geode.internal.util.IOUtils;
+import org.apache.geode.management.DistributedSystemMXBean;
+import org.apache.geode.management.internal.cli.util.ThreePhraseGenerator;
+
+/**
+ * Encapsulates methods used by StartServerCommand and StartLocatorCommand and their associated
+ * tests.
+ *
+ * @see StartLocatorCommand
+ * @see StartServerCommand
+ */
+public class StartMemberCommand {
+ public static final String GEODE_HOME = System.getenv("GEODE_HOME");
+
+ private static final String JAVA_HOME = System.getProperty("java.home");
+ static final int CMS_INITIAL_OCCUPANCY_FRACTION = 60;
+ private static final ThreePhraseGenerator nameGenerator = new ThreePhraseGenerator();
+
+ static final String CORE_DEPENDENCIES_JAR_PATHNAME =
+ IOUtils.appendToPath(GEODE_HOME, "lib", "geode-dependencies.jar");
+ static final String GEODE_JAR_PATHNAME =
+ IOUtils.appendToPath(GEODE_HOME, "lib", GemFireVersion.getGemFireJarFileName());
+ static final long PROCESS_STREAM_READER_ASYNC_STOP_TIMEOUT_MILLIS = 5 * 1000;
+ static final int INVALID_PID = -1;
+
+ static ThreePhraseGenerator getNameGenerator() {
+ return nameGenerator;
+ }
+
+ void setPropertyIfNotNull(Properties properties, String key, Object value) {
+ if (key != null && value != null) {
+ properties.setProperty(key, value.toString());
+ }
+ }
+
+ String resolveWorkingDir(String userSpecifiedDir, String memberName) {
+ File workingDir =
+ (userSpecifiedDir == null) ? new File(memberName) : new File(userSpecifiedDir);
+ String workingDirPath = IOUtils.tryGetCanonicalPathElseGetAbsolutePath(workingDir);
+ if (!workingDir.exists()) {
+ if (!workingDir.mkdirs()) {
+ throw new IllegalStateException(String.format(
+ "Could not create directory %s. Please verify directory path or user permissions.",
+ workingDirPath));
+ }
+ }
+ return workingDirPath;
+ }
+
+ void addGemFirePropertyFile(final List<String> commandLine, final File gemfirePropertiesFile) {
+ if (gemfirePropertiesFile != null) {
+ commandLine.add("-DgemfirePropertyFile=" + gemfirePropertiesFile.getAbsolutePath());
+ }
+ }
+
+ void addGemFireSecurityPropertyFile(final List<String> commandLine,
+ final File gemfireSecurityPropertiesFile) {
+ if (gemfireSecurityPropertiesFile != null) {
+ commandLine
+ .add("-DgemfireSecurityPropertyFile=" + gemfireSecurityPropertiesFile.getAbsolutePath());
+ }
+ }
+
+ void addGemFireSystemProperties(final List<String> commandLine,
+ final Properties gemfireProperties) {
+ for (final Object property : gemfireProperties.keySet()) {
+ final String propertyName = property.toString();
+ final String propertyValue = gemfireProperties.getProperty(propertyName);
+ if (org.apache.geode.internal.lang.StringUtils.isNotBlank(propertyValue)) {
+ commandLine.add(
+ "-D" + DistributionConfig.GEMFIRE_PREFIX + "" + propertyName + "=" + propertyValue);
+ }
+ }
+ }
+
+ void addJvmArgumentsAndOptions(final List<String> commandLine, final String[] jvmArgsOpts) {
+ if (jvmArgsOpts != null) {
+ commandLine.addAll(Arrays.asList(jvmArgsOpts));
+ }
+ }
+
+ void addInitialHeap(final List<String> commandLine, final String initialHeap) {
+ if (org.apache.geode.internal.lang.StringUtils.isNotBlank(initialHeap)) {
+ commandLine.add("-Xms" + initialHeap);
+ }
+ }
+
+ void addMaxHeap(final List<String> commandLine, final String maxHeap) {
+ if (org.apache.geode.internal.lang.StringUtils.isNotBlank(maxHeap)) {
+ commandLine.add("-Xmx" + maxHeap);
+ commandLine.add("-XX:+UseConcMarkSweepGC");
+ commandLine.add("-XX:CMSInitiatingOccupancyFraction=" + CMS_INITIAL_OCCUPANCY_FRACTION);
+ // commandLine.add("-XX:MinHeapFreeRatio=" + MINIMUM_HEAP_FREE_RATIO);
+ }
+ }
+
+ void addCurrentLocators(GfshCommand gfshCommand, final List<String> commandLine,
+ final Properties gemfireProperties) throws MalformedObjectNameException {
+ if (org.apache.geode.internal.lang.StringUtils
+ .isBlank(gemfireProperties.getProperty(LOCATORS))) {
+ String currentLocators = getCurrentLocators(gfshCommand);
+ if (org.apache.geode.internal.lang.StringUtils.isNotBlank(currentLocators)) {
+ commandLine.add("-D".concat(ProcessLauncherContext.OVERRIDDEN_DEFAULTS_PREFIX)
+ .concat(LOCATORS).concat("=").concat(currentLocators));
+ }
+ }
+ }
+
+ String getCurrentLocators(GfshCommand gfshCommand) throws MalformedObjectNameException {
+ String delimitedLocators = "";
+ try {
+ if (gfshCommand.isConnectedAndReady()) {
+ final DistributedSystemMXBean dsMBeanProxy = getDistributedSystemMXBean();
+ if (dsMBeanProxy != null) {
+ final String[] locators = dsMBeanProxy.listLocators();
+ if (locators != null && locators.length > 0) {
+ final StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < locators.length; i++) {
+ if (i > 0) {
+ sb.append(",");
+ }
+ sb.append(locators[i]);
+ }
+ delimitedLocators = sb.toString();
+ }
+ }
+ }
+ } catch (IOException e) { // thrown by getDistributedSystemMXBean
+ // leave delimitedLocators = ""
+ gfshCommand.getGfsh().logWarning("DistributedSystemMXBean is unavailable\n", e);
+ }
+ return delimitedLocators;
+ }
+
+ int readPid(final File pidFile) {
+ assert pidFile != null : "The file from which to read the process ID (pid) cannot be null!";
+ if (pidFile.isFile()) {
+ BufferedReader fileReader = null;
+ try {
+ fileReader = new BufferedReader(new FileReader(pidFile));
+ return Integer.parseInt(fileReader.readLine());
+ } catch (IOException | NumberFormatException ignore) {
+ } finally {
+ IOUtils.close(fileReader);
+ }
+ }
+ return INVALID_PID;
+ }
+
+ String getJavaPath() {
+ return new File(new File(JAVA_HOME, "bin"), "java").getPath();
+ }
+
+ String getSystemClasspath() {
+ return System.getProperty("java.class.path");
+ }
+
+ String toClasspath(final boolean includeSystemClasspath, String[] jarFilePathnames,
+ String... userClasspaths) {
+ // gemfire jar must absolutely be the first JAR file on the CLASSPATH!!!
+ StringBuilder classpath = new StringBuilder(getGemFireJarPath());
+
+ userClasspaths = (userClasspaths != null ? userClasspaths : ArrayUtils.EMPTY_STRING_ARRAY);
+
+ // Then, include user-specified classes on CLASSPATH to enable the user to override GemFire JAR
+ // dependencies
+ // with application-specific versions; this logic/block corresponds to classes/jar-files
+ // specified with the
+ // --classpath option to the 'start locator' and 'start server commands'; also this will
+ // override any
+ // System CLASSPATH environment variable setting, which is consistent with the Java platform
+ // behavior...
+ for (String userClasspath : userClasspaths) {
+ if (org.apache.geode.internal.lang.StringUtils.isNotBlank(userClasspath)) {
+ classpath.append((classpath.length() == 0)
+ ? org.apache.geode.internal.lang.StringUtils.EMPTY : File.pathSeparator);
+ classpath.append(userClasspath);
+ }
+ }
+
+ // Now, include any System-specified CLASSPATH environment variable setting...
+ if (includeSystemClasspath) {
+ classpath.append(File.pathSeparator);
+ classpath.append(getSystemClasspath());
+ }
+
+ jarFilePathnames =
+ (jarFilePathnames != null ? jarFilePathnames : ArrayUtils.EMPTY_STRING_ARRAY);
+
+ // And finally, include all GemFire dependencies on the CLASSPATH...
+ for (String jarFilePathname : jarFilePathnames) {
+ if (org.apache.geode.internal.lang.StringUtils.isNotBlank(jarFilePathname)) {
+ classpath.append((classpath.length() == 0)
+ ? org.apache.geode.internal.lang.StringUtils.EMPTY : File.pathSeparator);
+ classpath.append(jarFilePathname);
+ }
+ }
+ return classpath.toString();
+ }
+
+ String getGemFireJarPath() {
+ String classpath = getSystemClasspath();
+ String gemfireJarPath = GEODE_JAR_PATHNAME;
+ for (String classpathElement : classpath.split(File.pathSeparator)) {
+ // MUST CHANGE THIS TO REGEX SINCE VERSION CHANGES IN JAR NAME
+ if (classpathElement.endsWith("gemfire-core-8.2.0.0-SNAPSHOT.jar")) {
+ gemfireJarPath = classpathElement;
+ break;
+ }
+ }
+ return gemfireJarPath;
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/210ff9f1/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartMemberUtils.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartMemberUtils.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartMemberUtils.java
deleted file mode 100644
index 3e1053a..0000000
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartMemberUtils.java
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package org.apache.geode.management.internal.cli.commands;
-
-import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
-import static org.apache.geode.management.internal.cli.shell.MXBeanProvider.getDistributedSystemMXBean;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Properties;
-
-import javax.management.MalformedObjectNameException;
-
-import org.apache.commons.lang.ArrayUtils;
-
-import org.apache.geode.distributed.internal.DistributionConfig;
-import org.apache.geode.internal.GemFireVersion;
-import org.apache.geode.internal.process.ProcessLauncherContext;
-import org.apache.geode.internal.util.IOUtils;
-import org.apache.geode.management.DistributedSystemMXBean;
-import org.apache.geode.management.internal.cli.util.ThreePhraseGenerator;
-
-/**
- * Encapsulates methods used by StartServerCommand and StartLocatorCommand and their associated
- * tests.
- *
- * @see StartLocatorCommand
- * @see StartServerCommand
- */
-public class StartMemberUtils {
- public static final String GEODE_HOME = System.getenv("GEODE_HOME");
-
- private static final String JAVA_HOME = System.getProperty("java.home");
- static final int CMS_INITIAL_OCCUPANCY_FRACTION = 60;
- private static final ThreePhraseGenerator nameGenerator = new ThreePhraseGenerator();
-
- static final String CORE_DEPENDENCIES_JAR_PATHNAME =
- IOUtils.appendToPath(GEODE_HOME, "lib", "geode-dependencies.jar");
- static final String GEODE_JAR_PATHNAME =
- IOUtils.appendToPath(GEODE_HOME, "lib", GemFireVersion.getGemFireJarFileName());
- static final long PROCESS_STREAM_READER_ASYNC_STOP_TIMEOUT_MILLIS = 5 * 1000;
- static final int INVALID_PID = -1;
-
- static ThreePhraseGenerator getNameGenerator() {
- return nameGenerator;
- }
-
- static void setPropertyIfNotNull(Properties properties, String key, Object value) {
- if (key != null && value != null) {
- properties.setProperty(key, value.toString());
- }
- }
-
- static String resolveWorkingDir(String userSpecifiedDir, String memberName) {
- File workingDir =
- (userSpecifiedDir == null) ? new File(memberName) : new File(userSpecifiedDir);
- String workingDirPath = IOUtils.tryGetCanonicalPathElseGetAbsolutePath(workingDir);
- if (!workingDir.exists()) {
- if (!workingDir.mkdirs()) {
- throw new IllegalStateException(String.format(
- "Could not create directory %s. Please verify directory path or user permissions.",
- workingDirPath));
- }
- }
- return workingDirPath;
- }
-
- static void addGemFirePropertyFile(final List<String> commandLine,
- final File gemfirePropertiesFile) {
- if (gemfirePropertiesFile != null) {
- commandLine.add("-DgemfirePropertyFile=" + gemfirePropertiesFile.getAbsolutePath());
- }
- }
-
- static void addGemFireSecurityPropertyFile(final List<String> commandLine,
- final File gemfireSecurityPropertiesFile) {
- if (gemfireSecurityPropertiesFile != null) {
- commandLine
- .add("-DgemfireSecurityPropertyFile=" + gemfireSecurityPropertiesFile.getAbsolutePath());
- }
- }
-
- static void addGemFireSystemProperties(final List<String> commandLine,
- final Properties gemfireProperties) {
- for (final Object property : gemfireProperties.keySet()) {
- final String propertyName = property.toString();
- final String propertyValue = gemfireProperties.getProperty(propertyName);
- if (org.apache.geode.internal.lang.StringUtils.isNotBlank(propertyValue)) {
- commandLine.add(
- "-D" + DistributionConfig.GEMFIRE_PREFIX + "" + propertyName + "=" + propertyValue);
- }
- }
- }
-
- static void addJvmArgumentsAndOptions(final List<String> commandLine,
- final String[] jvmArgsOpts) {
- if (jvmArgsOpts != null) {
- commandLine.addAll(Arrays.asList(jvmArgsOpts));
- }
- }
-
- static void addInitialHeap(final List<String> commandLine, final String initialHeap) {
- if (org.apache.geode.internal.lang.StringUtils.isNotBlank(initialHeap)) {
- commandLine.add("-Xms" + initialHeap);
- }
- }
-
- static void addMaxHeap(final List<String> commandLine, final String maxHeap) {
- if (org.apache.geode.internal.lang.StringUtils.isNotBlank(maxHeap)) {
- commandLine.add("-Xmx" + maxHeap);
- commandLine.add("-XX:+UseConcMarkSweepGC");
- commandLine.add("-XX:CMSInitiatingOccupancyFraction=" + CMS_INITIAL_OCCUPANCY_FRACTION);
- // commandLine.add("-XX:MinHeapFreeRatio=" + MINIMUM_HEAP_FREE_RATIO);
- }
- }
-
- static void addCurrentLocators(GfshCommand gfshCommand, final List<String> commandLine,
- final Properties gemfireProperties) throws MalformedObjectNameException {
- if (org.apache.geode.internal.lang.StringUtils
- .isBlank(gemfireProperties.getProperty(LOCATORS))) {
- String currentLocators = getCurrentLocators(gfshCommand);
- if (org.apache.geode.internal.lang.StringUtils.isNotBlank(currentLocators)) {
- commandLine.add("-D".concat(ProcessLauncherContext.OVERRIDDEN_DEFAULTS_PREFIX)
- .concat(LOCATORS).concat("=").concat(currentLocators));
- }
- }
- }
-
- private static String getCurrentLocators(GfshCommand gfshCommand)
- throws MalformedObjectNameException {
- String delimitedLocators = "";
- try {
- if (gfshCommand.isConnectedAndReady()) {
- final DistributedSystemMXBean dsMBeanProxy = getDistributedSystemMXBean();
- if (dsMBeanProxy != null) {
- final String[] locators = dsMBeanProxy.listLocators();
- if (locators != null && locators.length > 0) {
- final StringBuilder sb = new StringBuilder();
- for (int i = 0; i < locators.length; i++) {
- if (i > 0) {
- sb.append(",");
- }
- sb.append(locators[i]);
- }
- delimitedLocators = sb.toString();
- }
- }
- }
- } catch (IOException e) { // thrown by getDistributedSystemMXBean
- // leave delimitedLocators = ""
- gfshCommand.getGfsh().logWarning("DistributedSystemMXBean is unavailable\n", e);
- }
- return delimitedLocators;
- }
-
- public static int readPid(final File pidFile) {
- assert pidFile != null : "The file from which to read the process ID (pid) cannot be null!";
- if (pidFile.isFile()) {
- BufferedReader fileReader = null;
- try {
- fileReader = new BufferedReader(new FileReader(pidFile));
- return Integer.parseInt(fileReader.readLine());
- } catch (IOException | NumberFormatException ignore) {
- } finally {
- IOUtils.close(fileReader);
- }
- }
- return INVALID_PID;
- }
-
- static String getJavaPath() {
- return new File(new File(JAVA_HOME, "bin"), "java").getPath();
- }
-
- static String getSystemClasspath() {
- return System.getProperty("java.class.path");
- }
-
- static String toClasspath(final boolean includeSystemClasspath, String[] jarFilePathnames,
- String... userClasspaths) {
- // gemfire jar must absolutely be the first JAR file on the CLASSPATH!!!
- StringBuilder classpath = new StringBuilder(getGemFireJarPath());
-
- userClasspaths = (userClasspaths != null ? userClasspaths : ArrayUtils.EMPTY_STRING_ARRAY);
-
- // Then, include user-specified classes on CLASSPATH to enable the user to override GemFire JAR
- // dependencies
- // with application-specific versions; this logic/block corresponds to classes/jar-files
- // specified with the
- // --classpath option to the 'start locator' and 'start server commands'; also this will
- // override any
- // System CLASSPATH environment variable setting, which is consistent with the Java platform
- // behavior...
- for (String userClasspath : userClasspaths) {
- if (org.apache.geode.internal.lang.StringUtils.isNotBlank(userClasspath)) {
- classpath.append((classpath.length() == 0)
- ? org.apache.geode.internal.lang.StringUtils.EMPTY : File.pathSeparator);
- classpath.append(userClasspath);
- }
- }
-
- // Now, include any System-specified CLASSPATH environment variable setting...
- if (includeSystemClasspath) {
- classpath.append(File.pathSeparator);
- classpath.append(getSystemClasspath());
- }
-
- jarFilePathnames =
- (jarFilePathnames != null ? jarFilePathnames : ArrayUtils.EMPTY_STRING_ARRAY);
-
- // And finally, include all GemFire dependencies on the CLASSPATH...
- for (String jarFilePathname : jarFilePathnames) {
- if (org.apache.geode.internal.lang.StringUtils.isNotBlank(jarFilePathname)) {
- classpath.append((classpath.length() == 0)
- ? org.apache.geode.internal.lang.StringUtils.EMPTY : File.pathSeparator);
- classpath.append(jarFilePathname);
- }
- }
- return classpath.toString();
- }
-
- static String getGemFireJarPath() {
- String classpath = getSystemClasspath();
- String gemfireJarPath = GEODE_JAR_PATHNAME;
- for (String classpathElement : classpath.split(File.pathSeparator)) {
- // MUST CHANGE THIS TO REGEX SINCE VERSION CHANGES IN JAR NAME
- if (classpathElement.endsWith("gemfire-core-8.2.0.0-SNAPSHOT.jar")) {
- gemfireJarPath = classpathElement;
- break;
- }
- }
- return gemfireJarPath;
- }
-}