You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by es...@apache.org on 2018/09/06 21:19:39 UTC

[geode] branch develop updated: GEODE-5702: Rethrows a specific TransactionExeption instead wrapped to a new TransactionException. (#2430)

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

eshu11 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 d429c0c  GEODE-5702: Rethrows a specific TransactionExeption instead wrapped to a new TransactionException. (#2430)
d429c0c is described below

commit d429c0c3fbd5597e5ee9232460128dca53d127a7
Author: pivotal-eshu <es...@pivotal.io>
AuthorDate: Thu Sep 6 14:19:34 2018 -0700

    GEODE-5702: Rethrows a specific TransactionExeption instead wrapped to a new TransactionException. (#2430)
---
 .../cache/tx/AbstractPeerTXRegionStub.java         | 32 +++++----
 .../cache/tx/AbstractPeerTXRegionStubTest.java     | 82 +++++++++++++++++++---
 2 files changed, 91 insertions(+), 23 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tx/AbstractPeerTXRegionStub.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tx/AbstractPeerTXRegionStub.java
index 1a8b0bb..c6a8d1c 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/tx/AbstractPeerTXRegionStub.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tx/AbstractPeerTXRegionStub.java
@@ -42,15 +42,17 @@ public abstract class AbstractPeerTXRegionStub implements TXRegionStub {
       RemoteFetchKeysMessage.FetchKeysResponse response =
           RemoteFetchKeysMessage.send((LocalRegion) getRegion(), state.getTarget());
       return response.waitForKeys();
-    } catch (RegionDestroyedException e) {
+    } catch (RegionDestroyedException regionDestroyedException) {
       throw new TransactionDataNotColocatedException(
           LocalizedStrings.RemoteMessage_REGION_0_NOT_COLOCATED_WITH_TRANSACTION
-              .toLocalizedString(e.getRegionFullPath()),
-          e);
-    } catch (CacheClosedException e) {
+              .toLocalizedString(regionDestroyedException.getRegionFullPath()),
+          regionDestroyedException);
+    } catch (CacheClosedException cacheClosedException) {
       throw new TransactionDataNodeHasDepartedException("Cache was closed while fetching keys");
-    } catch (Exception e) {
-      throw new TransactionException(e);
+    } catch (TransactionException transactionException) {
+      throw transactionException;
+    } catch (Exception exception) {
+      throw new TransactionException(exception);
     }
   }
 
@@ -60,16 +62,18 @@ public abstract class AbstractPeerTXRegionStub implements TXRegionStub {
       RemoteSizeMessage.SizeResponse response =
           RemoteSizeMessage.send(this.state.getTarget(), getRegion());
       return response.waitForSize();
-    } catch (RegionDestroyedException rde) {
+    } catch (RegionDestroyedException regionDestroyedException) {
       throw new TransactionDataNotColocatedException(
           LocalizedStrings.RemoteMessage_REGION_0_NOT_COLOCATED_WITH_TRANSACTION
-              .toLocalizedString(rde.getRegionFullPath()),
-          rde);
-    } catch (Exception e) {
-      throw new TransactionException(e);
+              .toLocalizedString(regionDestroyedException.getRegionFullPath()),
+          regionDestroyedException);
+    } catch (CacheClosedException cacheClosedException) {
+      throw new TransactionDataNodeHasDepartedException(
+          "Cache was closed while performing size operation");
+    } catch (TransactionException transactionException) {
+      throw transactionException;
+    } catch (Exception exception) {
+      throw new TransactionException(exception);
     }
   }
-
-
-
 }
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tx/AbstractPeerTXRegionStubTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tx/AbstractPeerTXRegionStubTest.java
index aa3cbc8..018297f 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tx/AbstractPeerTXRegionStubTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tx/AbstractPeerTXRegionStubTest.java
@@ -35,6 +35,8 @@ import org.apache.geode.cache.Region.Entry;
 import org.apache.geode.cache.RegionDestroyedException;
 import org.apache.geode.cache.TransactionDataNodeHasDepartedException;
 import org.apache.geode.cache.TransactionDataNotColocatedException;
+import org.apache.geode.cache.TransactionException;
+import org.apache.geode.distributed.DistributedMember;
 import org.apache.geode.distributed.internal.ClusterDistributionManager;
 import org.apache.geode.distributed.internal.InternalDistributedSystem;
 import org.apache.geode.distributed.internal.ReplyException;
@@ -107,11 +109,6 @@ public class AbstractPeerTXRegionStubTest {
     }
 
     @Override
-    public int entryCount() {
-      return 0;
-    }
-
-    @Override
     public void postPutAll(DistributedPutAllOperation putallOp, VersionedObjectList successfulPuts,
         InternalRegion region) {}
 
@@ -142,6 +139,8 @@ public class AbstractPeerTXRegionStubTest {
     state = mock(TXStateStub.class);
     region = mock(LocalRegion.class);
     txrStub = new TestingAbstractPeerTXRegionStub(state, region);
+
+    when(state.getTarget()).thenReturn(mock(DistributedMember.class));
   }
 
   @After
@@ -158,14 +157,13 @@ public class AbstractPeerTXRegionStubTest {
 
     txrStub.getRegionKeysForIteration();
     fail(
-        "AbstractPeerTXRegionStub expected to transalate CacheClosedException to TransactionDataNodeHasDepartedException ");
+        "AbstractPeerTXRegionStub expected to translate CacheClosedException to TransactionDataNodeHasDepartedException ");
   }
 
   @Test
   public void getRegionKeysForIterationTranslatesRemoteOperationException() {
     expectedException.expect(TransactionDataNodeHasDepartedException.class);
 
-
     InternalDistributedSystem system = mock(InternalDistributedSystem.class);
     ClusterDistributionManager manager = mock(ClusterDistributionManager.class);
     when(system.getDistributionManager()).thenReturn(manager);
@@ -183,7 +181,7 @@ public class AbstractPeerTXRegionStubTest {
     spy.waitForKeys();
 
     fail(
-        "Expected to transalate RemoteOperationException.CacheClosedException to TransactionDataNodeHasDepartedException ");
+        "Expected to translate RemoteOperationException.CacheClosedException to TransactionDataNodeHasDepartedException ");
   }
 
   @Test
@@ -197,7 +195,73 @@ public class AbstractPeerTXRegionStubTest {
 
     txrStub.getRegionKeysForIteration();
     fail(
-        "AbstractPeerTXRegionStub expected to transalate CacheClosedException to TransactionDataNodeHasDepartedException ");
+        "AbstractPeerTXRegionStub expected to translate CacheClosedException to TransactionDataNodeHasDepartedException ");
+  }
+
+  @Test
+  public void getRegionKeysForIterationRethrowTransactionException() {
+    expectedException.expect(TransactionDataNodeHasDepartedException.class);
+
+    when((region).getSystem()).thenThrow(TransactionDataNodeHasDepartedException.class);
+
+    txrStub.getRegionKeysForIteration();
+    fail(
+        "AbstractPeerTXRegionStub expected to rethrow TransactionDataNodeHasDepartedException ");
+  }
+
+  @Test
+  public void getRegionKeysForIterationTranslatesRuntimeException() {
+    expectedException.expect(TransactionException.class);
+
+    when((region).getSystem()).thenThrow(new RuntimeException());
+
+    txrStub.getRegionKeysForIteration();
+    fail(
+        "AbstractPeerTXRegionStub expected to translate RuntimeException to TransactionException ");
+  }
+
+  @Test
+  public void entryCountTranslatesCacheClosedException() {
+    expectedException.expect(TransactionDataNodeHasDepartedException.class);
+
+    when((region).getSystem()).thenThrow(CacheClosedException.class);
+
+    txrStub.entryCount();
+    fail(
+        "AbstractPeerTXRegionStub expected to translate CacheClosedException to TransactionDataNodeHasDepartedException ");
+  }
+
+  @Test
+  public void entryCountTranslatesRegionDestroyedException() {
+    expectedException.expect(TransactionDataNotColocatedException.class);
+
+    when((region).getSystem()).thenThrow(RegionDestroyedException.class);
+
+    txrStub.entryCount();
+    fail(
+        "AbstractPeerTXRegionStub expected to translate CacheClosedException to TransactionDataNodeHasDepartedException ");
+  }
+
+  @Test
+  public void entryCountRethrowTransactionException() {
+    expectedException.expect(TransactionDataNodeHasDepartedException.class);
+
+    when((region).getSystem()).thenThrow(TransactionDataNodeHasDepartedException.class);
+
+    txrStub.entryCount();
+    fail(
+        "AbstractPeerTXRegionStub expected to rethrow TransactionDataNodeHasDepartedException ");
+  }
+
+  @Test
+  public void entryCountTranslatesRuntimeException() {
+    expectedException.expect(TransactionException.class);
+
+    when((region).getSystem()).thenThrow(new RuntimeException());
+
+    txrStub.entryCount();
+    fail(
+        "AbstractPeerTXRegionStub expected to translate RuntimeException to TransactionException ");
   }
 
 }