geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From esh...@apache.org
Subject [geode] branch feature/GEODE-5702 updated: GEODE-5702: Rethrows a specific TransactionExeption instead wrapped to a new TransactionException.
Date Thu, 06 Sep 2018 19:20:31 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/feature/GEODE-5702 by this push:
     new 6948c8e  GEODE-5702: Rethrows a specific TransactionExeption instead wrapped to a
new TransactionException.
6948c8e is described below

commit 6948c8edcf2883d2cf929c9936d65ab4c2740bc5
Author: eshu <eshu@pivotal.io>
AuthorDate: Thu Sep 6 12:19:18 2018 -0700

    GEODE-5702: Rethrows a specific TransactionExeption instead wrapped to a new TransactionException.
---
 .../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
");
   }
 
 }


Mime
View raw message