[jbosscache-commits] JBoss Cache SVN: r5691 - in core/branches/2.1.X/src: main/java/org/jboss/cache/transaction and 1 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Fri Apr 25 08:45:29 EDT 2008


Author: manik.surtani at jboss.com
Date: 2008-04-25 08:45:29 -0400 (Fri, 25 Apr 2008)
New Revision: 5691

Modified:
   core/branches/2.1.X/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
   core/branches/2.1.X/src/main/java/org/jboss/cache/transaction/TransactionEntry.java
   core/branches/2.1.X/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java
Log:
JBCACHE-1326: Check that the transaction entry doesn't leak stuff after a transaction completes

Modified: core/branches/2.1.X/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
===================================================================
--- core/branches/2.1.X/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java	2008-04-25 12:43:32 UTC (rev 5690)
+++ core/branches/2.1.X/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java	2008-04-25 12:45:29 UTC (rev 5691)
@@ -1299,10 +1299,11 @@
        */
       private void cleanupInternalState()
       {
-         this.tx = null;
-         this.gtx = null;
-         this.modifications = null;
-         this.entry = null;
+         tx = null;
+         gtx = null;
+         modifications = null;
+         if (entry != null) entry.reset();
+         entry = null;
       }
 
       public String toString()

Modified: core/branches/2.1.X/src/main/java/org/jboss/cache/transaction/TransactionEntry.java
===================================================================
--- core/branches/2.1.X/src/main/java/org/jboss/cache/transaction/TransactionEntry.java	2008-04-25 12:43:32 UTC (rev 5690)
+++ core/branches/2.1.X/src/main/java/org/jboss/cache/transaction/TransactionEntry.java	2008-04-25 12:45:29 UTC (rev 5691)
@@ -438,6 +438,20 @@
     */
    public boolean existModifications()
    {
-      return !modification_list.isEmpty() || !cl_mod_list.isEmpty(); 
+      return !modification_list.isEmpty() || !cl_mod_list.isEmpty();
    }
+
+   /**
+    * Cleans up internal state
+    */
+   public void reset()
+   {
+      orderedSynchronizationHandler = null;
+      modification_list.clear();
+      cl_mod_list.clear();
+      option = null;
+      locks.clear();
+      if (dummyNodesCreatedByCacheLoader != null) dummyNodesCreatedByCacheLoader.clear();
+      removedNodes.clear();
+   }
 }

Modified: core/branches/2.1.X/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java
===================================================================
--- core/branches/2.1.X/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java	2008-04-25 12:43:32 UTC (rev 5690)
+++ core/branches/2.1.X/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java	2008-04-25 12:45:29 UTC (rev 5691)
@@ -4,12 +4,14 @@
 import org.jboss.cache.DefaultCacheFactory;
 import org.jboss.cache.Fqn;
 import org.jboss.cache.config.Configuration.CacheMode;
-
+import org.jboss.cache.transaction.TransactionEntry;
+import org.jboss.cache.transaction.TransactionTable;
 import static org.testng.AssertJUnit.*;
 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.Map;
 
@@ -90,7 +92,7 @@
    public void testScrubbingAfterOnePhaseCommit() throws Exception
    {
       setUpOnePhaseCache();
-      
+
       doScrubbingTest(true);
    }
 
@@ -102,7 +104,7 @@
    public void testScrubbingAfterOnePhaseRollback() throws Exception
    {
       setUpOnePhaseCache();
-      
+
       doScrubbingTest(true);
    }
 
@@ -110,13 +112,17 @@
    {
       // Start clean
       cache.getInvocationContext().reset();
-      
+
       tm.begin();
+      TransactionTable tt = cache.getTransactionTable();
       cache.getRoot().put("key", "value");
       assertNotNull("Tx should have been set up by now", cache.getInvocationContext().getTransaction());
       assertEquals("The same current transaction should be associated with this invocation ctx.", tm.getTransaction(), cache.getInvocationContext().getTransaction());
       assertNotNull("Gtx should have been set up by now", cache.getInvocationContext().getGlobalTransaction());
 
+      Transaction tx = tm.getTransaction();
+      TransactionEntry entry = tt.get(tt.get(tx));
+
       if (commit)
       {
          tm.commit();
@@ -129,6 +135,11 @@
       assertNull("Tx should have been scrubbed", cache.getInvocationContext().getTransaction());
       assertNull("Gtx should have been scrubbed", cache.getInvocationContext().getGlobalTransaction());
       assertEquals("MethodCall should have been scrubbed", null, cache.getInvocationContext().getMethodCall());
+
+      // check that the transaction entry hasn't leaked stuff.
+      assert entry.getModifications().isEmpty() : "Should have scrubbed modifications in transaction entry";
+      assert entry.getCacheLoaderModifications().isEmpty() : "Should have scrubbed modifications in transaction entry";
+      assert entry.getOrderedSynchronizationHandler() == null : "Should have removed the ordered sync handler";
    }
 
    private void setUpOnePhaseCache()
@@ -138,7 +149,7 @@
          cache.stop();
          cache = null;
       }
-      
+
       cache = (CacheSPI<Object, Object>) new DefaultCacheFactory().createCache("META-INF/conf-test/replSync-service.xml", false);
       cache.getConfiguration().setCacheMode(CacheMode.REPL_ASYNC);
       cache.start();




More information about the jbosscache-commits mailing list