Skip to content

Commit

Permalink
ISPN-845 - Memory leaks for 2 phase commit readonly transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
maniksurtani committed Jan 7, 2011
1 parent a4d542f commit 73e3f5c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
Expand Up @@ -158,6 +158,9 @@ public void start(Xid xid, int i) throws XAException {

public void end(Xid xid, int i) throws XAException {
if (trace) log.trace("end called on tx " + this.localTransaction.getGlobalTransaction());
// force a cleanup to release any objects held. Some TMs don't call commit if it is a READ ONLY tx. See ISPN-845
LocalTransaction localTransaction = txTable.getLocalTransaction(xid);
if (localTransaction != null && localTransaction.isReadOnly()) commit(xid, false);
}

public void forget(Xid xid) throws XAException {
Expand Down
49 changes: 49 additions & 0 deletions core/src/test/java/org/infinispan/tx/ReadOnlyTxCleanupTest.java
@@ -0,0 +1,49 @@
package org.infinispan.tx;

import org.infinispan.Cache;
import org.infinispan.config.Configuration;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.test.SingleCacheManagerTest;
import org.infinispan.test.TestingUtil;
import org.infinispan.test.fwk.CleanupAfterMethod;
import org.infinispan.test.fwk.TestCacheManagerFactory;
import org.infinispan.transaction.xa.TransactionTable;
import org.testng.annotations.Test;

import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.NotSupportedException;
import javax.transaction.RollbackException;
import javax.transaction.SystemException;
import javax.transaction.TransactionManager;

@Test(testName = "tx.ReadOnlyTxCleanupTest", groups = "functional")
@CleanupAfterMethod
public class ReadOnlyTxCleanupTest extends SingleCacheManagerTest {
@Override
protected EmbeddedCacheManager createCacheManager() throws Exception {
Configuration c = new Configuration();
return TestCacheManagerFactory.createCacheManager(c, true);
}

public void testReadOnlyTx() throws SystemException, RollbackException, HeuristicRollbackException, HeuristicMixedException, NotSupportedException {
Cache<String, String> c1 = cacheManager.getCache();
Cache<String, String> c2 = cacheManager.getCache("two");

c1.put("c1", "c1");
c2.put("c2", "c2");

TransactionManager tm1 = tm();
tm1.begin();
c1.get("c1");
c2.get("c2");
tm1.commit();

TransactionTable tt1 = TestingUtil.extractComponent(c1, TransactionTable.class);
TransactionTable tt2 = TestingUtil.extractComponent(c2, TransactionTable.class);

assert tt1.getLocalTxCount() == 0;
assert tt2.getLocalTxCount() == 0;
}

}

0 comments on commit 73e3f5c

Please sign in to comment.