From jbosscache-commits at lists.jboss.org Fri Sep 14 12:00:29 2007 Content-Type: multipart/mixed; boundary="===============3887002744160426818==" MIME-Version: 1.0 From: jbosscache-commits at lists.jboss.org To: jbosscache-commits at lists.jboss.org Subject: [jbosscache-commits] JBoss Cache SVN: r4463 - core/trunk/src/test/java/org/jboss/cache/transaction. Date: Fri, 14 Sep 2007 12:00:29 -0400 Message-ID: --===============3887002744160426818== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: manik.surtani(a)jboss.com Date: 2007-09-14 12:00:29 -0400 (Fri, 14 Sep 2007) New Revision: 4463 Added: core/trunk/src/test/java/org/jboss/cache/transaction/SimultaneousRollbac= kAndPutTest.java Log: Added tests for a series of bugs, including JBCACHE-923, JBCACHE-1164, JBCA= CHE-1165, JBCACHE-1166, JBCACHE-1168, JBCACHE-1183. Added: core/trunk/src/test/java/org/jboss/cache/transaction/SimultaneousRol= lbackAndPutTest.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/transaction/SimultaneousRollba= ckAndPutTest.java (rev 0) +++ core/trunk/src/test/java/org/jboss/cache/transaction/SimultaneousRollba= ckAndPutTest.java 2007-09-14 16:00:29 UTC (rev 4463) @@ -0,0 +1,96 @@ +package org.jboss.cache.transaction; + +import org.jboss.cache.Cache; +import org.jboss.cache.CacheImpl; +import org.jboss.cache.DefaultCacheFactory; +import org.jboss.cache.Fqn; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +import javax.transaction.RollbackException; +import javax.transaction.Transaction; +import javax.transaction.TransactionManager; +import java.util.ArrayList; +import java.util.List; + +/** + * To test JBCACHE-923 + * + * @author Manik Surtani + */ +(a)Test(groups =3D {"functional"}) +public class SimultaneousRollbackAndPutTest +{ + private Cache cache; + private TransactionManager tm; + private Fqn A =3D Fqn.fromString("/a"), B =3D Fqn.fromString("/b"); + + @BeforeTest(alwaysRun =3D true) + protected void setUp() throws Exception + { + cache =3D DefaultCacheFactory.getInstance().createCache(false); + cache.getConfiguration().setTransactionManagerLookupClass(DummyTrans= actionManagerLookup.class.getName()); + cache.start(); + tm =3D cache.getConfiguration().getRuntimeConfig().getTransactionMan= ager(); + cache.put(A, "k", "v"); + } + + @AfterTest(alwaysRun =3D true) + protected void tearDown() + { + cache.stop(); + } + + @AfterMethod(alwaysRun =3D true) + protected void resetCache() + { + cache.removeNode(B); + cache.getRoot().getChild(A).clearData(); + cache.put(A, "k", "v"); + } + + @Test(invocationCount =3D 200, alwaysRun =3D false) + public void testStaleLocks() throws Exception + { + // scenario: + // Thread starts tx in cache. E.g., create and put into B + tm.begin(); + final Transaction t =3D tm.getTransaction(); + final List exceptions =3D new ArrayList(); + + cache.put(B, "k", "v"); + + // now the container should attempt to rollback the tx in a separate= thread. + new Thread() + { + public void run() + { + try + { + t.rollback(); + } + catch (Exception e) + { + exceptions.add(e); + } + } + }.start(); + + // now try and put stuff in the main thread again + cache.put(A, "k2", "v2"); + try + { + tm.commit(); + } + catch (RollbackException expected) + { + // this is expected. + } + + assert 0 =3D=3D ((CacheImpl) cache).getNumberOfLocksHeld(); + + if (exceptions.size() > 0) throw ((Exception) exceptions.get(0)); + } +} --===============3887002744160426818==--