geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hiteshkhame...@apache.org
Subject [3/3] incubator-geode git commit: GEODE-1828 Added logging to debug the test
Date Wed, 31 Aug 2016 18:21:11 GMT
GEODE-1828 Added logging to debug the 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/331cf284
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/331cf284
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/331cf284

Branch: refs/heads/develop
Commit: 331cf284277a7dfe10494b99f275298f65877e6a
Parents: 15c92c1
Author: Hitesh Khamesra <hkhamesra@pivotal.io>
Authored: Wed Aug 31 11:21:18 2016 -0700
Committer: Hitesh Khamesra <hkhamesra@pivotal.io>
Committed: Wed Aug 31 11:21:18 2016 -0700

----------------------------------------------------------------------
 .../gemfire/internal/cache/ExpiryTask.java      |  4 ++
 .../gemfire/internal/cache/LocalRegion.java     |  4 ++
 .../com/gemstone/gemfire/TXExpiryJUnitTest.java |  4 ++
 .../gemfire/cache30/RegionTestCase.java         | 57 +++++++++++++++++++-
 4 files changed, 68 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/331cf284/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/ExpiryTask.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/ExpiryTask.java
b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/ExpiryTask.java
index 3f5b944..09ee1ea 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/ExpiryTask.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/ExpiryTask.java
@@ -511,6 +511,10 @@ public abstract class ExpiryTask extends SystemTimer.SystemTimerTask
{
    */
   public interface ExpiryTaskListener {
     /**
+     * Called after entry is schedule for expiration. 
+     */
+    public void afterSchedule(ExpiryTask et);
+    /**
      * Called after the given expiry task has run.
      * This means that the time it was originally
      * scheduled to run has elapsed and the scheduler

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/331cf284/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java
b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java
index 41b9578..4cbcbd0 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java
@@ -8697,6 +8697,10 @@ public class LocalRegion extends AbstractRegion
       }
       if (!es.addEntryExpiryTask(newTask)) {
         this.entryExpiryTasks.remove(re);
+      } else {
+        if (EntryExpiryTask.expiryTaskListener != null) {
+          EntryExpiryTask.expiryTaskListener.afterSchedule(newTask);
+        }
       }
       // @todo darrel: merge question: should we catch EntryNotFoundException
       // if addExpiryTask throws it?

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/331cf284/geode-core/src/test/java/com/gemstone/gemfire/TXExpiryJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/TXExpiryJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/TXExpiryJUnitTest.java
index f1c2809..caa4d86 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/TXExpiryJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/TXExpiryJUnitTest.java
@@ -25,6 +25,7 @@ import com.gemstone.gemfire.test.dunit.Wait;
 import com.gemstone.gemfire.test.dunit.WaitCriterion;
 import com.gemstone.gemfire.test.junit.categories.FlakyTest;
 import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -270,6 +271,9 @@ public class TXExpiryJUnitTest {
       this.et = et;
     }
     @Override
+    public void afterSchedule(ExpiryTask et) {
+    }
+    @Override
     public void afterReschedule(ExpiryTask et) {
       if (et == this.et) {
         if (!hasExpired()) {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/331cf284/geode-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java b/geode-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java
index e31e97b..aaa2abe 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java
@@ -24,8 +24,10 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.text.SimpleDateFormat;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -62,6 +64,7 @@ import com.gemstone.gemfire.internal.Assert;
 import com.gemstone.gemfire.internal.cache.EntryExpiryTask;
 import com.gemstone.gemfire.internal.cache.EntrySnapshot;
 import com.gemstone.gemfire.internal.cache.ExpiryTask;
+import com.gemstone.gemfire.internal.cache.ExpiryTask.ExpiryTaskListener;
 import com.gemstone.gemfire.internal.cache.LocalRegion;
 import com.gemstone.gemfire.test.dunit.Host;
 import com.gemstone.gemfire.test.dunit.Invoke;
@@ -3540,6 +3543,57 @@ public abstract class RegionTestCase extends JUnit4CacheTestCase {
     }
   }
   
+  class ExpiryCallbacks implements ExpiryTaskListener {
+
+    @Override
+    public void afterSchedule(ExpiryTask et) {
+      printState(et, "ExpiryCallbacks.afterSchedule " );
+    }
+    @Override
+    public void afterTaskRan(ExpiryTask et) {
+      printState(et, "ExpiryCallbacks.afterTaskRan " );
+    }
+    
+    void printState(ExpiryTask et, String callback) {
+      Date now = new Date();
+      Date ttl = now;
+      try {
+        ttl = new Date(et.getExpirationTime());
+      }catch(EntryNotFoundException enfx) {
+        //ignore
+      }
+      Date idleExpTime = now;
+      try {
+        idleExpTime = new Date(et.getIdleExpirationTime());
+      }catch(EntryNotFoundException enfx) {
+        //ignore
+      }
+      Date ttlTime = new Date(et.getTTLExpirationTime());
+      Date getNow = new Date(et.getNow());
+      Date scheduleETime = new Date(et.scheduledExecutionTime());
+      //et.getKey();
+      getCache().getLogger().info(callback + " now: " + getCurrentTimeStamp(now) + " ttl:"
+ getCurrentTimeStamp(ttl) + " idleExpTime:" + getCurrentTimeStamp(idleExpTime) + 
+          " ttlTime:" + getCurrentTimeStamp(ttlTime)  + " getNow:" + getCurrentTimeStamp(getNow)
+ " scheduleETime:" + getCurrentTimeStamp(scheduleETime) +
+          " getKey:" + et.getKey() + " isPending:" + et.isPending() +
+          " et :" + et +  
+          " Task reference " + System.identityHashCode(et));
+    }
+
+    public String getCurrentTimeStamp(Date d) {
+      return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(d);
+    }
+    @Override
+    public void afterReschedule(ExpiryTask et) {
+      printState(et, "ExpiryCallbacks.afterReschedule" );
+    }
+
+    @Override
+    public void afterExpire(ExpiryTask et) {
+      printState(et, "ExpiryCallbacks.afterExpire" );
+    }
+    
+  }
+  
   /**
    * Tests that an entry in a region that remains idle for a
    * given amount of time is destroyed.
@@ -3552,7 +3606,7 @@ public abstract class RegionTestCase extends JUnit4CacheTestCase {
     final int timeout = 20; // ms
     final String key = "KEY";
     final String value = "VALUE";
-    
+    EntryExpiryTask.expiryTaskListener = new ExpiryCallbacks();
     AttributesFactory factory = new AttributesFactory(getRegionAttributes());
     ExpirationAttributes expire =
             new ExpirationAttributes(timeout, ExpirationAction.DESTROY);
@@ -3599,6 +3653,7 @@ public abstract class RegionTestCase extends JUnit4CacheTestCase {
     } 
     finally {
       System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
+      EntryExpiryTask.expiryTaskListener = null;
     }
     
   }


Mime
View raw message