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 2016/04/08 18:26:45 UTC

[27/36] incubator-geode git commit: GEODE-1187 a server launched by Gfsh deletes PID file during auto-reconnect

GEODE-1187 a server launched by Gfsh deletes PID file during auto-reconnect

ServerLauncher needed to be made aware of auto-reconnect.  I changed
getCache() to look for a new, reconnected cache and I changed isWaiting()
to see if the current cache is in a reconnecting state.

I also changed the shutdown logic to cancel reconnect attempts if the
cache is in that state when a stop is requested.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/5ba923e3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/5ba923e3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/5ba923e3

Branch: refs/heads/feature/GEODE-17-2
Commit: 5ba923e3ff2b682e51e4b69169292bde1065c46e
Parents: 7413804
Author: Bruce Schuchardt <bs...@pivotal.io>
Authored: Thu Apr 7 10:28:15 2016 -0700
Committer: Bruce Schuchardt <bs...@pivotal.io>
Committed: Thu Apr 7 10:28:15 2016 -0700

----------------------------------------------------------------------
 .../gemfire/distributed/ServerLauncher.java     | 26 ++++++-
 .../membership/gms/membership/GMSJoinLeave.java |  2 -
 .../distributed/ServerLauncherJUnitTest.java    | 74 ++++++++++++++++++++
 .../internal/cache/PutAllCSDUnitTest.java       |  3 +-
 4 files changed, 98 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5ba923e3/geode-core/src/main/java/com/gemstone/gemfire/distributed/ServerLauncher.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/distributed/ServerLauncher.java b/geode-core/src/main/java/com/gemstone/gemfire/distributed/ServerLauncher.java
index 2a8c9f3..a055862 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/distributed/ServerLauncher.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/distributed/ServerLauncher.java
@@ -302,6 +302,15 @@ public class ServerLauncher extends AbstractLauncher<String> {
    * @see com.gemstone.gemfire.cache.Cache
    */
   final Cache getCache() {
+    if (this.cache != null) {
+      boolean isReconnecting = this.cache.isReconnecting();
+      if (isReconnecting) {
+        Cache newCache = this.cache.getReconnectedCache();
+        if (newCache != null) {
+          this.cache = newCache;
+        }
+      }
+    }
     return this.cache;
   }
 
@@ -837,7 +846,7 @@ public class ServerLauncher extends AbstractLauncher<String> {
    */
   final boolean isWaiting(final Cache cache) {
     //return (isRunning() && !getCache().isClosed());
-    return (isRunning() && cache.getDistributedSystem().isConnected());
+    return (isRunning() && (cache.getDistributedSystem().isConnected() || cache.isReconnecting()));
   }
 
   /**
@@ -1152,10 +1161,15 @@ public class ServerLauncher extends AbstractLauncher<String> {
   
   private ServerState stopInProcess() {
     if (isStoppable()) {
+      if (this.cache.isReconnecting()) {
+        this.cache.getDistributedSystem().stopReconnecting();
+      }
       this.cache.close();
       this.cache = null;
-      this.process.stop();
-      this.process = null;
+      if (this.process != null) {
+        this.process.stop();
+        this.process = null;
+      }
       INSTANCE.compareAndSet(this, null); // note: other thread may return Status.NOT_RESPONDING now
       this.running.set(false);
       return new ServerState(this, Status.STOPPED);
@@ -1254,6 +1268,12 @@ public class ServerLauncher extends AbstractLauncher<String> {
     }
   }
 
+  // For testing purposes only!
+  void setIsRunningForTest() {
+    this.running.set(true);
+  }
+
+
   private ServerState createNoResponseState(final Exception cause, final String errorMessage) {
     debug(cause);
     return new ServerState(this, Status.NOT_RESPONDING, errorMessage);

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5ba923e3/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/membership/GMSJoinLeave.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/membership/GMSJoinLeave.java b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/membership/GMSJoinLeave.java
index 1bc30af..d91b247 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/membership/GMSJoinLeave.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/membership/GMSJoinLeave.java
@@ -1145,8 +1145,6 @@ public class GMSJoinLeave implements JoinLeave, MessageHandler {
 
   /**
    * for testing, do not use in any other case as it is not thread safe
-   *
-   * @param req
    */
   JoinResponseMessage[] getJoinResponseMessage() {
     return joinResponse;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5ba923e3/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherJUnitTest.java
old mode 100644
new mode 100755
index d3a7050..395a9e6
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherJUnitTest.java
@@ -575,6 +575,76 @@ public class ServerLauncherJUnitTest {
   }
 
   @Test
+  public void reconnectedCacheIsDiscovered() throws Exception {
+    final Cache mockCache = mockContext.mock(Cache.class, "Cache");
+    final Cache mockReconnectedCache = mockContext.mock(Cache.class, "ReconnectedCache");
+
+    mockContext.checking(new Expectations() {{
+      exactly(2).of(mockCache).isReconnecting();
+      will(returnValue(Boolean.FALSE));
+
+      oneOf(mockCache).getCacheServers();
+      will(returnValue(Collections.emptyList()));
+
+      oneOf(mockCache).isReconnecting();
+      will(returnValue(Boolean.TRUE));
+
+      oneOf(mockCache).getReconnectedCache();
+      will(returnValue(mockReconnectedCache));
+
+      oneOf(mockReconnectedCache).close();
+
+    }});
+
+    final ServerLauncher serverLauncher =
+            new Builder()
+                    .setMemberName("serverOne")
+                    .setCache(mockCache)
+                    .build();
+
+    assertNotNull(serverLauncher);
+    serverLauncher.waitOnServer();
+  }
+
+  @Test
+  public void reconnectingDistributedSystemIsDisconnectedOnStop() throws Exception {
+    final Cache mockCache = mockContext.mock(Cache.class, "Cache");
+    final DistributedSystem mockDistributedSystem = mockContext.mock(DistributedSystem.class, "DistributedSystem");
+    final Cache mockReconnectedCache = mockContext.mock(Cache.class, "ReconnectedCache");
+
+    mockContext.checking(new Expectations() {{
+      exactly(1).of(mockCache).isReconnecting();
+      will(returnValue(Boolean.TRUE));
+
+      exactly(1).of(mockCache).getReconnectedCache();
+      will(returnValue(mockReconnectedCache));
+
+      exactly(2).of(mockReconnectedCache).isReconnecting();
+      will(returnValue(Boolean.TRUE));
+
+      exactly(1).of(mockReconnectedCache).getReconnectedCache();
+      will(returnValue(null));
+
+      oneOf(mockReconnectedCache).getDistributedSystem();
+      will(returnValue(mockDistributedSystem));
+
+      oneOf(mockDistributedSystem).stopReconnecting();
+
+      oneOf(mockReconnectedCache).close();
+    }});
+
+    final ServerLauncher serverLauncher =
+            new Builder()
+                    .setMemberName("serverOne")
+                    .setCache(mockCache)
+                    .build();
+
+    assertNotNull(serverLauncher);
+    serverLauncher.setIsRunningForTest();
+    serverLauncher.stop();
+  }
+
+  @Test
   public void testIsWaiting() {
     final Cache mockCache = mockContext.mock(Cache.class, "Cache");
     final DistributedSystem mockDistributedSystem = mockContext.mock(DistributedSystem.class, "DistributedSystem");
@@ -607,6 +677,8 @@ public class ServerLauncherJUnitTest {
       will(returnValue(mockDistributedSystem));
       oneOf(mockDistributedSystem).isConnected();
       will(returnValue(false));
+      oneOf(mockCache).isReconnecting();
+      will(returnValue(Boolean.FALSE));
     }});
 
     final ServerLauncher serverLauncher = new Builder().setMemberName("serverOne").build();
@@ -781,6 +853,8 @@ public class ServerLauncherJUnitTest {
       mockContext.checking(new Expectations() {{
         allowing(mockCache).getDistributedSystem();
         will(returnValue(mockDistributedSystem));
+        allowing(mockCache).isReconnecting();
+        will(returnValue(Boolean.FALSE));
         allowing(mockCache).getCacheServers();
         will(returnValue(Collections.emptyList()));
         oneOf(mockCache).close();

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5ba923e3/geode-cq/src/test/java/com/gemstone/gemfire/internal/cache/PutAllCSDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-cq/src/test/java/com/gemstone/gemfire/internal/cache/PutAllCSDUnitTest.java b/geode-cq/src/test/java/com/gemstone/gemfire/internal/cache/PutAllCSDUnitTest.java
old mode 100644
new mode 100755
index 8903302..48c5091
--- a/geode-cq/src/test/java/com/gemstone/gemfire/internal/cache/PutAllCSDUnitTest.java
+++ b/geode-cq/src/test/java/com/gemstone/gemfire/internal/cache/PutAllCSDUnitTest.java
@@ -2248,8 +2248,7 @@ public void testOneServer() throws CacheException, InterruptedException {
     // Stop server
     stopBridgeServers(getCache());
   }
-  
-  
+
   /**
    * Tests partial key putAll to 2 PR servers, because putting data at server
    * side is different between PR and LR. PR does it in postPutAll.