[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/invocationcontext ...

Manik Surtani msurtani at jboss.com
Wed Sep 6 07:35:07 EDT 2006


  User: msurtani
  Date: 06/09/06 07:35:07

  Added:       tests/functional/org/jboss/cache/invocationcontext 
                        TransactionTest.java
  Log:
  Created a new test to test the setting up of transactions
  
  Revision  Changes    Path
  1.1      date: 2006/09/06 11:35:07;  author: msurtani;  state: Exp;JBossCache/tests/functional/org/jboss/cache/invocationcontext/TransactionTest.java
  
  Index: TransactionTest.java
  ===================================================================
  package org.jboss.cache.invocationcontext;
  
  import junit.framework.TestCase;
  import org.jboss.cache.CacheSPI;
  import org.jboss.cache.Fqn;
  import org.jboss.cache.factories.DefaultCacheFactory;
  
  import javax.transaction.HeuristicMixedException;
  import javax.transaction.HeuristicRollbackException;
  import javax.transaction.NotSupportedException;
  import javax.transaction.RollbackException;
  import javax.transaction.SystemException;
  import javax.transaction.TransactionManager;
  import java.util.Map;
  
  /**
   * A test to ensure the transactional context is properly set up in the IC
   *
   * @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
   */
  public class TransactionTest extends TestCase
  {
     private CacheSPI cache;
  
     protected void setUp()
     {
        cache = (CacheSPI) new DefaultCacheFactory().createCache("META-INF/local-tx-service.xml");
     }
  
     protected void tearDown()
     {
        if (cache != null)
        {
           cache.stop();
           cache = null;
        }
     }
  
     public void testTxExistenceAfterWrite() throws SystemException, NotSupportedException, HeuristicMixedException, HeuristicRollbackException, RollbackException
     {
        TransactionManager tm = cache.getTransactionManager();
  
        // make sure we have a running transaction.
        tm.begin();
  
        assertNull("Tx should not have been set up yet", cache.getInvocationContext().getTransaction());
        assertNull("Gtx should not have been set up yet", cache.getInvocationContext().getGlobalTransaction());
  
        // now make a WRITE call into the cache (should start a tx)
        cache.put(Fqn.ROOT, "k", "v");
        Map data = cache.getData();
        assertEquals("Data map should not empty", 1, data.size());
  
        // but now we should have a local tx registered in the invocation context
        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());
  
        tm.commit();
     }
  
     public void testTxExistenceAfterRead() throws SystemException, NotSupportedException, HeuristicMixedException, HeuristicRollbackException, RollbackException
     {
        TransactionManager tm = cache.getTransactionManager();
  
        // make sure we have a running transaction.
        tm.begin();
  
        assertNull("Tx should not have been set up yet", cache.getInvocationContext().getTransaction());
        assertNull("Gtx should not have been set up yet", cache.getInvocationContext().getGlobalTransaction());
  
        // now make a WRITE call into the cache (should start a tx)
        Object value = cache.get(Fqn.ROOT, "k");
        assertNull("Value should be null", value);
  
        // but now we should have a local tx registered in the invocation context
        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());
  
        tm.commit();
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list