[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/optimistic ...
Manik Surtani
manik at jboss.org
Wed Jul 18 12:03:31 EDT 2007
User: msurtani
Date: 07/07/18 12:03:31
Modified: tests/functional/org/jboss/cache/optimistic
ConcurrentTransactionTest.java
Removed: tests/functional/org/jboss/cache/optimistic
ConcurrentCreationTest.java
Log:
Consolidated JBCACHE-1026 tests
Revision Changes Path
1.8 +65 -0 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.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- ConcurrentTransactionTest.java 20 Apr 2007 13:27:09 -0000 1.7
+++ ConcurrentTransactionTest.java 18 Jul 2007 16:03:31 -0000 1.8
@@ -8,12 +8,17 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
+import org.jboss.cache.InvocationContext;
import org.jboss.cache.NodeSPI;
+import org.jboss.cache.interceptors.Interceptor;
+import org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor;
+import org.jboss.cache.misc.TestingUtil;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import java.util.LinkedList;
import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
/**
@@ -22,6 +27,8 @@
public class ConcurrentTransactionTest extends AbstractOptimisticTestCase
{
private CacheSPI cache;
+ private Fqn f = Fqn.fromString("/a/b");
+ private List<Exception> exceptions = new CopyOnWriteArrayList<Exception>();
public ConcurrentTransactionTest(String name)
{
@@ -196,4 +203,62 @@
assertTrue("Should not have caught any exceptions!!", exceptions.isEmpty());
}
+
+ public class Putter extends Thread
+ {
+ public Putter(String name)
+ {
+ super(name);
+ }
+
+ public void run()
+ {
+ try
+ {
+ cache.put(new Fqn(f, getName()), "a", "b");
+ }
+ catch (Exception e)
+ {
+ exceptions.add(e);
+ }
+ }
+ }
+
+ public void testConcurrentPut() throws Exception
+ {
+ Interceptor in = new Interceptor()
+ {
+ public Object invoke(InvocationContext ctx) throws Throwable
+ {
+ if (Thread.currentThread().getName().equals("SLOWPUT")) Thread.sleep(1000);
+ return super.invoke(ctx);
+ }
+ };
+
+ List interceptors = cache.getInterceptorChain();
+ int i = 0;
+ for (i = 0; i < interceptors.size(); i++)
+ {
+ if (interceptors.get(i) instanceof OptimisticCreateIfNotExistsInterceptor) break;
+ }
+
+ cache.addInterceptor(in, i + 1);
+
+ System.out.println(cache.getInterceptorChain());
+
+ // now create 2 threads to do concurrent puts.
+ Putter slow = new Putter("SLOWPUT");
+ Putter fast = new Putter("FASTPUT");
+
+ // start the slow putter first
+ slow.start();
+ TestingUtil.sleepThread(200);
+ fast.start();
+
+ fast.join();
+ slow.join();
+
+ for (Exception e : exceptions) e.printStackTrace();
+ assertEquals(0, exceptions.size());
+ }
}
More information about the jboss-cvs-commits
mailing list