Skip to content

Commit

Permalink
GEODE-8432: use regionPath directly instead of getRegion when put eve… (
Browse files Browse the repository at this point in the history
  • Loading branch information
gesterzhou authored Aug 15, 2020
1 parent 515fd92 commit 8021084
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -693,15 +693,14 @@ public boolean put(Object object) throws InterruptedException, CacheException {

boolean isDREvent = isDREvent(sender.getCache(), value);

Region region = value.getRegion();
String regionPath = null;
if (isDREvent) {
regionPath = region.getFullPath();
} else {
regionPath = ColocationHelper.getLeaderRegion((PartitionedRegion) region).getFullPath();
String regionPath = value.getRegionPath();
if (!isDREvent) {
regionPath = ColocationHelper
.getLeaderRegion((PartitionedRegion) sender.getCache().getRegion(regionPath))
.getFullPath();
}
if (isDebugEnabled) {
logger.debug("Put is for the region {}", region);
logger.debug("Put is for the region {}", regionPath);
}
if (!this.userRegionNameToShadowPRMap.containsKey(regionPath)) {
if (isDebugEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand All @@ -37,6 +39,7 @@

import org.apache.geode.CancelCriterion;
import org.apache.geode.cache.DataPolicy;
import org.apache.geode.cache.PartitionAttributes;
import org.apache.geode.cache.PartitionAttributesFactory;
import org.apache.geode.cache.Region;
import org.apache.geode.internal.cache.AbstractBucketRegionQueue;
Expand Down Expand Up @@ -75,6 +78,52 @@ public void createParallelGatewaySenderQueue() {
false);
}

@Test
public void whenReplicatedDataRegionNotReadyShouldNotThrowException() throws Exception {
GatewaySenderEventImpl event = mock(GatewaySenderEventImpl.class);
when(event.makeHeapCopyIfOffHeap()).thenReturn(event);
when(event.getRegion()).thenReturn(null);
String regionPath = "/testRegion";
when(event.getRegionPath()).thenReturn(regionPath);
Mockito.doThrow(new IllegalStateException()).when(event).release();
Queue backingList = new LinkedList();
backingList.add(event);

queue = spy(queue);
doReturn(true).when(queue).isDREvent(any(), any());
boolean putDone = queue.put(event);
assertThat(putDone).isFalse();
}

@Test
public void whenPartitionedDataRegionNotReadyShouldNotThrowException() throws Exception {
GatewaySenderEventImpl event = mock(GatewaySenderEventImpl.class);
when(event.makeHeapCopyIfOffHeap()).thenReturn(event);
when(event.getRegion()).thenReturn(null);
String regionPath = "/testRegion";
when(event.getRegionPath()).thenReturn(regionPath);
PartitionedRegion region = mock(PartitionedRegion.class);
when(region.getFullPath()).thenReturn(regionPath);
when(cache.getRegion(regionPath)).thenReturn(region);
PartitionAttributes pa = mock(PartitionAttributes.class);
when(region.getPartitionAttributes()).thenReturn(pa);
when(pa.getColocatedWith()).thenReturn(null);

Mockito.doThrow(new IllegalStateException()).when(event).release();
Queue backingList = new LinkedList();
backingList.add(event);

BucketRegionQueue bucketRegionQueue = mockBucketRegionQueue(backingList);

TestableParallelGatewaySenderQueue queue = new TestableParallelGatewaySenderQueue(sender,
Collections.emptySet(), 0, 1, metaRegionFactory);
queue.setMockedAbstractBucketRegionQueue(bucketRegionQueue);

queue = spy(queue);
boolean putDone = queue.put(event);
assertThat(putDone).isFalse();
}

@Test
public void whenEventReleaseFromOffHeapFailsExceptionShouldNotBeThrownToAckReaderThread()
throws Exception {
Expand Down

0 comments on commit 8021084

Please sign in to comment.