[jbosscache-commits] JBoss Cache SVN: r4463 - core/trunk/src/test/java/org/jboss/cache/transaction.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Fri Sep 14 12:00:29 EDT 2007


Author: manik.surtani at 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/SimultaneousRollbackAndPutTest.java
Log:
Added tests for a series of bugs, including JBCACHE-923, JBCACHE-1164, JBCACHE-1165, JBCACHE-1166, JBCACHE-1168, JBCACHE-1183.

Added: core/trunk/src/test/java/org/jboss/cache/transaction/SimultaneousRollbackAndPutTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/transaction/SimultaneousRollbackAndPutTest.java	                        (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/transaction/SimultaneousRollbackAndPutTest.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 <a href="mailto:manik at jboss.org">Manik Surtani</a>
+ */
+ at Test(groups = {"functional"})
+public class SimultaneousRollbackAndPutTest
+{
+   private Cache cache;
+   private TransactionManager tm;
+   private Fqn A = Fqn.fromString("/a"), B = Fqn.fromString("/b");
+
+   @BeforeTest(alwaysRun = true)
+   protected void setUp() throws Exception
+   {
+      cache = DefaultCacheFactory.getInstance().createCache(false);
+      cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+      cache.start();
+      tm = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
+      cache.put(A, "k", "v");
+   }
+
+   @AfterTest(alwaysRun = true)
+   protected void tearDown()
+   {
+      cache.stop();
+   }
+
+   @AfterMethod(alwaysRun = true)
+   protected void resetCache()
+   {
+      cache.removeNode(B);
+      cache.getRoot().getChild(A).clearData();
+      cache.put(A, "k", "v");
+   }
+
+   @Test(invocationCount = 200, alwaysRun = false)
+   public void testStaleLocks() throws Exception
+   {
+      // scenario:
+      // Thread starts tx in cache.  E.g., create and put into B
+      tm.begin();
+      final Transaction t = tm.getTransaction();
+      final List exceptions = 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 == ((CacheImpl) cache).getNumberOfLocksHeld();
+
+      if (exceptions.size() > 0) throw ((Exception) exceptions.get(0));
+   }
+}




More information about the jbosscache-commits mailing list