geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [1/7] incubator-geode git commit: GEODE-774
Date Tue, 01 Mar 2016 00:09:46 GMT
Repository: incubator-geode
Updated Branches:
  refs/heads/feature/GEODE-949-2 adab5324a -> 527c43225


GEODE-774

Add and enhance junit tests for previous fix.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/1e31fa64
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/1e31fa64
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/1e31fa64

Branch: refs/heads/feature/GEODE-949-2
Commit: 1e31fa646f414aeea28c7fa28096b70dc2ccd120
Parents: 64855a2
Author: zhouxh <gzhou@pivotal.io>
Authored: Fri Feb 26 16:21:04 2016 -0800
Committer: zhouxh <gzhou@pivotal.io>
Committed: Mon Feb 29 12:37:09 2016 -0800

----------------------------------------------------------------------
 .../gemfire/internal/cache/BucketRegion.java    |  25 ++-
 .../internal/cache/DistributedRegion.java       |   2 +-
 .../AbstractDistributedRegionJUnitTest.java     | 166 +++++++++++++++++
 .../internal/cache/BucketRegionJUnitTest.java   | 186 +++++--------------
 .../cache/DistributedRegionJUnitTest.java       | 101 ++++++++++
 .../com/gemstone/gemfire/test/fake/Fakes.java   |   5 +-
 6 files changed, 339 insertions(+), 146 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1e31fa64/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/BucketRegion.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/BucketRegion.java
b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/BucketRegion.java
index 69f61c4..5b17040 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/BucketRegion.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/BucketRegion.java
@@ -922,13 +922,7 @@ implements Bucket
           logger.trace(LogMarker.DM, "LR.basicInvalidate: this cache has already seen this
event {}", event);
         }
         if (!getConcurrencyChecksEnabled() || event.hasValidVersionTag()) {
-          if (!event.isOriginRemote()
-              && getBucketAdvisor().isPrimary()) {
-            // This cache has processed the event, forward operation
-            // and event messages to backup buckets
-            new InvalidateOperation(event).distribute();
-          }
-          event.invokeCallbacks(this,true, false);
+          distributeInvalidateOperation(event);
         }
         return;
       }
@@ -936,6 +930,17 @@ implements Bucket
       endLocalWrite(event);
     }
   }
+
+  protected void distributeInvalidateOperation(EntryEventImpl event) {
+    if (!event.isOriginRemote()
+        && getBucketAdvisor().isPrimary()) {
+      // This cache has processed the event, forward operation
+      // and event messages to backup buckets
+      new InvalidateOperation(event).distribute();
+    }
+    event.invokeCallbacks(this,true, false);
+  }
+  
   @Override
   void basicInvalidatePart2(final RegionEntry re, final EntryEventImpl event,
       boolean clearConflict, boolean invokeCallbacks)
@@ -1312,7 +1317,7 @@ implements Bucket
         // This cache has processed the event, forward operation
         // and event messages to backup buckets
     	if (!getConcurrencyChecksEnabled() || event.hasValidVersionTag()) {
-          new UpdateEntryVersionOperation(event).distribute();
+          distributeUpdateEntryVersionOperation(event);
     	}
       }
       return;
@@ -1321,6 +1326,10 @@ implements Bucket
     }
   }
 
+  protected void distributeUpdateEntryVersionOperation(EntryEventImpl event) {
+    new UpdateEntryVersionOperation(event).distribute();
+  }
+  
   public int getRedundancyLevel()
   {
     return this.redundancy;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1e31fa64/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/DistributedRegion.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/DistributedRegion.java
b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/DistributedRegion.java
index 021eba6..19496da 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/DistributedRegion.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/DistributedRegion.java
@@ -2057,7 +2057,7 @@ public class DistributedRegion extends LocalRegion implements
     }
   }
 
-  private void distributeUpdateEntryVersion(EntryEventImpl event) {
+  protected void distributeUpdateEntryVersion(EntryEventImpl event) {
     if (!this.regionInvalid && event.isDistributed() && !event.isOriginRemote()
         && !isTX() /* only distribute if non-tx */) {
       if (event.isDistributed() && !event.isOriginRemote()) {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1e31fa64/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/AbstractDistributedRegionJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/AbstractDistributedRegionJUnitTest.java
b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/AbstractDistributedRegionJUnitTest.java
new file mode 100755
index 0000000..8eaeeb5
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/AbstractDistributedRegionJUnitTest.java
@@ -0,0 +1,166 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.internal.cache;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+
+import org.apache.logging.log4j.Logger;
+import org.junit.Test;
+
+import com.gemstone.gemfire.cache.AttributesFactory;
+import com.gemstone.gemfire.cache.DataPolicy;
+import com.gemstone.gemfire.cache.Operation;
+import com.gemstone.gemfire.cache.RegionAttributes;
+import com.gemstone.gemfire.cache.Scope;
+import com.gemstone.gemfire.distributed.internal.membership.InternalDistributedMember;
+import com.gemstone.gemfire.internal.cache.versions.VersionTag;
+import com.gemstone.gemfire.internal.logging.LogService;
+import com.gemstone.gemfire.test.fake.Fakes;
+
+import junit.framework.TestCase;
+
+public abstract class AbstractDistributedRegionJUnitTest extends TestCase {
+  protected static final Logger logger = LogService.getLogger();
+  
+  private RegionAttributes createRegionAttributes(
+      boolean isConcurrencyChecksEnabled) {
+    AttributesFactory factory = new AttributesFactory();
+    factory.setScope(Scope.DISTRIBUTED_ACK);
+    factory.setDataPolicy(DataPolicy.REPLICATE);
+    factory.setConcurrencyChecksEnabled(isConcurrencyChecksEnabled); //
+    RegionAttributes ra = factory.create();
+    return ra;
+  }
+  
+  private EventID createDummyEventID() {
+    byte[] memId = { 1,2,3 };
+    EventID eventId = new EventID(memId, 11, 12, 13);
+    return eventId;
+  }
+
+  private EntryEventImpl createDummyEvent(DistributedRegion region) {
+    // create a dummy event id
+    EventID eventId = createDummyEventID();
+    String key = "key1";
+    String value = "Value1";
+
+    // create an event
+    EntryEventImpl event = EntryEventImpl.create(region, Operation.CREATE, key,
+        value, null,  false /* origin remote */, null,
+        false /* generateCallbacks */,
+        eventId);
+    // avoid calling invokeCallbacks
+    event.callbacksInvoked(true);
+
+    return event;
+  }
+  
+  private VersionTag createVersionTag(boolean validVersionTag) {
+    InternalDistributedMember remotemember = mock(InternalDistributedMember.class);
+    VersionTag tag = VersionTag.create(remotemember);
+    if (validVersionTag) {
+      tag.setRegionVersion(1);
+      tag.setEntryVersion(1);
+    }
+    return tag;
+  }
+
+  private void doTest(DistributedRegion region, EntryEventImpl event, int cnt) {
+    // do the virtualPut test
+    verifyDistributeUpdate(region, event, cnt);
+    
+    // do the basicDestroy test
+    verifyDistributeDestroy(region, event, cnt);
+    
+    // do the basicInvalidate test
+    verifyDistributeInvalidate(region, event, cnt);
+    
+    // do the basicUpdateEntryVersion test
+    verifyDistributeUpdateEntryVersion(region, event, cnt);
+  }
+  
+  protected abstract void setInternalRegionArguments(InternalRegionArguments ira);
+  protected abstract DistributedRegion createAndDefineRegion(boolean isConcurrencyChecksEnabled,RegionAttributes
ra, 
+      InternalRegionArguments ira, GemFireCacheImpl cache);
+  protected abstract void verifyDistributeUpdate(DistributedRegion region, EntryEventImpl
event, int cnt);
+  protected abstract void verifyDistributeDestroy(DistributedRegion region, EntryEventImpl
event, int cnt);
+  protected abstract void verifyDistributeInvalidate(DistributedRegion region, EntryEventImpl
event, int cnt);
+  protected abstract void verifyDistributeUpdateEntryVersion(DistributedRegion region, EntryEventImpl
event, int cnt);
+
+  protected DistributedRegion prepare(boolean isConcurrencyChecksEnabled) {
+    GemFireCacheImpl cache = Fakes.cache();
+    
+    // create region attributes and internal region arguments
+    RegionAttributes ra = createRegionAttributes(isConcurrencyChecksEnabled);
+    InternalRegionArguments ira = new InternalRegionArguments();
+    
+    setInternalRegionArguments(ira);
+    
+    // create a region object
+    DistributedRegion region = createAndDefineRegion(isConcurrencyChecksEnabled, ra, ira,
cache);
+    if (isConcurrencyChecksEnabled) {
+      region.enableConcurrencyChecks();
+    }
+    
+    doNothing().when(region).notifyGatewaySender(any(), any());
+    doReturn(true).when(region).hasSeenEvent(any(EntryEventImpl.class));
+    return region;
+  }
+  
+  @Test
+  public void testConcurrencyFalseTagNull() {
+    // case 1: concurrencyCheckEanbled = false, version tag is null: distribute
+    DistributedRegion region = prepare(false);
+    EntryEventImpl event = createDummyEvent(region);
+    assertNull(event.getVersionTag());
+    doTest(region, event, 1);
+  }
+
+  @Test
+  public void testConcurrencyTrueTagNull() {
+    // case 2: concurrencyCheckEanbled = true,  version tag is null: not to distribute
+    DistributedRegion region = prepare(true);
+    EntryEventImpl event = createDummyEvent(region);
+    assertNull(event.getVersionTag());
+    doTest(region, event, 0);
+  }
+  
+  @Test
+  public void testConcurrencyTrueTagInvalid() {
+    // case 3: concurrencyCheckEanbled = true,  version tag is invalid: not to distribute
+    DistributedRegion region = prepare(true);
+    EntryEventImpl event = createDummyEvent(region);
+    VersionTag tag = createVersionTag(false);
+    event.setVersionTag(tag);
+    assertFalse(tag.hasValidVersion());
+    doTest(region, event, 0);
+  }
+    
+  @Test
+  public void testConcurrencyTrueTagValid() {
+    // case 4: concurrencyCheckEanbled = true,  version tag is valid: distribute
+    DistributedRegion region = prepare(true);
+    EntryEventImpl event = createDummyEvent(region);
+    VersionTag tag = createVersionTag(true);
+    event.setVersionTag(tag);
+    assertTrue(tag.hasValidVersion());
+    doTest(region, event, 1);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1e31fa64/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/BucketRegionJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/BucketRegionJUnitTest.java
b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/BucketRegionJUnitTest.java
index b2623fb..e8e4d1f 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/BucketRegionJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/BucketRegionJUnitTest.java
@@ -16,30 +16,16 @@
  */
 package com.gemstone.gemfire.internal.cache;
 
-import org.apache.logging.log4j.Logger;
-import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.mockito.Mockito;
 
-import com.gemstone.gemfire.cache.AttributesFactory;
-import com.gemstone.gemfire.cache.DataPolicy;
-import com.gemstone.gemfire.cache.Operation;
 import com.gemstone.gemfire.cache.RegionAttributes;
-import com.gemstone.gemfire.cache.Scope;
-import com.gemstone.gemfire.distributed.internal.DSClock;
-import com.gemstone.gemfire.distributed.internal.DistributionConfigImpl;
-import com.gemstone.gemfire.distributed.internal.DistributionManager;
-import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
-import com.gemstone.gemfire.distributed.internal.membership.InternalDistributedMember;
-import com.gemstone.gemfire.internal.cache.versions.VersionTag;
-import com.gemstone.gemfire.internal.logging.LogService;
 import com.gemstone.gemfire.test.junit.categories.UnitTest;
 
-import junit.framework.TestCase;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.*;
 
-import java.util.HashSet;
-import java.util.Properties;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
@@ -49,105 +35,44 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
  *
  */
 @Category(UnitTest.class)
-public class BucketRegionJUnitTest extends TestCase {
+public class BucketRegionJUnitTest extends DistributedRegionJUnitTest {
 
-  private static final Logger logger = LogService.getLogger();
-  GemFireCacheImpl cache = null;
-  InternalDistributedMember member = null;
-  PartitionedRegion pr = null;
-  BucketAdvisor ba = null;
-  RegionAttributes ra = null;
-  InternalRegionArguments ira = null;
-  BucketRegion br = null;
-  
-  private EntryEventImpl prepare(boolean isConcurrencyChecksEnabled) {
-    // mock cache, distributed system, distribution manager, and distributed member
-    cache = mock(GemFireCacheImpl.class);
-    InternalDistributedSystem ids = mock(InternalDistributedSystem.class);
-    DistributionManager dm = mock(DistributionManager.class);
-    member = mock(InternalDistributedMember.class);
-    InvalidateOperation io = mock(InvalidateOperation.class);
-
-    // mock PR, bucket advisor, DSClock 
-    pr = mock(PartitionedRegion.class);
-    ba = mock(BucketAdvisor.class);
-    DSClock clock = mock(DSClock.class);
-
-    // create some real objects
-    DistributionConfigImpl config = new DistributionConfigImpl(new Properties());
+  protected void setInternalRegionArguments(InternalRegionArguments ira) {
+    // PR specific
+    PartitionedRegion pr = mock(PartitionedRegion.class);
+    BucketAdvisor ba = mock(BucketAdvisor.class);
     ReadWriteLock primaryMoveLock = new ReentrantReadWriteLock();
     Lock activeWriteLock = primaryMoveLock.readLock();
-    GemFireCacheImpl.Stopper stopper = mock(GemFireCacheImpl.Stopper.class);
-
-    // define the mock objects' behaviors
-    when(cache.getDistributedSystem()).thenReturn(ids);
-    when(ids.getClock()).thenReturn(clock);
-    when(ids.getDistributionManager()).thenReturn(dm);
-    when(ids.getDistributedMember()).thenReturn(member);
-    when(dm.getConfig()).thenReturn(config);
-    when(member.getRoles()).thenReturn(new HashSet());
     when(ba.getActiveWriteLock()).thenReturn(activeWriteLock);
-    when (cache.getCancelCriterion()).thenReturn(stopper);
-    when(ids.getCancelCriterion()).thenReturn(stopper);
-
-    // create region attributes and internal region arguments
-    AttributesFactory factory = new AttributesFactory();
-    factory.setScope(Scope.DISTRIBUTED_ACK);
-    factory.setDataPolicy(DataPolicy.REPLICATE);
-    factory.setConcurrencyChecksEnabled(isConcurrencyChecksEnabled); //
-    ra = factory.create();
-    ira = new InternalRegionArguments().setPartitionedRegion(pr)
-        .setPartitionedRegionBucketRedundancy(1)
-        .setBucketAdvisor(ba);
-    // create a bucket region object
-    br = new BucketRegion("testRegion", ra, null, cache, ira);
+    when(ba.isPrimary()).thenReturn(true);
     
+    ira.setPartitionedRegion(pr)
+      .setPartitionedRegionBucketRedundancy(1)
+      .setBucketAdvisor(ba);
+  }
+  
+  protected DistributedRegion createAndDefineRegion(boolean isConcurrencyChecksEnabled,
+      RegionAttributes ra, InternalRegionArguments ira, GemFireCacheImpl cache) {
+    BucketRegion br = new BucketRegion("testRegion", ra, null, cache, ira);
+
     // since br is a real bucket region object, we need to tell mockito to monitor it
     br = Mockito.spy(br);
 
+//    doNothing().when(dm).addMembershipListener(any());
     doNothing().when(br).distributeUpdateOperation(any(), anyLong());
     doNothing().when(br).distributeDestroyOperation(any());
+    doNothing().when(br).distributeInvalidateOperation(any());
+    doNothing().when(br).distributeUpdateEntryVersionOperation(any());
     doNothing().when(br).checkForPrimary();
     doNothing().when(br).handleWANEvent(any());
     doReturn(false).when(br).needWriteLock(any());
-    doReturn(true).when(br).hasSeenEvent(any(EntryEventImpl.class));
     
-    EntryEventImpl event = createDummyEvent();
-    return event;
-  }
-  
-  private EventID createDummyEventID() {
-    byte[] memId = { 1,2,3 };
-    EventID eventId = new EventID(memId, 11, 12, 13);
-    return eventId;
+    return br;
   }
 
-  private EntryEventImpl createDummyEvent() {
-    // create a dummy event id
-    EventID eventId = createDummyEventID();
-    String key = "key1";
-    String value = "Value1";
-
-    // create an event
-    EntryEventImpl event = EntryEventImpl.create(br, Operation.CREATE, key,
-        value, null,  false /* origin remote */, null,
-        false /* generateCallbacks */,
-        eventId);
-
-    return event;
-  }
-  
-  private VersionTag createVersionTag(boolean invalid) {
-    VersionTag tag = VersionTag.create(member);
-    if (invalid == false) {
-      tag.setRegionVersion(1);
-      tag.setEntryVersion(1);
-    }
-    return tag;
-  }
-  
-  private void doTest(EntryEventImpl event, int cnt) {
-    // do the virtualPut test
+  protected void verifyDistributeUpdate(DistributedRegion region, EntryEventImpl event, int
cnt) {
+    assertTrue(region instanceof BucketRegion);
+    BucketRegion br = (BucketRegion)region;
     br.virtualPut(event, false, false, null, false, 12345L, false);
     // verify the result
     if (cnt > 0) {
@@ -155,8 +80,11 @@ public class BucketRegionJUnitTest extends TestCase {
     } else {
       verify(br, never()).distributeUpdateOperation(eq(event), eq(12345L));
     }
-    
-    // do the basicDestroy test
+  }
+  
+  protected void verifyDistributeDestroy(DistributedRegion region, EntryEventImpl event,
int cnt) {
+    assertTrue(region instanceof BucketRegion);
+    BucketRegion br = (BucketRegion)region;
     br.basicDestroy(event, false, null);
     // verify the result
     if (cnt > 0) {
@@ -164,45 +92,31 @@ public class BucketRegionJUnitTest extends TestCase {
     } else {
       verify(br, never()).distributeDestroyOperation(eq(event));
     }
-    
   }
   
-  @Test
-  public void testConcurrencyFalseTagNull() {
-    // case 1: concurrencyCheckEanbled = false, version tag is null: distribute
-    EntryEventImpl event = prepare(false);
-    assertNull(event.getVersionTag());
-    doTest(event, 1);
-  }
-
-  @Test
-  public void testConcurrencyTrueTagNull() {
-    // case 2: concurrencyCheckEanbled = true,  version tag is null: not to distribute
-    EntryEventImpl event = prepare(true);
-    assertNull(event.getVersionTag());
-    doTest(event, 0);
-  }
-  
-  @Test
-  public void testConcurrencyTrueTagInvalid() {
-    // case 3: concurrencyCheckEanbled = true,  version tag is invalid: not to distribute
-    EntryEventImpl event = prepare(true);
-    VersionTag tag = createVersionTag(true);
-    event.setVersionTag(tag);
-    assertFalse(tag.hasValidVersion());
-    doTest(event, 0);
+  protected void verifyDistributeInvalidate(DistributedRegion region, EntryEventImpl event,
int cnt) {
+    assertTrue(region instanceof BucketRegion);
+    BucketRegion br = (BucketRegion)region;
+    br.basicInvalidate(event);
+    // verify the result
+    if (cnt > 0) {
+      verify(br, times(cnt)).distributeInvalidateOperation(eq(event));
+    } else {
+      verify(br, never()).distributeInvalidateOperation(eq(event));
+    }
   }
     
-  @Test
-  public void testConcurrencyTrueTagValid() {
-    // case 4: concurrencyCheckEanbled = true,  version tag is valid: distribute
-    EntryEventImpl event = prepare(true);
-    VersionTag tag = createVersionTag(false);
-    event.setVersionTag(tag);
-    assertTrue(tag.hasValidVersion());
-    doTest(event, 1);
+  protected void verifyDistributeUpdateEntryVersion(DistributedRegion region, EntryEventImpl
event, int cnt) {
+    assertTrue(region instanceof BucketRegion);
+    BucketRegion br = (BucketRegion)region;
+    br.basicUpdateEntryVersion(event);
+    // verify the result
+    if (cnt > 0) {
+      verify(br, times(cnt)).distributeUpdateEntryVersionOperation(eq(event));
+    } else {
+      verify(br, never()).distributeUpdateEntryVersionOperation(eq(event));
+    }
   }
-
-
+  
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1e31fa64/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/DistributedRegionJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/DistributedRegionJUnitTest.java
b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/DistributedRegionJUnitTest.java
new file mode 100755
index 0000000..1383b76
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/DistributedRegionJUnitTest.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.internal.cache;
+
+import org.junit.experimental.categories.Category;
+import org.mockito.Mockito;
+
+import com.gemstone.gemfire.cache.RegionAttributes;
+import com.gemstone.gemfire.test.junit.categories.UnitTest;
+
+import junit.framework.TestCase;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.*;
+
+/**
+ * @author gzhou
+ *
+ */
+@Category(UnitTest.class)
+public class DistributedRegionJUnitTest extends AbstractDistributedRegionJUnitTest {
+
+  protected void setInternalRegionArguments(InternalRegionArguments ira) {
+  }
+  
+  protected DistributedRegion createAndDefineRegion(boolean isConcurrencyChecksEnabled,
+      RegionAttributes ra, InternalRegionArguments ira, GemFireCacheImpl cache) {
+    DistributedRegion region = new DistributedRegion("testRegion", ra, null, cache, ira);
+    if (isConcurrencyChecksEnabled) {
+      region.enableConcurrencyChecks();
+    }
+    
+    // since it is a real region object, we need to tell mockito to monitor it
+    region = Mockito.spy(region);
+
+    doNothing().when(region).distributeUpdate(any(), anyLong(), anyBoolean(), anyBoolean(),
any(), anyBoolean());
+    doNothing().when(region).distributeDestroy(any(), any());
+    doNothing().when(region).distributeInvalidate(any());
+    doNothing().when(region).distributeUpdateEntryVersion(any());
+    
+    return region;
+  }
+  
+  protected void verifyDistributeUpdate(DistributedRegion region, EntryEventImpl event, int
cnt) {
+    region.virtualPut(event, false, false, null, false, 12345L, false);
+    // verify the result
+    if (cnt > 0) {
+      verify(region, times(cnt)).distributeUpdate(eq(event), eq(12345L), anyBoolean(), anyBoolean(),
any(), anyBoolean());
+    } else {
+      verify(region, never()).distributeUpdate(eq(event), eq(12345L), anyBoolean(), anyBoolean(),
any(), anyBoolean());
+    }
+  }
+
+  protected void verifyDistributeDestroy(DistributedRegion region, EntryEventImpl event,
int cnt) {
+    region.basicDestroy(event, false, null);
+    // verify the result
+    if (cnt > 0) {
+      verify(region, times(cnt)).distributeDestroy(eq(event), any());
+    } else {
+      verify(region, never()).distributeDestroy(eq(event), any());
+    }
+  }
+
+  protected void verifyDistributeInvalidate(DistributedRegion region, EntryEventImpl event,
int cnt) {
+    region.basicInvalidate(event);
+    // verify the result
+    if (cnt > 0) {
+      verify(region, times(cnt)).distributeInvalidate(eq(event));
+    } else {
+      verify(region, never()).distributeInvalidate(eq(event));
+    }
+  }
+
+  protected void verifyDistributeUpdateEntryVersion(DistributedRegion region, EntryEventImpl
event, int cnt) {
+    region.basicUpdateEntryVersion(event);
+    // verify the result
+    if (cnt > 0) {
+      verify(region, times(cnt)).distributeUpdateEntryVersion(eq(event));
+    } else {
+      verify(region, never()).distributeUpdateEntryVersion(eq(event));
+    }
+  }
+  
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1e31fa64/geode-core/src/test/java/com/gemstone/gemfire/test/fake/Fakes.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/fake/Fakes.java b/geode-core/src/test/java/com/gemstone/gemfire/test/fake/Fakes.java
index ffb4896..99644b7 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/fake/Fakes.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/fake/Fakes.java
@@ -23,6 +23,7 @@ import java.net.UnknownHostException;
 import org.junit.Assert;
 
 import com.gemstone.gemfire.CancelCriterion;
+import com.gemstone.gemfire.distributed.internal.DSClock;
 import com.gemstone.gemfire.distributed.internal.DistributionConfig;
 import com.gemstone.gemfire.distributed.internal.DistributionManager;
 import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
@@ -59,6 +60,7 @@ public class Fakes {
     DistributionConfig config = mock(DistributionConfig.class);
     DistributionManager distributionManager = mock(DistributionManager.class);
     CancelCriterion systemCancelCriterion = mock(CancelCriterion.class);
+    DSClock clock = mock(DSClock.class);
     
     InternalDistributedMember member;
     try {
@@ -77,7 +79,8 @@ public class Fakes {
     when(system.getConfig()).thenReturn(config);
     when(system.getDistributionManager()).thenReturn(distributionManager);
     when(system.getCancelCriterion()).thenReturn(systemCancelCriterion);
-    
+    when(system.getClock()).thenReturn(clock);
+
     when(distributionManager.getId()).thenReturn(member);
     when(distributionManager.getConfig()).thenReturn(config);
     when(distributionManager.getSystem()).thenReturn(system);


Mime
View raw message