Author: mircea.markus
Date: 2008-06-11 05:30:03 -0400 (Wed, 11 Jun 2008)
New Revision: 5971
Added:
core/branches/1.4.X/tests/functional/org/jboss/cache/transaction/IsolationLevelReadUncommitedTest.java
Log:
added a new unit test
Added:
core/branches/1.4.X/tests/functional/org/jboss/cache/transaction/IsolationLevelReadUncommitedTest.java
===================================================================
---
core/branches/1.4.X/tests/functional/org/jboss/cache/transaction/IsolationLevelReadUncommitedTest.java
(rev 0)
+++
core/branches/1.4.X/tests/functional/org/jboss/cache/transaction/IsolationLevelReadUncommitedTest.java 2008-06-11
09:30:03 UTC (rev 5971)
@@ -0,0 +1,102 @@
+package org.jboss.cache.transaction;
+
+import EDU.oswego.cs.dl.util.concurrent.Latch;
+
+import javax.transaction.Transaction;
+import javax.transaction.SystemException;
+import javax.transaction.NotSupportedException;
+
+import org.jboss.cache.TreeCache;
+import org.jboss.cache.DummyTransactionManagerLookup;
+import org.jboss.cache.lock.IsolationLevel;
+import junit.framework.TestCase;
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ * @since 2.2
+ */
+public class IsolationLevelReadUncommitedTest extends TestCase {
+
+ private TreeCache cache = null;
+
+ private Transaction startTransaction() throws SystemException, NotSupportedException
+ {
+ DummyTransactionManager mgr = DummyTransactionManager.getInstance();
+ mgr.begin();
+ return mgr.getTransaction();
+ }
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ cache = new TreeCache();
+ cache.setCacheMode(TreeCache.LOCAL);
+ cache.setIsolationLevel(IsolationLevel.READ_UNCOMMITTED);
+
cache.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ cache.setLockAcquisitionTimeout(1000);
+ cache.startService();
+ }
+
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+
+ cache.stopService();
+ cache.destroyService();
+ cache = null;
+ }
+
+ /**
+ * Tests following scenario:
+ * tx1 starts and create /a/b/c
+ * tx2 starts and adds a key value under /a/b
+ * tx2 commits
+ * tx1 rollabcks
+ *
+ * the key/value added bu tx should be in the cache still, and should not be affected
by tx1 rollback.
+ */
+ public void testInterlacedTx() throws Exception
+ {
+ Transaction tx = startTransaction();
+ cache.put("/a/b/c", "key", "value");
+ System.out.println("Tx1 just added /a/b/c");
+ System.out.println(cache.printLockInfo());
+ Latch latch = new Latch();
+ TxThread txThread = new TxThread(cache, latch);
+ txThread.start();
+ latch.acquire();
+ tx.rollback();
+ System.out.println("Tx1 just rolled back");
+ System.out.println(cache.printLockInfo());
+
+ assertNotNull(cache.get("/a/b"));
+ assertNotNull(cache.get("/a/b", "newKey"));
+ }
+
+ private class TxThread extends Thread
+ {
+ TreeCache cache;
+ Latch latch;
+
+ private TxThread(TreeCache cache, Latch latch) {
+ this.cache = cache;
+ this.latch = latch;
+ }
+
+ public void run() {
+ try {
+ Transaction tx = startTransaction();
+ cache.put("/a/b","newKey","newValue");
+ System.out.println("Tx2 just updated /a/b");
+ System.out.println(cache.printLockInfo());
+ tx.commit();
+ System.out.println("Tx2 commited");
+ latch.release();
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException();
+ }
+ }
+ }
+}
\ No newline at end of file
Show replies by date