[jbosscache-commits] JBoss Cache SVN: r7710 - core/branches/flat/src/test/java/org/horizon/expiry.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Tue Feb 17 13:37:38 EST 2009


Author: mircea.markus
Date: 2009-02-17 13:37:38 -0500 (Tue, 17 Feb 2009)
New Revision: 7710

Modified:
   core/branches/flat/src/test/java/org/horizon/expiry/ExpiryTest.java
Log:
changed expectations

Modified: core/branches/flat/src/test/java/org/horizon/expiry/ExpiryTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/expiry/ExpiryTest.java	2009-02-17 18:26:06 UTC (rev 7709)
+++ core/branches/flat/src/test/java/org/horizon/expiry/ExpiryTest.java	2009-02-17 18:37:38 UTC (rev 7710)
@@ -54,16 +54,18 @@
       m.put("k1", "v");
       m.put("k2", "v");
       cache.putAll(m, lifespan, TimeUnit.MILLISECONDS);
-      while (System.currentTimeMillis() < startTime + lifespan + 100) {
-         if (System.currentTimeMillis() < startTime + lifespan) {
-            assert cache.get("k1").equals("v");
-            assert cache.get("k2").equals("v");
-         } else {
-            assert cache.get("k1") == null;
-            assert cache.get("k2") == null;
-         }
+      while (System.currentTimeMillis() < startTime + lifespan) {
+         assert cache.get("k1").equals("v");
+         assert cache.get("k2").equals("v");
          Thread.sleep(50);
       }
+
+      //make sure that in the next 2 secs data is removed
+      while (System.currentTimeMillis() < startTime + lifespan + 2000) {
+         if (cache.get("k1") == null && cache.get("k2") == null) return;
+      }
+      assert cache.get("k1") == null;
+      assert cache.get("k2") == null;
    }
 
    public void testExpiryInPutIfAbsent() throws InterruptedException {
@@ -71,15 +73,18 @@
       long startTime = System.currentTimeMillis();
       long lifespan = 1000;
       assert cache.putIfAbsent("k", "v", lifespan, TimeUnit.MILLISECONDS) == null;
-      while (System.currentTimeMillis() < startTime + lifespan + 100) {
-         if (System.currentTimeMillis() < startTime + lifespan) {
-            assert cache.get("k").equals("v");
-         } else {
-            assert cache.get("k") == null;
-         }
+      while (System.currentTimeMillis() < startTime + lifespan) {
+         assert cache.get("k").equals("v");
          Thread.sleep(50);
       }
 
+      //make sure that in the next 2 secs data is removed
+      while (System.currentTimeMillis() < startTime + lifespan + 2000) {
+         if (cache.get("k") == null) break;
+         Thread.sleep(50);
+      }
+      assert cache.get("k") == null;
+
       cache.put("k", "v");
       assert cache.putIfAbsent("k", "v", lifespan, TimeUnit.MILLISECONDS) != null;
    }
@@ -95,25 +100,32 @@
       long startTime = System.currentTimeMillis();
       assert cache.replace("k", "v", lifespan, TimeUnit.MILLISECONDS) != null;
       assert cache.get("k").equals("v");
-      while (System.currentTimeMillis() < startTime + lifespan + 100) {
-         if (System.currentTimeMillis() < startTime + lifespan) {
-            assert cache.get("k").equals("v");
-         } else {
-            assert cache.get("k") == null;
-         }
+      while (System.currentTimeMillis() < startTime + lifespan) {
+         assert cache.get("k").equals("v");
          Thread.sleep(50);
       }
 
+      //make sure that in the next 2 secs data is removed
+      while (System.currentTimeMillis() < startTime + lifespan + 2000) {
+         if (cache.get("k") == null) break;
+         Thread.sleep(50);
+      }
+      assert cache.get("k") == null;
+
+
       startTime = System.currentTimeMillis();
       cache.put("k", "v");
       assert cache.replace("k", "v", "v2", lifespan, TimeUnit.MILLISECONDS);
-      while (System.currentTimeMillis() < startTime + lifespan + 100) {
-         if (System.currentTimeMillis() < startTime + lifespan) {
-            assert cache.get("k").equals("v2");
-         } else {
-            assert cache.get("k") == null;
-         }
+      while (System.currentTimeMillis() < startTime + lifespan) {
+         assert cache.get("k").equals("v2");
          Thread.sleep(50);
       }
+
+      //make sure that in the next 2 secs data is removed
+      while (System.currentTimeMillis() < startTime + lifespan + 2000) {
+         if (cache.get("k") == null) break;
+         Thread.sleep(50);
+      }
+      assert cache.get("k") == null;
    }
 }




More information about the jbosscache-commits mailing list