From jbosscache-commits at lists.jboss.org Fri Jun 27 17:25:42 2008 Content-Type: multipart/mixed; boundary="===============6599494845800632247==" MIME-Version: 1.0 From: jbosscache-commits at lists.jboss.org To: jbosscache-commits at lists.jboss.org Subject: [jbosscache-commits] JBoss Cache SVN: r6107 - core/trunk/src/test/java/org/jboss/cache/api/mvcc. Date: Fri, 27 Jun 2008 17:25:42 -0400 Message-ID: --===============6599494845800632247== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: manik.surtani(a)jboss.com Date: 2008-06-27 17:25:42 -0400 (Fri, 27 Jun 2008) New Revision: 6107 Removed: core/trunk/src/test/java/org/jboss/cache/api/mvcc/LockParentForChildInse= rtRemoveTest.java core/trunk/src/test/java/org/jboss/cache/api/mvcc/LockTest.java Log: More MVCC tests Deleted: core/trunk/src/test/java/org/jboss/cache/api/mvcc/LockParentForChi= ldInsertRemoveTest.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- core/trunk/src/test/java/org/jboss/cache/api/mvcc/LockParentForChildIns= ertRemoveTest.java 2008-06-27 17:28:57 UTC (rev 6106) +++ core/trunk/src/test/java/org/jboss/cache/api/mvcc/LockParentForChildIns= ertRemoveTest.java 2008-06-27 21:25:42 UTC (rev 6107) @@ -1,12 +0,0 @@ -package org.jboss.cache.api.mvcc; - -import org.testng.annotations.Test; - -(a)Test(groups =3D {"functional", "mvcc"}) -public class LockParentForChildInsertRemoveTest extends LockTest -{ - public LockParentForChildInsertRemoveTest() - { - lockParentForInsertRemove =3D true; - } -} Deleted: core/trunk/src/test/java/org/jboss/cache/api/mvcc/LockTest.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- core/trunk/src/test/java/org/jboss/cache/api/mvcc/LockTest.java 2008-06= -27 17:28:57 UTC (rev 6106) +++ core/trunk/src/test/java/org/jboss/cache/api/mvcc/LockTest.java 2008-06= -27 21:25:42 UTC (rev 6107) @@ -1,423 +0,0 @@ -package org.jboss.cache.api.mvcc; - -import org.jboss.cache.Cache; -import org.jboss.cache.DefaultCacheFactory; -import org.jboss.cache.Fqn; -import org.jboss.cache.config.Configuration.CacheMode; -import org.jboss.cache.config.Configuration.NodeLockingScheme; -import org.jboss.cache.factories.UnitTestCacheConfigurationFactory; -import org.jboss.cache.invocation.InvocationContextContainer; -import org.jboss.cache.lock.IsolationLevel; -import org.jboss.cache.lock.LockManager; -import org.jboss.cache.lock.MVCCLockManager.LockContainer; -import org.jboss.cache.transaction.DummyTransactionManagerLookup; -import org.jboss.cache.util.TestingUtil; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import javax.transaction.Transaction; -import javax.transaction.TransactionManager; -import java.util.Collections; - -/** - * @author Manik Surtani (manik(a)jbo= ss.org) - * @since 3.0 - */ -(a)Test(groups =3D {"functional", "mvcc"}) -public class LockTest -{ - Cache cache; - TransactionManager tm; - Fqn A =3D Fqn.fromString("/a"); - Fqn AB =3D Fqn.fromString("/a/b"); - Fqn ABC =3D Fqn.fromString("/a/b/c"); - Fqn ABCD =3D Fqn.fromString("/a/b/c/d"); - LockManager lockManager; - InvocationContextContainer icc; - boolean lockParentForInsertRemove =3D false; - boolean repeatableRead =3D true; - - - @BeforeMethod - public void setUp() - { - cache =3D new DefaultCacheFactory().createCache(Unit= TestCacheConfigurationFactory.createConfiguration(CacheMode.LOCAL), false); - cache.getConfiguration().setNodeLockingScheme(NodeLockingScheme.MVCC= ); - cache.getConfiguration().setTransactionManagerLookupClass(DummyTrans= actionManagerLookup.class.getName()); - cache.getConfiguration().setLockParentForChildInsertRemove(lockParen= tForInsertRemove); - cache.getConfiguration().setIsolationLevel(repeatableRead ? Isolatio= nLevel.REPEATABLE_READ : IsolationLevel.READ_COMMITTED); - cache.start(); - lockManager =3D TestingUtil.extractComponentRegistry(cache).getCompo= nent(LockManager.class); - icc =3D TestingUtil.extractComponentRegistry(cache).getComponent(Inv= ocationContextContainer.class); - tm =3D TestingUtil.extractComponentRegistry(cache).getComponent(Tran= sactionManager.class); - } - - @AfterMethod - public void tearDown() - { - TestingUtil.killCaches(cache); - } - - private void assertLocked(Fqn fqn) - { - assert lockManager.isLocked(fqn) : fqn + " not locked!"; - assert icc.get().getLocks().contains(fqn) : "Lock not recorded for "= + fqn; - } - - private void assertNotLocked(Fqn fqn) - { - // can't rely on the negative test since other nodes may share the s= ame lock with lock striping. -// assert !lockManager.isLocked(fqn) : fqn + " is locked!"; - assert !icc.get().getLocks().contains(fqn) : fqn + " lock recorded!"; - } - - private void assertNoLocks() - { - LockContainer lc =3D (LockContainer) TestingUtil.extractField(lockMa= nager, "lockContainer"); - assert lc.getNumLocksHeld() =3D=3D 0 : "Stale locks exist!" + lockMa= nager.printLockInfo(); - assert icc.get().getLocks().isEmpty() : "Stale (?) locks recorded! "= + icc.get().getLocks(); - } - - public void testLocksOnPutKeyVal() throws Exception - { - tm.begin(); - cache.put(AB, "k", "v"); - if (lockParentForInsertRemove) - assertLocked(Fqn.ROOT); - else - assertNotLocked(Fqn.ROOT); - assertLocked(A); - assertLocked(AB); - assertNotLocked(ABC); - tm.commit(); - - assertNoLocks(); - - tm.begin(); - assert cache.get(AB, "k").equals("v"); - assertNotLocked(Fqn.ROOT); - assertNotLocked(A); - assertNotLocked(AB); - assertNotLocked(ABC); - tm.commit(); - - assertNoLocks(); - - tm.begin(); - cache.put(ABC, "k", "v"); - assertNotLocked(Fqn.ROOT); - assertNotLocked(A); - if (lockParentForInsertRemove) - assertLocked(AB); - else - assertNotLocked(AB); - assertLocked(ABC); - tm.commit(); - - assertNoLocks(); - } - - public void testLocksOnPutData() throws Exception - { - tm.begin(); - cache.put(AB, Collections.singletonMap("k", "v")); - if (lockParentForInsertRemove) - assertLocked(Fqn.ROOT); - else - assertNotLocked(Fqn.ROOT); - assertLocked(A); - assertLocked(AB); - assertNotLocked(ABC); - tm.commit(); - - assertNoLocks(); - - tm.begin(); - assert cache.get(AB, "k").equals("v"); - assertNotLocked(Fqn.ROOT); - assertNotLocked(A); - assertNotLocked(AB); - assertNotLocked(ABC); - tm.commit(); - - assertNoLocks(); - - tm.begin(); - cache.put(ABC, Collections.singletonMap("k", "v")); - assertNotLocked(Fqn.ROOT); - assertNotLocked(A); - if (lockParentForInsertRemove) - assertLocked(AB); - else - assertNotLocked(AB); - assertLocked(ABC); - tm.commit(); - - assertNoLocks(); - } - - public void testLocksOnRemoveNode() throws Exception - { - // init some data on a node - cache.put(AB, Collections.singletonMap("k", "v")); - - assert "v".equals(cache.get(AB, "k")); - - tm.begin(); - cache.removeNode(AB); - assertLocked(AB); - if (lockParentForInsertRemove) - assertLocked(A); - else - assertNotLocked(A); - assertNotLocked(Fqn.ROOT); - tm.commit(); - assert cache.getNode(AB) =3D=3D null : "Should not exist"; - assertNoLocks(); - } - - public void testLocksOnEvictNode() throws Exception - { - // init some data on a node - cache.put(AB, Collections.singletonMap("k", "v")); - - assert "v".equals(cache.get(AB, "k")); - - tm.begin(); - cache.evict(AB); - assertLocked(AB); - if (lockParentForInsertRemove) - assertLocked(A); - else - assertNotLocked(A); - assertNotLocked(Fqn.ROOT); - tm.commit(); - assert cache.getNode(AB) =3D=3D null : "Should not exist"; - assertNoLocks(); - } - - public void testLocksOnEvictRecursiveNode() throws Exception - { - // init some data on a node - cache.put(AB, Collections.singletonMap("k", "v")); - cache.put(ABC, Collections.singletonMap("k", "v")); - cache.put(ABCD, Collections.singletonMap("k", "v")); - - assert "v".equals(cache.get(AB, "k")); - assert "v".equals(cache.get(ABC, "k")); - assert "v".equals(cache.get(ABCD, "k")); - - tm.begin(); - cache.evict(AB, true); - assertLocked(AB); - assertLocked(ABC); - assertLocked(ABCD); - if (lockParentForInsertRemove) - assertLocked(A); - else - assertNotLocked(A); - assertNotLocked(Fqn.ROOT); - tm.commit(); - assert cache.getNode(AB) =3D=3D null : "Should not exist"; - assertNoLocks(); - } - - public void testLocksOnRemoveNonexistentNode() throws Exception - { - assert cache.getNode(AB) =3D=3D null : "Should not exist"; - - tm.begin(); - cache.removeNode(AB); - assertLocked(AB); - if (lockParentForInsertRemove) - assertLocked(A); - else - assertNotLocked(A); - assertNotLocked(Fqn.ROOT); - tm.commit(); - assert cache.getNode(AB) =3D=3D null : "Should not exist"; - assertNoLocks(); - } - - public void testLocksOnEvictNonexistentNode() throws Exception - { - assert cache.getNode(AB) =3D=3D null : "Should not exist"; - - tm.begin(); - cache.evict(AB); - assertLocked(AB); - if (lockParentForInsertRemove) - assertLocked(A); - else - assertNotLocked(A); - assertNotLocked(Fqn.ROOT); - tm.commit(); - assert cache.getNode(AB) =3D=3D null : "Should not exist"; - assertNoLocks(); - } - - public void testLocksOnRemoveData() throws Exception - { - // init some data on a node - cache.put(AB, "k", "v"); - cache.put(AB, "k2", "v2"); - - assert "v".equals(cache.get(AB, "k")); - assert "v2".equals(cache.get(AB, "k2")); - - // remove - tm.begin(); - Object x =3D cache.remove(AB, "k"); - assert x.equals("v"); - assertLocked(AB); - assertNotLocked(A); - assertNotLocked(Fqn.ROOT); - tm.commit(); - assert cache.get(AB, "k") =3D=3D null : "Should not exist"; - assert "v2".equals(cache.get(AB, "k2")); - assertNoLocks(); - - // clearData - tm.begin(); - cache.clearData(AB); - assertLocked(AB); - assertNotLocked(A); - assertNotLocked(Fqn.ROOT); - tm.commit(); - - assert cache.get(AB, "k") =3D=3D null : "Should not exist"; - assert cache.get(AB, "k2") =3D=3D null : "Should not exist"; - assertNoLocks(); - - // nonexistent key - assert cache.get(AB, "k3") =3D=3D null : "Should not exist"; - tm.begin(); - cache.remove(AB, "k3"); - assertLocked(AB); - assertNotLocked(A); - assertNotLocked(Fqn.ROOT); - tm.commit(); - assertNoLocks(); - } - - public void testLocksOnRemoveDataNonExistentNode() throws Exception - { - assert cache.getNode(AB) =3D=3D null : "Should not exist"; - - tm.begin(); - cache.remove(AB, "k"); - assertNotLocked(AB); - assertNotLocked(A); - assertNotLocked(Fqn.ROOT); - tm.commit(); - assert cache.getNode(AB) =3D=3D null : "Should not exist"; - } - - public void testReadMethods() throws Exception - { - cache.put(AB, "k", "v"); - - tm.begin(); - assert "v".equals(cache.get(AB, "k")); - assertNoLocks(); - tm.commit(); - assertNoLocks(); - - tm.begin(); - assert cache.getData(AB).containsKey("k"); - assertNoLocks(); - tm.commit(); - assertNoLocks(); - - tm.begin(); - assert cache.getKeys(AB).contains("k"); - assertNoLocks(); - tm.commit(); - assertNoLocks(); - - tm.begin(); - assert cache.getNode(AB) !=3D null; - assertNoLocks(); - tm.commit(); - assertNoLocks(); - - tm.begin(); - assert !(cache.getNode(A).getChildrenNames().isEmpty()); - assertNoLocks(); - tm.commit(); - assertNoLocks(); - } - - public void testWriteDoesntBlockRead() throws Exception - { - cache.put(AB, "k", "v"); - - // start a write. - tm.begin(); - cache.put(AB, "k2", "v2"); - assertLocked(AB); - Transaction write =3D tm.suspend(); - - // now start a read and confirm that the write doesn't block it. - tm.begin(); - assert "v".equals(cache.get(AB, "k")); - assert null =3D=3D cache.get(AB, "k2") : "Should not see uncommitted= changes"; - Transaction read =3D tm.suspend(); - - // commit the write - tm.resume(write); - tm.commit(); - - assertNoLocks(); - - tm.resume(read); - if (repeatableRead) - assert null =3D=3D cache.get(AB, "k2") : "Should have repeatable = read"; - else - assert "v2".equals(cache.get(AB, "k2")) : "Read committed should = see committed changes"; - tm.commit(); - assertNoLocks(); - } - - public void testWriteDoesntBlockReadNonexistent() throws Exception - { - // start a write. - tm.begin(); - cache.put(AB, "k", "v"); - assertLocked(AB); - Transaction write =3D tm.suspend(); - - // now start a read and confirm that the write doesn't block it. - tm.begin(); - assert null =3D=3D cache.get(AB, "k") : "Should not see uncommitted = changes"; - assert null =3D=3D cache.getNode(AB); - Transaction read =3D tm.suspend(); - - // commit the write - tm.resume(write); - tm.commit(); - - assertNoLocks(); - - tm.resume(read); - if (repeatableRead) - { - assert null =3D=3D cache.get(AB, "k") : "Should have repeatable r= ead"; - assert null =3D=3D cache.getNode(AB); - } - else - { - assert "v".equals(cache.get(AB, "k")) : "Read committed should se= e committed changes"; - assert null !=3D cache.getNode(AB); - } - tm.commit(); - assertNoLocks(); - } - - // TODO: Test write conflicts - with and without allowing write skew. = Multiple cases involving concurrent removes, concurrent put + remove, etc. - // TODO: Test Replication with MVCC - // TODO: Test state transfer with MVCC - // TODO: Test Cache loading with MVCC - // TODO: Test spreading of Fqns among locks. Need a better algorithm? -} --===============6599494845800632247==--