@Test public void testAddGemFirePropertyFileToCommandLine() { final List<String> commandLine = new ArrayList<String>(); assertTrue(commandLine.isEmpty()); getLauncherLifecycleCommands().addGemFirePropertyFile(commandLine, null); assertTrue(commandLine.isEmpty()); getLauncherLifecycleCommands().addGemFirePropertyFile(commandLine, StringUtils.EMPTY_STRING); assertTrue(commandLine.isEmpty()); getLauncherLifecycleCommands().addGemFirePropertyFile(commandLine, " "); assertTrue(commandLine.isEmpty()); getLauncherLifecycleCommands().addGemFirePropertyFile(commandLine, "/path/to/gemfire.properties"); assertFalse(commandLine.isEmpty()); assertTrue(commandLine.contains("-DgemfirePropertyFile=/path/to/gemfire.properties")); }
protected String getJConsolePathname() { return getJdkToolPathname("jconsole" + getExecutableSuffix(), new JConsoleNotFoundException(CliStrings.START_JCONSOLE__NOT_FOUND_ERROR_MESSAGE)); }
commandLine.add(getJConsolePathname()); String jmxServiceUrl = getJmxServiceUrlAsString(member);
protected String getJdkToolPathname(final Stack<String> pathnames, final GemFireException throwable) { assertNotNull(pathnames, "The JDK tool executable pathnames cannot be null!"); assertNotNull(throwable, "The GemFireException cannot be null!"); try { // assume 'java.home' JVM System property refers to the JDK installation directory. note, however, that the // 'java.home' JVM System property usually refers to the JRE used to launch this application return IOUtils.verifyPathnameExists(pathnames.pop()); } catch (EmptyStackException ignore) { throw throwable; } catch (FileNotFoundException ignore) { return getJdkToolPathname(pathnames, throwable); } }
commandLine.add(getJavaPath()); commandLine.add("-classpath"); commandLine.add(getServerClasspath(false, userClasspath)); addCurrentLocators(commandLine, gemfireProperties); addGemFirePropertyFile(commandLine, gemfirePropertiesPathname); addGemFireSecurityPropertyFile(commandLine, gfSecurityPropertiesPath); addGemFireSystemProperties(commandLine, gemfireProperties); addJvmArgumentsAndOptions(commandLine, jvmArgsOpts); addJvmOptionsForOutOfMemoryErrors(commandLine); addInitialHeap(commandLine, initialHeap); addMaxHeap(commandLine, maxHeap); if (launcher.isDebugging() || isDebugging()) { commandLine.add("--debug");
commandLine.add(getJavaPath()); commandLine.add("-server"); commandLine.add("-classpath"); commandLine.add(getLocatorClasspath(Boolean.TRUE.equals(includeSystemClasspath), userClasspath)); addCurrentLocators(commandLine, gemfireProperties); addGemFirePropertyFile(commandLine, gemfirePropertiesPathname); addGemFireSecurityPropertyFile(commandLine, gemfireSecurityPropertiesPathname); addGemFireSystemProperties(commandLine, gemfireProperties); addJvmArgumentsAndOptions(commandLine, jvmArgsOpts); addInitialHeap(commandLine, initialHeap); addMaxHeap(commandLine, maxHeap); if (launcher.isDebugging() || isDebugging()) { commandLine.add("--debug");
final int oldPid = readPid(locatorPidFile); String[] locatorCommandLine = createStartLocatorCommandLine(locatorLauncher, gemfirePropertiesPathname, gemfireSecurityPropertiesPathname, gemfireProperties, classpath, includeSystemClasspath, jvmArgsOpts, initialHeap, maxHeap); final boolean registeredLocatorSignalListener = getGfsh().getSignalHandler().registerListener(locatorSignalListener); getGfsh().logInfo(String.format(CliStrings.START_LOCATOR__RUN_MESSAGE, IOUtils.tryGetCanonicalPathElseGetAbsolutePath(new File(locatorLauncher.getWorkingDirectory()))), null); locatorState = (ProcessUtils.isAvailable() ? locatorStatus(locatorPidFile, oldPid, memberName) : locatorStatus(workingDirectory, memberName)); if (isStartingOrNotResponding(locatorState.getStatus()) && !(StringUtils.isBlank(currentLocatorStatusMessage) || currentLocatorStatusMessage.equalsIgnoreCase(previousLocatorStatusMessage))) && isStartingOrNotResponding(locatorState.getStatus())); getGfsh().getSignalHandler().unregisterListener(locatorSignalListener); && isStartingNotRespondingOrNull(locatorState)); String locatorHostName = StringUtils.defaultIfBlank(locatorLauncher.getHostnameForClients(), getLocalHost()); int locatorPort = locatorLauncher.getPort(); if (shouldAutoConnect(connect)) { doAutoConnect(locatorHostName, locatorPort, gemfirePropertiesPathname, gemfireSecurityPropertiesPathname, infoResultData);
ClassUtils.forName(ATTACH_API_CLASS_NAME, new AttachAPINotFoundException(getAttachAPINotFoundMessage())); getGfsh().printAsSevere(CliStrings.format(CliStrings.GEMFIRE_0_PROPERTIES_1_NOT_FOUND_MESSAGE, "", gemfirePropertiesPathname)); getGfsh().printAsSevere(CliStrings.format(CliStrings.GEMFIRE_0_PROPERTIES_1_NOT_FOUND_MESSAGE, "Security ", gfSecurityPropertiesPathname)); final int oldPid = readPid(locatorPidFile); final String[] locatorCommandLine = createStartLocatorCommandLine(locatorLauncher, gemfirePropertiesPathname, gfSecurityPropertiesPathname, gemfireProperties, jvmArgsOpts, initialHeap, maxHeap); final boolean registeredLocatorSignalListener = getGfsh().getSignalHandler().registerListener(locatorSignalListener); getGfsh().logInfo(String.format(CliStrings.START_LOCATOR__RUN_MESSAGE, IOUtils.tryGetCanonicalPathElseGetAbsolutePath(new File(locatorLauncher.getWorkingDirectory()))), null); locatorState = locatorStatus(locatorPidFile, oldPid, memberName); if (isStartingOrNotResponding(locatorState.getStatus()) && !(StringUtils.isBlank(currentLocatorStatusMessage) || currentLocatorStatusMessage.equalsIgnoreCase(previousLocatorStatusMessage))) while (!(registeredLocatorSignalListener && locatorSignalListener.isSignaled()) && isStartingOrNotResponding(locatorState .getStatus())); stderrReader.stop(); locatorProcess.getErrorStream().close(); getGfsh().getSignalHandler().unregisterListener(locatorSignalListener);
ClassUtils.forName(ATTACH_API_CLASS_NAME, new AttachAPINotFoundException(getAttachAPINotFoundMessage())); if (isConnectedAndReady()) { final MemberMXBean locatorProxy = getMemberMXBean(member); .setCommand(LocatorLauncher.Command.STATUS) .setBindAddress(locatorHost) .setDebug(isDebugging()) .setPid(pid) .setPort(locatorPort) SystemFailure.checkFailure(); return ResultBuilder.createShellClientErrorResult(String.format(CliStrings.STATUS_LOCATOR__GENERAL_ERROR_MESSAGE, getLocatorId(locatorHost, locatorPort), StringUtils.defaultIfBlank(workingDirectory, SystemUtils.CURRENT_DIRECTORY), toString(t, getGfsh().getDebug())));
if (isConnectedAndReady()) { final MemberMXBean locatorProxy = getMemberMXBean(member); return createStatusLocatorResult(state); .setCommand(LocatorLauncher.Command.STATUS) .setBindAddress(locatorHost) .setDebug(isDebugging()) .setPid(pid) .setPort(locatorPort) return createStatusLocatorResult(state); SystemFailure.checkFailure(); return ResultBuilder.createShellClientErrorResult(String.format(CliStrings.STATUS_LOCATOR__GENERAL_ERROR_MESSAGE, getLocatorId(locatorHost, locatorPort), StringUtils.defaultIfBlank(workingDirectory, SystemUtils.CURRENT_DIRECTORY), toString(t, getGfsh().getDebug())));
@Test(expected = NullPointerException.class) public void testGetJdkToolPathnameWithNullGemFireException() { try { getLauncherLifecycleCommands().getJdkToolPathname(new Stack<String>(), null); } catch (NullPointerException expected) { assertEquals("The GemFireException cannot be null!", expected.getMessage()); throw expected; } }
@Test(expected = IllegalArgumentException.class) public void testCreateJmxServiceUrlWithInvalidMemberName() { try { System.err.println(getLauncherLifecycleCommands().getJmxServiceUrlAsString("memberOne[]")); } catch (IllegalArgumentException expected) { assertEquals(CliStrings.START_JCONSOLE__CONNECT_BY_MEMBER_NAME_ID_ERROR_MESSAGE, expected.getMessage()); throw expected; } }
@Test public void testAddInitialHeapToCommandLine() { final List<String> commandLine = new ArrayList<String>(); assertTrue(commandLine.isEmpty()); getLauncherLifecycleCommands().addInitialHeap(commandLine, null); assertTrue(commandLine.isEmpty()); getLauncherLifecycleCommands().addInitialHeap(commandLine, StringUtils.EMPTY_STRING); assertTrue(commandLine.isEmpty()); getLauncherLifecycleCommands().addInitialHeap(commandLine, " "); assertTrue(commandLine.isEmpty()); getLauncherLifecycleCommands().addInitialHeap(commandLine, "512M"); assertFalse(commandLine.isEmpty()); assertEquals("-Xms512M", commandLine.get(0)); }
@Test public void testGetLocatorId() { assertEquals("tidepool[11235]", getLauncherLifecycleCommands().getLocatorId("tidepool", 11235)); assertEquals("tidepool.gemstone.com[11235]", getLauncherLifecycleCommands().getLocatorId("tidepool.gemstone.com", 11235)); assertEquals("tidepool["+ DistributionLocator.DEFAULT_LOCATOR_PORT + "]", getLauncherLifecycleCommands().getLocatorId("tidepool", null)); }
@Test public void testAddGemFireSystemPropertiesToCommandLine() { final List<String> commandLine = new ArrayList<String>(); assertTrue(commandLine.isEmpty()); getLauncherLifecycleCommands().addGemFireSystemProperties(commandLine, new Properties()); assertTrue(commandLine.isEmpty()); final Properties gemfireProperties = new Properties(); gemfireProperties.setProperty(DistributionConfig.LOCATORS_NAME, "localhost[11235]"); gemfireProperties.setProperty(DistributionConfig.LOG_LEVEL_NAME, "config"); gemfireProperties.setProperty(DistributionConfig.LOG_FILE_NAME, StringUtils.EMPTY_STRING); gemfireProperties.setProperty(DistributionConfig.MCAST_PORT_NAME, "0"); gemfireProperties.setProperty(DistributionConfig.NAME_NAME, "tidepool"); getLauncherLifecycleCommands().addGemFireSystemProperties(commandLine, gemfireProperties); assertFalse(commandLine.isEmpty()); assertEquals(4, 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("-Dgemfire.".concat(propertyName).concat("="))); } } else { assertTrue(commandLine.contains("-Dgemfire.".concat(propertyName).concat("=").concat(propertyValue))); } } }
@Test public void testAddMaxHeapToCommandLine() { final List<String> commandLine = new ArrayList<String>(); assertTrue(commandLine.isEmpty()); getLauncherLifecycleCommands().addMaxHeap(commandLine, null); assertTrue(commandLine.isEmpty()); getLauncherLifecycleCommands().addMaxHeap(commandLine, StringUtils.EMPTY_STRING); assertTrue(commandLine.isEmpty()); getLauncherLifecycleCommands().addMaxHeap(commandLine, " "); assertTrue(commandLine.isEmpty()); getLauncherLifecycleCommands().addMaxHeap(commandLine, "1024M"); assertFalse(commandLine.isEmpty()); assertEquals(3, commandLine.size()); assertEquals("-Xmx1024M", commandLine.get(0)); assertEquals("-XX:+UseConcMarkSweepGC", commandLine.get(1)); assertEquals("-XX:CMSInitiatingOccupancyFraction=" + LauncherLifecycleCommands.CMS_INITIAL_OCCUPANCY_FRACTION, commandLine.get(2)); }
@Test public void testAddJvmArgumentsAndOptionsToCommandLine() { final List<String> commandLine = new ArrayList<String>(); assertTrue(commandLine.isEmpty()); getLauncherLifecycleCommands().addJvmArgumentsAndOptions(commandLine, null); assertTrue(commandLine.isEmpty()); getLauncherLifecycleCommands().addJvmArgumentsAndOptions(commandLine, new String[] { }); assertTrue(commandLine.isEmpty()); getLauncherLifecycleCommands().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 testAddJvmOptionsForOutOfMemoryErrors() { final List<String> jvmOptions = new ArrayList<String>(1); getLauncherLifecycleCommands().addJvmOptionsForOutOfMemoryErrors(jvmOptions); if (SystemUtils.isHotSpotVM()) { assertEquals(getExpectedJvmOptionsForOOMErrors(), jvmOptions.size()); if (SystemUtils.isWindows()) { assertTrue(jvmOptions.contains("-XX:OnOutOfMemoryError=\"taskkill")); int oomStartIndex = jvmOptions.indexOf("-XX:OnOutOfMemoryError=\"taskkill"); assertEquals(jvmOptions.get(oomStartIndex + 1), "/F"); assertEquals(jvmOptions.get(oomStartIndex + 2), "/PID"); assertEquals(jvmOptions.get(oomStartIndex + 3), "%p\""); } else { assertTrue(jvmOptions.contains("-XX:OnOutOfMemoryError=\"kill -9 %p\"")); } } else if (SystemUtils.isJ9VM()) { assertEquals(1, jvmOptions.size()); assertTrue(jvmOptions.contains("-Xcheck:memory")); } else if (SystemUtils.isJRockitVM()) { assertEquals(1, jvmOptions.size()); assertTrue(jvmOptions.contains("-XXexitOnOutOfMemory")); } else { assertTrue(jvmOptions.isEmpty()); } }
commandLine.add(getJavaPath()); commandLine.add("-server"); commandLine.add("-classpath"); commandLine.add(getServerClasspath(Boolean.TRUE.equals(includeSystemClasspath), launcher.isSpringXmlLocationSpecified(), userClasspath)); addCurrentLocators(commandLine, gemfireProperties); addGemFirePropertyFile(commandLine, gemfirePropertiesPathname); addGemFireSecurityPropertyFile(commandLine, gemfireSecurityPropertiesPathname); addGemFireSystemProperties(commandLine, gemfireProperties); addJvmArgumentsAndOptions(commandLine, jvmArgsOpts); addJvmOptionsForOutOfMemoryErrors(commandLine); addInitialHeap(commandLine, initialHeap); addMaxHeap(commandLine, maxHeap); if (launcher.isDebugging() || isDebugging()) { commandLine.add("--debug");
commandLine.add(getJavaPath()); commandLine.add("-classpath"); commandLine.add(getLocatorClasspath(false)); addCurrentLocators(commandLine, gemfireProperties); addGemFirePropertyFile(commandLine, gemfirePropertiesPathname); addGemFireSecurityPropertyFile(commandLine, gfSecurityPropertiesPathname); addGemFireSystemProperties(commandLine, gemfireProperties); addJvmArgumentsAndOptions(commandLine, jvmArgsOpts); addInitialHeap(commandLine, initialHeap); addMaxHeap(commandLine, maxHeap); if (launcher.isDebugging() || isDebugging()) { commandLine.add("--debug");