[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/optimistic ...
Manik Surtani
manik at jboss.org
Fri Apr 20 09:09:41 EDT 2007
User: msurtani
Date: 07/04/20 09:09:41
Modified: tests/functional/org/jboss/cache/optimistic Tag:
Branch_JBossCache_1_4_0
ConcurrentTransactionTest.java
Log:
JBCACHE-1026
Revision Changes Path
No revision
No revision
1.1.2.2 +116 -1 JBossCache/tests/functional/org/jboss/cache/optimistic/ConcurrentTransactionTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ConcurrentTransactionTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/optimistic/ConcurrentTransactionTest.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -b -r1.1.2.1 -r1.1.2.2
--- ConcurrentTransactionTest.java 10 Jul 2006 12:17:35 -0000 1.1.2.1
+++ ConcurrentTransactionTest.java 20 Apr 2007 13:09:41 -0000 1.1.2.2
@@ -12,6 +12,11 @@
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
+import java.util.List;
+import java.util.LinkedList;
+import java.util.Iterator;
+
+import EDU.oswego.cs.dl.util.concurrent.Latch;
/**
*
@@ -30,7 +35,10 @@
{
try
{
- cache = createCache();
+ //cache = createCache();
+ cache = createCacheUnstarted();
+ cache.setUseRegionBasedMarshalling(true);
+ cache.startService();
}
catch (Exception e)
{
@@ -79,4 +87,111 @@
OptimisticTreeNode n = (OptimisticTreeNode) cache.get(Fqn.ROOT);
System.out.println(n.getVersion());
}
+
+ public void testConcurrentCreationTestWithEmptyCache() throws Exception
+ {
+ doConcurrentCreationTest(false);
+ }
+
+ public void testConcurrentCreationTestWithEmptyCacheActivated() throws Exception
+ {
+ assertNotNull("Region manager is null!", cache.getRegionManager());
+ cache.activateRegion("/parent");
+ assertTrue(cache.exists("/parent"));
+ doConcurrentCreationTest(false);
+ }
+
+ public void testConcurrentCreationTestWithPopulatedCache() throws Exception
+ {
+ doConcurrentCreationTest(true);
+ }
+
+ public void testConcurrentReadAndRemove() throws Exception
+ {
+ final List exceptions = new LinkedList();
+ final Latch readerLatch = new Latch();
+ final Latch readerFinishedLatch = new Latch();
+ final Fqn fqn = Fqn.fromString("/parent/child");
+
+ cache.put(fqn, "k", "v");
+
+ class Reader extends Thread
+ {
+ public void run()
+ {
+ try
+ {
+ cache.getTransactionManager().begin();
+ cache.get(fqn, "k"); // read
+ readerFinishedLatch.release();
+ readerLatch.acquire(); // wait
+ cache.getTransactionManager().commit();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ exceptions.add(e);
+
+ }
+ }
+ }
+
+ Thread reader = new Reader();
+
+ reader.start();
+ readerFinishedLatch.acquire();
+ cache.remove(fqn.getParent());
+ assertFalse(cache.exists(fqn.getParent()));
+ readerLatch.release();
+ reader.join();
+
+ assertTrue("Should not have caught any exceptions!!", exceptions.isEmpty());
+ }
+
+
+ private void doConcurrentCreationTest(boolean prepopulateParent) throws Exception
+ {
+ if (prepopulateParent) cache.put("/parent/dummy", "k", "v");
+
+ final List exceptions = new LinkedList();
+ final Latch latch = new Latch();
+
+ class ConcurrentCreator extends Thread
+ {
+ private String name;
+ public ConcurrentCreator(String name)
+ {
+ this.name = name;
+ }
+
+ public void run()
+ {
+ try
+ {
+ cache.getTransactionManager().begin();
+ cache.put("/parent/child" + name, "key", "value");
+ latch.acquire();
+ cache.getTransactionManager().commit();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ exceptions.add(e);
+ }
+ }
+ }
+
+ Thread one = new ConcurrentCreator("one");
+ Thread two = new ConcurrentCreator("two");
+
+ one.start();
+ two.start();
+
+ latch.release();
+
+ one.join();
+ two.join();
+
+ assertTrue("Should not have caught any exceptions!!", exceptions.isEmpty());
+ }
}
More information about the jboss-cvs-commits
mailing list