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 2015/07/22 02:29:10 UTC

[1/4] incubator-geode git commit: improved testEntryTtl3

Repository: incubator-geode
Updated Branches:
  refs/heads/feature/GEODE-148 d21095edd -> 0bf3f7a72


improved testEntryTtl3


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

Branch: refs/heads/feature/GEODE-148
Commit: 190b136ef9f414ad3b606e200a8300f1f38174d3
Parents: d21095e
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Tue Jul 21 14:24:47 2015 -0700
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Tue Jul 21 14:24:47 2015 -0700

----------------------------------------------------------------------
 .../gemfire/cache30/RegionTestCase.java         | 181 ++++++-------------
 1 file changed, 54 insertions(+), 127 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/190b136e/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java
index 8f20e12..acf071c 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java
@@ -2404,16 +2404,18 @@ public abstract class RegionTestCase extends CacheTestCase {
   }
 
   /**
-   * Expire an entry with a ttl time.  Set a new ttl time, create the
-   * same entry again, make sure it observes the <em>new</em> ttl time.
+   * Configure entry expiration with a ttl time.
+   * Create an entry and records its scheduled expiration time.
+   * Then mutate the region expiration configuration and confirm
+   * that the entry's expiration time is rescheduled.
    */
   public void testEntryTtl3() {
     final String name = this.getUniqueName();
-    final int timeout1 = 200; // ms
-    final int timeout2 = 2000;
+    // test no longer waits for this expiration to happen
+    final int timeout1 = 500 * 1000; // ms
+    final int timeout2 = 2000 * 1000; // ms
     final String key1 = "KEY1";
     final String value1 = "VALUE1";
-    final String value2 = "VALUE2";
     
     AttributesFactory factory = new AttributesFactory(getRegionAttributes());
     ExpirationAttributes expire1 =
@@ -2429,139 +2431,64 @@ public abstract class RegionTestCase extends CacheTestCase {
     factory.addCacheListener(list);
     RegionAttributes attrs = factory.create();
     
-    Region region = null;
+    LocalRegion region;
     System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
     try {
-      region = createRegion(name, attrs);
+      region = (LocalRegion) createRegion(name, attrs);
+    } finally {
+      System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
+    }
 
-      // DebuggerSupport.waitForJavaDebugger(getLogWriter(), "Set breakpoint in
-      // invalidate");
-      ExpiryTask.suspendExpiration();
-      Region.Entry entry = null;
-      long tilt;
-      eventCount = 0;
-      try {
-        region.create(key1, value1);
-        tilt = System.currentTimeMillis() + timeout1;
-        assertTrue(list.waitForInvocation(1000));
-        entry = region.getEntry(key1);
-        Assert.assertTrue(value1.equals(entry.getValue()));
-      }
-      finally {
-        ExpiryTask.permitExpiration();
-      }
-      waitForInvalidate(entry, tilt);
-      if (!getRegionAttributes().getDataPolicy().withPartitioning()) {
-        // Disk regions are VERY slow, so we need to wait for the event...
-        WaitCriterion wc = new WaitCriterion() {
-          public boolean done() {
-            return eventCount == 1;
-          }
-          public String description() {
-            return "eventCount never became 1";
-          }
-        };
-        DistributedTestCase.waitForCriterion(wc, 10 * 1000, 100, true);
-      }
-      eventCount = 0;
+    region.create(key1, value1);
+    EntryExpiryTask eet = region.getEntryExpiryTask(key1);
+    final long firstExpiryTime = eet.getExpirationTime();
 
-      // Do it again with a put (I guess)
-      ExpiryTask.suspendExpiration();
-      try {
-        region.put(key1, value1);
-        tilt = System.currentTimeMillis() + timeout1;
-        entry = region.getEntry(key1);
-        Assert.assertTrue(value1.equals(entry.getValue()));
-        assertTrue(list.waitForInvocation(1000));
-      }
-      finally {
-        ExpiryTask.permitExpiration();
+    AttributesMutator mutt = region.getAttributesMutator();
+    ExpirationAttributes expire2 = new ExpirationAttributes(timeout2, ExpirationAction.INVALIDATE);
+    mutt.setEntryTimeToLive(expire2);
+    eet = region.getEntryExpiryTask(key1);
+    final long secondExpiryTime = eet.getExpirationTime();
+    if ((secondExpiryTime - firstExpiryTime) <= 0) {
+      fail("expiration time should have been greater after changing region config from 500 to 2000. firstExpiryTime=" + firstExpiryTime + " secondExpiryTime=" + secondExpiryTime);
+    }
+    
+    // now set back to be more recent
+    mutt = region.getAttributesMutator();
+    ExpirationAttributes expire3 = new ExpirationAttributes(timeout1, ExpirationAction.INVALIDATE);
+    mutt.setEntryTimeToLive(expire3);
+    eet = region.getEntryExpiryTask(key1);
+    final long thirdExpiryTime = eet.getExpirationTime();
+    assertEquals(firstExpiryTime, thirdExpiryTime);
+    // confirm that it still has not expired
+    assertEquals(0, eventCount);
+    
+    // now set it to a really short time and make sure it expires immediately
+    waitForExpiryClockToChange(region);
+    final Region.Entry entry = region.getEntry(key1);
+    mutt = region.getAttributesMutator();
+    ExpirationAttributes expire4 = new ExpirationAttributes(1, ExpirationAction.INVALIDATE);
+    mutt.setEntryTimeToLive(expire4);
+    WaitCriterion wc = new WaitCriterion() {
+      public boolean done() {
+        return fetchEntryValue(entry) == null;
       }
-      waitForInvalidate(entry, tilt);
-      if (!getRegionAttributes().getDataPolicy().withPartitioning()) {
-        // Disk regions are VERY slow, so we need to wait for the event...
-        WaitCriterion wc = new WaitCriterion() {
-          public boolean done() {
-            return eventCount == 1;
-          }
-          public String description() {
-            return "eventCount never became 1";
-          }
-        };
-        DistributedTestCase.waitForCriterion(wc, 10 * 1000, 100, true);
+      public String description() {
+        return "entry never became invalid";
       }
-      eventCount = 0;
-
-      // Change custom expiry for this region now...
-      AttributesMutator mutt = region.getAttributesMutator();
-      ExpirationAttributes expire2 = new ExpirationAttributes(timeout2,
-          ExpirationAction.INVALIDATE);
-      mutt.setEntryTimeToLive(expire2);
+    };
+    DistributedTestCase.waitForCriterion(wc, 10 * 1000, 10, true);
 
-      ExpiryTask.suspendExpiration();
-      try {
-        region.put(key1, value2);
-        tilt = System.currentTimeMillis() + timeout2;
-        entry = region.getEntry(key1);
-        Assert.assertTrue(value2.equals(entry.getValue()));
-        assertTrue(list.waitForInvocation(1000));
-      }
-      finally {
-        ExpiryTask.permitExpiration();
-        if (region.getAttributes().getPartitionAttributes() != null)
-          System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
+    WaitCriterion waitForEventCountToBeOne = new WaitCriterion() {
+      public boolean done() {
+        return eventCount == 1;
       }
-      waitForInvalidate(entry, tilt);
-      if (!region.getAttributes().getDataPolicy().withPartitioning()) {
-        // Disk regions are VERY slow, so we need to wait for the event...
-        WaitCriterion wc = new WaitCriterion() {
-          public boolean done() {
-            return eventCount == 1;
-          }
-          public String description() {
-            return "eventCount never became 1";
-          }
-        };
-        DistributedTestCase.waitForCriterion(wc, 10 * 1000, 100, true);
+      public String description() {
+        return "eventCount never became 1";
       }
-      eventCount = 0;
-    
-    // Change custom expiry for this region now...
-    mutt = region.getAttributesMutator();
-    expire2 =
-      new ExpirationAttributes(timeout2, ExpirationAction.INVALIDATE);
-    mutt.setEntryTimeToLive(expire2);
-    
-    ExpiryTask.suspendExpiration();
-    try {
-      region.put(key1, value2);
-      tilt = System.currentTimeMillis() + timeout2;
-      entry = region.getEntry(key1);
-      Assert.assertTrue(value2.equals(entry.getValue()));
-      assertTrue(list.waitForInvocation(5000));
-    } 
-    finally {
-      ExpiryTask.permitExpiration();
-    }
-    waitForInvalidate(entry, tilt);
-    if (!region.getAttributes().getDataPolicy().withPartitioning()) {
-      // Disk regions are VERY slow, so we need to wait for the event...
-      WaitCriterion wc = new WaitCriterion() {
-        public boolean done() {
-          return eventCount == 1;
-        }
-        public String description() {
-          return "eventCount never became 1";
-        }
-      };
-      DistributedTestCase.waitForCriterion(wc, 10 * 1000, 100, true);
-    }
+    };
+    DistributedTestCase.waitForCriterion(waitForEventCountToBeOne, 10 * 1000, 10, true);
     eventCount = 0;
   }
-  finally {
-    System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
-    }
-  }
 
 //  /**
 //   * Expire an entry with a ttl time.  Set a new ttl time, create the


[3/4] incubator-geode git commit: optimized testCustomEntryIdleTimeout3

Posted by ds...@apache.org.
optimized testCustomEntryIdleTimeout3


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

Branch: refs/heads/feature/GEODE-148
Commit: 9f02366c4ab2ff7d1813223eaa9d45d9e821c3d3
Parents: e82c4d3
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Tue Jul 21 14:58:20 2015 -0700
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Tue Jul 21 14:58:20 2015 -0700

----------------------------------------------------------------------
 .../gemfire/cache30/RegionTestCase.java         | 152 +++++++------------
 1 file changed, 55 insertions(+), 97 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9f02366c/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java
index ff24434..78e8889 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java
@@ -3038,22 +3038,22 @@ public abstract class RegionTestCase extends CacheTestCase {
   }
   
   /**
-   * Expire an entry with a custom idle time.  Set a new idle time, create the
-   * same entry again, make sure it observes the <em>new</em> idle time.
+   * Configure custome entry expiration with an idle time.
+   * Create an entry and records its scheduled expiration time.
+   * Then mutate the region expiration configuration and confirm
+   * that the entry's expiration time is rescheduled.
    */
   public void testCustomEntryIdleTimeout3() {
-
     final String name = this.getUniqueName();
-    final int timeout1 = 200; // ms
-    final int timeout2 = 2000;
+    // test no longer waits for this expiration to happen
+    final int timeout1 = 500 * 1000; // ms
+    final int timeout2 = 2000 * 1000; // ms
     final String key1 = "KEY1";
     final String value1 = "VALUE1";
-    final String value2 = "VALUE2";
     
     AttributesFactory factory = new AttributesFactory(getRegionAttributes());
     ExpirationAttributes expire1 =
             new ExpirationAttributes(timeout1, ExpirationAction.INVALIDATE);
-//    factory.setEntryIdleTimeout(expire);
     factory.setCustomEntryIdleTimeout(new TestExpiry(key1, expire1));
     factory.setStatisticsEnabled(true);
     TestCacheListener list = new TestCacheListener() {
@@ -3065,104 +3065,62 @@ public abstract class RegionTestCase extends CacheTestCase {
     factory.addCacheListener(list);
     RegionAttributes attrs = factory.create();
     
-    Region region = null;
+    LocalRegion region;
     System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
     try {
-      region = createRegion(name, attrs);
-    } 
-    finally {
-      if(region.getAttributes().getPartitionAttributes() == null)
-        System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
+      region = (LocalRegion) createRegion(name, attrs);
+    } finally {
+      System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
     }
 
-    // DebuggerSupport.waitForJavaDebugger(getLogWriter(), "Set breakpoint in invalidate");
-    ExpiryTask.suspendExpiration();
-    Region.Entry entry = null;
-    long tilt;
-    try {
-      region.create(key1, value1);
-      tilt = System.currentTimeMillis() + timeout1;
-      assertTrue(list.waitForInvocation(5000));
-      entry = region.getEntry(key1);
-      Assert.assertTrue(value1.equals(entry.getValue()));
-    } 
-    finally {
-      ExpiryTask.permitExpiration();
-    }
-    waitForInvalidate(entry, tilt);
-    if (!getRegionAttributes().getDataPolicy().withPartitioning()) {
-      // Disk regions are VERY slow, so we need to wait for the event...
-      WaitCriterion wc = new WaitCriterion() {
-        public boolean done() {
-          return eventCount == 1;
-        }
-        public String description() {
-          return "eventCount never became 1";
-        }
-      };
-      DistributedTestCase.waitForCriterion(wc, 10 * 1000, 100, true);
-    }
-    eventCount = 0;
+    region.create(key1, value1);
+    EntryExpiryTask eet = region.getEntryExpiryTask(key1);
+    final long firstExpiryTime = eet.getExpirationTime();
 
-    // Do it again with a put (I guess)
-    ExpiryTask.suspendExpiration();
-    try {
-      region.put(key1, value1);
-      tilt = System.currentTimeMillis() + timeout1;
-      entry = region.getEntry(key1);
-      Assert.assertTrue(value1.equals(entry.getValue()));
-      assertTrue(list.waitForInvocation(5000));
-    } 
-    finally {
-      ExpiryTask.permitExpiration();
-    }
-    waitForInvalidate(entry, tilt);
-    if (!getRegionAttributes().getDataPolicy().withPartitioning()) {
-      // Disk regions are VERY slow, so we need to wait for the event...
-      WaitCriterion wc = new WaitCriterion() {
-        public boolean done() {
-          return eventCount == 1;
-        }
-        public String description() {
-          return "eventCount never became 1";
-        }
-      };
-      DistributedTestCase.waitForCriterion(wc, 10 * 1000, 100, true);
-    }
-    eventCount = 0;
-    
-    // Change custom expiry for this region now...
     AttributesMutator mutt = region.getAttributesMutator();
-    ExpirationAttributes expire2 =
-      new ExpirationAttributes(timeout2, ExpirationAction.INVALIDATE);
+    ExpirationAttributes expire2 = new ExpirationAttributes(timeout2, ExpirationAction.INVALIDATE);
     mutt.setCustomEntryIdleTimeout(new TestExpiry(key1, expire2));
-    
-    ExpiryTask.suspendExpiration();
-    try {
-      region.put(key1, value2);
-      tilt = System.currentTimeMillis() + timeout2;
-      entry = region.getEntry(key1);
-      Assert.assertTrue(value2.equals(entry.getValue()));
-      assertTrue(list.waitForInvocation(5000));
-    } 
-    finally {
-      if(region.getAttributes().getPartitionAttributes() != null)
-        System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
-      ExpiryTask.permitExpiration();
-    }
-    waitForInvalidate(entry, tilt);
-    if (!getRegionAttributes().getDataPolicy().withPartitioning()) {
-      // Disk regions are VERY slow, so we need to wait for the event...
-      WaitCriterion wc = new WaitCriterion() {
-        public boolean done() {
-          return eventCount == 1;
-        }
-        public String description() {
-          return "eventCount never became 1";
-        }
-      };
-      DistributedTestCase.waitForCriterion(wc, 10 * 1000, 100, true);
+    eet = region.getEntryExpiryTask(key1);
+    final long secondExpiryTime = eet.getExpirationTime();
+    if ((secondExpiryTime - firstExpiryTime) <= 0) {
+      fail("expiration time should have been greater after changing region config from 500 to 2000. firstExpiryTime=" + firstExpiryTime + " secondExpiryTime=" + secondExpiryTime);
     }
+    
+    // now set back to be more recent
+    mutt = region.getAttributesMutator();
+    ExpirationAttributes expire3 = new ExpirationAttributes(timeout1, ExpirationAction.INVALIDATE);
+    mutt.setCustomEntryIdleTimeout(new TestExpiry(key1, expire3));
+    eet = region.getEntryExpiryTask(key1);
+    final long thirdExpiryTime = eet.getExpirationTime();
+    assertEquals(firstExpiryTime, thirdExpiryTime);
+    // confirm that it still has not expired
+    assertEquals(0, eventCount);
+    
+    // now set it to a really short time and make sure it expires immediately
+    waitForExpiryClockToChange(region);
+    final Region.Entry entry = region.getEntry(key1);
+    mutt = region.getAttributesMutator();
+    ExpirationAttributes expire4 = new ExpirationAttributes(1, ExpirationAction.INVALIDATE);
+    mutt.setCustomEntryIdleTimeout(new TestExpiry(key1, expire4));
+    WaitCriterion wc = new WaitCriterion() {
+      public boolean done() {
+        return fetchEntryValue(entry) == null;
+      }
+      public String description() {
+        return "entry never became invalid";
+      }
+    };
+    DistributedTestCase.waitForCriterion(wc, 10 * 1000, 10, true);
+
+    WaitCriterion waitForEventCountToBeOne = new WaitCriterion() {
+      public boolean done() {
+        return eventCount == 1;
+      }
+      public String description() {
+        return "eventCount never became 1";
+      }
+    };
+    DistributedTestCase.waitForCriterion(waitForEventCountToBeOne, 10 * 1000, 10, true);
     eventCount = 0;
   }
 


[2/4] incubator-geode git commit: fixed testEntryIdleTimeout3

Posted by ds...@apache.org.
fixed testEntryIdleTimeout3


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

Branch: refs/heads/feature/GEODE-148
Commit: e82c4d39358563e7bc4559e7a2944abdce2f0820
Parents: 190b136
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Tue Jul 21 14:51:10 2015 -0700
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Tue Jul 21 14:51:10 2015 -0700

----------------------------------------------------------------------
 .../gemfire/cache30/RegionTestCase.java         | 151 +++++++------------
 1 file changed, 55 insertions(+), 96 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e82c4d39/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java
index acf071c..ff24434 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java
@@ -3167,17 +3167,18 @@ public abstract class RegionTestCase extends CacheTestCase {
   }
 
   /**
-   * Expire an entry with a given idle time.  Set a new idle time, create the
-   * same entry again, make sure it observes the <em>new</em> idle time.
+   * Configure entry expiration with a idle time.
+   * Create an entry and records its scheduled expiration time.
+   * Then mutate the region expiration configuration and confirm
+   * that the entry's expiration time is rescheduled.
    */
   public void testEntryIdleTimeout3() {
-
     final String name = this.getUniqueName();
-    final int timeout1 = 200; // ms
-    final int timeout2 = 2000;
+    // test no longer waits for this expiration to happen
+    final int timeout1 = 500 * 1000; // ms
+    final int timeout2 = 2000 * 1000; // ms
     final String key1 = "KEY1";
     final String value1 = "VALUE1";
-    final String value2 = "VALUE2";
     
     AttributesFactory factory = new AttributesFactory(getRegionAttributes());
     ExpirationAttributes expire1 =
@@ -3193,104 +3194,62 @@ public abstract class RegionTestCase extends CacheTestCase {
     factory.addCacheListener(list);
     RegionAttributes attrs = factory.create();
     
-    Region region = null;
+    LocalRegion region;
     System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
     try {
-      region = createRegion(name, attrs);
-    } 
-    finally {
-      if(region.getAttributes().getPartitionAttributes() == null)
-        System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
+      region = (LocalRegion) createRegion(name, attrs);
+    } finally {
+      System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
     }
 
-    // DebuggerSupport.waitForJavaDebugger(getLogWriter(), "Set breakpoint in invalidate");
-    ExpiryTask.suspendExpiration();
-    Region.Entry entry = null;
-    long tilt;
-    try {
-      region.create(key1, value1);
-      tilt = System.currentTimeMillis() + timeout1;
-      assertTrue(list.waitForInvocation(5000));
-      entry = region.getEntry(key1);
-      Assert.assertTrue(value1.equals(entry.getValue()));
-    } 
-    finally {
-      ExpiryTask.permitExpiration();
-    }
-    waitForInvalidate(entry, tilt);
-    if (!getRegionAttributes().getDataPolicy().withPartitioning()) {
-      // Disk regions are VERY slow, so we need to wait for the event...
-      WaitCriterion wc = new WaitCriterion() {
-        public boolean done() {
-          return eventCount == 1;
-        }
-        public String description() {
-          return "eventCount never became 1";
-        }
-      };
-      DistributedTestCase.waitForCriterion(wc, 10 * 1000, 100, true);
-    }
-    eventCount = 0;
+    region.create(key1, value1);
+    EntryExpiryTask eet = region.getEntryExpiryTask(key1);
+    final long firstExpiryTime = eet.getExpirationTime();
 
-    // Do it again with a put (I guess)
-    ExpiryTask.suspendExpiration();
-    try {
-      region.put(key1, value1);
-      tilt = System.currentTimeMillis() + timeout1;
-      entry = region.getEntry(key1);
-      Assert.assertTrue(value1.equals(entry.getValue()));
-      assertTrue(list.waitForInvocation(5000));
-    } 
-    finally {
-      ExpiryTask.permitExpiration();
-    }
-    waitForInvalidate(entry, tilt);
-    if (!getRegionAttributes().getDataPolicy().withPartitioning()) {
-      // Disk regions are VERY slow, so we need to wait for the event...
-      WaitCriterion wc = new WaitCriterion() {
-        public boolean done() {
-          return eventCount == 1;
-        }
-        public String description() {
-          return "eventCount never became 1";
-        }
-      };
-      DistributedTestCase.waitForCriterion(wc, 10 * 1000, 100, true);
-    }
-    eventCount = 0;
-    
-    // Change expiry for this region now...
     AttributesMutator mutt = region.getAttributesMutator();
-    ExpirationAttributes expire2 =
-      new ExpirationAttributes(timeout2, ExpirationAction.INVALIDATE);
+    ExpirationAttributes expire2 = new ExpirationAttributes(timeout2, ExpirationAction.INVALIDATE);
     mutt.setEntryIdleTimeout(expire2);
-    
-    ExpiryTask.suspendExpiration();
-    try {
-      region.put(key1, value2);
-      tilt = System.currentTimeMillis() + timeout2;
-      entry = region.getEntry(key1);
-      Assert.assertTrue(value2.equals(entry.getValue()));
-      assertTrue(list.waitForInvocation(5000));
-    } 
-    finally {
-      ExpiryTask.permitExpiration();
-      if(region.getAttributes().getPartitionAttributes() != null)
-        System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
-    }
-    waitForInvalidate(entry, tilt);
-    if (!region.getAttributes().getDataPolicy().withPartitioning()) {
-      // Disk regions are VERY slow, so we need to wait for the event...
-      WaitCriterion wc = new WaitCriterion() {
-        public boolean done() {
-          return eventCount == 1;
-        }
-        public String description() {
-          return "eventCount never became 1";
-        }
-      };
-      DistributedTestCase.waitForCriterion(wc, 10 * 1000, 100, true);
+    eet = region.getEntryExpiryTask(key1);
+    final long secondExpiryTime = eet.getExpirationTime();
+    if ((secondExpiryTime - firstExpiryTime) <= 0) {
+      fail("expiration time should have been greater after changing region config from 500 to 2000. firstExpiryTime=" + firstExpiryTime + " secondExpiryTime=" + secondExpiryTime);
     }
+    
+    // now set back to be more recent
+    mutt = region.getAttributesMutator();
+    ExpirationAttributes expire3 = new ExpirationAttributes(timeout1, ExpirationAction.INVALIDATE);
+    mutt.setEntryIdleTimeout(expire3);
+    eet = region.getEntryExpiryTask(key1);
+    final long thirdExpiryTime = eet.getExpirationTime();
+    assertEquals(firstExpiryTime, thirdExpiryTime);
+    // confirm that it still has not expired
+    assertEquals(0, eventCount);
+    
+    // now set it to a really short time and make sure it expires immediately
+    waitForExpiryClockToChange(region);
+    final Region.Entry entry = region.getEntry(key1);
+    mutt = region.getAttributesMutator();
+    ExpirationAttributes expire4 = new ExpirationAttributes(1, ExpirationAction.INVALIDATE);
+    mutt.setEntryIdleTimeout(expire4);
+    WaitCriterion wc = new WaitCriterion() {
+      public boolean done() {
+        return fetchEntryValue(entry) == null;
+      }
+      public String description() {
+        return "entry never became invalid";
+      }
+    };
+    DistributedTestCase.waitForCriterion(wc, 10 * 1000, 10, true);
+
+    WaitCriterion waitForEventCountToBeOne = new WaitCriterion() {
+      public boolean done() {
+        return eventCount == 1;
+      }
+      public String description() {
+        return "eventCount never became 1";
+      }
+    };
+    DistributedTestCase.waitForCriterion(waitForEventCountToBeOne, 10 * 1000, 10, true);
     eventCount = 0;
   }
 


[4/4] incubator-geode git commit: optimized testEntryIdleTtl and testRegionIdleInvalidate

Posted by ds...@apache.org.
optimized testEntryIdleTtl and testRegionIdleInvalidate


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

Branch: refs/heads/feature/GEODE-148
Commit: 0bf3f7a727422b23bdc582140459b5bf67af9a18
Parents: 9f02366
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Tue Jul 21 15:54:59 2015 -0700
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Tue Jul 21 15:54:59 2015 -0700

----------------------------------------------------------------------
 .../gemfire/internal/cache/ExpiryTask.java      |  4 +-
 .../gemfire/cache30/RegionTestCase.java         | 57 +++++++-------------
 2 files changed, 22 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/0bf3f7a7/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/ExpiryTask.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/ExpiryTask.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/ExpiryTask.java
index ccab3aa..95cd3a8 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/ExpiryTask.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/ExpiryTask.java
@@ -104,7 +104,7 @@ public abstract class ExpiryTask extends SystemTimer.SystemTimerTask {
   }
 
   /** Return the absolute time when TTL expiration occurs, or 0 if not used */
-  protected final long getTTLExpirationTime() throws EntryNotFoundException {
+  public final long getTTLExpirationTime() throws EntryNotFoundException {
     long ttl = getTTLAttributes().getTimeout();
     long tilt = 0;
     if (ttl > 0) {
@@ -117,7 +117,7 @@ public abstract class ExpiryTask extends SystemTimer.SystemTimerTask {
   }
 
   /** Return the absolute time when idle expiration occurs, or 0 if not used */
-  protected final long getIdleExpirationTime() throws EntryNotFoundException {
+  public final long getIdleExpirationTime() throws EntryNotFoundException {
     long idle = getIdleAttributes().getTimeout();
     long tilt = 0;
     if (idle > 0) {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/0bf3f7a7/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java
index 78e8889..0e65491 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java
@@ -3693,10 +3693,10 @@ public abstract class RegionTestCase extends CacheTestCase {
   public void testEntryIdleTtl() {
 
     final String name = this.getUniqueName();
-    final int timeout = 2000; // ms
+    // test no longer waits for this timeout to expire
+    final int timeout = 2000; // seconds
     final String key = "IDLE_TTL_KEY";
     final String value = "IDLE_TTL_VALUE";
-    long tilt;
     AttributesFactory factory = new AttributesFactory(getRegionAttributes());
     ExpirationAttributes expireIdle =
             new ExpirationAttributes(timeout / 2, ExpirationAction.DESTROY);
@@ -3705,44 +3705,27 @@ public abstract class RegionTestCase extends CacheTestCase {
       new ExpirationAttributes(timeout, ExpirationAction.DESTROY);
     factory.setEntryTimeToLive(expireTtl);
     factory.setStatisticsEnabled(true);
-    TestCacheListener list = new TestCacheListener() {
-      public void afterCreate2(EntryEvent e) { }
-      public void afterDestroy2(EntryEvent e) { }
-    };
-    factory.setCacheListener(list);
     RegionAttributes attrs = factory.create();
     
-    Region region = null;
-    System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
-    try {
-      region = createRegion(name, attrs);
-    ExpiryTask.suspendExpiration();
+    LocalRegion region = (LocalRegion) createRegion(name, attrs);
    
-    try {
-      tilt = System.currentTimeMillis() + timeout; // *earliest* time to expect expiration
-      region.create(key, value);
-      assertTrue(list.wasInvoked());
-    } 
-    finally {
-      ExpiryTask.permitExpiration();
-    }
-    } 
-    finally {
-      System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
+    region.create(key, value);
+    EntryExpiryTask eet = region.getEntryExpiryTask(key);
+    final long firstIdleExpiryTime = eet.getIdleExpirationTime();
+    final long firstTTLExpiryTime = eet.getTTLExpirationTime();
+    if ((firstIdleExpiryTime - firstTTLExpiryTime) >= 0) {
+      fail("idle should be less than ttl: idle=" + firstIdleExpiryTime + " ttl=" + firstTTLExpiryTime);
     }
-    // Fondle the entry until timeout
-    for (;;) {
-      if (System.currentTimeMillis() > tilt + 30 * 1000) { // allow a lot of time for slow machine
-        fail("Region did not honor ttl");
-      }
-      Object val = region.get(key);
-      if (val == null) {
-        if (System.currentTimeMillis() < tilt) { // intentionally refetch time
-          fail("Region expired value prematurely?");
-        }
-        break; // success
-      }
-      pause(timeout / 10); // wait then fondle again
+    waitForExpiryClockToChange(region);
+    region.get(key);
+    eet = region.getEntryExpiryTask(key);
+    final long secondIdleExpiryTime = eet.getIdleExpirationTime();
+    final long secondTTLExpiryTime = eet.getTTLExpirationTime();
+    // make sure the get does not change the ttl expiry time
+    assertEquals(firstTTLExpiryTime, secondTTLExpiryTime);
+    // and does change the idle expiry time
+    if ((secondIdleExpiryTime - firstIdleExpiryTime) <= 0) {
+      fail("idle should have increased: idle=" + firstIdleExpiryTime + " idle2=" + secondIdleExpiryTime);
     }
   }
   
@@ -3805,7 +3788,7 @@ public abstract class RegionTestCase extends CacheTestCase {
     
     final String name = this.getUniqueName();
     final String subname = this.getUniqueName() + "-SUB";
-    final int timeout = 222; // ms
+    final int timeout = 22; // ms
     final Object key = "KEY";
     final Object value = "VALUE";