[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/optimistic ...
Manik Surtani
manik at jboss.org
Wed Jul 18 09:18:23 EDT 2007
User: msurtani
Date: 07/07/18 09:18:23
Added: tests/functional/org/jboss/cache/optimistic Tag:
Branch_JBossCache_1_4_0 ConcurrentCreationTest.java
Log:
JBCACHE-1026
Revision Changes Path
No revision
No revision
1.1.2.1 +112 -0 JBossCache/tests/functional/org/jboss/cache/optimistic/Attic/ConcurrentCreationTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ConcurrentCreationTest.java
===================================================================
RCS file: ConcurrentCreationTest.java
diff -N ConcurrentCreationTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ConcurrentCreationTest.java 18 Jul 2007 13:18:23 -0000 1.1.2.1
@@ -0,0 +1,112 @@
+package org.jboss.cache.optimistic;
+
+import junit.framework.TestCase;
+import org.jboss.cache.DummyTransactionManagerLookup;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.TreeCache;
+import org.jboss.cache.interceptors.Interceptor;
+import org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor;
+import org.jboss.cache.misc.TestingUtil;
+import org.jgroups.blocks.MethodCall;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+/**
+ * @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
+ */
+public class ConcurrentCreationTest extends TestCase
+{
+ private Fqn f = Fqn.fromString("/a/b");
+ private TreeCache c;
+ private List exceptions = new CopyOnWriteArrayList();
+
+ protected void setUp() throws Exception
+ {
+ c = new TreeCache();
+ c.setNodeLockingScheme("OPTIMISTIC");
+ c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ c.start();
+ }
+
+ protected void tearDown()
+ {
+ c.stop();
+ }
+
+ public class Putter extends Thread
+ {
+ public Putter(String name)
+ {
+ super(name);
+ }
+
+ public void run()
+ {
+ try
+ {
+ c.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(MethodCall c) throws Throwable
+ {
+ String threadName = Thread.currentThread().getName();
+ System.out.println("Called by " + threadName);
+ if (threadName.equals("SLOWPUT"))
+ {
+ System.out.println("Delaying " + threadName);
+ Thread.sleep(1000);
+ System.out.println("Delayed " + threadName);
+ }
+ System.out.println("Passing up " + threadName);
+ Object o = super.invoke(c);
+ System.out.println("Returning " + threadName);
+ return o;
+ }
+ };
+
+ List interceptors = c.getInterceptors();
+ int i=0;
+ for (i=0; i<interceptors.size(); i++)
+ {
+ if (interceptors.get(i) instanceof OptimisticCreateIfNotExistsInterceptor) break;
+ }
+
+ Interceptor prev = (Interceptor) interceptors.get(i);
+ Interceptor next = (Interceptor) interceptors.get(i+1);
+
+ in.setNext(next);
+ prev.setNext(in);
+
+ c.setInterceptorChain((Interceptor) interceptors.get(0));
+
+ System.out.println(c.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 (Iterator e = exceptions.iterator() ; e.hasNext() ;) ((Exception) e.next()).printStackTrace();
+ assertEquals(0, exceptions.size());
+ }
+
+}
More information about the jboss-cvs-commits
mailing list