geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bschucha...@apache.org
Subject [43/50] [abbrv] incubator-geode git commit: optimized testEntryIdleTtl and testRegionIdleInvalidate
Date Mon, 27 Jul 2015 23:20:06 GMT
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/62d010dd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/62d010dd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/62d010dd

Branch: refs/heads/feature/GEODE-77
Commit: 62d010dd49441cbecfe7a4a806d60ac020aa4fac
Parents: af1b99f
Author: Darrel Schneider <dschneider@pivotal.io>
Authored: Tue Jul 21 15:54:59 2015 -0700
Committer: Darrel Schneider <dschneider@pivotal.io>
Committed: Thu Jul 23 17:14:08 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/62d010dd/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/62d010dd/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";
     


Mime
View raw message