@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); }
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 setPortAboveMaxValueThrowsIllegalArgumentException() throws Exception { assertThatThrownBy(() -> new Builder().setPort(65536)) .isInstanceOf(IllegalArgumentException.class); }
new LocatorLauncher.Builder().setBindAddress(bindAddress).setForce(force).setPort(port) .setRedirectOutput(redirectOutput).setWorkingDirectory(workingDirectory); if (hostnameForClients != null) {
setPort((Integer) options.valueOf("port"));
final LocatorLauncher locatorLauncher = 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(); }
@Test public void setPortToNegativeValueThrowsIllegalArgumentException() { assertThatThrownBy(() -> new Builder().setPort(-1)) .isInstanceOf(IllegalArgumentException.class); }
@Test public void setPortToNullUsesDefaultLocatorPort() throws Exception { Builder builder = new Builder(); assertThat(builder.setPort(null).getPort()).isEqualTo(Integer.valueOf(DEFAULT_LOCATOR_PORT)); }
@Test public void setPortReturnsBuilderInstance() throws Exception { Builder builder = new Builder(); assertThat(builder.setPort(null)).isSameAs(builder); }