Author: manik.surtani(a)jboss.com
Date: 2008-04-25 08:43:32 -0400 (Fri, 25 Apr 2008)
New Revision: 5690
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
core/trunk/src/main/java/org/jboss/cache/transaction/TransactionEntry.java
core/trunk/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java
Log:
JBCACHE-1327 - prevent leakage of MethodCall and CacheCommand in InvocationContexts
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2008-04-25
12:22:40 UTC (rev 5689)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2008-04-25
12:43:32 UTC (rev 5690)
@@ -1204,10 +1204,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;
}
@Override
Modified: core/trunk/src/main/java/org/jboss/cache/transaction/TransactionEntry.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/transaction/TransactionEntry.java 2008-04-25
12:22:40 UTC (rev 5689)
+++ core/trunk/src/main/java/org/jboss/cache/transaction/TransactionEntry.java 2008-04-25
12:43:32 UTC (rev 5690)
@@ -408,4 +408,18 @@
}
return false;
}
+
+ /**
+ * Cleans up internal state
+ */
+ public void reset()
+ {
+ orderedSynchronizationHandler = null;
+ modificationList.clear();
+ classLoadeModList.clear();
+ option = null;
+ locks.clear();
+ if (dummyNodesCreatedByCacheLoader != null)
dummyNodesCreatedByCacheLoader.clear();
+ removedNodes.clear();
+ }
}
Modified: core/trunk/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java 2008-04-25
12:22:40 UTC (rev 5689)
+++
core/trunk/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java 2008-04-25
12:43:32 UTC (rev 5690)
@@ -4,11 +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;
@@ -112,11 +115,16 @@
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();
@@ -130,6 +138,11 @@
assertNull("Gtx should have been scrubbed",
cache.getInvocationContext().getGlobalTransaction());
assertEquals("Method call should have been scrubbed", null,
cache.getInvocationContext().getMethodCall());
assertEquals("Cache command should have been scrubbed", null,
cache.getInvocationContext().getExecutingCommand());
+
+ // 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()