geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dschnei...@apache.org
Subject [05/35] incubator-geode git commit: GEODE-361: fix expiry races in unit test
Date Tue, 03 Nov 2015 19:38:37 GMT
GEODE-361: fix expiry races in unit test

The test now uses WaitCriterion when waiting
for an expiration. Also it now configures
millisecond expiry so the test runs faster.


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

Branch: refs/heads/develop
Commit: 5cf63899ca5270d736339e1ad1192751a97cf66c
Parents: 82966c4
Author: Darrel Schneider <dschneider@pivotal.io>
Authored: Mon Oct 26 16:01:01 2015 -0700
Committer: Darrel Schneider <dschneider@pivotal.io>
Committed: Mon Oct 26 16:02:10 2015 -0700

----------------------------------------------------------------------
 .../gemstone/gemfire/cache30/CacheTestCase.java | 10 +++
 .../cache30/RegionReliabilityTestCase.java      | 84 ++++++++++++--------
 2 files changed, 60 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5cf63899/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheTestCase.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheTestCase.java b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheTestCase.java
index 3ef9c27..23bb89d 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheTestCase.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheTestCase.java
@@ -551,6 +551,16 @@ public abstract class CacheTestCase extends DistributedTestCase {
   throws RegionExistsException, TimeoutException {
     return getCache().createRegion(rootName, attrs);
   }
+  public final Region createExpiryRootRegion(String rootName, RegionAttributes attrs)
+  throws RegionExistsException, TimeoutException {
+    System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
+    try {
+      return createRootRegion(rootName, attrs);
+    } finally {
+      System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
+    }
+  }
+
 
   /**
    * send an unordered message requiring an ack to all connected members 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5cf63899/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionReliabilityTestCase.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionReliabilityTestCase.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionReliabilityTestCase.java
index 1f89bd2..f197425 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionReliabilityTestCase.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionReliabilityTestCase.java
@@ -26,7 +26,9 @@ import com.gemstone.gemfire.distributed.internal.membership.*;
 import com.gemstone.gemfire.internal.cache.*;
 
 import java.util.concurrent.locks.Lock;
+
 import dunit.*;
+import dunit.DistributedTestCase.WaitCriterion;
 
 import java.io.*;
 import java.util.*;
@@ -526,7 +528,7 @@ public abstract class RegionReliabilityTestCase extends ReliabilityTestCase
{
     fac.setScope(getRegionScope());
     fac.setStatisticsEnabled(true);
     RegionAttributes attr = fac.create();
-    Region region = createRootRegion(name, attr);
+    final Region region = createExpiryRootRegion(name, attr);
     
     // wait for memberTimeout to expire
     waitForMemberTimeout();
@@ -557,7 +559,7 @@ public abstract class RegionReliabilityTestCase extends ReliabilityTestCase
{
     AttributesMutator mutator = region.getAttributesMutator();
     mutator.setEntryTimeToLive(
       new ExpirationAttributes(1, ExpirationAction.LOCAL_DESTROY));
-    sleep(2000);
+    sleep(200);
 
     // make sure no values were expired
     Set entries = ((LocalRegion) region).basicEntries(false);
@@ -573,10 +575,7 @@ public abstract class RegionReliabilityTestCase extends ReliabilityTestCase
{
       }
     });
     
-    // sleep and make sure value expires
-    sleep(2000);
-    assertEquals(null, region.get("expireMe"));
-    assertTrue(region.size() == 0);
+    waitForEntryDestroy(region, "expireMe");
   }
   
   /**
@@ -610,7 +609,7 @@ public abstract class RegionReliabilityTestCase extends ReliabilityTestCase
{
     fac.setScope(getRegionScope());
     fac.setStatisticsEnabled(true);
     RegionAttributes attr = fac.create();
-    Region region = createRootRegion(name, attr);
+    final Region region = createExpiryRootRegion(name, attr);
     
     // wait for memberTimeout to expire
     waitForMemberTimeout();
@@ -620,7 +619,7 @@ public abstract class RegionReliabilityTestCase extends ReliabilityTestCase
{
       new ExpirationAttributes(1, ExpirationAction.LOCAL_DESTROY));
       
     // sleep and make sure region does not expire
-    sleep(2000);
+    sleep(200);
     assertFalse(region.isDestroyed());
     
     // create region in vm1
@@ -634,9 +633,7 @@ public abstract class RegionReliabilityTestCase extends ReliabilityTestCase
{
       }
     });
     
-    // sleep and make sure region expires
-    sleep(2000);
-    assertTrue(region.isDestroyed());
+    waitForRegionDestroy(region);
   }
   
   /**
@@ -753,8 +750,8 @@ public abstract class RegionReliabilityTestCase extends ReliabilityTestCase
{
     fac.setScope(getRegionScope());
     fac.setStatisticsEnabled(true);
     RegionAttributes attr = fac.create();
-    Region region = createRootRegion(name, attr);
-    
+    final Region region = createExpiryRootRegion(name, attr);
+     
     // wait for memberTimeout to expire
     waitForMemberTimeout();
 
@@ -784,12 +781,16 @@ public abstract class RegionReliabilityTestCase extends ReliabilityTestCase
{
     AttributesMutator mutator = region.getAttributesMutator();
     mutator.setEntryTimeToLive(
       new ExpirationAttributes(1, ExpirationAction.LOCAL_DESTROY));
-    sleep(2000);
+    WaitCriterion wc1 = new WaitCriterion() {
+      public boolean done() {
+        return ((LocalRegion) region).basicEntries(false).size() == 0;
+      }
+      public String description() {
+        return "expected zero entries but have " + ((LocalRegion) region).basicEntries(false).size();
+      }
+    };
+    DistributedTestCase.waitForCriterion(wc1, 30*1000, 10, true);
 
-    // make sure values was expired
-    Set entries = ((LocalRegion) region).basicEntries(false);
-    assertTrue(entries.size() == 0);
-    
     // create region again
     Host.getHost(0).getVM(1).invoke(new CacheSerializableRunnable("Create Region") {
       public void run2() throws CacheException {
@@ -801,11 +802,8 @@ public abstract class RegionReliabilityTestCase extends ReliabilityTestCase
{
     });
     
     region.put("expireMe", "expireMe");
-    assertTrue(region.size() == 1);
     
-    // sleep and make sure value expires again
-    sleep(2000);
-    assertEquals(null, region.get("expireMe"));
+    waitForEntryDestroy(region, "expireMe");
     assertTrue(region.size() == 0);
   }
   
@@ -840,7 +838,7 @@ public abstract class RegionReliabilityTestCase extends ReliabilityTestCase
{
     fac.setScope(getRegionScope());
     fac.setStatisticsEnabled(true);
     RegionAttributes attr = fac.create();
-    Region region = createRootRegion(name, attr);
+    final Region region = createExpiryRootRegion(name, attr);
     
     // wait for memberTimeout to expire
     waitForMemberTimeout();
@@ -849,9 +847,7 @@ public abstract class RegionReliabilityTestCase extends ReliabilityTestCase
{
     mutator.setRegionTimeToLive(
       new ExpirationAttributes(1, ExpirationAction.LOCAL_DESTROY));
       
-    // sleep and make sure region does expire
-    sleep(2000);
-    assertTrue(region.isDestroyed());
+    waitForRegionDestroy(region);
   }
   
   /**
@@ -948,7 +944,7 @@ public abstract class RegionReliabilityTestCase extends ReliabilityTestCase
{
     fac.setScope(getRegionScope());
     fac.setStatisticsEnabled(true);
     RegionAttributes attr = fac.create();
-    Region region = createRootRegion(name, attr);
+    final Region region = createExpiryRootRegion(name, attr);
     
     // wait for memberTimeout to expire
     waitForMemberTimeout();
@@ -961,13 +957,35 @@ public abstract class RegionReliabilityTestCase extends ReliabilityTestCase
{
     AttributesMutator mutator = region.getAttributesMutator();
     mutator.setEntryTimeToLive(
       new ExpirationAttributes(1, ExpirationAction.LOCAL_DESTROY));
-    sleep(2000);
 
-    // make sure value was expired
-    assertNull(region.get("expireMe"));
+    waitForEntryDestroy(region, "expireMe");
     assertTrue(region.size() == 0);
   }
   
+  public static void waitForRegionDestroy(final Region region) {
+    WaitCriterion wc = new WaitCriterion() {
+      public boolean done() {
+        return region.isDestroyed();
+      }
+      public String description() {
+        return "expected region " + region + " to be destroyed";
+      }
+    };
+    DistributedTestCase.waitForCriterion(wc, 30*1000, 10, true);
+  }
+  
+  public static void waitForEntryDestroy(final Region region, final Object key) {
+    WaitCriterion wc = new WaitCriterion() {
+      public boolean done() {
+        return region.get(key) == null;
+      }
+      public String description() {
+        return "expected entry " + key + " to not exist but it has the value " + region.get(key);
+      }
+    };
+    DistributedTestCase.waitForCriterion(wc, 30*1000, 10, true);
+  }
+  
   /**
    * Tests affect of FULL_ACCESS on local region expiration actions.
    */
@@ -998,7 +1016,7 @@ public abstract class RegionReliabilityTestCase extends ReliabilityTestCase
{
     fac.setScope(getRegionScope());
     fac.setStatisticsEnabled(true);
     RegionAttributes attr = fac.create();
-    Region region = createRootRegion(name, attr);
+    final Region region = createExpiryRootRegion(name, attr);
     
     // wait for memberTimeout to expire
     waitForMemberTimeout();
@@ -1007,9 +1025,7 @@ public abstract class RegionReliabilityTestCase extends ReliabilityTestCase
{
     mutator.setRegionTimeToLive(
       new ExpirationAttributes(1, ExpirationAction.LOCAL_DESTROY));
       
-    // sleep and make sure region does expire
-    sleep(2000);
-    assertTrue(region.isDestroyed());
+    waitForRegionDestroy(region);
   }
   
   protected static Boolean[] detectedDeparture_testCommitDistributionException = 


Mime
View raw message