You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by bs...@apache.org on 2019/12/20 21:28:48 UTC

[geode] 01/01: ensure that exceptions are translated to those acceptable by geode-core

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

bschuchardt pushed a commit to branch feature/GEODE-7556c
in repository https://gitbox.apache.org/repos/asf/geode.git

commit c510d3000177c078a7014daec0f44d7b71a66946
Author: Bruce Schuchardt <bs...@pivotal.io>
AuthorDate: Fri Dec 20 13:27:46 2019 -0800

    ensure that exceptions are translated to those acceptable by geode-core
---
 .../java/org/apache/geode/distributed/LocatorDUnitTest.java  |  5 +++++
 .../apache/geode/distributed/internal/DistributionImpl.java  | 12 +++++++++++-
 .../geode/distributed/internal/membership/gms/Services.java  |  6 ++++++
 3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/geode-core/src/distributedTest/java/org/apache/geode/distributed/LocatorDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/distributed/LocatorDUnitTest.java
index 94acffe..9aa364d 100644
--- a/geode-core/src/distributedTest/java/org/apache/geode/distributed/LocatorDUnitTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/distributed/LocatorDUnitTest.java
@@ -809,11 +809,16 @@ public class LocatorDUnitTest implements Serializable {
         // throw DistributedSystemDisconnectedException which should have cause as
         // ForceDisconnectException.
         await().until(() -> !mmgr.getMembership().isConnected());
+        await().untilAsserted(() -> {
+          Throwable cause = mmgr.getShutdownCause();
+          assertThat(cause).isInstanceOf(ForcedDisconnectException.class);
+        });
         try (IgnoredException i = addIgnoredException("Membership: requesting removal of")) {
           mmgr.requestMemberRemoval((InternalDistributedMember) mem1, "test reasons");
           fail("It should have thrown exception in requestMemberRemoval");
         } catch (DistributedSystemDisconnectedException e) {
           // expected
+          assertThat(e.getCause()).isInstanceOf(ForcedDisconnectException.class);
         } finally {
           hook.reset();
         }
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionImpl.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionImpl.java
index 9e1af37..323da85 100644
--- a/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionImpl.java
@@ -337,6 +337,10 @@ public class DistributionImpl implements Distribution {
     try {
       membership.checkCancelled();
     } catch (MembershipClosedException e) {
+      if (e.getCause() instanceof MemberDisconnectedException) {
+        ForcedDisconnectException fde = new ForcedDisconnectException(e.getCause().getMessage());
+        throw new DistributedSystemDisconnectedException(e.getMessage(), fde);
+      }
       throw new DistributedSystemDisconnectedException(e.getMessage());
     }
   }
@@ -466,8 +470,10 @@ public class DistributionImpl implements Distribution {
     try {
       return membership.requestMemberRemoval(member, reason);
     } catch (MemberDisconnectedException | MembershipClosedException e) {
+      checkCancelled();
       throw new DistributedSystemDisconnectedException("Distribution is closed");
     } catch (RuntimeException e) {
+      checkCancelled();
       if (!membership.isConnected()) {
         throw new DistributedSystemDisconnectedException("Distribution is closed", e);
       }
@@ -584,7 +590,11 @@ public class DistributionImpl implements Distribution {
 
   @Override
   public Throwable getShutdownCause() {
-    return membership.getShutdownCause();
+    Throwable cause = membership.getShutdownCause();
+    if (cause instanceof MemberDisconnectedException) {
+      cause = new ForcedDisconnectException(cause.getMessage());
+    }
+    return cause;
   }
 
   @Override
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/Services.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/Services.java
index 9da4c98..e02540c 100644
--- a/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/Services.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/Services.java
@@ -392,6 +392,12 @@ public class Services<ID extends MemberIdentifier> {
     }
 
     public RuntimeException generateCancelledException(Throwable e) {
+      if (shutdownCause instanceof MemberDisconnectedException) {
+        MembershipClosedException newException =
+            new MembershipClosedException("membership shutdown",
+                e);
+        throw newException;
+      }
       String reason = cancelInProgress();
       if (reason == null) {
         return null;