Anonymous avatar Anonymous committed 6093067

Cache.flushAll(Date flushDate) throws NeedsRefreshException when flush date is not yet reached
Issue number: CACHE-241
Submitted by: Lars Torunski

Comments (0)

Files changed (2)

src/java/com/opensymphony/oscache/base/Cache.java

      */
     public boolean isFlushed(CacheEntry cacheEntry) {
         if (flushDateTime != null) {
-            long lastUpdate = cacheEntry.getLastUpdate();
+            final long lastUpdate = cacheEntry.getLastUpdate();
+            final long flushTime = flushDateTime.getTime();
 
-            return (flushDateTime.getTime() >= lastUpdate);
+            // CACHE-241: check flushDateTime with current time also
+            return (flushTime <= System.currentTimeMillis()) && (flushTime >= lastUpdate);
         } else {
             return false;
         }

src/test/java/com/opensymphony/oscache/general/TestGeneralCacheAdministrator.java

  */
 package com.opensymphony.oscache.general;
 
+import java.util.Date;
+
 import com.opensymphony.oscache.base.*;
 import com.opensymphony.oscache.base.events.CacheEntryEventListener;
 import com.opensymphony.oscache.base.events.CacheMapAccessEventListener;
         }
     }
 
+
+    /**
+     * Bug CACHE-241
+     */
+	public void testFlushDateTomorrow() {
+		GeneralCacheAdministrator cacheAdmin = new GeneralCacheAdministrator(null);
+		
+		cacheAdmin.putInCache("key1", "key1value");
+		
+		try {
+			assertNotNull(cacheAdmin.getFromCache("key1"));
+		} catch (NeedsRefreshException e1) {
+			fail("Previous cache key1 doesn't exsits in GCA for the test!");
+		}
+		
+		cacheAdmin.flushAll(new Date(System.currentTimeMillis() + 5000)); // flush in 5 sec.
+		try {
+			cacheAdmin.getFromCache("key1"); 
+		} catch (NeedsRefreshException e) {
+			cacheAdmin.cancelUpdate("key1");
+			fail("NRE is thrown, but key will expire in 5s."); // it fails here
+		}
+	}
+
+
     /**
      * Utility method that tries to get an item from the cache and verify
      * if all goes as expected
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.