/** * Creates a Properties object with configuration settings that the launcher has that should take * precedence over anything the user has defined in their gemfire properties file. * * @return a Properties object with GemFire properties that the launcher has defined. * @see #getDistributedSystemProperties(java.util.Properties) * @see java.util.Properties */ protected Properties getDistributedSystemProperties() { return getDistributedSystemProperties(null); }
/** * Gets the name or ID of the member in the GemFire distributed system. This method prefers name * if specified, otherwise the ID is returned. If name was not specified to the Builder that * created this Launcher and this call is not in-process, then null is returned. * * @return a String value indicating the member's name if specified, otherwise the member's ID is * returned if this call is made in-process, or finally, null is returned if neither name * name was specified or the call is out-of-process. * @see #getMemberName() * @see #getMemberId() */ public String getMember() { if (isNotBlank(getMemberName())) { return getMemberName(); } if (isNotBlank(getMemberId())) { return getMemberId(); } return null; }
/** * Validates the arguments passed to the Builder when the 'start' command has been issued. * * @see org.apache.geode.distributed.ServerLauncher.Command#START */ void validateOnStart() { if (Command.START == getCommand()) { if (isBlank(getMemberName()) && !isSet(System.getProperties(), DistributionConfig.GEMFIRE_PREFIX + NAME) && !isSet(getDistributedSystemProperties(), NAME) && !isSet(loadGemFireProperties(DistributedSystem.getPropertyFileURL()), NAME)) { throw new IllegalStateException( String.format( MEMBER_NAME_ERROR_MESSAGE, "Server", "Server")); } if (!CURRENT_DIRECTORY.equalsIgnoreCase(getWorkingDirectory())) { throw new IllegalStateException( String.format( AbstractLauncher.WORKING_DIRECTORY_OPTION_NOT_VALID_ERROR_MESSAGE, "Server", "Server")); } } }
boolean isPidInProcess() { Integer pid = getPid(); return pid != null && pid == identifyPidOrNot(); }
/** * Gets the fully qualified canonical path of the log file for the process. * * @return a String value indicating the canonical path of the log file for the process. */ protected String getLogFileCanonicalPath() { try { return getLogFile().getCanonicalPath(); } catch (IOException handled) { return getLogFileName(); } }
/** * Gets a File reference with the path to the log file for the process. * * @return a File reference to the path of the log file for the process. */ protected File getLogFile() { return new File(getWorkingDirectory(), getLogFileName()); }
/** * Gets the name of this member (this Locator) in the GemFire distributed system and determined by * the 'name' GemFire property. * * @return a String indicating the name of the member (this Locator) in the GemFire distributed * system. */ @Override public String getMemberName() { return defaultIfBlank(this.memberName, super.getMemberName()); }
@Test public void getMemberReturnsMemberIdIfMemberNameIsEmpty() throws Exception { AbstractLauncher<?> launcher = createAbstractLauncher(StringUtils.EMPTY, "123"); assertThat(launcher.getMember()).isEqualTo("123").isEqualTo(launcher.getMemberId()); }
@Test public void getMemberIdReturnsBlankIfBlank() throws Exception { AbstractLauncher<?> launcher = createAbstractLauncher(null, " "); assertThat(launcher.getMemberId()).isEqualTo(" "); }
@Test public void isSetReturnsFalseIfPropertyHasEmptyValue() throws Exception { Properties properties = new Properties(); properties.setProperty(NAME, ""); assertThat(AbstractLauncher.isSet(properties, NAME)).isFalse(); }
@Test public void getDistributedSystemPropertiesIncludesDefaults() throws Exception { AbstractLauncher<?> launcher = createAbstractLauncher("TestMember", "123"); Properties defaults = new Properties(); defaults.setProperty("testKey", "testValue"); Properties properties = launcher.getDistributedSystemProperties(defaults); assertThat(properties.getProperty(NAME)).isEqualTo(launcher.getMemberName()); assertThat(properties.getProperty("testKey")).isEqualTo("testValue"); }
@Test public void getMemberPrefersMemberNameOverMemberId() throws Exception { AbstractLauncher<?> launcher = createAbstractLauncher("memberOne", "123"); assertThat(launcher.getMember()).isEqualTo("memberOne").isEqualTo(launcher.getMemberName()); }
@Test public void loadGemFirePropertiesWithNonExistingURLReturnsEmptyProperties() throws Exception { URL nonExistingUrl = new URL("file:///path/to/non_existing/gemfire.properties"); Properties properties = AbstractLauncher.loadGemFireProperties(nonExistingUrl); assertThat(properties).isNotNull().isEmpty(); }
@Test public void getMemberReturnsNullIfMemberIdIsNull() throws Exception { AbstractLauncher<?> launcher = createAbstractLauncher(null, null); assertThat(launcher.getMember()).isNull(); }
/** * Asserts that the specified port is available on all network interfaces on this local system. * * @param port an integer indicating the network port to listen for client network requests. * @throws BindException if the network port is not available. */ protected static void assertPortAvailable(final int port) throws BindException { assertPortAvailable(null, port); }
/** * Gets the name of this member (this Server) in the GemFire distributed system as determined by * the 'name' GemFire property. * * @return a String indicating the name of the member (this Server) in the GemFire distributed * system. */ @Override public String getMemberName() { return defaultIfBlank(this.memberName, super.getMemberName()); }
@Test public void getMemberReturnsMemberIdIfMemberNameIsBlank() throws Exception { AbstractLauncher<?> launcher = createAbstractLauncher(" ", "123"); assertThat(launcher.getMember()).isEqualTo("123").isEqualTo(launcher.getMemberId()); }
@Test public void getMemberIdReturnsEmptyIfEmpty() throws Exception { AbstractLauncher<?> launcher = createAbstractLauncher(null, StringUtils.EMPTY); assertThat(launcher.getMemberId()).isEqualTo(StringUtils.EMPTY); }
@Test public void isSetReturnsFalseIfPropertyHasBlankValue() throws Exception { Properties properties = new Properties(); properties.setProperty(NAME, " "); assertThat(AbstractLauncher.isSet(properties, NAME)).isFalse(); }
@Test public void loadGemFirePropertiesWithNullURLReturnsEmptyProperties() throws Exception { URL nullUrl = null; Properties properties = AbstractLauncher.loadGemFireProperties(nullUrl); assertThat(properties).isNotNull().isEmpty(); }