You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ji...@apache.org on 2019/11/04 15:56:54 UTC

[geode] branch develop updated: GEODE-7401: add LocatorLauncherStartupRule (#4272)

This is an automated email from the ASF dual-hosted git repository.

jinmeiliao pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new 0dae0da  GEODE-7401: add LocatorLauncherStartupRule (#4272)
0dae0da is described below

commit 0dae0da29de8ab919ac90c6d7b3823cbdaf0a929
Author: Jinmei Liao <ji...@pivotal.io>
AuthorDate: Mon Nov 4 07:56:32 2019 -0800

    GEODE-7401: add LocatorLauncherStartupRule (#4272)
    
    Co-authored-by: Darrel Schneider <ds...@pivotal.io>
---
 .../distributed/LocatorLauncherStatusTest.java     | 64 +++++++++++++++++
 .../apache/geode/distributed/LocatorLauncher.java  | 13 ++++
 .../junit/rules/LocatorLauncherStartupRule.java    | 80 ++++++++++++++++++++++
 3 files changed, 157 insertions(+)

diff --git a/geode-core/src/integrationTest/java/org/apache/geode/distributed/LocatorLauncherStatusTest.java b/geode-core/src/integrationTest/java/org/apache/geode/distributed/LocatorLauncherStatusTest.java
new file mode 100644
index 0000000..b9d1e84
--- /dev/null
+++ b/geode-core/src/integrationTest/java/org/apache/geode/distributed/LocatorLauncherStatusTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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 org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Properties;
+
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import org.apache.geode.cache.ssl.CertStores;
+import org.apache.geode.cache.ssl.CertificateBuilder;
+import org.apache.geode.cache.ssl.CertificateMaterial;
+import org.apache.geode.test.junit.rules.LocatorLauncherStartupRule;
+
+public class LocatorLauncherStatusTest {
+  private static Properties properties;
+
+  static {
+    CertificateMaterial ca = new CertificateBuilder()
+        .commonName("Test CA")
+        .isCA()
+        .generate();
+    try {
+      CertificateMaterial memberMaterial = new CertificateBuilder()
+          .commonName("member")
+          .issuedBy(ca)
+          .generate();
+
+      CertStores memberStore = new CertStores("member");
+      memberStore.withCertificate("member", memberMaterial);
+      memberStore.trust("ca", ca);
+
+      properties = memberStore.propertiesWith("all", false, false);
+    } catch (Exception e) {
+      throw new RuntimeException(e.getMessage(), e);
+    }
+  }
+
+  @ClassRule
+  public static LocatorLauncherStartupRule launcher =
+      new LocatorLauncherStartupRule().withProperties(properties).withAutoStart();
+
+  @Test
+  public void status() {
+    LocatorLauncher.LocatorState locatorState = LocatorLauncher.getLocatorState();
+    assertThat(locatorState.getStatus().getDescription()).isEqualTo("online");
+  }
+
+}
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/LocatorLauncher.java b/geode-core/src/main/java/org/apache/geode/distributed/LocatorLauncher.java
index 09ad4c5..9aae32c 100644
--- a/geode-core/src/main/java/org/apache/geode/distributed/LocatorLauncher.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/LocatorLauncher.java
@@ -1792,6 +1792,19 @@ public class LocatorLauncher extends AbstractLauncher<String> {
     }
 
     /**
+     * add the properties in the Gemfire Distributed System Property
+     *
+     * @param properties a property object that holds one or more Gemfire Distributed System
+     *        properties as described in {@link ConfigurationProperties}
+     * @return this Builder instance
+     * @since Geode 1.12
+     */
+    public Builder set(Properties properties) {
+      this.distributedSystemProperties.putAll(properties);
+      return this;
+    }
+
+    /**
      * Validates the configuration settings and properties of this Builder, ensuring that all
      * invariants have been met. Currently, the only invariant constraining the Builder is that the
      * user must specify the member name for the Locator in the GemFire distributed system as a
diff --git a/geode-dunit/src/main/java/org/apache/geode/test/junit/rules/LocatorLauncherStartupRule.java b/geode-dunit/src/main/java/org/apache/geode/test/junit/rules/LocatorLauncherStartupRule.java
new file mode 100644
index 0000000..9a81774
--- /dev/null
+++ b/geode-dunit/src/main/java/org/apache/geode/test/junit/rules/LocatorLauncherStartupRule.java
@@ -0,0 +1,80 @@
+/*
+ * 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.test.junit.rules;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.Properties;
+
+import org.junit.rules.TemporaryFolder;
+
+import org.apache.geode.distributed.ConfigurationProperties;
+import org.apache.geode.distributed.LocatorLauncher;
+import org.apache.geode.test.junit.rules.serializable.SerializableExternalResource;
+
+public class LocatorLauncherStartupRule extends SerializableExternalResource {
+  private LocatorLauncher launcher;
+  private final TemporaryFolder temp = new TemporaryFolder();
+  private final Properties properties = new Properties();
+  private boolean autoStart;
+
+  public LocatorLauncherStartupRule withAutoStart() {
+    autoStart = true;
+    return this;
+  }
+
+  public LocatorLauncherStartupRule withProperties(Properties properties) {
+    this.properties.putAll(properties);
+    return this;
+  }
+
+  public LocatorLauncherStartupRule withProperty(String key, String value) {
+    this.properties.put(key, value);
+    return this;
+  }
+
+  @Override
+  public void before() {
+    LocatorLauncher.Builder builder = new LocatorLauncher.Builder()
+        .setPort(0)
+        .set(properties)
+        .setMemberName("locator-0")
+        .set(ConfigurationProperties.LOG_LEVEL, "config");
+    try {
+      temp.create();
+    } catch (IOException e) {
+      throw new UncheckedIOException(e);
+    }
+    builder.setWorkingDirectory(temp.getRoot().getAbsolutePath());
+    launcher = builder.build();
+
+    if (autoStart) {
+      start();
+    }
+  }
+
+  public void start() {
+    launcher.start();
+  }
+
+  @Override
+  public void after() {
+    if (launcher != null) {
+      launcher.stop();
+    }
+    temp.delete();
+  }
+}