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

agingade pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git

commit df7f72cd9087b8cc367fe43002c4a605b782e792
Author: Anil <aging...@pivotal.io>
AuthorDate: Mon Oct 9 17:09:55 2017 -0700

    GEODE-3796 Changes are made to validate region version after the region is 
initialized.
---
 .../cache/versions/RegionVersionVector.java        |  9 +--
 .../versions/RegionVersionVectorJUnitTest.java     | 68 +++++++++++++++++++++-
 2 files changed, 72 insertions(+), 5 deletions(-)

diff --git 
a/geode-core/src/main/java/org/apache/geode/internal/cache/versions/RegionVersionVector.java
 
b/geode-core/src/main/java/org/apache/geode/internal/cache/versions/RegionVersionVector.java
index aa9ba38..af59f06 100644
--- 
a/geode-core/src/main/java/org/apache/geode/internal/cache/versions/RegionVersionVector.java
+++ 
b/geode-core/src/main/java/org/apache/geode/internal/cache/versions/RegionVersionVector.java
@@ -113,7 +113,7 @@ public abstract class RegionVersionVector<T extends 
VersionSource<?>>
   private transient boolean isLiveVector;
 
   /** for debugging we keep a reference to the region for use in log messages 
*/
-  private transient String regionName;
+  private transient LocalRegion region;
 
   private ConcurrentHashMap<T, Long> memberToGCVersion;
 
@@ -153,7 +153,7 @@ public abstract class RegionVersionVector<T extends 
VersionSource<?>>
   public RegionVersionVector(T ownerId, LocalRegion owner) {
     this.myId = ownerId;
     this.isLiveVector = true;
-    this.regionName = owner == null ? "" : "region " + owner.getFullPath();
+    this.region = owner;
 
     this.localExceptions = new RegionVersionHolder<T>(0);
     this.memberToVersion = new ConcurrentHashMap<T, 
RegionVersionHolder<T>>(INITIAL_CAPACITY,
@@ -606,10 +606,11 @@ public abstract class RegionVersionVector<T extends 
VersionSource<?>>
       // recovers. So we can only assert that the local member has already seen
       // the replayed event.
       synchronized (localExceptions) {
-        if (this.localVersion.get() < tag.getRegionVersion()) {
+        if (region != null && region.isInitialized()
+            && this.localVersion.get() < tag.getRegionVersion()) {
           Assert.fail(
               "recordVersion invoked for a local version tag that is higher 
than our local version. rvv="
-                  + this + ", tag=" + tag + " " + regionName);
+                  + this + ", tag=" + tag + " " + region.getName());
         }
       }
     }
diff --git 
a/geode-core/src/test/java/org/apache/geode/internal/cache/versions/RegionVersionVectorJUnitTest.java
 
b/geode-core/src/test/java/org/apache/geode/internal/cache/versions/RegionVersionVectorJUnitTest.java
index 17a6db1..b9d3cf6 100644
--- 
a/geode-core/src/test/java/org/apache/geode/internal/cache/versions/RegionVersionVectorJUnitTest.java
+++ 
b/geode-core/src/test/java/org/apache/geode/internal/cache/versions/RegionVersionVectorJUnitTest.java
@@ -15,23 +15,31 @@
 package org.apache.geode.internal.cache.versions;
 
 import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.DataInput;
 import java.io.DataInputStream;
+import java.io.DataOutput;
 import java.io.DataOutputStream;
+import java.io.IOException;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
 
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
-
+import org.junit.rules.ExpectedException;
 import org.apache.geode.DataSerializer;
+import org.apache.geode.InternalGemFireError;
 import 
org.apache.geode.distributed.internal.membership.InternalDistributedMember;
 import org.apache.geode.internal.HeapDataOutputStream;
 import org.apache.geode.internal.InternalDataSerializer;
 import org.apache.geode.internal.Version;
+import org.apache.geode.internal.cache.LocalRegion;
 import org.apache.geode.internal.cache.persistence.DiskStoreID;
 import org.apache.geode.test.dunit.NetworkUtils;
 import org.apache.geode.test.junit.categories.UnitTest;
@@ -39,6 +47,9 @@ import org.apache.geode.test.junit.categories.UnitTest;
 @Category(UnitTest.class)
 public class RegionVersionVectorJUnitTest {
 
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
   @Test
   public void testExceptionsWithContains() {
     DiskStoreID ownerId = new DiskStoreID(0, 0);
@@ -527,6 +538,61 @@ public class RegionVersionVectorJUnitTest {
     assertEquals("failed test for bug #48576", version, 
tag.getRegionVersion());
   }
 
+  @Test
+  public void testRecordVersionDuringRegionInit() {
+    LocalRegion mockRegion = mock(LocalRegion.class);
+    when(mockRegion.isInitialized()).thenReturn(false);
+    final String local = NetworkUtils.getIPLiteral();
+    InternalDistributedMember ownerId = new InternalDistributedMember(local, 
101);
+    VMVersionTag tag = new VMVersionTag();
+    tag.setRegionVersion(1L);
+
+    RegionVersionVector rvv = createRegionVersionVector(ownerId, mockRegion);
+    rvv.recordVersion(ownerId, tag);
+    assertEquals(1, rvv.getVersionForMember(ownerId));
+  }
+
+  @Test
+  public void testRecordVersionAfterRegionInitThrowsException() {
+    expectedException.expect(InternalGemFireError.class);
+    LocalRegion mockRegion = mock(LocalRegion.class);
+    when(mockRegion.isInitialized()).thenReturn(true);
+    final String local = NetworkUtils.getIPLiteral();
+    InternalDistributedMember ownerId = new InternalDistributedMember(local, 
101);
+    VMVersionTag tag = new VMVersionTag();
+    tag.setRegionVersion(1L);
+
+    RegionVersionVector rvv = createRegionVersionVector(ownerId, mockRegion);
+    rvv.recordVersion(ownerId, tag);
+  }
+
+  public RegionVersionVector 
createRegionVersionVector(InternalDistributedMember ownerId,
+      LocalRegion owner) {
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    RegionVersionVector rvv = new RegionVersionVector(ownerId, owner) {
+      @Override
+      public int getDSFID() {
+        return 0;
+      }
+
+      @Override
+      protected RegionVersionVector createCopy(VersionSource ownerId, 
ConcurrentHashMap vector,
+          long version, ConcurrentHashMap gcVersions, long gcVersion, boolean 
singleMember,
+          RegionVersionHolder clonedLocalHolder) {
+        return null;
+      }
+
+      @Override
+      protected void writeMember(VersionSource member, DataOutput out) throws 
IOException {}
+
+      @Override
+      protected VersionSource readMember(DataInput in) throws IOException, 
ClassNotFoundException {
+        return null;
+      }
+    };
+    return rvv;
+  }
+
   private void doExceptionsWithContains(DiskStoreID id, 
DiskRegionVersionVector rvv) {
     rvv.recordVersion(id, 10);
 

-- 
To stop receiving notification emails like this one, please contact
"commits@geode.apache.org" <commits@geode.apache.org>.

Reply via email to