@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()); }
.setDebug(Boolean.TRUE).setDeletePidFileOnStop(Boolean.TRUE).setForce(Boolean.TRUE) .setHostnameForClients("localhost").setMemberName("customLocator").setPort(10101) .setRedirectOutput(Boolean.TRUE).build();
/** * Launches a GemFire Locator from the command-line configured with the given arguments. * * @param args the command-line arguments used to configure the GemFire Locator at runtime. */ public static void main(final String... args) { try { new Builder(args).build().run(); } catch (AttachAPINotFoundException handled) { System.err.println(handled.getMessage()); } }
locatorLauncherBuilder.setMemberName(memberName); LocatorLauncher locatorLauncher = locatorLauncherBuilder.build();
final LocatorLauncher locatorLauncher = new LocatorLauncher.Builder().setCommand(LocatorLauncher.Command.STOP) .setDebug(isDebugging()).setPid(pid).setWorkingDirectory(workingDirectory).build();
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()); }
@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(); }
public static LocatorState fromDirectory(final String workingDirectory, final String memberName) { LocatorState locatorState = new LocatorLauncher.Builder().setWorkingDirectory(workingDirectory).build().status(); if (ObjectUtils.equals(locatorState.getMemberName(), memberName)) { return locatorState; } return new LocatorState(new LocatorLauncher.Builder().build(), Status.NOT_RESPONDING); }
@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(); } }