Author: manik.surtani(a)jboss.com
Date: 2008-04-25 08:51:05 -0400 (Fri, 25 Apr 2008)
New Revision: 5692
Modified:
core/tags/2.1.1.GA/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
core/tags/2.1.1.GA/src/main/java/org/jboss/cache/transaction/TransactionEntry.java
core/tags/2.1.1.GA/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java
Log:
Modified:
core/tags/2.1.1.GA/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
===================================================================
---
core/tags/2.1.1.GA/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2008-04-25
12:45:29 UTC (rev 5691)
+++
core/tags/2.1.1.GA/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2008-04-25
12:51:05 UTC (rev 5692)
@@ -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/tags/2.1.1.GA/src/main/java/org/jboss/cache/transaction/TransactionEntry.java
===================================================================
---
core/tags/2.1.1.GA/src/main/java/org/jboss/cache/transaction/TransactionEntry.java 2008-04-25
12:45:29 UTC (rev 5691)
+++
core/tags/2.1.1.GA/src/main/java/org/jboss/cache/transaction/TransactionEntry.java 2008-04-25
12:51:05 UTC (rev 5692)
@@ -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/tags/2.1.1.GA/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java
===================================================================
---
core/tags/2.1.1.GA/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java 2008-04-25
12:45:29 UTC (rev 5691)
+++
core/tags/2.1.1.GA/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java 2008-04-25
12:51:05 UTC (rev 5692)
@@ -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();