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 2020/01/16 00:35:58 UTC
[geode] branch feature/GEODE-7706 updated: GEODE-7706: throw
correct TransactionDataRebalancedException.
This is an automated email from the ASF dual-hosted git repository.
eshu11 pushed a commit to branch feature/GEODE-7706
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/feature/GEODE-7706 by this push:
new 17f29ba GEODE-7706: throw correct TransactionDataRebalancedException.
17f29ba is described below
commit 17f29ba93d9423600c4c0f3b407cc9011766f565
Author: Eric Shu <es...@EricMacBookPro.local>
AuthorDate: Wed Jan 15 16:34:22 2020 -0800
GEODE-7706: throw correct TransactionDataRebalancedException.
---
.../geode/internal/cache/PartitionedRegion.java | 6 +-
.../internal/cache/PartitionedRegionTest.java | 64 ++++++++++++++++++++++
2 files changed, 66 insertions(+), 4 deletions(-)
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegion.java b/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegion.java
index ac3148a..a94bbac 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegion.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegion.java
@@ -9555,10 +9555,8 @@ public class PartitionedRegion extends LocalRegion
"Transactional data moved, due to rebalancing.",
pbe);
} catch (RegionDestroyedException ignore) {
- // TODO: why is this purposely not wrapping the original cause?
- throw new TransactionDataNotColocatedException(
- String.format("Key %s is not colocated with transaction",
- entryKey));
+ throw new TransactionDataRebalancedException(
+ "Transactional data moved, due to rebalancing.");
}
return br;
}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/PartitionedRegionTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/PartitionedRegionTest.java
index 71405f9..4bea39f 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/PartitionedRegionTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/PartitionedRegionTest.java
@@ -19,6 +19,7 @@ import static org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueImpl.get
import static org.apache.geode.internal.statistics.StatisticsClockFactory.disabledClock;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
@@ -57,6 +58,9 @@ import org.apache.geode.cache.CacheWriter;
import org.apache.geode.cache.Operation;
import org.apache.geode.cache.PartitionAttributesFactory;
import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionDestroyedException;
+import org.apache.geode.cache.TransactionDataRebalancedException;
+import org.apache.geode.cache.TransactionException;
import org.apache.geode.cache.asyncqueue.AsyncEventQueue;
import org.apache.geode.cache.wan.GatewaySender;
import org.apache.geode.distributed.DistributedLockService;
@@ -439,6 +443,66 @@ public class PartitionedRegionTest {
.doesNotThrowAnyException();
}
+ @Test
+ public void getDataRegionForWriteThrowsTransactionExceptionIfNotDataStore() {
+ PartitionedRegion spyPartitionedRegion = spy(partitionedRegion);
+
+ KeyInfo keyInfo = mock(KeyInfo.class);
+ when(keyInfo.getBucketId()).thenReturn(1);
+ doReturn(null).when(spyPartitionedRegion).getDataStore();
+
+ Throwable caughtException =
+ catchThrowable(() -> spyPartitionedRegion.getDataRegionForWrite(keyInfo));
+
+ assertThat(caughtException).isInstanceOf(TransactionException.class).hasMessage(
+ "PartitionedRegion Transactions cannot execute on nodes with local max memory zero");
+ }
+
+ @Test
+ public void getDataRegionForWriteThrowsTransactionDataRebalancedExceptionIfGetInitializedBucketThrowsForceReattemptException()
+ throws Exception {
+ PartitionedRegion spyPartitionedRegion = spy(partitionedRegion);
+
+ KeyInfo keyInfo = mock(KeyInfo.class);
+ Object key = new Object();
+ PartitionedRegionDataStore dataStore = mock(PartitionedRegionDataStore.class);
+ when(keyInfo.getBucketId()).thenReturn(1);
+ when(keyInfo.getKey()).thenReturn(key);
+ when(keyInfo.isCheckPrimary()).thenReturn(true);
+ doReturn(dataStore).when(spyPartitionedRegion).getDataStore();
+ doThrow(new ForceReattemptException("")).when(dataStore)
+ .getInitializedBucketWithKnownPrimaryForId(key, 1);
+ doReturn(mock(InternalDistributedMember.class)).when(spyPartitionedRegion).createBucket(1, 0,
+ null);
+
+ Throwable caughtException =
+ catchThrowable(() -> spyPartitionedRegion.getDataRegionForWrite(keyInfo));
+
+ assertThat(caughtException).isInstanceOf(TransactionDataRebalancedException.class)
+ .hasMessage("Transactional data moved, due to rebalancing.");
+ }
+
+ @Test
+ public void getDataRegionForWriteThrowsTransactionDataRebalancedExceptionIfGetInitializedBucketThrowsRegionDestroyedException()
+ throws Exception {
+ PartitionedRegion spyPartitionedRegion = spy(partitionedRegion);
+
+ KeyInfo keyInfo = mock(KeyInfo.class);
+ Object key = new Object();
+ PartitionedRegionDataStore dataStore = mock(PartitionedRegionDataStore.class);
+ when(keyInfo.getBucketId()).thenReturn(1);
+ when(keyInfo.getKey()).thenReturn(key);
+ doReturn(dataStore).when(spyPartitionedRegion).getDataStore();
+ doThrow(new RegionDestroyedException("", "")).when(dataStore)
+ .getInitializedBucketWithKnownPrimaryForId(key, 1);
+
+ Throwable caughtException =
+ catchThrowable(() -> spyPartitionedRegion.getDataRegionForWrite(keyInfo));
+
+ assertThat(caughtException).isInstanceOf(TransactionDataRebalancedException.class)
+ .hasMessage("Transactional data moved, due to rebalancing.");
+ }
+
private static <K> Set<K> asSet(K... values) {
Set<K> set = new HashSet<>();
Collections.addAll(set, values);