You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ds...@apache.org on 2018/05/01 19:40:55 UTC

[geode] branch develop updated: GEODE-5152: add unit tests for txApplyPut (#1889)

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

dschneider 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 7b9e8c2  GEODE-5152: add unit tests for txApplyPut (#1889)
7b9e8c2 is described below

commit 7b9e8c21c6af53e90b7084571010af76e51852ab
Author: Darrel Schneider <ds...@pivotal.io>
AuthorDate: Tue May 1 12:40:48 2018 -0700

    GEODE-5152: add unit tests for txApplyPut (#1889)
---
 .../internal/cache/AbstractRegionMapTest.java      | 63 ++++++++++++++++++----
 1 file changed, 52 insertions(+), 11 deletions(-)

diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/AbstractRegionMapTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/AbstractRegionMapTest.java
index dbfe764..310e0a3 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/AbstractRegionMapTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/AbstractRegionMapTest.java
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyLong;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
@@ -822,6 +823,7 @@ public class AbstractRegionMapTest {
     protected TxTestableAbstractRegionMap() {
       super(null);
       LocalRegion owner = mock(LocalRegion.class);
+      when(owner.getMyId()).thenReturn(mock(InternalDistributedMember.class));
       when(owner.getCache()).thenReturn(mock(InternalCache.class));
       when(owner.isAllEvents()).thenReturn(true);
       when(owner.isInitialized()).thenReturn(true);
@@ -835,13 +837,37 @@ public class AbstractRegionMapTest {
       throws Exception {
     AbstractRegionMap arm = new TxRegionEntryTestableAbstractRegionMap();
     List<EntryEventImpl> pendingCallbacks = new ArrayList<>();
+    TXId txId = new TXId(mock(InternalDistributedMember.class), 1);
+    TXRmtEvent txRmtEvent = mock(TXRmtEvent.class);
+    EventID eventId = mock(EventID.class);
+    Object newValue = "value";
+
+    arm.txApplyPut(Operation.UPDATE, KEY, newValue, false, txId, txRmtEvent, eventId, null,
+        pendingCallbacks, null, null, null, null, 1);
+
+    assertEquals(1, pendingCallbacks.size());
+    verify(arm._getOwner(), times(1)).txApplyPutPart2(any(), any(), anyLong(), anyBoolean(),
+        anyBoolean(), anyBoolean());
+    verify(arm._getOwner(), never()).invokeTXCallbacks(EnumListenerEvent.AFTER_UPDATE, UPDATEEVENT,
+        false);
+  }
 
+  @Test
+  public void txApplyPutOnPrimaryConstructsPendingCallbacksWhenPutIfAbsentReturnsExistingEntry()
+      throws Exception {
+    AbstractRegionMap arm = new TxPutIfAbsentTestableAbstractRegionMap();
+    List<EntryEventImpl> pendingCallbacks = new ArrayList<>();
+    TXId txId = new TXId(arm._getOwner().getMyId(), 1);
+    TXRmtEvent txRmtEvent = mock(TXRmtEvent.class);
+    EventID eventId = mock(EventID.class);
     Object newValue = "value";
-    arm.txApplyPut(Operation.UPDATE, KEY, newValue, false,
-        new TXId(mock(InternalDistributedMember.class), 1), mock(TXRmtEvent.class),
-        mock(EventID.class), null, pendingCallbacks, null, null, null, null, 1);
+
+    arm.txApplyPut(Operation.UPDATE, KEY, newValue, false, txId, txRmtEvent, eventId, null,
+        pendingCallbacks, null, null, null, null, 1);
 
     assertEquals(1, pendingCallbacks.size());
+    verify(arm._getOwner(), times(1)).txApplyPutPart2(any(), any(), anyLong(), anyBoolean(),
+        anyBoolean(), anyBoolean());
     verify(arm._getOwner(), never()).invokeTXCallbacks(EnumListenerEvent.AFTER_UPDATE, UPDATEEVENT,
         false);
   }
@@ -850,13 +876,17 @@ public class AbstractRegionMapTest {
   public void txApplyPutOnSecondaryNotifiesClientsWhenRegionEntryIsRemoved() throws Exception {
     AbstractRegionMap arm = new TxRemovedRegionEntryTestableAbstractRegionMap();
     List<EntryEventImpl> pendingCallbacks = new ArrayList<>();
-
+    TXId txId = new TXId(mock(InternalDistributedMember.class), 1);
+    TXRmtEvent txRmtEvent = mock(TXRmtEvent.class);
+    EventID eventId = mock(EventID.class);
     Object newValue = "value";
-    arm.txApplyPut(Operation.UPDATE, KEY, newValue, false,
-        new TXId(mock(InternalDistributedMember.class), 1), mock(TXRmtEvent.class),
-        mock(EventID.class), null, pendingCallbacks, null, null, null, null, 1);
+
+    arm.txApplyPut(Operation.UPDATE, KEY, newValue, false, txId, txRmtEvent, eventId, null,
+        pendingCallbacks, null, null, null, null, 1);
 
     assertEquals(0, pendingCallbacks.size());
+    verify(arm._getOwner(), never()).txApplyPutPart2(any(), any(), anyLong(), anyBoolean(),
+        anyBoolean(), anyBoolean());
     verify(arm._getOwner(), times(1)).invokeTXCallbacks(EnumListenerEvent.AFTER_UPDATE, UPDATEEVENT,
         false);
   }
@@ -865,13 +895,17 @@ public class AbstractRegionMapTest {
   public void txApplyPutOnSecondaryNotifiesClientsWhenRegionEntryIsNull() throws Exception {
     AbstractRegionMap arm = new TxNoRegionEntryTestableAbstractRegionMap();
     List<EntryEventImpl> pendingCallbacks = new ArrayList<>();
-
+    TXId txId = new TXId(mock(InternalDistributedMember.class), 1);
+    TXRmtEvent txRmtEvent = mock(TXRmtEvent.class);
+    EventID eventId = mock(EventID.class);
     Object newValue = "value";
-    arm.txApplyPut(Operation.UPDATE, KEY, newValue, false,
-        new TXId(mock(InternalDistributedMember.class), 1), mock(TXRmtEvent.class),
-        mock(EventID.class), null, pendingCallbacks, null, null, null, null, 1);
+
+    arm.txApplyPut(Operation.UPDATE, KEY, newValue, false, txId, txRmtEvent, eventId, null,
+        pendingCallbacks, null, null, null, null, 1);
 
     assertEquals(0, pendingCallbacks.size());
+    verify(arm._getOwner(), never()).txApplyPutPart2(any(), any(), anyLong(), anyBoolean(),
+        anyBoolean(), anyBoolean());
     verify(arm._getOwner(), times(1)).invokeTXCallbacks(EnumListenerEvent.AFTER_UPDATE, UPDATEEVENT,
         false);
   }
@@ -908,6 +942,13 @@ public class AbstractRegionMapTest {
     }
   }
 
+  private static class TxPutIfAbsentTestableAbstractRegionMap extends TxTestableAbstractRegionMap {
+    @Override
+    public RegionEntry putEntryIfAbsent(Object key, RegionEntry newRe) {
+      return mock(RegionEntry.class);
+    }
+  }
+
   private static class TxRemovedRegionEntryTestableAbstractRegionMap
       extends TxTestableAbstractRegionMap {
     @Override

-- 
To stop receiving notification emails like this one, please contact
dschneider@apache.org.