@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) .setRedirectOutput(Boolean.TRUE).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()); }
new LocatorLauncher.Builder().setBindAddress(bindAddress).setForce(force).setPort(port) .setRedirectOutput(redirectOutput).setWorkingDirectory(workingDirectory); if (hostnameForClients != null) { locatorLauncherBuilder.setHostnameForClients(hostnameForClients); locatorLauncherBuilder.setMemberName(memberName); LocatorLauncher locatorLauncher = locatorLauncherBuilder.build();
new LocatorLauncher.Builder().setCommand(LocatorLauncher.Command.STOP) .setDebug(isDebugging()).setPid(pid).setWorkingDirectory(workingDirectory).build();
parseCommand(args); parseMemberName(args); final OptionSet options = getParser().parse(args); setDebug(options.has("debug")); setDeletePidFileOnStop(options.has("delete-pid-file-on-stop")); setForce(options.has("force")); setHelp(options.has("help")); setRedirectOutput(options.has("redirect-output")); if (!isHelping()) { if (options.has("bind-address")) { setBindAddress(ObjectUtils.toString(options.valueOf("bind-address"))); setWorkingDirectory(ObjectUtils.toString(options.valueOf("dir"))); setHostnameForClients(ObjectUtils.toString(options.valueOf("hostname-for-clients"))); setPid((Integer) options.valueOf("pid")); setPort((Integer) options.valueOf("port")); setCommand(Command.VERSION);
new LocatorLauncher.Builder().setCommand(LocatorLauncher.Command.STATUS) .setBindAddress(locatorHost).setDebug(isDebugging()).setPid(pid).setPort(locatorPort) .setWorkingDirectory(workingDirectory).build();
@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()); }
/** * 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; } } } }
/** * 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 setPortToZeroOrGreaterUsesValue() throws Exception { Builder builder = new Builder(); builder.setPort(0); assertThat(builder.getPort().intValue()).isEqualTo(0); builder.setPort(1); assertThat(builder.getPort().intValue()).isEqualTo(1); builder.setPort(80); assertThat(builder.getPort().intValue()).isEqualTo(80); builder.setPort(1024); assertThat(builder.getPort().intValue()).isEqualTo(1024); builder.setPort(65535); assertThat(builder.getPort().intValue()).isEqualTo(65535); }
@Test public void getMemberNameReturnsNullByDefault() throws Exception { assertThat(new Builder().getMemberName()).isNull(); }
@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 getHostnameForClientsReturnsNullByDefault() throws Exception { assertThat(new Builder().getHostnameForClients()).isNull(); }
@Test public void getRedirectOutputReturnsNullByDefault() throws Exception { assertThat(new LocatorLauncher.Builder().getRedirectOutput()).isNull(); }
@Test public void parseMemberNameWithCommandAndOptionsResultsInNull() throws Exception { Builder builder = new Builder(); builder.parseMemberName(Command.START.getName(), "--opt", "-o"); assertThat(builder.getMemberName()).isNull(); }
@Test public void parseCommandWithTwoCommandsWithoutSwitchesUsesFirstCommand() throws Exception { Builder builder = new Builder(); builder.parseCommand("START", Command.STATUS.getName()); assertThat(builder.getCommand()).isEqualTo(Command.START); }
@Test public void parseCommandWithStatusResultsInStatusCommand() throws Exception { Builder builder = new Builder(); builder.parseCommand("Status"); assertThat(builder.getCommand()).isEqualTo(Command.STATUS); }