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 2016/07/01 22:05:05 UTC

[1/2] incubator-geode git commit: improved tombstone unit test

Repository: incubator-geode
Updated Branches:
  refs/heads/feature/GEODE-1420 7c325a156 -> bb07a2933


improved tombstone unit test


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

Branch: refs/heads/feature/GEODE-1420
Commit: ecf6c1bbad1d3d38498bb8b308fad5c406f916c3
Parents: 7c325a1
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Fri Jul 1 11:13:15 2016 -0700
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Fri Jul 1 11:13:15 2016 -0700

----------------------------------------------------------------------
 .../internal/cache/TombstoneService.java        | 17 +++++-
 .../gemfire/cache30/MultiVMRegionTestCase.java  | 55 +++++++++++++-------
 2 files changed, 51 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ecf6c1bb/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/TombstoneService.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/TombstoneService.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/TombstoneService.java
index 3e92c16..b322371 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/TombstoneService.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/TombstoneService.java
@@ -187,6 +187,13 @@ public class TombstoneService {
     return replicatedTombstoneSweeper.decrementGCBlockCount();
   }
   
+  public long getScheduledTombstoneCount() {
+    long result = 0;
+    result += replicatedTombstoneSweeper.getScheduledTombstoneCount();
+    result += nonReplicatedTombstoneSweeper.getScheduledTombstoneCount();
+    return result;
+  }
+  
   /**
    * remove tombstones from the given region that have region-versions <= those in the given removal map
    * @return a collection of keys removed (only if the region is a bucket - empty otherwise)
@@ -642,7 +649,7 @@ public class TombstoneService {
     }
     @Override
     public String toString() {
-      return getQueue().toString() + " expired batch size = " + expiredTombstones.size();
+      return getQueue().toString() + " batchedExpiredTombstones = " + expiredTombstones.toString();
     }
 
     @Override
@@ -668,6 +675,10 @@ public class TombstoneService {
     protected void beforeSleepChecks() {
       testHookIfIdleExpireBatch();
     }
+    @Override
+    public long getScheduledTombstoneCount() {
+      return super.getScheduledTombstoneCount() + this.expiredTombstones.size();
+    }
   }
   
   private static abstract class TombstoneSweeper implements Runnable {
@@ -951,6 +962,10 @@ public class TombstoneService {
         unlockQueueHead();
       }
     }
+    
+    public long getScheduledTombstoneCount() {
+      return getQueue().size();
+    }
 
     /**
      * For each expired tombstone this sweeper knows about call the predicate.

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ecf6c1bb/geode-core/src/test/java/com/gemstone/gemfire/cache30/MultiVMRegionTestCase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/cache30/MultiVMRegionTestCase.java b/geode-core/src/test/java/com/gemstone/gemfire/cache30/MultiVMRegionTestCase.java
index dc42d97..b6e89b3 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/cache30/MultiVMRegionTestCase.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/cache30/MultiVMRegionTestCase.java
@@ -8626,11 +8626,11 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
             @Override
             public String description() {
               return "Waiting for all tombstones to expire.  There are now " + CCRegion.getTombstoneCount()
-              + " tombstones left out of " + count + " initial tombstones";
+              + " tombstones left out of " + count + " initial tombstones. " + CCRegion.getCache().getTombstoneService();
             }
           };
           try {
-            Wait.waitForCriterion(waitForExpiration, TombstoneService.REPLICATE_TOMBSTONE_TIMEOUT+10000, 1000, true);
+            Wait.waitForCriterion(waitForExpiration, TombstoneService.REPLICATE_TOMBSTONE_TIMEOUT+10000, 100, true);
           } catch (AssertionError e) {
             CCRegion.dumpBackingMap();
             com.gemstone.gemfire.test.dunit.LogWriterUtils.getLogWriter().info("tombstone service state: " + CCRegion.getCache().getTombstoneService());
@@ -8639,11 +8639,6 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
         }
       });
 
-      // Now check to see if tombstones are resurrected by a put/create.
-      // The entries should be created okay and the callback should be afterCreate.
-      // The tombstone count won't go down until the entries are swept, but then
-      // the count should fall to zero.
-
       vm0.invoke(new SerializableRunnable("create/destroy entries and check tombstone count") {
         @Override
         public void run() {
@@ -8658,10 +8653,10 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
               @Override
               public String description() {
                 return "Waiting for all tombstones to expire.  There are now " + CCRegion.getTombstoneCount()
-                  + " tombstones left out of " + origCount + " initial tombstones";
+                  + " tombstones left out of " + origCount + " initial tombstones. " + CCRegion.getCache().getTombstoneService();
               }
             };
-            Wait.waitForCriterion(waitForExpiration, TombstoneService.REPLICATE_TOMBSTONE_TIMEOUT+10000, 1000, true);
+            Wait.waitForCriterion(waitForExpiration, TombstoneService.REPLICATE_TOMBSTONE_TIMEOUT+10000, 100, true);
             logger.debug("creating tombstones.  current count={}", CCRegion.getTombstoneCount());
             for (int i=0; i<numEntries; i++) {
               CCRegion.create("cckey" + i, i);
@@ -8669,7 +8664,7 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
             }
             logger.debug("done creating tombstones.  current count={}", CCRegion.getTombstoneCount());
             count = CCRegion.getTombstoneCount();
-            assertEquals("expected "+numEntries+" tombstones", numEntries, count);
+            assertEquals(numEntries, count);
             assertEquals(0, CCRegion.size());
             afterCreates = 0;
             AttributesMutator m = CCRegion.getAttributesMutator();
@@ -8695,8 +8690,7 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
       vm1.invoke(new SerializableRunnable("check tombstone count and install listener") {
         @Override
         public void run() {
-          long count = CCRegion.getTombstoneCount();
-          assertEquals("expected ten tombstones", numEntries, count);
+          assertEquals(numEntries, CCRegion.getTombstoneCount());
           afterCreates = 0;
           AttributesMutator m = CCRegion.getAttributesMutator();
           m.addCacheListener(new CacheListenerAdapter() {
@@ -8707,6 +8701,11 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
           });
         }});
 
+      // Now check to see if tombstones are resurrected by a create.
+      // The entries should be created okay and the callback should be afterCreate.
+      // The tombstone count won't go down until the entries are swept, but then
+      // the count should fall to zero.
+
       vm0.invoke(new SerializableRunnable("create entries and check afterCreate and tombstone count") {
         @Override
         public void run() {
@@ -8721,6 +8720,18 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
             if (CCRegion.getScope().isDistributedNoAck()) {
               sendSerialMessageToAll(); // flush the ops
             }
+            WaitCriterion waitForExpiration = new WaitCriterion() {
+              @Override
+              public boolean done() {
+                return CCRegion.getCache().getTombstoneService().getScheduledTombstoneCount() ==  0;
+              }
+              @Override
+              public String description() {
+                return "Waiting for all scheduled tombstones to be removed.  There are now " + CCRegion.getCache().getTombstoneService().getScheduledTombstoneCount()
+                  + " tombstones left out of " + numEntries + " initial tombstones. " + CCRegion.getCache().getTombstoneService();
+              }
+            };
+            Wait.waitForCriterion(waitForExpiration, 10000, 100, true);
           } catch (CacheException e) {
             fail("while performing create operations", e);
           }
@@ -8734,17 +8745,21 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
           assertEquals("expected zero tombstones", 0, count);
           assertEquals("expected "+numEntries+" afterCreates", numEntries, afterCreates);
           assertEquals(numEntries, CCRegion.size());
+          WaitCriterion waitForExpiration = new WaitCriterion() {
+            @Override
+            public boolean done() {
+              return CCRegion.getCache().getTombstoneService().getScheduledTombstoneCount() ==  0;
+            }
+            @Override
+            public String description() {
+              return "Waiting for all scheduled tombstones to be removed.  There are now " + CCRegion.getCache().getTombstoneService().getScheduledTombstoneCount()
+                + " tombstones left out of " + numEntries + " initial tombstones. " + CCRegion.getCache().getTombstoneService();
+            }
+          };
+          Wait.waitForCriterion(waitForExpiration, 10000, 100, true);
         }
       });
 
-      vm0.invoke(new SerializableRunnable("check region size and tombstone count") {
-        @Override
-        public void run() {
-          long count = CCRegion.getTombstoneCount();
-          assertEquals("expected all tombstones to be expired", 0, count);
-          assertEquals(numEntries, CCRegion.size());
-        }
-      });
     } finally {
       SerializableRunnable resetTimeout = new SerializableRunnable() {
         @Override


[2/2] incubator-geode git commit: improved unit test assertions to provide more info when they fail

Posted by ds...@apache.org.
improved unit test assertions to provide more info when they fail


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

Branch: refs/heads/feature/GEODE-1420
Commit: bb07a2933af5c93a3133c6bb1e27901fc4be4f10
Parents: ecf6c1b
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Fri Jul 1 14:58:12 2016 -0700
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Fri Jul 1 14:58:12 2016 -0700

----------------------------------------------------------------------
 .../internal/cache/TombstoneService.java        | 11 ++++----
 .../gemfire/cache30/MultiVMRegionTestCase.java  | 29 ++++++++++----------
 2 files changed, 21 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bb07a293/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/TombstoneService.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/TombstoneService.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/TombstoneService.java
index b322371..2813864 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/TombstoneService.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/TombstoneService.java
@@ -370,10 +370,6 @@ public class TombstoneService {
       tombstone.region.getRegionMap().removeTombstone(tombstone.entry, tombstone, false, true);
     }
     @Override
-    public String toString() {
-      return getQueue().toString();
-    }
-    @Override
     protected void checkExpiredTombstones() {
     }
     @Override
@@ -649,7 +645,7 @@ public class TombstoneService {
     }
     @Override
     public String toString() {
-      return getQueue().toString() + " batchedExpiredTombstones = " + expiredTombstones.toString();
+      return super.toString() + " batchedExpiredTombstones[" + expiredTombstones.size() + "] = " + expiredTombstones.toString();
     }
 
     @Override
@@ -966,6 +962,11 @@ public class TombstoneService {
     public long getScheduledTombstoneCount() {
       return getQueue().size();
     }
+    
+    @Override
+    public String toString() {
+      return "[" + getQueue().size() + "] " + getQueue().toString();
+    }
 
     /**
      * For each expired tombstone this sweeper knows about call the predicate.

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bb07a293/geode-core/src/test/java/com/gemstone/gemfire/cache30/MultiVMRegionTestCase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/cache30/MultiVMRegionTestCase.java b/geode-core/src/test/java/com/gemstone/gemfire/cache30/MultiVMRegionTestCase.java
index b6e89b3..bf68610 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/cache30/MultiVMRegionTestCase.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/cache30/MultiVMRegionTestCase.java
@@ -8542,6 +8542,13 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
     vm3.invoke(() -> this.assertNoClearTimeouts());
   }
   
+  private void checkCCRegionTombstoneCount(String msg, int expected) {
+    int actual = CCRegion.getTombstoneCount();
+    if (expected != actual) {
+      assertEquals(msg + " region tombstone count was " + actual + " expected=" + expected + " TombstoneService=" + CCRegion.getCache().getTombstoneService(),
+          expected, actual);
+    }
+  }
   public void versionTestTombstones() {
     disconnectAllFromDS();
     Host host = Host.getHost(0);
@@ -8601,8 +8608,7 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
               assertTrue("entry should not exist", !CCRegion.containsKey("cckey"+i));
               assertTrue("entry should not contain a value", !CCRegion.containsValueForKey("cckey"+i));
             }
-            long count = CCRegion.getTombstoneCount();
-            assertEquals("expected "+numEntries+" tombstones", numEntries, count);
+            checkCCRegionTombstoneCount("after destroys in this vm ", numEntries);
             assertTrue("region should not contain a tombstone", !CCRegion.containsValue(Token.TOMBSTONE));
             if (CCRegion.getScope().isDistributedNoAck()) {
               sendSerialMessageToAll(); // flush the ops
@@ -8616,8 +8622,7 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
       vm1.invoke(new SerializableRunnable("check tombstone count(2)") {
         @Override
         public void run() {
-          final long count = CCRegion.getTombstoneCount();
-          assertEquals("expected "+numEntries+" tombstones", numEntries, count);
+          checkCCRegionTombstoneCount("after destroys in other vm ", numEntries);
           WaitCriterion waitForExpiration = new WaitCriterion() {
             @Override
             public boolean done() {
@@ -8626,7 +8631,7 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
             @Override
             public String description() {
               return "Waiting for all tombstones to expire.  There are now " + CCRegion.getTombstoneCount()
-              + " tombstones left out of " + count + " initial tombstones. " + CCRegion.getCache().getTombstoneService();
+              + " tombstones left out of " + numEntries + " initial tombstones. " + CCRegion.getCache().getTombstoneService();
             }
           };
           try {
@@ -8642,8 +8647,7 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
       vm0.invoke(new SerializableRunnable("create/destroy entries and check tombstone count") {
         @Override
         public void run() {
-          long count = CCRegion.getTombstoneCount();
-          final long origCount = count;
+          final int origCount = CCRegion.getTombstoneCount();
           try {
             WaitCriterion waitForExpiration = new WaitCriterion() {
               @Override
@@ -8663,8 +8667,7 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
               CCRegion.destroy("cckey" + i);
             }
             logger.debug("done creating tombstones.  current count={}", CCRegion.getTombstoneCount());
-            count = CCRegion.getTombstoneCount();
-            assertEquals(numEntries, count);
+            checkCCRegionTombstoneCount("after create+destroy in this vm ", numEntries);
             assertEquals(0, CCRegion.size());
             afterCreates = 0;
             AttributesMutator m = CCRegion.getAttributesMutator();
@@ -8690,7 +8693,7 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
       vm1.invoke(new SerializableRunnable("check tombstone count and install listener") {
         @Override
         public void run() {
-          assertEquals(numEntries, CCRegion.getTombstoneCount());
+          checkCCRegionTombstoneCount("after create+destroy in other vm ", numEntries);
           afterCreates = 0;
           AttributesMutator m = CCRegion.getAttributesMutator();
           m.addCacheListener(new CacheListenerAdapter() {
@@ -8713,8 +8716,7 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
             for (int i=0; i<numEntries; i++) {
               CCRegion.create("cckey" + i, i);
             }
-            long count = CCRegion.getTombstoneCount();
-            assertEquals("expected zero tombstones", 0, count);
+            checkCCRegionTombstoneCount("after create in this vm", 0);
             assertEquals("expected "+numEntries+" afterCreates", numEntries, afterCreates);
             assertEquals(numEntries, CCRegion.size());
             if (CCRegion.getScope().isDistributedNoAck()) {
@@ -8741,8 +8743,7 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
       vm1.invoke(new SerializableRunnable("check afterCreate and tombstone count") {
         @Override
         public void run() {
-          long count = CCRegion.getTombstoneCount();
-          assertEquals("expected zero tombstones", 0, count);
+          checkCCRegionTombstoneCount("after create in other vm", 0);
           assertEquals("expected "+numEntries+" afterCreates", numEntries, afterCreates);
           assertEquals(numEntries, CCRegion.size());
           WaitCriterion waitForExpiration = new WaitCriterion() {