/** * Iterates the list of arguments in search of the Locator's GemFire member name. If the * argument does not start with '-' or is not the name of a Locator launcher command, then the * value is presumed to be the member name for the Locator in GemFire. * * @param args the array of arguments from which to search for the Locator's member name in * GemFire. * @see org.apache.geode.distributed.LocatorLauncher.Command#isCommand(String) * @see #parseArguments(String...) */ protected void parseMemberName(final String... args) { if (args != null) { for (String arg : args) { if (!(arg.startsWith(OPTION_PREFIX) || Command.isCommand(arg))) { setMemberName(arg); break; } } } }
@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()); }
new LocatorLauncher.Builder().setCommand(LocatorLauncher.Command.START) .setDebug(Boolean.TRUE).setDeletePidFileOnStop(Boolean.TRUE).setForce(Boolean.TRUE) .setHostnameForClients("localhost").setMemberName("customLocator").setPort(10101) .setRedirectOutput(Boolean.TRUE).build();
locatorLauncherBuilder.setMemberName(memberName);
@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()); }
@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(); }
@Test public void setMemberNameWithEmptyStringThrowsIllegalArgumentException() { assertThatThrownBy(() -> new Builder().setMemberName("")) .isInstanceOf(IllegalArgumentException.class); }
@Test public void setMemberNameWithNullStringThrowsIllegalArgumentException() { assertThatThrownBy(() -> new Builder().setMemberName(null)) .isInstanceOf(IllegalArgumentException.class); }
@Test public void setMemberNameWithBlankStringThrowsIllegalArgumentException() { assertThatThrownBy(() -> new Builder().setMemberName(" ")) .isInstanceOf(IllegalArgumentException.class); }
@Test public void setMemberNameToStringUsesValue() throws Exception { Builder builder = new Builder(); builder.setMemberName("locatorOne"); assertThat(builder.getMemberName()).isEqualTo("locatorOne"); }
@Test public void setMemberNameReturnsBuilderInstance() throws Exception { Builder builder = new Builder(); assertThat(builder.setMemberName("serverOne")).isSameAs(builder); }