Anonymous avatar Anonymous committed 23404fc

Fixed a bug with the thread handling, and shaved a couple of seconds off the sleep() calls.

Comments (0)

Files changed (1)

src/core/test/com/opensymphony/oscache/base/TestConcurrency.java

      */
     public void testStaleEntry() {
         String key = "stale";
+        assertFalse("The cache should not be in blocking mode for this test.", admin.isBlocking());
+
         admin.putInCache(key, VALUE);
 
         try {
 
             // Sleep for a bit to simulate the time taken to build the cache entry
             try {
-                Thread.sleep(1000);
+                Thread.sleep(200);
             } catch (InterruptedException ie) {
             }
 
                 admin.cancelUpdate(key);
                 fail("Should not have received a NeedsRefreshException");
             }
+            // Give the GetEntry thread a chance to finish
+            try {
+                Thread.sleep(200);
+            } catch (InterruptedException ie) {
+            }
         }
     }
 
         p.setProperty(AbstractCacheAdministrator.CACHE_BLOCKING_KEY, "true");
         admin = new GeneralCacheAdministrator(p);
 
+        assertTrue("The cache should be in blocking mode for this test.", admin.isBlocking());
+
         // Use a unique key in case these test entries are being persisted
         String key = "blocking";
-        String NEW_VALUE = VALUE + "abc";
+        String NEW_VALUE = VALUE + " abc";
         admin.putInCache(key, VALUE);
 
-        // Sleep for a couple of seconds
         try {
-            Thread.sleep(1100);
-        } catch (InterruptedException ie) {
-        }
-
-        try {
-            // This should throw a NeedsRefreshException since the entry is
-            // more than 1 second old
-            admin.getFromCache(key, 1);
+            // Force a NeedsRefreshException
+            admin.getFromCache(key, 0);
             fail("NeedsRefreshException should have been thrown");
         } catch (NeedsRefreshException nre) {
             // Fire off another thread to get the same cache entry.
             // Since blocking mode is enabled this thread should block
             // until the entry has been updated.
-            GetEntry getEntry = new GetEntry(key, NEW_VALUE, 1, false);
+            GetEntry getEntry = new GetEntry(key, NEW_VALUE, 0, false);
             Thread thread = new Thread(getEntry);
             thread.start();
 
             // Sleep for a bit to simulate the time taken to build the cache entry
             try {
-                Thread.sleep(500);
+                Thread.sleep(200);
             } catch (InterruptedException ie) {
             }
-
             // Putting the entry in the cache should mean that threads now retrieve
             // the updated entry
             admin.putInCache(key, NEW_VALUE);
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.