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 2018/11/12 17:25:40 UTC
[geode] branch develop updated: GEODE-6031: Add getCache to
Launcher APIs
This is an automated email from the ASF dual-hosted git repository.
klund 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 8a2b7bc GEODE-6031: Add getCache to Launcher APIs
8a2b7bc is described below
commit 8a2b7bc83d37db1883a5646ebb5055fcf0c95ef7
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Fri Nov 9 13:44:07 2018 -0800
GEODE-6031: Add getCache to Launcher APIs
Also add getLocator to LocatorLauncher API.
---
.../LocatorLauncherLocalIntegrationTest.java | 63 +++++++++++++---------
.../ServerLauncherLocalIntegrationTest.java | 7 +++
.../apache/geode/distributed/LocatorLauncher.java | 33 +++++++++---
.../apache/geode/distributed/ServerLauncher.java | 20 +++----
4 files changed, 83 insertions(+), 40 deletions(-)
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/distributed/LocatorLauncherLocalIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/distributed/LocatorLauncherLocalIntegrationTest.java
index 8fb139e..9a227f0 100755
--- a/geode-core/src/integrationTest/java/org/apache/geode/distributed/LocatorLauncherLocalIntegrationTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/distributed/LocatorLauncherLocalIntegrationTest.java
@@ -33,6 +33,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.apache.geode.cache.Cache;
import org.apache.geode.distributed.LocatorLauncher.Builder;
import org.apache.geode.distributed.LocatorLauncher.LocatorState;
import org.apache.geode.distributed.internal.InternalLocator;
@@ -48,51 +49,51 @@ import org.apache.geode.internal.process.ProcessType;
public class LocatorLauncherLocalIntegrationTest extends LocatorLauncherIntegrationTestCase {
@Before
- public void setUpLocatorLauncherLocalIntegrationTest() throws Exception {
+ public void setUpLocatorLauncherLocalIntegrationTest() {
disconnectFromDS();
System.setProperty(ProcessType.PROPERTY_TEST_PREFIX, getUniqueName() + "-");
assertThat(new ProcessControllerFactory().isAttachAPIFound()).isTrue();
}
@After
- public void tearDownLocatorLauncherLocalIntegrationTest() throws Exception {
+ public void tearDownLocatorLauncherLocalIntegrationTest() {
disconnectFromDS();
}
@Test
- public void usesLocatorPortAsDefaultPort() throws Exception {
+ public void usesLocatorPortAsDefaultPort() {
launcher = givenLocatorLauncher();
assertThat(launcher.getPort()).isEqualTo(defaultLocatorPort);
}
@Test
- public void startReturnsOnline() throws Exception {
+ public void startReturnsOnline() {
launcher = givenLocatorLauncher();
assertThat(launcher.start().getStatus()).isEqualTo(ONLINE);
}
@Test
- public void startWithPortUsesPort() throws Exception {
+ public void startWithPortUsesPort() {
LocatorLauncher launcher = startLocator(newBuilder().setPort(defaultLocatorPort));
- assertThat(launcher.getLocator().getPort()).isEqualTo(defaultLocatorPort);
+ assertThat(launcher.getInternalLocator().getPort()).isEqualTo(defaultLocatorPort);
}
@Test
- public void startWithPortZeroUsesAnEphemeralPort() throws Exception {
+ public void startWithPortZeroUsesAnEphemeralPort() {
LocatorLauncher launcher = startLocator(newBuilder().setPort(0));
- assertThat(launcher.getLocator().getPort()).isGreaterThan(0);
- assertThat(launcher.getLocator().isPeerLocator()).isTrue();
+ assertThat(launcher.getInternalLocator().getPort()).isGreaterThan(0);
+ assertThat(launcher.getInternalLocator().isPeerLocator()).isTrue();
}
@Test
- public void startUsesBuilderValues() throws Exception {
+ public void startUsesBuilderValues() {
LocatorLauncher launcher = startLocator(newBuilder().setPort(nonDefaultLocatorPort));
- InternalLocator locator = launcher.getLocator();
+ InternalLocator locator = launcher.getInternalLocator();
assertThat(locator.getPort()).isEqualTo(nonDefaultLocatorPort);
DistributedSystem system = locator.getDistributedSystem();
@@ -103,21 +104,21 @@ public class LocatorLauncherLocalIntegrationTest extends LocatorLauncherIntegrat
}
@Test
- public void startCreatesPidFile() throws Exception {
+ public void startCreatesPidFile() {
startLocator();
assertThat(getPidFile()).exists();
}
@Test
- public void pidFileContainsServerPid() throws Exception {
+ public void pidFileContainsServerPid() {
startLocator();
assertThat(getLocatorPid()).isEqualTo(localPid);
}
@Test
- public void startDeletesStaleControlFiles() throws Exception {
+ public void startDeletesStaleControlFiles() {
File stopRequestFile = givenControlFile(getProcessType().getStopRequestFileName());
File statusRequestFile = givenControlFile(getProcessType().getStatusRequestFileName());
File statusFile = givenControlFile(getProcessType().getStatusFileName());
@@ -130,7 +131,7 @@ public class LocatorLauncherLocalIntegrationTest extends LocatorLauncherIntegrat
}
@Test
- public void startOverwritesStalePidFile() throws Exception {
+ public void startOverwritesStalePidFile() {
givenPidFile(fakePid);
startLocator();
@@ -139,7 +140,7 @@ public class LocatorLauncherLocalIntegrationTest extends LocatorLauncherIntegrat
}
@Test
- public void startWithDefaultPortInUseFailsWithBindException() throws Exception {
+ public void startWithDefaultPortInUseFailsWithBindException() {
givenLocatorPortInUse(defaultLocatorPort);
launcher = new Builder().build();
@@ -149,12 +150,12 @@ public class LocatorLauncherLocalIntegrationTest extends LocatorLauncherIntegrat
}
@Test
- public void startWithLocatorPortInUseFailsWithBindException() throws Exception {
+ public void startWithLocatorPortInUseFailsWithBindException() {
givenServerPortInUse(nonDefaultLocatorPort);
launcher = new Builder().setPort(nonDefaultLocatorPort).build();
- assertThatThrownBy(() -> this.launcher.start()).isInstanceOf(RuntimeException.class)
+ assertThatThrownBy(() -> launcher.start()).isInstanceOf(RuntimeException.class)
.hasCauseInstanceOf(BindException.class);
}
@@ -198,7 +199,7 @@ public class LocatorLauncherLocalIntegrationTest extends LocatorLauncherIntegrat
}
@Test
- public void statusWithEmptyPidFileThrowsIllegalArgumentException() throws Exception {
+ public void statusWithEmptyPidFileThrowsIllegalArgumentException() {
givenEmptyPidFile();
LocatorLauncher launcher = new Builder().setWorkingDirectory(getWorkingDirectoryPath()).build();
@@ -232,7 +233,7 @@ public class LocatorLauncherLocalIntegrationTest extends LocatorLauncherIntegrat
* This test takes > 1 minute to run in {@link LocatorLauncherLocalFileIntegrationTest}.
*/
@Test
- public void statusWithStalePidFileReturnsNotResponding() throws Exception {
+ public void statusWithStalePidFileReturnsNotResponding() {
givenPidFile(fakePid);
LocatorState locatorState =
@@ -242,7 +243,7 @@ public class LocatorLauncherLocalIntegrationTest extends LocatorLauncherIntegrat
}
@Test
- public void stopWithPidReturnsStopped() throws Exception {
+ public void stopWithPidReturnsStopped() {
givenRunningLocator();
LocatorState locatorState = new Builder().setPid(localPid).build().stop();
@@ -251,7 +252,7 @@ public class LocatorLauncherLocalIntegrationTest extends LocatorLauncherIntegrat
}
@Test
- public void stopWithPidDeletesPidFile() throws Exception {
+ public void stopWithPidDeletesPidFile() {
givenRunningLocator(newBuilder().setDeletePidFileOnStop(true));
new Builder().setPid(localPid).build().stop();
@@ -260,7 +261,7 @@ public class LocatorLauncherLocalIntegrationTest extends LocatorLauncherIntegrat
}
@Test
- public void stopWithWorkingDirectoryReturnsStopped() throws Exception {
+ public void stopWithWorkingDirectoryReturnsStopped() {
givenRunningLocator();
LocatorState locatorState =
@@ -270,11 +271,25 @@ public class LocatorLauncherLocalIntegrationTest extends LocatorLauncherIntegrat
}
@Test
- public void stopWithWorkingDirectoryDeletesPidFile() throws Exception {
+ public void stopWithWorkingDirectoryDeletesPidFile() {
givenRunningLocator(newBuilder().setDeletePidFileOnStop(true));
new Builder().setWorkingDirectory(getWorkingDirectoryPath()).build().stop();
assertDeletionOf(getPidFile());
}
+
+ @Test
+ public void getCacheReturnsTheCache() {
+ givenRunningLocator();
+
+ assertThat(launcher.getCache()).isInstanceOf(Cache.class);
+ }
+
+ @Test
+ public void getLocatorReturnsTheLocator() {
+ givenRunningLocator();
+
+ assertThat(launcher.getLocator()).isInstanceOf(Locator.class);
+ }
}
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/distributed/ServerLauncherLocalIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/distributed/ServerLauncherLocalIntegrationTest.java
index 81b3c07..6d4ca21 100755
--- a/geode-core/src/integrationTest/java/org/apache/geode/distributed/ServerLauncherLocalIntegrationTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/distributed/ServerLauncherLocalIntegrationTest.java
@@ -376,4 +376,11 @@ public class ServerLauncherLocalIntegrationTest extends ServerLauncherLocalInteg
assertDeletionOf(getPidFile());
}
+
+ @Test
+ public void getCacheReturnsTheCache() {
+ givenRunningServer();
+
+ assertThat(launcher.getCache()).isInstanceOf(Cache.class);
+ }
}
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 70e4d15..082e144 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
@@ -51,6 +51,7 @@ import joptsimple.OptionParser;
import joptsimple.OptionSet;
import org.apache.commons.lang.exception.ExceptionUtils;
+import org.apache.geode.cache.Cache;
import org.apache.geode.cache.client.internal.locator.LocatorStatusRequest;
import org.apache.geode.cache.client.internal.locator.LocatorStatusResponse;
import org.apache.geode.distributed.internal.DistributionConfig;
@@ -282,12 +283,32 @@ public class LocatorLauncher extends AbstractLauncher<String> {
}
/**
- * Gets the reference to the Locator object representing the running GemFire Locator.
+ * Gets a reference to the {@code Cache} that was created by this {@code LocatorLauncher}.
+ *
+ * @return a reference to the Cache
+ * @see Cache
+ */
+ public Cache getCache() {
+ return getInternalLocator().getCache();
+ }
+
+ /**
+ * Gets a reference to the {@code Locator} that was created by this {@code LocatorLauncher}.
*
* @return a reference to the Locator.
+ * @see Locator
+ */
+ public Locator getLocator() {
+ return locator;
+ }
+
+ /**
+ * Gets a reference to the {@code Locator} as an {@code InternalLocator}. For internal use only.
+ *
+ * @return a reference to the Locator as an InternalLocator.
*/
- InternalLocator getLocator() {
- return this.locator;
+ InternalLocator getInternalLocator() {
+ return locator;
}
/**
@@ -734,12 +755,12 @@ public class LocatorLauncher extends AbstractLauncher<String> {
try {
// make sure the Locator was started and the reference was set
- assert getLocator() != null : "The Locator must first be started with a call to start!";
+ assert getInternalLocator() != null : "The Locator must first be started with a call to start!";
debug("Waiting on Locator (%1$s) to stop...", getId());
// prevent the JVM from exiting by joining the Locator Thread
- getLocator().waitToStop();
+ getInternalLocator().waitToStop();
} catch (InterruptedException handled) {
Thread.currentThread().interrupt();
t = handled;
@@ -968,7 +989,7 @@ public class LocatorLauncher extends AbstractLauncher<String> {
* process with an embedded Locator).
*/
protected boolean isStoppable() {
- return (isRunning() && getLocator() != null);
+ return (isRunning() && getInternalLocator() != null);
}
/**
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/ServerLauncher.java b/geode-core/src/main/java/org/apache/geode/distributed/ServerLauncher.java
index 0d7b848..e8ed955 100755
--- a/geode-core/src/main/java/org/apache/geode/distributed/ServerLauncher.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/ServerLauncher.java
@@ -332,22 +332,22 @@ public class ServerLauncher extends AbstractLauncher<String> {
}
/**
- * Gets a reference to the Cache that was created when the GemFire Server was started.
+ * Gets a reference to the {@code Cache} that was created by this {@code ServerLauncher}.
*
- * @return a reference to the Cache created by the GemFire Server start operation.
- * @see org.apache.geode.cache.Cache
+ * @return a reference to the Cache
+ * @see Cache
*/
- Cache getCache() {
- if (this.cache != null) {
- boolean isReconnecting = this.cache.isReconnecting();
+ public Cache getCache() {
+ if (cache != null) {
+ boolean isReconnecting = cache.isReconnecting();
if (isReconnecting) {
- Cache newCache = this.cache.getReconnectedCache();
+ Cache newCache = cache.getReconnectedCache();
if (newCache != null) {
- this.cache = newCache;
+ cache = newCache;
}
}
}
- return this.cache;
+ return cache;
}
/**
@@ -847,7 +847,7 @@ public class ServerLauncher extends AbstractLauncher<String> {
}
}
- private Cache createCache(Properties gemfireProperties) {
+ Cache createCache(Properties gemfireProperties) {
ServiceLoader<ServerLauncherCacheProvider> loader =
ServiceLoader.load(ServerLauncherCacheProvider.class);
for (ServerLauncherCacheProvider provider : loader) {