[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/lock ...
Manik Surtani
manik at jboss.org
Mon Jul 30 07:19:14 EDT 2007
User: msurtani
Date: 07/07/30 07:19:14
Added: tests/functional/org/jboss/cache/lock
PessimisticLockTest.java
Log:
JBCACHE-1157
Revision Changes Path
1.2 +93 -0 JBossCache/tests/functional/org/jboss/cache/lock/PessimisticLockTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: PessimisticLockTest.java
===================================================================
RCS file: PessimisticLockTest.java
diff -N PessimisticLockTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ PessimisticLockTest.java 30 Jul 2007 11:19:14 -0000 1.2
@@ -0,0 +1,93 @@
+package org.jboss.cache.lock;
+
+import junit.framework.TestCase;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.NodeSPI;
+import org.jboss.cache.transaction.DummyTransactionManagerLookup;
+
+import javax.transaction.TransactionManager;
+
+/**
+ * basic locking test
+ *
+ * @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
+ * @since 2.0.0
+ */
+public class PessimisticLockTest extends TestCase
+{
+ private Cache cache;
+ private TransactionManager tm;
+ private Fqn fqn = Fqn.fromString("/a/b/c");
+ private static final Log log = LogFactory.getLog(PessimisticLockTest.class);
+
+ protected void setUp()
+ {
+ cache = DefaultCacheFactory.getInstance().createCache(false);
+ cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ cache.start();
+ tm = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
+ }
+
+ protected void tearDown()
+ {
+ cache.stop();
+ }
+
+ public void testPut() throws Exception
+ {
+ cache.put(fqn, "k", "v");
+
+ tm.begin();
+ cache.put(fqn, "k2", "v2");
+ NodeSPI n = (NodeSPI) cache.getRoot().getChild(fqn);
+
+ assertFalse(n.getLock().isReadLocked());
+ assertTrue(n.getLock().isWriteLocked());
+ assertTrue(n.getParent().getLock().isReadLocked());
+ assertFalse(n.getParent().getLock().isWriteLocked());
+ assertTrue(n.getParent().getParent().getLock().isReadLocked());
+ assertFalse(n.getParent().getParent().getLock().isWriteLocked());
+
+ tm.commit();
+ }
+
+ public void testGet() throws Exception
+ {
+ cache.put(fqn, "k", "v");
+
+ tm.begin();
+ cache.get(fqn, "k2");
+ NodeSPI n = (NodeSPI) cache.getRoot().getChild(fqn);
+
+ assertTrue(n.getLock().isReadLocked());
+ assertFalse(n.getLock().isWriteLocked());
+ assertTrue(n.getParent().getLock().isReadLocked());
+ assertFalse(n.getParent().getLock().isWriteLocked());
+ assertTrue(n.getParent().getParent().getLock().isReadLocked());
+ assertFalse(n.getParent().getParent().getLock().isWriteLocked());
+
+ tm.commit();
+ }
+
+ public void testRemove() throws Exception
+ {
+ cache.put(fqn, "k", "v");
+ tm.begin();
+ cache.remove(fqn, "k2");
+ NodeSPI n = (NodeSPI) cache.getRoot().getChild(fqn);
+
+ assertFalse(n.getLock().isReadLocked());
+ assertTrue(n.getLock().isWriteLocked());
+ assertTrue(n.getParent().getLock().isReadLocked());
+ assertFalse(n.getParent().getLock().isWriteLocked());
+ assertTrue(n.getParent().getParent().getLock().isReadLocked());
+ assertFalse(n.getParent().getParent().getLock().isWriteLocked());
+
+ tm.commit();
+
+ }
+}
More information about the jboss-cvs-commits
mailing list