[jbosscache-commits] JBoss Cache SVN: r7839 - core/branches/flat/src/test/java/org/horizon/loader/bdbje.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Wed Mar 4 05:14:23 EST 2009


Author: adriancole
Date: 2009-03-04 05:14:23 -0500 (Wed, 04 Mar 2009)
New Revision: 7839

Modified:
   core/branches/flat/src/test/java/org/horizon/loader/bdbje/BdbjeLearningTest.java
Log:
disabled by default

Modified: core/branches/flat/src/test/java/org/horizon/loader/bdbje/BdbjeLearningTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/bdbje/BdbjeLearningTest.java	2009-03-04 10:10:36 UTC (rev 7838)
+++ core/branches/flat/src/test/java/org/horizon/loader/bdbje/BdbjeLearningTest.java	2009-03-04 10:14:23 UTC (rev 7839)
@@ -42,7 +42,6 @@
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
-import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Random;
@@ -56,7 +55,7 @@
  * @version $Id: $
  * @since 1.0
  */
- at Test(groups = "unit", enabled = true, testName = "loader.bdbje.BdbjeLearningTest")
+ at Test(groups = "learning", enabled = false, testName = "loader.bdbje.BdbjeLearningTest")
 public class BdbjeLearningTest {
    String dbHome = TestingUtil.TEST_FILES + "/Horizon-BdbjeLearningTest";
    Environment env;
@@ -67,9 +66,11 @@
    private static final String STORED_ENTRIES = "storedEntriesDb";
    private Database storedEntriesDb;
    private StoredMap<Object, StoredEntry> cacheMap;
+   final Random r = new Random();
+   protected StoredEntry[] entries;
 
 
-   @BeforeMethod
+   @BeforeMethod(firstTimeOnly = true)
    public void setUp() throws Exception {
       new File(dbHome).mkdirs();
       System.out.println("Opening environment in: " + dbHome);
@@ -97,8 +98,10 @@
       cacheMap =
             new StoredMap<Object, StoredEntry>(storedEntriesDb,
                                                storedEntryKeyBinding, storedEntryValueBinding, true);
+      entries = new StoredEntry[10];
+      for (int i = 0; i < entries.length; i++)
+         entries[i] = new StoredEntry("k" + i, "v" + i);
 
-
    }
 
    public void testTransactionWorker() throws Exception {
@@ -122,7 +125,7 @@
    }
 
 
-   @AfterMethod
+   @AfterMethod(lastTimeOnly = true)
    public void tearDown() throws Exception {
       storedEntriesDb.close();
       javaCatalog.close();
@@ -662,72 +665,16 @@
       assert expected.isEmpty();
    }
 
-   public void testConcurrency() throws Throwable {
-      int numThreads = 3;
-      final int loops = 500;
-      final String[] keys = new String[10];
-      final String[] values = new String[10];
-      for (int i = 0; i < 10; i++) keys[i] = "k" + i;
-      for (int i = 0; i < 10; i++) values[i] = "v" + i;
-
-
-      final Random r = new Random();
-      final List<Throwable> throwables = new LinkedList<Throwable>();
-
-      final Runnable store = new Runnable() {
-         public void run() {
-            try {
-               int randomInt = r.nextInt(10);
-               store(new StoredEntry(keys[randomInt], values[randomInt]));
-            } catch (Throwable e) {
-               throwables.add(e);
-            }
-         }
-      };
-
-      final Runnable remove = new Runnable() {
-         public void run() {
-            try {
-               cacheMap.remove(keys[r.nextInt(10)]);
-            } catch (Throwable e) {
-               throwables.add(e);
-            }
-         }
-      };
-
-      final Runnable get = new Runnable() {
-         public void run() {
-            try {
-               int randomInt = r.nextInt(10);
-               StoredEntry se = load(keys[randomInt]);
-               assert se == null || se.getValue().equals(values[randomInt]);
-               loadAll();
-            } catch (Throwable e) {
-               throwables.add(e);
-            }
-         }
-      };
-
-      Thread[] threads = new Thread[numThreads];
-
-      for (int i = 0; i < numThreads; i++) {
-         threads[i] = new Thread(getClass().getSimpleName() + "-" + i) {
-            public void run() {
-               for (int i = 0; i < loops; i++) {
-                  store.run();
-                  remove.run();
-                  get.run();
-               }
-            }
-         };
+   @Test(threadPoolSize = 3, invocationCount = 3, timeOut = 10000)
+   public void testConcurrency() throws CacheLoaderException {
+      for (int i = 0; i < 500; i++) {
+         store(entries[r.nextInt(entries.length)]);
+         cacheMap.remove(entries[r.nextInt(entries.length)]);
+         int index = r.nextInt(entries.length);
+         StoredEntry entry = load(entries[index]);
+         assert entry == null || entry.getValue().equals(entries[index].getValue());
+         loadAll();
       }
-
-      for (Thread t : threads) t.start();
-      for (Thread t : threads) t.join();
-
-      if (!throwables.isEmpty()) throw throwables.get(0);
    }
-
-
 }
 




More information about the jbosscache-commits mailing list