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 2016/10/13 17:14:53 UTC
[16/20] incubator-geode git commit: Added test for LocatorLauncher
using gemfireProperties
Added test for LocatorLauncher using gemfireProperties
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/24a6096a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/24a6096a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/24a6096a
Branch: refs/heads/feature/GEODE-1466
Commit: 24a6096ad2cb03d701412ce5096163e80317ec90
Parents: 254995b
Author: Kirk Lund <kl...@apache.org>
Authored: Tue Oct 11 16:32:42 2016 -0700
Committer: Kirk Lund <kl...@apache.org>
Committed: Thu Oct 13 10:15:05 2016 -0700
----------------------------------------------------------------------
.../geode/distributed/AbstractLauncher.java | 2 +-
.../geode/internal/PropertiesResolver.java | 8 +-
.../LocatorLauncherIntegrationTest.java | 22 +++-
...ocatorLauncherPropertiesIntegrationTest.java | 126 +++++++++++++++++++
4 files changed, 152 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/24a6096a/geode-core/src/main/java/org/apache/geode/distributed/AbstractLauncher.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/AbstractLauncher.java b/geode-core/src/main/java/org/apache/geode/distributed/AbstractLauncher.java
index 110721f..e301078 100644
--- a/geode-core/src/main/java/org/apache/geode/distributed/AbstractLauncher.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/AbstractLauncher.java
@@ -151,7 +151,7 @@ public abstract class AbstractLauncher<T extends Comparable<T>> implements Runna
* @return a Properties instance populated with the gemfire.properties.
* @see java.net.URL
*/
- protected static Properties loadGemFireProperties(final URL url) {
+ protected static Properties loadGemFireProperties(final URL url) { // TODO: GEODE-1466
final Properties properties = new Properties();
if (url != null) {
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/24a6096a/geode-core/src/main/java/org/apache/geode/internal/PropertiesResolver.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/PropertiesResolver.java b/geode-core/src/main/java/org/apache/geode/internal/PropertiesResolver.java
index f105bcd..9bd0325 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/PropertiesResolver.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/PropertiesResolver.java
@@ -28,10 +28,10 @@ import org.apache.geode.internal.util.IOUtils;
public class PropertiesResolver {
- static final String GEODE_PROPERTIES_FILE_PROPERTY = "geodePropertyFile";
- static final String GEMFIRE_PROPERTIES_FILE_PROPERTY = DistributedSystem.PROPERTIES_FILE_PROPERTY;
- static final String DEFAULT_GEODE_PROPERTIES_FILE_NAME = "geode.properties";
- static final String DEFAULT_GEMFIRE_PROPERTIES_FILE_NAME = "gemfire.properties";
+ public static final String GEODE_PROPERTIES_FILE_PROPERTY = "geodePropertyFile";
+ public static final String GEMFIRE_PROPERTIES_FILE_PROPERTY = DistributedSystem.PROPERTIES_FILE_PROPERTY;
+ public static final String DEFAULT_GEODE_PROPERTIES_FILE_NAME = "geode.properties";
+ public static final String DEFAULT_GEMFIRE_PROPERTIES_FILE_NAME = "gemfire.properties";
private static URI propertiesFileURL = findPropertiesFileLocation();
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/24a6096a/geode-core/src/test/java/org/apache/geode/distributed/LocatorLauncherIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/distributed/LocatorLauncherIntegrationTest.java b/geode-core/src/test/java/org/apache/geode/distributed/LocatorLauncherIntegrationTest.java
index 729ec9c..169015a 100755
--- a/geode-core/src/test/java/org/apache/geode/distributed/LocatorLauncherIntegrationTest.java
+++ b/geode-core/src/test/java/org/apache/geode/distributed/LocatorLauncherIntegrationTest.java
@@ -19,6 +19,7 @@ package org.apache.geode.distributed;
import org.apache.geode.distributed.LocatorLauncher.Builder;
import org.apache.geode.distributed.LocatorLauncher.Command;
import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.internal.PropertiesResolver;
import org.apache.geode.internal.i18n.LocalizedStrings;
import org.apache.geode.test.junit.categories.IntegrationTest;
import org.junit.Rule;
@@ -133,6 +134,25 @@ public class LocatorLauncherIntegrationTest {
}
@Test
+ public void testBuildWithMemberNameSetInGeodePropertiesOnStart() throws Exception {
+ // given: gemfire.properties with a name
+ Properties gemfireProperties = new Properties();
+ gemfireProperties.setProperty(NAME, "locator123");
+ useGemFirePropertiesFileInTemporaryFolder(PropertiesResolver.DEFAULT_GEODE_PROPERTIES_FILE_NAME, gemfireProperties); // TODO: GEODE-1466
+
+ // when: starting with null MemberName
+ LocatorLauncher launcher = new Builder()
+ .setCommand(Command.START)
+ .setMemberName(null)
+ .build();
+
+ // then: name in gemfire.properties file should be used for MemberName
+ assertThat(launcher).isNotNull();
+ assertThat(launcher.getCommand()).isEqualTo(Command.START);
+ assertThat(launcher.getMemberName()).isNull();
+ }
+
+ @Test
public void testBuildWithNoMemberNameOnStart() throws Exception {
// given: gemfire.properties with no name
useGemFirePropertiesFileInTemporaryFolder(DistributionConfig.GEMFIRE_PREFIX + "properties", new Properties());
@@ -239,7 +259,7 @@ public class LocatorLauncherIntegrationTest {
* </ol>
*/
private void useGemFirePropertiesFileInTemporaryFolder(final String fileName, final Properties gemfireProperties) throws Exception {
- File propertiesFile = new File(this.temporaryFolder.getRoot().getCanonicalPath(), fileName);
+ File propertiesFile = this.temporaryFolder.newFile(fileName);
System.setProperty(DistributedSystem.PROPERTIES_FILE_PROPERTY, propertiesFile.getCanonicalPath());
gemfireProperties.store(new FileWriter(propertiesFile, false), this.testName.getMethodName());
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/24a6096a/geode-core/src/test/java/org/apache/geode/distributed/LocatorLauncherPropertiesIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/distributed/LocatorLauncherPropertiesIntegrationTest.java b/geode-core/src/test/java/org/apache/geode/distributed/LocatorLauncherPropertiesIntegrationTest.java
new file mode 100644
index 0000000..eb310aa
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/distributed/LocatorLauncherPropertiesIntegrationTest.java
@@ -0,0 +1,126 @@
+/*
+ * 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 org.apache.geode.distributed;
+
+import static java.util.concurrent.TimeUnit.*;
+import static org.apache.geode.distributed.ConfigurationProperties.*;
+import static org.assertj.core.api.Assertions.*;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Properties;
+
+import com.jayway.awaitility.Awaitility;
+import com.jayway.awaitility.core.ConditionFactory;
+import org.apache.commons.io.FileUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.contrib.java.lang.system.RestoreSystemProperties;
+import org.junit.rules.TemporaryFolder;
+
+import org.apache.geode.distributed.AbstractLauncher.Status;
+import org.apache.geode.distributed.LocatorLauncher.Builder;
+import org.apache.geode.distributed.internal.SharedConfiguration;
+import org.apache.geode.internal.PropertiesResolver;
+import org.apache.geode.internal.lang.StringUtils;
+import org.apache.geode.internal.util.IOUtils;
+
+public class LocatorLauncherPropertiesIntegrationTest {
+
+ private File propsFile;
+
+ private LocatorLauncher launcher;
+ private String workingDirectory;
+ private String clusterConfigDirectory;
+
+ @Rule
+ public RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
+
+ @Rule
+ public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+ @Before
+ public void before() throws Exception {
+ this.workingDirectory = this.temporaryFolder.getRoot().getCanonicalPath();
+ this.clusterConfigDirectory = this.temporaryFolder.newFolder(SharedConfiguration.CLUSTER_CONFIG_DISK_DIR_PREFIX).getCanonicalPath();
+ }
+
+ @After
+ public void after() throws Exception {
+ if (this.launcher != null) {
+ this.launcher.stop();
+ this.launcher = null;
+ }
+ try {
+ FileUtils.forceDelete(propsFile);
+ } catch (Exception ignored) {
+ }
+ }
+
+ @Test
+ public void usesNameInGemFireProperties() throws Throwable {
+ String memberName = "myLocatorName";
+ createPropertiesFile("myGemfire.properties", memberName);
+
+ this.launcher = new Builder().setPort(0).set(CLUSTER_CONFIGURATION_DIR, this.clusterConfigDirectory).build();
+ this.launcher.start();
+ awaitLocator(this.launcher);
+
+ System.out.println(this.launcher.status());
+ assertThat(this.launcher.status().getMemberName()).isEqualTo(memberName);
+
+ assertThat(this.launcher.stop().getStatus()).isEqualTo(Status.STOPPED);
+ }
+
+ private void createPropertiesFile(String filename, String memberName) throws IOException {
+ System.setProperty(PropertiesResolver.GEMFIRE_PROPERTIES_FILE_PROPERTY, filename);
+
+ propsFile = new File(System.getProperty("user.home"), filename);
+ propsFile.deleteOnExit();
+
+ Properties properties = new Properties();
+ properties.setProperty(NAME, memberName);
+ properties.store(new FileOutputStream(propsFile), null);
+ }
+
+ private void awaitLocator(LocatorLauncher launcher) throws Exception {
+ await().until(() -> assertThat(Status.ONLINE.equals(launcher.status().getStatus())).isTrue());
+ }
+
+ private void awaitLocator(int port) throws Exception {
+ awaitLocator(new Builder().setPort(port).build());
+ }
+
+ private ConditionFactory await() {
+ return Awaitility.await().atMost(10, MINUTES);
+ }
+
+ private int readPid(final File pidFile) throws IOException {
+ BufferedReader reader = null;
+ try {
+ reader = new BufferedReader(new FileReader(pidFile));
+ return Integer.parseInt(StringUtils.trim(reader.readLine()));
+ } finally {
+ IOUtils.close(reader);
+ }
+ }
+}