[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/transaction ...
Manik Surtani
msurtani at jboss.com
Wed Oct 11 09:56:31 EDT 2006
User: msurtani
Date: 06/10/11 09:56:31
Added: tests/functional/org/jboss/cache/transaction
SuspendTxTest.java
Log:
JBCACHE-785
Revision Changes Path
1.2 +91 -0 JBossCache/tests/functional/org/jboss/cache/transaction/SuspendTxTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: SuspendTxTest.java
===================================================================
RCS file: SuspendTxTest.java
diff -N SuspendTxTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ SuspendTxTest.java 11 Oct 2006 13:56:31 -0000 1.2
@@ -0,0 +1,91 @@
+package org.jboss.cache.transaction;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.TreeCache;
+
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+/**
+ * Based on a contribution by Owen Taylor
+ *
+ * @author otaylor at redhat.com
+ * @author Manik Surtani (manik at jboss.org)
+ */
+public class SuspendTxTest extends TestCase
+{
+ TreeCache cache;
+ TransactionManager mgr;
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ cache = new TreeCache();
+ cache.getConfiguration().setCacheMode("local");
+ cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
+ cache.start();
+ mgr = cache.getTransactionManager();
+ }
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ cache.stop();
+ if (mgr.getTransaction() != null)
+ {
+ mgr.rollback();
+ }
+ mgr = null;
+ }
+
+ /**
+ * Tests that locks created when a transaction is suspended are independent
+ * from the transaction.
+ */
+ public void testSuspendedLocks() throws Exception
+ {
+ mgr.begin();
+
+ cache.put("/one/two", "key1", "val1");
+ int numLocksBefore = cache.getNumberOfLocksHeld();
+
+ Transaction tx = mgr.suspend();
+
+ cache.put("/a/b", "key1", "val1");
+ mgr.resume(tx);
+
+ assertEquals(numLocksBefore, cache.getNumberOfLocksHeld());
+ }
+
+ /**
+ * Tests that locks created when a transaction is suspended are independent
+ * from the transaction.
+ */
+ public void testSuspendedUsingOptionsLocks() throws Exception
+ {
+ mgr.begin();
+
+ cache.put("/one/two", "key1", "val1");
+ int numLocksBefore = cache.getNumberOfLocksHeld();
+
+ cache.getInvocationContext().getOptionOverrides().setFailSilently(true); // will cause any current txs to be suspended for the duration of this call.
+ cache.put(Fqn.fromString("/a/b"), "key1", "val1");
+
+ assertEquals(numLocksBefore, cache.getNumberOfLocksHeld());
+ }
+
+
+ public static Test suite()
+ {
+ return new TestSuite(SuspendTxTest.class);
+ }
+
+ public static void main(String[] args)
+ {
+ junit.textui.TestRunner.run(suite());
+ }
+
+}
More information about the jboss-cvs-commits
mailing list