[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/lock ...
Manik Surtani
msurtani at jboss.com
Tue Jan 30 16:34:26 EST 2007
User: msurtani
Date: 07/01/30 16:34:26
Added: tests/functional/org/jboss/cache/lock
WriteLockOnParentTest.java
Log:
JBCACHE-955
Revision Changes Path
1.2 +169 -0 JBossCache/tests/functional/org/jboss/cache/lock/WriteLockOnParentTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: WriteLockOnParentTest.java
===================================================================
RCS file: WriteLockOnParentTest.java
diff -N WriteLockOnParentTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ WriteLockOnParentTest.java 30 Jan 2007 21:34:26 -0000 1.2
@@ -0,0 +1,169 @@
+package org.jboss.cache.lock;
+
+import junit.framework.TestCase;
+
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import java.util.Collections;
+
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
+
+public class WriteLockOnParentTest extends TestCase
+{
+ private CacheSPI cache;
+ private TransactionManager tm;
+ private Fqn a = Fqn.fromString("/a"), a_b = Fqn.fromString("/a/b"), a_c = Fqn.fromString("/a/c");
+
+ protected void setUp() throws Exception
+ {
+ cache = (CacheSPI) DefaultCacheFactory.getInstance().createCache(false);
+ cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
+ // reduce LAT so the test runs faster
+ cache.getConfiguration().setLockAcquisitionTimeout(500);
+
+ cache.start();
+ tm = cache.getTransactionManager();
+ }
+
+ protected void tearDown() throws Exception
+ {
+ if (tm.getTransaction() != null)
+ {
+ try
+ {
+ tm.rollback();
+ }
+ catch (Exception e)
+ {
+ // do sweet F.A.
+ }
+ }
+ cache.stop();
+ }
+
+ public void testDefaultCfg()
+ {
+ assertFalse("Locking of parent nodes for child inserts and removes should be false by default", cache.getConfiguration().isLockParentForChildInsertRemove());
+ }
+
+ public void testDefaultChildInsert() throws Exception
+ {
+ cache.put(a, Collections.emptyMap());
+
+ assertNotNull("/a should exist", cache.peek(a, false));
+
+ // concurrent insert of /a/b and /a/c
+ tm.begin();
+ cache.put(a_b, Collections.emptyMap());
+ Transaction t1 = tm.suspend();
+
+ tm.begin();
+ cache.put(a_c, Collections.emptyMap());
+ tm.commit();
+
+ tm.resume(t1);
+ tm.commit();
+
+ assertNotNull("/a/b should exist", cache.peek(a_b, false));
+ assertNotNull("/a/c should exist", cache.peek(a_c, false));
+ }
+
+ public void testLockParentChildInsert() throws Exception
+ {
+ cache.getConfiguration().setLockParentForChildInsertRemove(true);
+ cache.put(a, Collections.emptyMap());
+
+ assertNotNull("/a should exist", cache.peek(a, false));
+
+ // concurrent insert of /a/b and /a/c
+ tm.begin();
+ cache.put(a_b, Collections.emptyMap());
+ Transaction t1 = tm.suspend();
+
+ tm.begin();
+ try
+ {
+ cache.put(a_c, Collections.emptyMap());
+ fail("Should not get here.");
+ }
+ catch (TimeoutException e)
+ {
+ // expected
+ }
+ tm.commit();
+
+ tm.resume(t1);
+ tm.commit();
+
+ assertNotNull("/a/b should exist", cache.peek(a_b, false));
+ assertNull("/a/c should not exist", cache.peek(a_c, false));
+ }
+
+ public void testDefaultChildRemove() throws Exception
+ {
+ cache.put(a, Collections.emptyMap());
+ cache.put(a_b, Collections.emptyMap());
+ cache.put(a_c, Collections.emptyMap());
+
+ assertNotNull("/a should exist", cache.peek(a, false));
+ assertNotNull("/a/b should exist", cache.peek(a_b, false));
+ assertNotNull("/a/c should exist", cache.peek(a_c, false));
+
+ // concurrent remove of /a/b and /a/c
+ tm.begin();
+ cache.removeNode(a_b);
+ Transaction t1 = tm.suspend();
+
+ tm.begin();
+ cache.removeNode(a_c);
+ tm.commit();
+
+ tm.resume(t1);
+ tm.commit();
+
+ assertNotNull("/a should exist", cache.peek(a, false));
+ assertNull("/a/b should not exist", cache.peek(a_b, false));
+ assertNull("/a/c should not exist", cache.peek(a_c, false));
+ }
+
+ public void testLockParentChildRemove() throws Exception
+ {
+ cache.getConfiguration().setLockParentForChildInsertRemove(true);
+
+ cache.put(a, Collections.emptyMap());
+ cache.put(a_b, Collections.emptyMap());
+ cache.put(a_c, Collections.emptyMap());
+
+ assertNotNull("/a should exist", cache.peek(a, false));
+ assertNotNull("/a/b should exist", cache.peek(a_b, false));
+ assertNotNull("/a/c should exist", cache.peek(a_c, false));
+
+ // concurrent remove of /a/b and /a/c
+ tm.begin();
+ cache.removeNode(a_b);
+ Transaction t1 = tm.suspend();
+
+ tm.begin();
+ try
+ {
+ cache.removeNode(a_c);
+ fail("Should not get here.");
+ }
+ catch (TimeoutException e)
+ {
+ // expected
+ }
+ tm.commit();
+
+ tm.resume(t1);
+ tm.commit();
+
+ assertNotNull("/a should exist", cache.peek(a, false));
+ assertNull("/a/b should not exist", cache.peek(a_b, false));
+ assertNotNull("/a/c should exist", cache.peek(a_c, false));
+ }
+
+}
More information about the jboss-cvs-commits
mailing list