@Test public void testCreateStartLocatorCommandLineWithAllOptions() throws Exception { LocatorLauncher locatorLauncher = new LocatorLauncher.Builder().setCommand(LocatorLauncher.Command.START) .setDebug(Boolean.TRUE).setDeletePidFileOnStop(Boolean.TRUE).setForce(Boolean.TRUE) .setHostnameForClients("localhost").setMemberName("customLocator").setPort(10101)
@Test public void testCreateStartLocatorCommandLine() throws Exception { LocatorLauncher locatorLauncher = new LocatorLauncher.Builder().setMemberName("defaultLocator") .setCommand(LocatorLauncher.Command.START).build(); String[] commandLineElements = startLocatorCommand.createStartLocatorCommandLine(locatorLauncher, null, null, new Properties(), null, false, null, null, null); Set<String> expectedCommandLineElements = new HashSet<>(); expectedCommandLineElements.add(StartMemberUtils.getJavaPath()); expectedCommandLineElements.add("-server"); expectedCommandLineElements.add("-classpath"); expectedCommandLineElements.add(StartMemberUtils.getGemFireJarPath().concat(File.pathSeparator) .concat(StartMemberUtils.CORE_DEPENDENCIES_JAR_PATHNAME)); expectedCommandLineElements.add("-Dgemfire.launcher.registerSignalHandlers=true"); expectedCommandLineElements.add("-Djava.awt.headless=true"); expectedCommandLineElements.add("-Dsun.rmi.dgc.server.gcInterval=9223372036854775806"); expectedCommandLineElements.add("org.apache.geode.distributed.LocatorLauncher"); expectedCommandLineElements.add("start"); expectedCommandLineElements.add("defaultLocator"); expectedCommandLineElements.add("--port=10334"); assertNotNull(commandLineElements); assertTrue(commandLineElements.length > 0); assertEquals(commandLineElements.length, expectedCommandLineElements.size()); for (String commandLineElement : commandLineElements) { expectedCommandLineElements.remove(commandLineElement); } assertTrue(String.format("Expected ([]); but was (%1$s)", expectedCommandLineElements), expectedCommandLineElements.isEmpty()); }
@Test public void buildCreatesLocatorLauncherWithBuilderValues() throws Exception { Builder builder = new Builder(); LocatorLauncher launcher = builder.setCommand(Command.START).setDebug(true) .setHostnameForClients("beanstock.vmware.com").setMemberName("Beanstock").setPort(8192) .setRedirectOutput(Boolean.TRUE).build(); assertThat(launcher.getCommand()).isEqualTo(builder.getCommand()); assertThat(launcher.isDebugging()).isTrue(); assertThat(launcher.getHostnameForClients()).isEqualTo(builder.getHostnameForClients()); assertThat(launcher.getMemberName()).isEqualTo(builder.getMemberName()); assertThat(launcher.getPort()).isEqualTo(builder.getPort()); assertThat(launcher.getWorkingDirectory()).isEqualTo(builder.getWorkingDirectory()); assertThat(launcher.isRedirectingOutput()).isTrue(); assertThat(launcher.isHelping()).isFalse(); assertThat(launcher.isRunning()).isFalse(); }
new LocatorLauncher.Builder().setCommand(LocatorLauncher.Command.STOP) .setDebug(isDebugging()).setPid(pid).setWorkingDirectory(workingDirectory).build();
setCommand(Command.VERSION);
new LocatorLauncher.Builder().setCommand(LocatorLauncher.Command.STATUS) .setBindAddress(locatorHost).setDebug(isDebugging()).setPid(pid).setPort(locatorPort) .setWorkingDirectory(workingDirectory).build();
@Test public void testLocatorCommandLineWithRestAPI() throws Exception { LocatorLauncher locatorLauncher = new LocatorLauncher.Builder().setCommand(LocatorLauncher.Command.START) .setMemberName("testLocatorCommandLineWithRestAPI").setBindAddress("localhost") .setPort(11111).build(); Properties gemfireProperties = new Properties(); gemfireProperties.setProperty(HTTP_SERVICE_PORT, "8089"); gemfireProperties.setProperty(HTTP_SERVICE_BIND_ADDRESS, "localhost"); String[] commandLineElements = startLocatorCommand.createStartLocatorCommandLine(locatorLauncher, null, null, gemfireProperties, null, false, new String[0], null, null); assertNotNull(commandLineElements); assertTrue(commandLineElements.length > 0); Set<String> expectedCommandLineElements = new HashSet<>(6); expectedCommandLineElements.add(locatorLauncher.getCommand().getName()); expectedCommandLineElements.add(locatorLauncher.getMemberName().toLowerCase()); expectedCommandLineElements.add(String.format("--port=%1$d", locatorLauncher.getPort())); expectedCommandLineElements .add("-d" + DistributionConfig.GEMFIRE_PREFIX + "" + HTTP_SERVICE_PORT + "=" + "8089"); expectedCommandLineElements.add("-d" + DistributionConfig.GEMFIRE_PREFIX + "" + HTTP_SERVICE_BIND_ADDRESS + "=" + "localhost"); for (String commandLineElement : commandLineElements) { expectedCommandLineElements.remove(commandLineElement.toLowerCase()); } assertTrue(String.format("Expected ([]); but was (%1$s)", expectedCommandLineElements), expectedCommandLineElements.isEmpty()); }
/** * Iterates the list of arguments in search of the target Locator launcher command. * * @param args an array of arguments from which to search for the Locator launcher command. * @see org.apache.geode.distributed.LocatorLauncher.Command#valueOfName(String) * @see #parseArguments(String...) */ protected void parseCommand(final String... args) { // search the list of arguments for the command; technically, the command should be the first // argument in the // list, but does it really matter? stop after we find one valid command. if (args != null) { for (String arg : args) { final Command command = Command.valueOfName(arg); if (command != null) { setCommand(command); break; } } } }
@Test public void buildUsesMemberNameSetInApiProperties() { LocatorLauncher launcher = new Builder().setCommand(LocatorLauncher.Command.START).set(NAME, "locatorABC").build(); assertThat(launcher.getMemberName()).isNull(); assertThat(launcher.getProperties().getProperty(NAME)).isEqualTo("locatorABC"); }
@Test public void buildUsesMemberNameSetInSystemPropertiesOnStart() { System.setProperty(DistributionConfig.GEMFIRE_PREFIX + NAME, "locatorXYZ"); LocatorLauncher launcher = new Builder().setCommand(LocatorLauncher.Command.START).build(); assertThat(launcher.getCommand()).isEqualTo(LocatorLauncher.Command.START); assertThat(launcher.getMemberName()).isNull(); } }
@Test public void setCommandWithNullResultsInDefaultCommand() throws Exception { Builder builder = new Builder(); new Builder().setCommand(null); assertThat(builder.getCommand()).isEqualTo(Builder.DEFAULT_COMMAND); }
@Test public void setCommandReturnsBuilderInstance() throws Exception { Builder builder = new Builder(); assertThat(builder.setCommand(Command.STATUS)).isSameAs(builder); }
@Test public void setCommandToStatusResultsInStatus() throws Exception { Builder builder = new Builder(); builder.setCommand(Command.STATUS); assertThat(builder.getCommand()).isEqualTo(Command.STATUS); }