You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2015/12/02 23:34:05 UTC
incubator-geode git commit: GEODE-291: Add and fix tests for this
ticket
Repository: incubator-geode
Updated Branches:
refs/heads/feature/GEODE-291 857b86f6b -> dd9f361d1
GEODE-291: Add and fix tests for this ticket
Extract file I/O tests to integration test class.
Change PROPERTY_FILE and use of system property gemfirePropertyFile
to enable unit testing. Make same changes for gemfireSecurityPropertyFile.
Create unit and integration tests for DistributedSystem class.
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/dd9f361d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/dd9f361d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/dd9f361d
Branch: refs/heads/feature/GEODE-291
Commit: dd9f361d1020fb5ca5e2963609f5a275e7ecc8d8
Parents: 857b86f
Author: Kirk Lund <kl...@pivotal.io>
Authored: Wed Dec 2 14:33:18 2015 -0800
Committer: Kirk Lund <kl...@pivotal.io>
Committed: Wed Dec 2 14:33:18 2015 -0800
----------------------------------------------------------------------
.../gemfire/distributed/AbstractLauncher.java | 2 +-
.../gemfire/distributed/DistributedSystem.java | 208 ++++++++++++++-----
.../DistributedSystemIntegrationJUnitTest.java | 91 ++++++++
.../distributed/DistributedSystemJUnitTest.java | 78 +++++++
.../LocatorLauncherIntegrationJUnitTest.java | 198 ++++++++++++++++++
.../distributed/LocatorLauncherJUnitTest.java | 154 +-------------
6 files changed, 537 insertions(+), 194 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/dd9f361d/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/AbstractLauncher.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/AbstractLauncher.java b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/AbstractLauncher.java
index bfd3de7..205f501 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/AbstractLauncher.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/AbstractLauncher.java
@@ -170,7 +170,7 @@ public abstract class AbstractLauncher<T extends Comparable<T>> implements Runna
catch (Exception e) {
try {
// not in the file system, try the classpath
- properties.load(AbstractLauncher.class.getResourceAsStream(DistributedSystem.PROPERTY_FILE));
+ properties.load(AbstractLauncher.class.getResourceAsStream(DistributedSystem.getPropertiesFile()));
}
catch (Exception ignore) {
// not in the file system or the classpath; gemfire.properties does not exist
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/dd9f361d/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/DistributedSystem.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/DistributedSystem.java b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/DistributedSystem.java
index e2fccd9..159db86 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/DistributedSystem.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/DistributedSystem.java
@@ -1943,26 +1943,59 @@ public abstract class DistributedSystem implements StatisticsFactory {
*/
public abstract String getName();
-// /**
-// * Fires an "informational" <code>SystemMembershipEvent</code> that
-// * is delivered to all {@link
-// * com.gemstone.gemfire.admin.SystemMembershipListener}s.
-// *
-// * @param callback
-// * A user-specified object that is delivered with the {@link
-// * com.gemstone.gemfire.admin.SystemMembershipEvent}
-// * triggered by invoking this method.
-// *
-// * @see com.gemstone.gemfire.admin.SystemMembershipListener#memberInfo
-// *
-// * @since 4.0
-// */
-// public abstract void fireInfoEvent(Object callback);
+ /**
+ * The <code>PROPERTIES_FILE_PROPERTY</code> is the system property
+ * that can be used to specify the name of the properties file that the
+ * connect method will check for when it looks for a properties file. Unless
+ * the value specifies the fully qualified path to the file, the file will
+ * be searched for, in order, in the following directories:
+ * <ol>
+ * <li> the current directory
+ * <li> the home directory
+ * <li> the class path
+ * </ol>
+ * Only the first file found will be used.
+ * <p>
+ * The default value is {@link #PROPERTIES_FILE_DEFAULT}. However
+ * if the <code>PROPERTIES_FILE_PROPERTY</code> is set then its value
+ * will be used instead of the default. If this value is a relative file
+ * system path then the above search is done. If it is an absolute
+ * file system path then that file must exist; no search for it is
+ * done.
+ *
+ * @see #PROPERTIES_FILE_DEFAULT
+ * @see #getPropertiesFile()
+ * @since 9.0
+ */
+ public static final String PROPERTIES_FILE_PROPERTY = "gemfirePropertyFile";
+
+ /**
+ * The default value of <code>PROPERTIES_FILE_PROPERTY</code> is
+ * <code>"gemfire.properties"</code>. The location of the file will be
+ * resolved during connect as described for {@link #PROPERTIES_FILE_PROPERTY}.
+ *
+ * @see #PROPERTIES_FILE_PROPERTY
+ * @see #getPropertiesFile()
+ * @since 9.0
+ */
+ public static final String PROPERTIES_FILE_DEFAULT = "gemfire.properties";
/**
+ * Returns the current value of {@link #PROPERTIES_FILE_PROPERTY} system
+ * property if set or the default value {@link #PROPERTIES_FILE_DEFAULT}.
+ *
+ * @see #PROPERTIES_FILE_PROPERTY
+ * @see #PROPERTIES_FILE_DEFAULT
+ * @since 9.0
+ */
+ public static String getPropertiesFile() {
+ return System.getProperty(PROPERTIES_FILE_PROPERTY, PROPERTIES_FILE_DEFAULT);
+ }
+
+ /**
* The <code>PROPERTY_FILE</code> is the name of the
- * property file that the connect method will check for when
- * it looks for a property file.
+ * properties file that the connect method will check for when
+ * it looks for a properties file.
* The file will be searched for, in order, in the following directories:
* <ol>
* <li> the current directory
@@ -1978,60 +2011,139 @@ public abstract class DistributedSystem implements StatisticsFactory {
* system path then the above search is done. If it is an absolute
* file system path then that file must exist; no search for it is
* done.
+ *
+ * @see #getPropertiesFile()
* @since 5.0
- * */
- public static final String PROPERTY_FILE = System.getProperty("gemfirePropertyFile", "gemfire.properties");
+ * @deprecated As of 9.0, please use {@link #getPropertiesFile()} instead.
+ */
+ public static String PROPERTY_FILE = getPropertiesFile();
+
+ /**
+ * The <code>SECURITY_PROPERTIES_FILE_PROPERTY</code> is the system property
+ * that can be used to specify the name of the property file that the
+ * connect method will check for when it looks for a property file. Unless
+ * the value specifies the fully qualified path to the file, the file will
+ * be searched for, in order, in the following directories:
+ * <ol>
+ * <li> the current directory
+ * <li> the home directory
+ * <li> the class path
+ * </ol>
+ * Only the first file found will be used.
+ * <p>
+ * The default value is {@link #SECURITY_PROPERTIES_FILE_DEFAULT}. However
+ * if the <code>SECURITY_PROPERTIES_FILE_PROPERTY</code> is set then its value
+ * will be used instead of the default. If this value is a relative file
+ * system path then the above search is done. If it is an absolute
+ * file system path then that file must exist; no search for it is
+ * done.
+ *
+ * @see #SECURITY_PROPERTIES_FILE_DEFAULT
+ * @see #getSecurityPropertiesFile()
+ * @since 9.0
+ */
+ public static final String SECURITY_PROPERTIES_FILE_PROPERTY = "gemfireSecurityPropertyFile";
+
+ /**
+ * The default value of <code>SECURITY_PROPERTIES_FILE_PROPERTY</code> is
+ * <code>"gfsecurity.properties"</code>. The location of the file will be
+ * resolved during connect as described for {@link #SECURITY_PROPERTIES_FILE_PROPERTY}.
+ *
+ * @see #SECURITY_PROPERTIES_FILE_PROPERTY
+ * @see #getSecurityPropertiesFile()
+ * @since 9.0
+ */
+ public static final String SECURITY_PROPERTIES_FILE_DEFAULT = "gfsecurity.properties";
/**
+ * Returns the current value of {@link #SECURITY_PROPERTIES_FILE_PROPERTY} system
+ * property if set or the default value {@link #SECURITY_PROPERTIES_FILE_DEFAULT}.
+ *
+ * @see #SECURITY_PROPERTIES_FILE_PROPERTY
+ * @see #SECURITY_PROPERTIES_FILE_DEFAULT
+ * @since 9.0
+ */
+ public static String getSecurityPropertiesFile() {
+ return System.getProperty(SECURITY_PROPERTIES_FILE_PROPERTY, SECURITY_PROPERTIES_FILE_DEFAULT);
+ }
+
+ /**
* The <code>SECURITY_PROPERTY_FILE</code> is the name of the
- * property file that the connect method will check for when
- * it looks for a security property file.
- * The file will be searched for, in order, in the following directories:
- * <ol>
- * <li> the current directory
- * <li> the home directory
- * <li> the class path
- * </ol>
- * Only the first file found will be used.
- * <p>
- * The default value of SECURITY_PROPERTY_FILE is
- * <code>"gfsecurity.properties"</code>. However if the
- * "gemfireSecurityPropertyFile" system property is set then its value is
- * the value of SECURITY_PROPERTY_FILE. If this value is a relative file
- * system path then the above search is done. If it is an absolute
- * file system path then that file must exist; no search for it is
- * done.
- * @since 6.6.2
+ * property file that the connect method will check for when
+ * it looks for a security property file.
+ * The file will be searched for, in order, in the following directories:
+ * <ol>
+ * <li> the current directory
+ * <li> the home directory
+ * <li> the class path
+ * </ol>
+ * Only the first file found will be used.
+ * <p>
+ * The default value of SECURITY_PROPERTY_FILE is
+ * <code>"gfsecurity.properties"</code>. However if the
+ * "gemfireSecurityPropertyFile" system property is set then its value is
+ * the value of SECURITY_PROPERTY_FILE. If this value is a relative file
+ * system path then the above search is done. If it is an absolute
+ * file system path then that file must exist; no search for it is
+ * done.
+ *
+ * @see #getSecurityPropertiesFile()
+ * @since 6.6.2
+ * @deprecated As of 9.0, please use {@link #getSecurityPropertiesFile()} instead.
*/
- public static final String SECURITY_PROPERTY_FILE = System.getProperty("gemfireSecurityPropertyFile",
- "gfsecurity.properties");
+ public static String SECURITY_PROPERTY_FILE = getSecurityPropertiesFile();
+
+ /**
+ * Gets an <code>URL</code> for the properties file, if one can be found,
+ * that the connect method will use as its properties file.
+ * <p>
+ * See {@link #PROPERTIES_FILE_PROPERTY} for information on the name of
+ * the properties file and what locations it will be looked for in.
+ *
+ * @return a <code>URL</code> that names the GemFire property file.
+ * Null is returned if no property file was found.
+ * @see #PROPERTIES_FILE_PROPERTY
+ * @see #PROPERTIES_FILE_DEFAULT
+ * @see #getPropertiesFile()
+ * @since 9.0
+ */
+ public static URL getPropertiesFileURL() {
+ return getFileURL(getPropertiesFile());
+ }
/**
* Gets an <code>URL</code> for the property file, if one can be found,
* that the connect method will use as its property file.
* <p>
- * See {@link #PROPERTY_FILE} for information on the name of
+ * See {@link #PROPERTIES_FILE_PROPERTY} for information on the name of
* the property file and what locations it will be looked for in.
+ *
* @return a <code>URL</code> that names the GemFire property file.
* Null is returned if no property file was found.
+ * @see #getPropertiesFileURL()
* @since 5.0
+ * @deprecated As of 9.0, please use {@link #getPropertiesFileURL()}
*/
public static URL getPropertyFileURL() {
- return getFileURL(PROPERTY_FILE);
+ return getPropertiesFileURL();
}
/**
- * Gets an <code>URL</code> for the security property file, if one can be found,
- * that the connect method will use as its property file.
+ * Gets an <code>URL</code> for the security properties file, if one can be found,
+ * that the connect method will use as its properties file.
* <p>
- * See {@link #SECURITY_PROPERTY_FILE} for information on the name of
- * the property file and what locations it will be looked for in.
- * @return a <code>URL</code> that names the GemFire security property file.
- * Null is returned if no property file was found.
+ * See {@link #SECURITY_PROPERTIES_FILE_PROPERTY} for information on the name of
+ * the properties file and what locations it will be looked for in.
+ *
+ * @return a <code>URL</code> that names the GemFire security properties file.
+ * Null is returned if no properties file was found.
+ * @see #SECURITY_PROPERTIES_FILE_PROPERTY
+ * @see #SECURITY_PROPERTIES_FILE_DEFAULT
+ * @see #getSecurityPropertiesFile()
* @since 6.6.2
*/
public static URL getSecurityPropertiesFileURL() {
- return getFileURL(SECURITY_PROPERTY_FILE);
+ return getFileURL(getSecurityPropertiesFile());
}
private static URL getFileURL(String fileName) {
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/dd9f361d/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/DistributedSystemIntegrationJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/DistributedSystemIntegrationJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/DistributedSystemIntegrationJUnitTest.java
new file mode 100755
index 0000000..d54dfd0
--- /dev/null
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/DistributedSystemIntegrationJUnitTest.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.distributed;
+
+import static org.assertj.core.api.Assertions.*;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.net.URL;
+import java.util.Properties;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.contrib.java.lang.system.RestoreSystemProperties;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TemporaryFolder;
+import org.junit.rules.TestName;
+
+import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+
+/**
+ * Integration tests for DistributedSystem class. These tests require file system I/O.
+ */
+@Category(IntegrationTest.class)
+public class DistributedSystemIntegrationJUnitTest {
+
+ @Rule
+ public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
+
+ @Rule
+ public final TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+ @Rule
+ public final TestName testName = new TestName();
+
+ @Test
+ public void getPropertiesFileShouldUsePathInSystemProperty() throws Exception {
+ File propertiesFile = this.temporaryFolder.newFile("test.properties");
+ System.setProperty(DistributedSystem.PROPERTIES_FILE_PROPERTY, propertiesFile.getCanonicalPath());
+ Properties properties = new Properties();
+ properties.store(new FileWriter(propertiesFile, false), this.testName.getMethodName());
+
+ assertThat(DistributedSystem.getPropertiesFile()).isEqualTo(propertiesFile.getCanonicalPath());
+ }
+
+ @Test
+ public void getPropertiesFileUrlShouldUsePathInSystemProperty() throws Exception {
+ File propertiesFile = this.temporaryFolder.newFile("test.properties");
+ System.setProperty(DistributedSystem.PROPERTIES_FILE_PROPERTY, propertiesFile.getCanonicalPath());
+ Properties properties = new Properties();
+ properties.store(new FileWriter(propertiesFile, false), this.testName.getMethodName());
+
+ URL propertiesURL = propertiesFile.getCanonicalFile().toURI().toURL();
+ assertThat(DistributedSystem.getPropertiesFileURL()).isEqualTo(propertiesURL);
+ }
+
+ @Test
+ public void getSecurityPropertiesFileShouldUsePathInSystemProperty() throws Exception {
+ File propertiesFile = this.temporaryFolder.newFile("testsecurity.properties");
+ System.setProperty(DistributedSystem.SECURITY_PROPERTIES_FILE_PROPERTY, propertiesFile.getCanonicalPath());
+ Properties properties = new Properties();
+ properties.store(new FileWriter(propertiesFile, false), this.testName.getMethodName());
+
+ assertThat(DistributedSystem.getSecurityPropertiesFile()).isEqualTo(propertiesFile.getCanonicalPath());
+ }
+
+ @Test
+ public void getSecurityPropertiesFileUrlShouldUsePathInSystemProperty() throws Exception {
+ File propertiesFile = this.temporaryFolder.newFile("testsecurity.properties");
+ System.setProperty(DistributedSystem.SECURITY_PROPERTIES_FILE_PROPERTY, propertiesFile.getCanonicalPath());
+ Properties properties = new Properties();
+ properties.store(new FileWriter(propertiesFile, false), this.testName.getMethodName());
+
+ URL propertiesURL = propertiesFile.getCanonicalFile().toURI().toURL();
+ assertThat(DistributedSystem.getSecurityPropertiesFileURL()).isEqualTo(propertiesURL);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/dd9f361d/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/DistributedSystemJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/DistributedSystemJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/DistributedSystemJUnitTest.java
new file mode 100755
index 0000000..56a9646
--- /dev/null
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/DistributedSystemJUnitTest.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.distributed;
+
+import static org.assertj.core.api.Assertions.*;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.contrib.java.lang.system.RestoreSystemProperties;
+import org.junit.experimental.categories.Category;
+
+import com.gemstone.gemfire.test.junit.categories.UnitTest;
+
+/**
+ * Unit tests for DistributedSystem class.
+ */
+@Category(UnitTest.class)
+public class DistributedSystemJUnitTest {
+
+ @Rule
+ public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
+
+ @Test
+ public void getPropertiesFileShouldUseDefault() throws Exception {
+ assertThat(DistributedSystem.getPropertiesFile()).isEqualTo(DistributedSystem.PROPERTIES_FILE_DEFAULT);
+ }
+
+ @Test
+ public void getPropertiesFileShouldUseSystemProperty() throws Exception {
+ String propertiesFileName = "test.properties";
+ System.setProperty(DistributedSystem.PROPERTIES_FILE_PROPERTY, propertiesFileName);
+
+ assertThat(DistributedSystem.getPropertiesFile()).isEqualTo(propertiesFileName);
+ }
+
+ @Test
+ public void getPropertiesFileShouldUseSystemPropertyPath() throws Exception {
+ String propertiesFileName = "/home/test.properties";
+ System.setProperty(DistributedSystem.PROPERTIES_FILE_PROPERTY, propertiesFileName);
+
+ assertThat(DistributedSystem.getPropertiesFile()).isEqualTo(propertiesFileName);
+ }
+
+ @Test
+ public void getSecurityPropertiesFileShouldUseDefault() throws Exception {
+ assertThat(DistributedSystem.getSecurityPropertiesFile()).isEqualTo(DistributedSystem.SECURITY_PROPERTIES_FILE_DEFAULT);
+ }
+
+ @Test
+ public void getSecurityPropertiesFileShouldUseSystemProperty() throws Exception {
+ String propertiesFileName = "testsecurity.properties";
+ System.setProperty(DistributedSystem.SECURITY_PROPERTIES_FILE_PROPERTY, propertiesFileName);
+
+ assertThat(DistributedSystem.getSecurityPropertiesFile()).isEqualTo(propertiesFileName);
+ }
+
+ @Test
+ public void getSecurityPropertiesFileShouldUseSystemPropertyPath() throws Exception {
+ String propertiesFileName = "/home/testsecurity.properties";
+ System.setProperty(DistributedSystem.SECURITY_PROPERTIES_FILE_PROPERTY, propertiesFileName);
+
+ assertThat(DistributedSystem.getSecurityPropertiesFile()).isEqualTo(propertiesFileName);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/dd9f361d/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherIntegrationJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherIntegrationJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherIntegrationJUnitTest.java
new file mode 100755
index 0000000..db5b952
--- /dev/null
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherIntegrationJUnitTest.java
@@ -0,0 +1,198 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.distributed;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.util.Properties;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.contrib.java.lang.system.RestoreSystemProperties;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TemporaryFolder;
+import org.junit.rules.TestName;
+
+import com.gemstone.gemfire.distributed.LocatorLauncher.Builder;
+import com.gemstone.gemfire.distributed.LocatorLauncher.Command;
+import com.gemstone.gemfire.distributed.internal.DistributionConfig;
+import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
+import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+
+/**
+ * Integration tests for LocatorLauncher. These tests require file system I/O.
+ */
+@Category(IntegrationTest.class)
+public class LocatorLauncherIntegrationJUnitTest {
+
+ @Rule
+ public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
+
+ @Rule
+ public final TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+ @Rule
+ public final TestName testName = new TestName();
+
+ @Test
+ public void testBuilderParseArguments() throws Exception {
+ String expectedWorkingDirectory = this.temporaryFolder.getRoot().getCanonicalPath();
+ Builder builder = new Builder();
+
+ builder.parseArguments("start", "memberOne", "--bind-address", InetAddress.getLocalHost().getHostAddress(),
+ "--dir", expectedWorkingDirectory, "--hostname-for-clients", "Tucows", "--pid", "1234", "--port", "11235",
+ "--redirect-output", "--force", "--debug");
+
+ assertEquals(Command.START, builder.getCommand());
+ assertEquals(InetAddress.getLocalHost(), builder.getBindAddress());
+ assertEquals(expectedWorkingDirectory, builder.getWorkingDirectory());
+ assertEquals("Tucows", builder.getHostnameForClients());
+ assertEquals(1234, builder.getPid().intValue());
+ assertEquals(11235, builder.getPort().intValue());
+ assertTrue(builder.getRedirectOutput());
+ assertTrue(builder.getForce());
+ assertTrue(builder.getDebug());
+ }
+
+ @Test
+ public void testBuilderParseArgumentsWithCommandInArguments() throws Exception {
+ String expectedWorkingDirectory = this.temporaryFolder.getRoot().getCanonicalPath();
+ Builder builder = new Builder();
+
+ builder.parseArguments("start", "--dir=" + expectedWorkingDirectory, "--port", "12345", "memberOne");
+
+ assertEquals(Command.START, builder.getCommand());
+ assertFalse(Boolean.TRUE.equals(builder.getDebug()));
+ assertFalse(Boolean.TRUE.equals(builder.getForce()));
+ assertFalse(Boolean.TRUE.equals(builder.getHelp()));
+ assertNull(builder.getBindAddress());
+ assertNull(builder.getHostnameForClients());
+ assertEquals("12345", builder.getMemberName());
+ assertNull(builder.getPid());
+ assertEquals(expectedWorkingDirectory, builder.getWorkingDirectory());
+ assertEquals(12345, builder.getPort().intValue());
+ }
+
+ @Test
+ public void testBuildWithMemberNameSetInGemfirePropertiesOnStart() throws Exception {
+ File propertiesFile = new File(this.temporaryFolder.getRoot().getCanonicalPath(), "gemfire.properties");
+ System.setProperty(DistributedSystem.PROPERTIES_FILE_PROPERTY, propertiesFile.getCanonicalPath());
+
+ Properties gemfireProperties = new Properties();
+ gemfireProperties.setProperty(DistributionConfig.NAME_NAME, "locator123");
+ gemfireProperties.store(new FileWriter(propertiesFile, false), this.testName.getMethodName());
+ assertTrue(propertiesFile.isFile());
+ assertTrue(propertiesFile.exists());
+
+ LocatorLauncher launcher = new Builder().setCommand(Command.START).setMemberName(null).build();
+
+ assertNotNull(launcher);
+ assertEquals(Command.START, launcher.getCommand());
+ assertNull(launcher.getMemberName());
+ }
+
+ @Test
+ public void testSetAndGetWorkingDirectory() throws Exception {
+ String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
+ Builder builder = new Builder();
+
+ assertEquals(AbstractLauncher.DEFAULT_WORKING_DIRECTORY, builder.getWorkingDirectory());
+ assertSame(builder, builder.setWorkingDirectory(null));
+ assertEquals(AbstractLauncher.DEFAULT_WORKING_DIRECTORY, builder.getWorkingDirectory());
+ assertSame(builder, builder.setWorkingDirectory(""));
+ assertEquals(AbstractLauncher.DEFAULT_WORKING_DIRECTORY, builder.getWorkingDirectory());
+ assertSame(builder, builder.setWorkingDirectory(" "));
+ assertEquals(AbstractLauncher.DEFAULT_WORKING_DIRECTORY, builder.getWorkingDirectory());
+ assertSame(builder, builder.setWorkingDirectory(rootFolder));
+ assertEquals(rootFolder, builder.getWorkingDirectory());
+ assertSame(builder, builder.setWorkingDirectory(null));
+ assertEquals(AbstractLauncher.DEFAULT_WORKING_DIRECTORY, builder.getWorkingDirectory());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testSetWorkingDirectoryToFile() throws IOException {
+ File tmpFile = File.createTempFile("tmp", "file");
+
+ assertNotNull(tmpFile);
+ assertTrue(tmpFile.isFile());
+
+ tmpFile.deleteOnExit();
+
+ try {
+ new Builder().setWorkingDirectory(tmpFile.getCanonicalPath());
+ }
+ catch (IllegalArgumentException expected) {
+ assertEquals(LocalizedStrings.Launcher_Builder_WORKING_DIRECTORY_NOT_FOUND_ERROR_MESSAGE
+ .toLocalizedString("Locator"), expected.getMessage());
+ assertTrue(expected.getCause() instanceof FileNotFoundException);
+ assertEquals(tmpFile.getCanonicalPath(), expected.getCause().getMessage());
+ throw expected;
+ }
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testSetWorkingDirectoryToNonExistingDirectory() {
+ try {
+ new Builder().setWorkingDirectory("/path/to/non_existing/directory");
+ }
+ catch (IllegalArgumentException expected) {
+ assertEquals(LocalizedStrings.Launcher_Builder_WORKING_DIRECTORY_NOT_FOUND_ERROR_MESSAGE
+ .toLocalizedString("Locator"), expected.getMessage());
+ assertTrue(expected.getCause() instanceof FileNotFoundException);
+ assertEquals("/path/to/non_existing/directory", expected.getCause().getMessage());
+ throw expected;
+ }
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testBuildWithNoMemberNameOnStart() throws Exception {
+ System.setProperty("user.dir", this.temporaryFolder.getRoot().getCanonicalPath());
+ try {
+ new Builder().setCommand(Command.START).build();
+ }
+ catch (IllegalStateException expected) {
+ assertEquals(LocalizedStrings.Launcher_Builder_MEMBER_NAME_VALIDATION_ERROR_MESSAGE.toLocalizedString("Locator"),
+ expected.getMessage());
+ throw expected;
+ }
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testBuildWithMismatchingCurrentAndWorkingDirectoryOnStart() throws Exception {
+ try {
+ new Builder().setCommand(Command.START)
+ .setMemberName("memberOne")
+ .setWorkingDirectory(this.temporaryFolder.getRoot().getCanonicalPath())
+ .build();
+ }
+ catch (IllegalStateException expected) {
+ assertEquals(LocalizedStrings.Launcher_Builder_WORKING_DIRECTORY_OPTION_NOT_VALID_ERROR_MESSAGE
+ .toLocalizedString("Locator"), expected.getMessage());
+ throw expected;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/dd9f361d/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherJUnitTest.java
index 003a098..c1b6ed0 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherJUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherJUnitTest.java
@@ -17,14 +17,9 @@
package com.gemstone.gemfire.distributed;
import static org.junit.Assert.*;
-import static org.junit.Assume.*;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
-import java.util.Properties;
import com.gemstone.gemfire.distributed.LocatorLauncher.Builder;
import com.gemstone.gemfire.distributed.LocatorLauncher.Command;
@@ -34,8 +29,11 @@ import com.gemstone.gemfire.test.junit.categories.UnitTest;
import joptsimple.OptionException;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.contrib.java.lang.system.RestoreSystemProperties;
import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
/**
* The LocatorLauncherJUnitTest class is a test suite of test cases for testing the contract and functionality of
@@ -52,46 +50,13 @@ import org.junit.experimental.categories.Category;
* @since 7.0
*/
@Category(UnitTest.class)
-public class LocatorLauncherJUnitTest extends CommonLauncherTestSuite {
+public class LocatorLauncherJUnitTest {
- @Test
- public void testBuilderParseArguments() throws Exception {
- String expectedWorkingDirectory = this.temporaryFolder.getRoot().getCanonicalPath().toString();
- Builder builder = new Builder();
-
- builder.parseArguments("start", "memberOne", "--bind-address", InetAddress.getLocalHost().getHostAddress(),
- "--dir", expectedWorkingDirectory, "--hostname-for-clients", "Tucows", "--pid", "1234", "--port", "11235",
- "--redirect-output", "--force", "--debug");
-
- assertEquals(Command.START, builder.getCommand());
- assertEquals(InetAddress.getLocalHost(), builder.getBindAddress());
- assertEquals(expectedWorkingDirectory, builder.getWorkingDirectory());
- assertEquals("Tucows", builder.getHostnameForClients());
- assertEquals(1234, builder.getPid().intValue());
- assertEquals(11235, builder.getPort().intValue());
- assertTrue(builder.getRedirectOutput());
- assertTrue(builder.getForce());
- assertTrue(builder.getDebug());
- }
-
- @Test
- public void testBuilderParseArgumentsWithCommandInArguments() throws Exception {
- String expectedWorkingDirectory = this.temporaryFolder.getRoot().getCanonicalPath().toString();
- Builder builder = new Builder();
-
- builder.parseArguments("start", "--dir=" + expectedWorkingDirectory, "--port", "12345", "memberOne");
-
- assertEquals(Command.START, builder.getCommand());
- assertFalse(Boolean.TRUE.equals(builder.getDebug()));
- assertFalse(Boolean.TRUE.equals(builder.getForce()));
- assertFalse(Boolean.TRUE.equals(builder.getHelp()));
- assertNull(builder.getBindAddress());
- assertNull(builder.getHostnameForClients());
- assertEquals("12345", builder.getMemberName());
- assertNull(builder.getPid());
- assertEquals(expectedWorkingDirectory, builder.getWorkingDirectory());
- assertEquals(12345, builder.getPort().intValue());
- }
+ @Rule
+ public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
+
+ @Rule
+ public final TestName testName = new TestName();
@Test(expected = IllegalArgumentException.class)
public void testBuilderParseArgumentsWithNonNumericPort() {
@@ -307,59 +272,6 @@ public class LocatorLauncherJUnitTest extends CommonLauncherTestSuite {
}
@Test
- public void testSetAndGetWorkingDirectory() throws Exception {
- String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath().toString();
- Builder builder = new Builder();
-
- assertEquals(AbstractLauncher.DEFAULT_WORKING_DIRECTORY, builder.getWorkingDirectory());
- assertSame(builder, builder.setWorkingDirectory(null));
- assertEquals(AbstractLauncher.DEFAULT_WORKING_DIRECTORY, builder.getWorkingDirectory());
- assertSame(builder, builder.setWorkingDirectory(""));
- assertEquals(AbstractLauncher.DEFAULT_WORKING_DIRECTORY, builder.getWorkingDirectory());
- assertSame(builder, builder.setWorkingDirectory(" "));
- assertEquals(AbstractLauncher.DEFAULT_WORKING_DIRECTORY, builder.getWorkingDirectory());
- assertSame(builder, builder.setWorkingDirectory(rootFolder));
- assertEquals(rootFolder, builder.getWorkingDirectory());
- assertSame(builder, builder.setWorkingDirectory(null));
- assertEquals(AbstractLauncher.DEFAULT_WORKING_DIRECTORY, builder.getWorkingDirectory());
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testSetWorkingDirectoryToFile() throws IOException {
- File tmpFile = File.createTempFile("tmp", "file");
-
- assertNotNull(tmpFile);
- assertTrue(tmpFile.isFile());
-
- tmpFile.deleteOnExit();
-
- try {
- new Builder().setWorkingDirectory(tmpFile.getCanonicalPath());
- }
- catch (IllegalArgumentException expected) {
- assertEquals(LocalizedStrings.Launcher_Builder_WORKING_DIRECTORY_NOT_FOUND_ERROR_MESSAGE
- .toLocalizedString("Locator"), expected.getMessage());
- assertTrue(expected.getCause() instanceof FileNotFoundException);
- assertEquals(tmpFile.getCanonicalPath(), expected.getCause().getMessage());
- throw expected;
- }
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testSetWorkingDirectoryToNonExistingDirectory() {
- try {
- new Builder().setWorkingDirectory("/path/to/non_existing/directory");
- }
- catch (IllegalArgumentException expected) {
- assertEquals(LocalizedStrings.Launcher_Builder_WORKING_DIRECTORY_NOT_FOUND_ERROR_MESSAGE
- .toLocalizedString("Locator"), expected.getMessage());
- assertTrue(expected.getCause() instanceof FileNotFoundException);
- assertEquals("/path/to/non_existing/directory", expected.getCause().getMessage());
- throw expected;
- }
- }
-
- @Test
public void testBuild() throws Exception {
Builder builder = new Builder();
@@ -396,26 +308,6 @@ public class LocatorLauncherJUnitTest extends CommonLauncherTestSuite {
}
@Test
- public void testBuildWithMemberNameSetInGemfirePropertiesOnStart() throws Exception {
- System.setProperty("user.dir", this.temporaryFolder.getRoot().getCanonicalPath());
-
- Properties gemfireProperties = new Properties();
- gemfireProperties.setProperty(DistributionConfig.NAME_NAME, "locator123");
- File gemfirePropertiesFile = writeGemFirePropertiesToFile(gemfireProperties, "gemfire.properties",
- String.format("Test gemfire.properties file for %1$s.%2$s.", getClass().getSimpleName(),
- "testBuildWithMemberNameSetInGemfirePropertiesOnStart"));
-
- assertNotNull(gemfirePropertiesFile);
- assertTrue(gemfirePropertiesFile.isFile());
-
- LocatorLauncher launcher = new Builder().setCommand(Command.START).setMemberName(null).build();
-
- assertNotNull(launcher);
- assertEquals(Command.START, launcher.getCommand());
- assertNull(launcher.getMemberName());
- }
-
- @Test
public void testBuildWithMemberNameSetInSystemPropertiesOnStart() {
System.setProperty(DistributionConfig.GEMFIRE_PREFIX + DistributionConfig.NAME_NAME, "locatorXYZ");
@@ -428,32 +320,4 @@ public class LocatorLauncherJUnitTest extends CommonLauncherTestSuite {
assertEquals(LocatorLauncher.Command.START, launcher.getCommand());
assertNull(launcher.getMemberName());
}
-
- @Test(expected = IllegalStateException.class)
- public void testBuildWithNoMemberNameOnStart() throws Exception {
- System.setProperty("user.dir", this.temporaryFolder.getRoot().getCanonicalPath());
- try {
- new Builder().setCommand(Command.START).build();
- }
- catch (IllegalStateException expected) {
- assertEquals(LocalizedStrings.Launcher_Builder_MEMBER_NAME_VALIDATION_ERROR_MESSAGE.toLocalizedString("Locator"),
- expected.getMessage());
- throw expected;
- }
- }
-
- @Test(expected = IllegalStateException.class)
- public void testBuildWithMismatchingCurrentAndWorkingDirectoryOnStart() throws Exception {
- try {
- new Builder().setCommand(Command.START)
- .setMemberName("memberOne")
- .setWorkingDirectory(this.temporaryFolder.getRoot().getCanonicalPath().toString())
- .build();
- }
- catch (IllegalStateException expected) {
- assertEquals(LocalizedStrings.Launcher_Builder_WORKING_DIRECTORY_OPTION_NOT_VALID_ERROR_MESSAGE
- .toLocalizedString("Locator"), expected.getMessage());
- throw expected;
- }
- }
}