Anonymous avatar Anonymous committed 6079f1c

Beefed up the concurrency test

Comments (0)

Files changed (1)

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

     // Constants needed in the tests
     private final String KEY = "key";
     private final String VALUE = "This is some content";
-    private final int ITERATION_COUNT = 50;
-    private final int THREAD_COUNT = 30;
-    private final int UNIQUE_KEYS = 15;
+    private final int ITERATION_COUNT = 5; //500;
+    private final int THREAD_COUNT = 6; //600;
+    private final int UNIQUE_KEYS = 1013;
 
     /**
      * Class constructor.
     public void setUp() {
         // At first invocation, create a new Cache
         if (admin == null) {
+            Properties config = new Properties();
+            config.setProperty(AbstractCacheAdministrator.CACHE_CAPACITY_KEY, "70");
+            config.setProperty(AbstractCacheAdministrator.CACHE_BLOCKING_KEY, "false");
             admin = new GeneralCacheAdministrator();
             assertNotNull(admin);
         }
      * Verify that we can concurrently access the cache without problems
      */
     public void testPut() {
-        Thread thread = null;
+        Thread[] thread = new Thread[THREAD_COUNT];
 
         for (int idx = 0; idx < THREAD_COUNT; idx++) {
             OSGeneralTest runner = new OSGeneralTest();
-            thread = new Thread(runner);
-            thread.start();
+            thread[idx] = new Thread(runner);
+            thread[idx].start();
         }
 
+        boolean stillAlive;
+
         do {
             try {
                 Thread.sleep(100);
             } catch (InterruptedException e) {
                 // do nothing
             }
-        } while (thread.isAlive());
+
+            stillAlive = false;
+
+            int i = 0;
+
+            while ((i < thread.length) && !stillAlive) {
+                stillAlive |= thread[i++].isAlive();
+            }
+        } while (stillAlive);
     }
 
     /**
         }
 
         public void run() {
-            for (int i = 0; i < ITERATION_COUNT; i++) {
+            int start = (int) (Math.random() * UNIQUE_KEYS);
+            System.out.print(start + " ");
+
+            for (int i = start; i < (start + ITERATION_COUNT); i++) {
                 doit(i);
             }
         }
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.