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

Manik Surtani msurtani at jboss.com
Tue Sep 12 07:49:00 EDT 2006


  User: msurtani
  Date: 06/09/12 07:49:00

  Modified:    tests/functional/org/jboss/cache/transaction 
                        ReplicatedTransactionDeadlockTest.java
  Log:
  Added more logging to help debug concurrency errors
  
  Revision  Changes    Path
  1.5       +47 -54    JBossCache/tests/functional/org/jboss/cache/transaction/ReplicatedTransactionDeadlockTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ReplicatedTransactionDeadlockTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/transaction/ReplicatedTransactionDeadlockTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- ReplicatedTransactionDeadlockTest.java	6 Sep 2006 15:31:00 -0000	1.4
  +++ ReplicatedTransactionDeadlockTest.java	12 Sep 2006 11:49:00 -0000	1.5
  @@ -3,6 +3,8 @@
   import junit.framework.Test;
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
   import org.jboss.cache.Fqn;
   import org.jboss.cache.TreeCache;
   import org.jboss.cache.config.Configuration;
  @@ -55,19 +57,20 @@
    *
    * @author Marian Nikolov
    * @author $Author: msurtani $
  - * @version $Date: 2006/09/06 15:31:00 $
  + * @version $Date: 2006/09/12 11:49:00 $
    */
   public class ReplicatedTransactionDeadlockTest extends TestCase
   {
  -   /**
  -    * The number of worker threads to start concurrently.
  -    */
  +
  +   // Number of worker threads
      private static final int NUM_WORKERS = 2;
  -   /**
  -    * The number of test runs to perform.
  -    */
  +
  +   // The number of test runs to perform.
      private static final int NUM_RUNS = 100;
   
  +   // useful to increase this to get thread dumps, etc.  Typically should be set to 10,000 though.
  +   private static final long LOCK_ACQUISITION_TIMEOUT = 10000;
  +
      /**
       * The initial context factory properties.
       */
  @@ -85,16 +88,18 @@
      /**
       * Exception recorded if any of the worker threads fails.
       */
  -   private static volatile Exception mcl_exception = null;
  +   private static volatile Exception exception = null;
   
      /**
       * The source cache where we put modifications.
       */
  -   private TreeCache m_srcCache = null;
  +   private TreeCache srcCache = null;
      /**
       * The target cache where we replicate modifications.
       */
  -   private TreeCache m_dstCache = null;
  +   private TreeCache dstCache = null;
  +
  +   private Log log = LogFactory.getLog(ReplicatedTransactionDeadlockTest.class);
   
      static
      {
  @@ -119,30 +124,32 @@
      protected void setUp() throws Exception
      {
         super.setUp();
  -      mcl_exception = null;
  +      exception = null;
         m_contextFactory = System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
         System.setProperty(Context.INITIAL_CONTEXT_FACTORY, CONTEXT_FACTORY);
         DummyTransactionManager.getInstance();
         // setup and start the source cache
  -      m_srcCache = new TreeCache();
  -      m_srcCache.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/replSync-service.xml"));
  -      m_srcCache.getConfiguration().setTransactionManagerLookupClass(
  +      srcCache = new TreeCache();
  +      srcCache.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/replSync-service.xml"));
  +      srcCache.getConfiguration().setTransactionManagerLookupClass(
                 "org.jboss.cache.DummyTransactionManagerLookup");
  -      m_srcCache.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
  +      srcCache.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
   
  -      m_srcCache.getConfiguration().setSyncCommitPhase(true);
  -      m_srcCache.create();
  -      m_srcCache.start();
  +      srcCache.getConfiguration().setSyncCommitPhase(true);
  +      srcCache.getConfiguration().setLockAcquisitionTimeout(LOCK_ACQUISITION_TIMEOUT);
  +      srcCache.create();
  +      srcCache.start();
         // setup and start the destination cache
  -      m_dstCache = new TreeCache();
  -      m_dstCache.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/replSync-service.xml"));
  -      m_dstCache.getConfiguration().setTransactionManagerLookupClass(
  +      dstCache = new TreeCache();
  +      dstCache.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/replSync-service.xml"));
  +      dstCache.getConfiguration().setTransactionManagerLookupClass(
                 "org.jboss.cache.DummyTransactionManagerLookup");
  -      m_dstCache.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
  +      dstCache.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
   
  -      m_dstCache.getConfiguration().setSyncCommitPhase(true);
  -      m_dstCache.create();
  -      m_dstCache.start();
  +      dstCache.getConfiguration().setSyncCommitPhase(true);
  +      dstCache.getConfiguration().setLockAcquisitionTimeout(LOCK_ACQUISITION_TIMEOUT);
  +      dstCache.create();
  +      dstCache.start();
      }
   
      /**
  @@ -152,10 +159,10 @@
      {
         super.tearDown();
         DummyTransactionManager.destroy();
  -      m_srcCache.stop();
  -      m_srcCache = null;
  -      m_dstCache.stop();
  -      m_dstCache = null;
  +      srcCache.stop();
  +      srcCache = null;
  +      dstCache.stop();
  +      dstCache = null;
         if (m_contextFactory != null)
         {
            System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
  @@ -186,10 +193,10 @@
         // repeat the test several times since it's not always reproducible
         for (int i = 0; i < NUM_RUNS; i++)
         {
  -         if (mcl_exception != null)
  +         if (exception != null)
            {
               // terminate the test on the first failed worker
  -            fail("Due to an exception: " + mcl_exception);
  +            fail("Due to an exception: " + exception);
            }
            // start several worker threads to work with the same FQN
            Worker[] t = new Worker[NUM_WORKERS];
  @@ -199,10 +206,7 @@
               t[j].start();
            }
            // wait for all workers to complete before repeating the test
  -         for (int j = 0; j < t.length; j++)
  -         {
  -            t[j].join();
  -         }
  +         for (Worker aT : t) aT.join();
         }
      }
   
  @@ -219,22 +223,11 @@
      }
   
      /**
  -    * Log a message.
  -    *
  -    * @param msg The meessage to be logged.
  -    */
  -   private void log(String msg)
  -   {
  -      System.out.println(System.currentTimeMillis() + " "
  -              + Thread.currentThread() + " " + msg);
  -   }
  -
  -   /**
       * A worker thread that applies the concurrent modifications.
       *
       * @author Marian Nikolov
       * @author $Author: msurtani $
  -    * @version $Date: 2006/09/06 15:31:00 $
  +    * @version $Date: 2006/09/12 11:49:00 $
       */
      private class Worker extends Thread
      {
  @@ -254,18 +247,18 @@
            try
            {
               UserTransaction tx = getTransaction();
  -            log("begin");
  +            log.warn("begin");
               tx.begin();
  -            log("put");
  -            m_srcCache.put(new Fqn("Node"), Boolean.FALSE, Boolean.TRUE);
  -            log("commit");
  +            log.warn("put");
  +            srcCache.put(new Fqn("Node"), Boolean.FALSE, Boolean.TRUE);
  +            log.warn("commit");
               tx.commit();
  -            log("leave");
  +            log.warn("leave");
            }
            catch (Exception e)
            {
  -            log("caught exception " + e);
  -            mcl_exception = e;
  +            log.error("caught exception " + e, e);
  +            exception = e;
            }
         }
      }
  
  
  



More information about the jboss-cvs-commits mailing list