[jboss-user] [JBossCache] - Re: TransactionTable HashMap

mraccola do-not-reply at jboss.com
Mon Dec 17 09:52:35 EST 2007


Yes, I am using two cache instances, one as a Hibernate 2nd-level cache, one as a custom application cache.  I can see in the Hibernate cache (which is called from Hibernate) that although the same exact path through JBC is taken the cleanup is done in the transaction syncronization.  However, this is NOT happening for my custom cache.  

I have attached a JUnit test to demonstrate what I am seeing.  Note that in my test the assertions at the bottom of the test (Lines 70 and 71) fail because the size of the HashMap is > 0.

What am I doing wrong?

Test Case

  | package fleetcycle.model.framework.cache;
  | 
  | import java.io.InputStream;
  | import java.util.Properties;
  | 
  | import javax.naming.Context;
  | import javax.naming.InitialContext;
  | import javax.transaction.UserTransaction;
  | 
  | import junit.framework.TestCase;
  | 
  | import org.jboss.cache.Fqn;
  | import org.jboss.cache.PropertyConfigurator;
  | import org.jboss.cache.TreeCache;
  | import org.jboss.cache.config.Option;
  | 
  | public class Test_CacheLeak extends TestCase
  | {
  | 
  |     public void testLeak() throws Exception
  |     {
  |         final String ITEM = "item";
  |         TreeCache cache = new TreeCache();
  |         InputStream configStream = this.getClass().getResourceAsStream("/treecache-app.xml");
  |         PropertyConfigurator configs = new PropertyConfigurator();
  |         configs.configure(cache, configStream);
  |         cache.start();
  | 
  |         Fqn regionFqn = Fqn.fromString("/TestRegion");
  | 
  |         boolean fail = false;
  |         int iterationCnt = 100;
  | 
  |         Properties prop = new Properties();
  |         prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.cache.transaction.DummyContextFactory");
  | 
  |         for (int i = 0; i < iterationCnt; i++)
  |         {
  |             UserTransaction tx = (UserTransaction) new InitialContext(prop).lookup("UserTransaction");
  |             try
  |             {
  |                 tx.begin();
  |                 Option option = new Option();
  |                 option.setFailSilently(true);
  |                 Fqn keyFqn = new Fqn(new Object[]{regionFqn, "testRoot/testNode" + i});
  |                 cache.put(keyFqn, ITEM, "testVal", option);
  |                 tx.commit();
  |                 if (fail) throw new RuntimeException();
  |                 System.out.println("Committing");
  |             } catch (Throwable ex)
  |             {
  |                 System.out.println("Rolling back=" + ex.getMessage());
  |                 ex.printStackTrace();
  |                 try
  |                 {
  |                     tx.rollback();
  |                 } catch (Throwable t)
  |                 {}
  |             }
  |         }
  | 
  |         for (int i = 0; i < iterationCnt; i++)
  |         {
  |             Fqn keyFqn = new Fqn(new Object[]{regionFqn, "testRoot/testNode" + i});
  |             assertNotNull("Expected cache item not found", cache.get(keyFqn, ITEM));
  |         }
  | 
  |         int gtxCnt = cache.getTransactionTable().getNumGlobalTransactions();
  |         int txCnt = cache.getTransactionTable().getNumLocalTransactions();
  |         assertEquals("Global transaction count is > 0", 0, gtxCnt);
  |         assertEquals("Local transaction count is > 0", 0, txCnt);
  |     }
  | 
  | }
  | 

treecache-app.xml

  | <?xml version="1.0" encoding="UTF-8"?>
  | <server>
  |     <classpath codebase="./lib" archives="jboss-cache.jar, jgroups.jar" />
  |     <mbean code="org.jboss.cache.TreeCache" name="jboss.cache:service=TreeCache_FCXP_app">
  |         <depends>jboss:service=Naming</depends>
  |         <depends>jboss:service=TransactionManager</depends>
  | 
  |         <attribute name="ClusterName">FCXP_app</attribute>
  |         <attribute name="CacheMode">LOCAL</attribute>
  |         <attribute name="SyncReplTimeout">10000</attribute>
  |         <attribute name="LockAcquisitionTimeout">15000</attribute>
  |         <attribute name="FetchInMemoryState">false</attribute>
  |         <attribute name="NodeLockingScheme">OPTIMISTIC</attribute>
  |         <attribute name="TransactionManagerLookupClass">org.jboss.cache.DummyTransactionManagerLookup</attribute>
  |         <!-- Uncomment this line for WebSphere -->
  |         <!-- attribute name="UseInterceptorMbeans">false</attribute -->
  | 
  |         <attribute name="EvictionPolicyConfig">
  |             <config>
  |                 <attribute name="wakeUpIntervalSeconds">5</attribute>
  |                 <!-- Cache wide default -->
  |                 <region name="/_default_" policyClass="org.jboss.cache.eviction.LRUPolicy">
  |                     <attribute name="maxNodes">0</attribute>
  |                     <attribute name="timeToIdleSeconds">10000</attribute>
  |                 </region>
  |             </config>
  |         </attribute>
  |     </mbean>
  | </server>
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4113409#4113409

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4113409



More information about the jboss-user mailing list