[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/transaction ...
Manik Surtani
msurtani at jboss.com
Fri Jan 5 12:12:10 EST 2007
User: msurtani
Date: 07/01/05 12:12:10
Added: tests/functional/org/jboss/cache/transaction Tag:
Branch_JBossCache_1_4_0
MultipleThreadSameTxTest.java
Log:
added test for JBCACHE-928
Revision Changes Path
No revision
No revision
1.1.2.1 +97 -0 JBossCache/tests/functional/org/jboss/cache/transaction/Attic/MultipleThreadSameTxTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MultipleThreadSameTxTest.java
===================================================================
RCS file: MultipleThreadSameTxTest.java
diff -N MultipleThreadSameTxTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ MultipleThreadSameTxTest.java 5 Jan 2007 17:12:10 -0000 1.1.2.1
@@ -0,0 +1,97 @@
+package org.jboss.cache.transaction;
+
+import junit.framework.TestCase;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.TreeCache;
+
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Experiment to test behaviour of multiple threads working on the same tx
+ *
+ * @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
+ * @since 1.4.0
+ */
+public class MultipleThreadSameTxTest extends TestCase
+{
+ private TreeCache cache;
+ private TransactionManager tm;
+ private Fqn fqn = Fqn.fromString("/test");
+
+ protected void setUp() throws Exception
+ {
+ cache = new TreeCache();
+ cache.setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
+ cache.startService();
+ tm = cache.getTransactionManager();
+ }
+
+ protected void tearDown()
+ {
+ try
+ {
+ if (tm != null && tm.getTransaction() != null)
+ {
+ try
+ {
+ tm.rollback();
+ }
+ catch (SystemException e)
+ {
+ // do nothing
+ }
+ }
+ }
+ catch (SystemException e)
+ {
+ // do nothing
+ }
+ if (cache != null) cache.stopService();
+ cache = null;
+ tm = null;
+ }
+
+ public void testControl() throws Exception
+ {
+ assertEquals(0, cache.getNumberOfLocksHeld());
+ tm.begin();
+ cache.put(fqn, "k", "v");
+ assertEquals(2, cache.getNumberOfLocksHeld());
+ tm.rollback();
+ assertEquals(0, cache.getNumberOfLocksHeld());
+ }
+
+ public void testRollbackInDifferentThread() throws Exception
+ {
+ tm.begin();
+ cache.put(fqn, "k", "v");
+ assertEquals(2, cache.getNumberOfLocksHeld());
+ final List errors = new LinkedList();
+
+ Thread t = new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ tm.rollback();
+ }
+ catch (SystemException e)
+ {
+ e.printStackTrace();
+ errors.add(e);
+ }
+ }
+ };
+
+ t.start();
+ t.join();
+
+ assertTrue("Rollback should have no errs", errors.isEmpty());
+ assertEquals(0, cache.getNumberOfLocksHeld());
+ }
+
+}
More information about the jboss-cvs-commits
mailing list