geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dschnei...@apache.org
Subject [1/2] incubator-geode git commit: added more unit test coverage
Date Mon, 15 Aug 2016 23:27:43 GMT
Repository: incubator-geode
Updated Branches:
  refs/heads/feature/GEODE-1691 0151965d0 -> 707f841cc


added more unit test coverage


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

Branch: refs/heads/feature/GEODE-1691
Commit: 68488b69e2133346511298ff559dc8bc0acf8da4
Parents: 0151965
Author: Darrel Schneider <dschneider@pivotal.io>
Authored: Mon Aug 15 16:04:09 2016 -0700
Committer: Darrel Schneider <dschneider@pivotal.io>
Committed: Mon Aug 15 16:04:09 2016 -0700

----------------------------------------------------------------------
 .../internal/cache/EntryEventImplTest.java      | 245 +++++++++++++++++--
 1 file changed, 220 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/68488b69/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/EntryEventImplTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/EntryEventImplTest.java
b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/EntryEventImplTest.java
index 6ed271b..bc8a64e 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/EntryEventImplTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/EntryEventImplTest.java
@@ -16,7 +16,6 @@
  */
 package com.gemstone.gemfire.internal.cache;
 
-import static com.gemstone.gemfire.internal.offheap.annotations.OffHeapIdentifier.ENTRY_EVENT_NEW_VALUE;
 import static org.junit.Assert.*;
 import static org.mockito.Mockito.*;
 
@@ -29,11 +28,10 @@ import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
 import com.gemstone.gemfire.cache.Operation;
-import com.gemstone.gemfire.distributed.DistributedMember;
+import com.gemstone.gemfire.cache.SerializedCacheValue;
 import com.gemstone.gemfire.internal.cache.EntryEventImpl.NewValueImporter;
 import com.gemstone.gemfire.internal.cache.EntryEventImpl.OldValueImporter;
 import com.gemstone.gemfire.internal.offheap.StoredObject;
-import com.gemstone.gemfire.internal.offheap.annotations.Retained;
 import com.gemstone.gemfire.test.junit.categories.UnitTest;
 
 @Category(UnitTest.class)
@@ -375,15 +373,33 @@ public class EntryEventImplTest {
   }
 
   @Test
-  public void verifyGetNewValueBlocksRelease() throws InterruptedException {
+  public void verifyExternalReadMethodsBlockedByRelease() throws InterruptedException {
     LocalRegion region = mock(LocalRegion.class);
     StoredObject newValue = mock(StoredObject.class);
     when(newValue.hasRefCount()).thenReturn(true);
+    when(newValue.isSerialized()).thenReturn(true);
     when(newValue.retain()).thenReturn(true);
     when(newValue.getDeserializedValue(any(), any())).thenReturn("newValue");
+    final byte[] serializedNewValue = new byte[]{(byte)'n', (byte)'e', (byte)'w'};
+    when(newValue.getSerializedValue()).thenReturn(serializedNewValue);
+    StoredObject oldValue = mock(StoredObject.class);
+    when(oldValue.hasRefCount()).thenReturn(true);
+    when(oldValue.isSerialized()).thenReturn(true);
+    when(oldValue.retain()).thenReturn(true);
+    when(oldValue.getDeserializedValue(any(), any())).thenReturn("oldValue");
+    final byte[] serializedOldValue = new byte[]{(byte)'o', (byte)'l', (byte)'d'};
+    when(oldValue.getSerializedValue()).thenReturn(serializedOldValue);
     final CountDownLatch releaseCountDown = new CountDownLatch(1);
     final TestableEntryEventImpl e = new TestableEntryEventImpl(region, key, newValue, releaseCountDown);
+    e.setOldValue(oldValue);
     assertEquals("newValue", e.getNewValue());
+    assertEquals("oldValue", e.getOldValue());
+    final SerializedCacheValue<?> serializableNewValue = e.getSerializedNewValue();
+    assertEquals(serializedNewValue, serializableNewValue.getSerializedValue());
+    assertEquals("newValue", serializableNewValue.getDeserializedValue());
+    final SerializedCacheValue<?> serializableOldValue = e.getSerializedOldValue();
+    assertEquals(serializedOldValue, serializableOldValue.getSerializedValue());
+    assertEquals("oldValue", serializableOldValue.getDeserializedValue());
     Thread doRelease = new Thread(() -> {e.release();});
     doRelease.start(); // release thread will be stuck until releaseCountDown changes
     Awaitility.await().pollInterval(1, TimeUnit.MILLISECONDS).pollDelay(1, TimeUnit.MILLISECONDS).timeout(15,
TimeUnit.SECONDS)
@@ -394,33 +410,117 @@ public class EntryEventImplTest {
     // Now start a getNewValue. It should block on the release.
     Thread doGetNewValue = new Thread(() -> {e.getAndCacheNewValue();});
     doGetNewValue.start();
+    // Now start a getOldValue. It should block on the release.
+    Thread doGetOldValue = new Thread(() -> {e.getAndCacheOldValue();});
+    doGetOldValue.start();
+    // Now start a getSerializedValue on serializableNewValue. It should block on the release.
+    Thread doSNVgetSerializedValue = new Thread(() -> {e.getAndCacheSerializedNew(serializableNewValue);});
+    doSNVgetSerializedValue.start();
+    // Now start a getDeserializedValue on serializableNewValue. It should block on the release.
+    Thread doSNVgetDeserializedValue = new Thread(() -> {e.getAndCachDeserializedNew(serializableNewValue);});
+    doSNVgetDeserializedValue.start();
+    // Now start a getSerializedValue on serializableOldValue. It should block on the release.
+    Thread doSOVgetSerializedValue = new Thread(() -> {e.getAndCacheSerializedOld(serializableOldValue);});
+    doSOVgetSerializedValue.start();
+    // Now start a getDeserializedValue on serializableOldValue. It should block on the release.
+    Thread doSOVgetDeserializedValue = new Thread(() -> {e.getAndCachDeserializedOld(serializableOldValue);});
+    doSOVgetDeserializedValue.start();
+    
     Awaitility.await().pollInterval(1, TimeUnit.MILLISECONDS).pollDelay(1, TimeUnit.MILLISECONDS).timeout(15,
TimeUnit.SECONDS)
-    .until(() -> assertEquals(true, e.isAboutToCall()));
-    // it should now be hung in getNewValue; so just wait for a little bit for it to finish
+    .until(() -> assertEquals(true, e.isAboutToCallGetNewValue() && e.isAboutToCallGetOldValue()
+        && e.isAboutToCallSerializedNew() && e.isAboutToCallDeserializedNew()
+        && e.isAboutToCallSerializedOld() && e.isAboutToCallDeserializedOld()
+        ));
+    // all the threads should now be hung waiting on release; so just wait for a little bit
for it to improperly finish
     doGetNewValue.join(50);
-    if (e.hasFinishedCall()) {
-      fail("expected doGetNewValue thread to be hung. It completed with " + e.getCachedValue());
+    if (e.hasFinishedCallOfGetNewValue()) {
+      fail("expected doGetNewValue thread to be hung. It completed with " + e.getCachedNewValue());
+    }
+    if (e.hasFinishedCallOfGetOldValue()) {
+      fail("expected doGetOldValue thread to be hung. It completed with " + e.getCachedOldValue());
+    }
+    if (e.hasFinishedCallOfSerializedNew()) {
+      fail("expected doSNVgetSerializedValue thread to be hung. It completed with " + e.getTestCachedSerializedNew());
+    }
+    if (e.hasFinishedCallOfDeserializedNew()) {
+      fail("expected doSNVgetDeserializedValue thread to be hung. It completed with " + e.getCachedDeserializedNew());
     }
-    // now signal the release to go ahead
+    if (e.hasFinishedCallOfSerializedOld()) {
+      fail("expected doSOVgetSerializedValue thread to be hung. It completed with " + e.getCachedSerializedOld());
+    }
+    if (e.hasFinishedCallOfDeserializedOld()) {
+      fail("expected doSOVgetDeserializedValue thread to be hung. It completed with " + e.getCachedDeserializedOld());
+    }
+   // now signal the release to go ahead
     releaseCountDown.countDown();
     doRelease.join();
     assertEquals(false, e.offHeapOk);
     // which should allow getNewValue to complete
     Awaitility.await().pollInterval(1, TimeUnit.MILLISECONDS).pollDelay(1, TimeUnit.MILLISECONDS).timeout(15,
TimeUnit.SECONDS)
-    .until(() -> assertEquals(true, e.hasFinishedCall()));
+    .until(() -> assertEquals(true, e.hasFinishedCallOfGetNewValue()));
     doGetNewValue.join();
-    if (!(e.getCachedValue() instanceof IllegalStateException)) {
+    if (!(e.getCachedNewValue() instanceof IllegalStateException)) {
       // since the release happened before getNewValue we expect it to get an exception
-      fail("unexpected success of getNewValue. It returned " + e.getCachedValue());
+      fail("unexpected success of getNewValue. It returned " + e.getCachedNewValue());
+    }
+    // which should allow getOldValue to complete
+    Awaitility.await().pollInterval(1, TimeUnit.MILLISECONDS).pollDelay(1, TimeUnit.MILLISECONDS).timeout(15,
TimeUnit.SECONDS)
+    .until(() -> assertEquals(true, e.hasFinishedCallOfGetOldValue()));
+    doGetOldValue.join();
+    if (!(e.getCachedOldValue() instanceof IllegalStateException)) {
+      fail("unexpected success of getOldValue. It returned " + e.getCachedOldValue());
+    }
+    // which should allow doSNVgetSerializedValue to complete
+    Awaitility.await().pollInterval(1, TimeUnit.MILLISECONDS).pollDelay(1, TimeUnit.MILLISECONDS).timeout(15,
TimeUnit.SECONDS)
+    .until(() -> assertEquals(true, e.hasFinishedCallOfSerializedNew()));
+    doSNVgetSerializedValue.join();
+    if (!(e.getTestCachedSerializedNew() instanceof IllegalStateException)) {
+      fail("unexpected success of new getSerializedValue. It returned " + e.getTestCachedSerializedNew());
+    }
+    // which should allow doSNVgetDeserializedValue to complete
+    Awaitility.await().pollInterval(1, TimeUnit.MILLISECONDS).pollDelay(1, TimeUnit.MILLISECONDS).timeout(15,
TimeUnit.SECONDS)
+    .until(() -> assertEquals(true, e.hasFinishedCallOfDeserializedNew()));
+    doSNVgetDeserializedValue.join();
+    if (!(e.getCachedDeserializedNew() instanceof IllegalStateException)) {
+      fail("unexpected success of new getDeserializedValue. It returned " + e.getCachedDeserializedNew());
+    }
+    // which should allow doSOVgetSerializedValue to complete
+    Awaitility.await().pollInterval(1, TimeUnit.MILLISECONDS).pollDelay(1, TimeUnit.MILLISECONDS).timeout(15,
TimeUnit.SECONDS)
+    .until(() -> assertEquals(true, e.hasFinishedCallOfSerializedOld()));
+    doSOVgetSerializedValue.join();
+    if (!(e.getCachedSerializedOld() instanceof IllegalStateException)) {
+      fail("unexpected success of old getSerializedValue. It returned " + e.getCachedSerializedOld());
+    }
+    // which should allow doSOVgetDeserializedValue to complete
+    Awaitility.await().pollInterval(1, TimeUnit.MILLISECONDS).pollDelay(1, TimeUnit.MILLISECONDS).timeout(15,
TimeUnit.SECONDS)
+    .until(() -> assertEquals(true, e.hasFinishedCallOfDeserializedOld()));
+    doSOVgetDeserializedValue.join();
+    if (!(e.getCachedDeserializedOld() instanceof IllegalStateException)) {
+      fail("unexpected success of old getDeserializedValue. It returned " + e.getCachedDeserializedOld());
     }
   }
 
   private static class TestableEntryEventImpl extends EntryEventImpl {
     private final CountDownLatch releaseCountDown;
     private volatile boolean waitingOnRelease = false;
-    private volatile boolean aboutToCall = false;
-    private volatile boolean finishedCall = false;
-    private volatile Object cachedValue = null;
+    private volatile boolean aboutToCallGetNewValue = false;
+    private volatile boolean finishedCallOfGetNewValue = false;
+    private volatile Object cachedNewValue = null;
+    private volatile boolean aboutToCallGetOldValue = false;
+    private volatile boolean finishedCallOfGetOldValue = false;
+    private volatile Object cachedOldValue = null;
+    private volatile boolean aboutToCallSerializedNew = false;
+    private volatile Object testCachedSerializedNew = null;
+    private volatile boolean finishedCallOfSerializedNew = false;
+    private volatile boolean aboutToCallDeserializedNew = false;
+    private volatile Object cachedDeserializedNew = null;
+    private volatile boolean finishedCallOfDeserializedNew = false;
+    private volatile boolean aboutToCallSerializedOld = false;
+    private volatile Object cachedSerializedOld = null;
+    private volatile boolean finishedCallOfSerializedOld = false;
+    private volatile boolean aboutToCallDeserializedOld = false;
+    private volatile Object cachedDeserializedOld = null;
+    private volatile boolean finishedCallOfDeserializedOld = false;
     
     public TestableEntryEventImpl(LocalRegion region, Object key,
         Object newValue, CountDownLatch releaseCountDown) {
@@ -428,27 +528,122 @@ public class EntryEventImplTest {
       callbacksInvoked(true);
       this.releaseCountDown = releaseCountDown;
     }
-    public Object getCachedValue() {
-      return this.cachedValue;
+    public Object getCachedDeserializedOld() {
+      return this.cachedDeserializedOld;
+    }
+    public boolean hasFinishedCallOfDeserializedOld() {
+      return this.finishedCallOfDeserializedOld;
+    }
+    public Object getCachedSerializedOld() {
+      return this.cachedSerializedOld;
+    }
+    public boolean hasFinishedCallOfSerializedOld() {
+      return this.finishedCallOfSerializedOld;
+    }
+    public Object getCachedDeserializedNew() {
+      return this.cachedDeserializedNew;
+    }
+    public Object getTestCachedSerializedNew() {
+      return this.testCachedSerializedNew;
+    }
+    public boolean hasFinishedCallOfDeserializedNew() {
+      return this.finishedCallOfDeserializedNew;
+    }
+    public boolean hasFinishedCallOfSerializedNew() {
+      return this.finishedCallOfSerializedNew;
+    }
+    public boolean isAboutToCallDeserializedOld() {
+      return this.aboutToCallDeserializedOld;
+    }
+    public boolean isAboutToCallSerializedOld() {
+      return this.aboutToCallSerializedOld;
+    }
+    public boolean isAboutToCallDeserializedNew() {
+      return this.aboutToCallDeserializedNew;
+    }
+    public boolean isAboutToCallSerializedNew() {
+      return this.aboutToCallSerializedNew;
+    }
+    public void getAndCachDeserializedOld(SerializedCacheValue<?> serializableOldValue)
{
+      try {
+        this.aboutToCallDeserializedOld = true;
+        this.cachedDeserializedOld = serializableOldValue.getDeserializedValue();
+      } catch (IllegalStateException ex) {
+        this.cachedDeserializedOld = ex;
+      } finally {
+        this.finishedCallOfDeserializedOld = true;
+      }
+    }
+    public void getAndCacheSerializedOld(SerializedCacheValue<?> serializableOldValue)
{
+      try {
+        this.aboutToCallSerializedOld = true;
+        this.cachedSerializedOld = serializableOldValue.getSerializedValue();
+      } catch (IllegalStateException ex) {
+        this.cachedSerializedOld = ex;
+      } finally {
+        this.finishedCallOfSerializedOld = true;
+      }
+    }
+    public void getAndCachDeserializedNew(SerializedCacheValue<?> serializableNewValue)
{
+      try {
+        this.aboutToCallDeserializedNew = true;
+        this.cachedDeserializedNew = serializableNewValue.getDeserializedValue();
+      } catch (IllegalStateException ex) {
+        this.cachedDeserializedNew = ex;
+      } finally {
+        this.finishedCallOfDeserializedNew = true;
+      }
+    }
+    public void getAndCacheSerializedNew(SerializedCacheValue<?> serializableNewValue)
{
+      try {
+        this.aboutToCallSerializedNew = true;
+        this.testCachedSerializedNew = serializableNewValue.getSerializedValue();
+      } catch (IllegalStateException ex) {
+        this.testCachedSerializedNew = ex;
+      } finally {
+        this.finishedCallOfSerializedNew = true;
+      }
+    }
+    public Object getCachedNewValue() {
+      return this.cachedNewValue;
     }
     public void getAndCacheNewValue() {
       try {
-        this.aboutToCall = true;
-        this.cachedValue = getNewValue();
+        this.aboutToCallGetNewValue = true;
+        this.cachedNewValue = getNewValue();
       } catch (IllegalStateException ex) {
-        this.cachedValue = ex;
+        this.cachedNewValue = ex;
       } finally {
-        this.finishedCall = true;
+        this.finishedCallOfGetNewValue = true;
+      }
+    }
+    public Object getCachedOldValue() {
+      return this.cachedOldValue;
+    }
+    public void getAndCacheOldValue() {
+      try {
+        this.aboutToCallGetOldValue = true;
+        this.cachedOldValue = getOldValue();
+      } catch (IllegalStateException ex) {
+        this.cachedOldValue = ex;
+      } finally {
+        this.finishedCallOfGetOldValue = true;
       }
     }
     public boolean isWaitingOnRelease() {
       return this.waitingOnRelease;
     }
-    public boolean isAboutToCall() {
-      return this.aboutToCall;
+    public boolean isAboutToCallGetNewValue() {
+      return this.aboutToCallGetNewValue;
+    }
+    public boolean hasFinishedCallOfGetNewValue() {
+      return this.finishedCallOfGetNewValue;
+    }
+    public boolean isAboutToCallGetOldValue() {
+      return this.aboutToCallGetOldValue;
     }
-    public boolean hasFinishedCall() {
-      return this.finishedCall;
+    public boolean hasFinishedCallOfGetOldValue() {
+      return this.finishedCallOfGetOldValue;
     }
     @Override
     void testHookReleaseInProgress() {


Mime
View raw message