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

Manik Surtani msurtani at jboss.com
Tue Dec 5 10:27:52 EST 2006


  User: msurtani
  Date: 06/12/05 10:27:52

  Modified:    tests/functional/org/jboss/cache/lock    Tag:
                        Branch_JBossCache_1_4_0
                        ReadWriteLockWithUpgradeTest.java
                        UpgradeLockTest.java LockReleaseTest.java
  Log:
  Ported stuff from 1.3.0.SP4 + upgraded JGroups
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.2.2.1   +124 -0    JBossCache/tests/functional/org/jboss/cache/lock/ReadWriteLockWithUpgradeTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ReadWriteLockWithUpgradeTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/lock/ReadWriteLockWithUpgradeTest.java,v
  retrieving revision 1.2
  retrieving revision 1.2.2.1
  diff -u -b -r1.2 -r1.2.2.1
  --- ReadWriteLockWithUpgradeTest.java	5 May 2006 12:06:58 -0000	1.2
  +++ ReadWriteLockWithUpgradeTest.java	5 Dec 2006 15:27:52 -0000	1.2.2.1
  @@ -5,11 +5,15 @@
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
   import org.jboss.cache.misc.TestingUtil;
  +import org.jboss.cache.TreeCache;
  +import org.jboss.cache.DataNode;
   
   import java.io.FileWriter;
   import java.io.IOException;
   import java.io.Writer;
   import java.util.Vector;
  +import java.util.ArrayList;
  +import java.util.List;
   
   /**
    * NonBlockingWriterLock is a read/write lock (with upgrade) that has
  @@ -615,5 +619,125 @@
         if (t1.isAlive() || t2.isAlive())
            fail("Possible deadlock resulted in testRead.");
      }
  +
  +   public void testCacheContentionOnRoot() throws Exception
  +    {
  +       final int threads = 10, loops = 100;
  +       TreeCache cache = null;
  +       try
  +       {
  +          cache = new TreeCache();
  +          cache.startService();
  +          final DataNode root = cache.getRoot();
  +          final List exceptions = new ArrayList();
  +          final List timeouts = new ArrayList();
  +
  +
  +          // get a hold of the WL first
  +          root.acquire(Thread.currentThread(), 10, DataNode.LOCK_TYPE_WRITE);
  +
  +          Thread[] t = new Thread[threads];
  +
  +          for (int i=0; i<t.length; i++)
  +          {
  +             t[i] = new Thread()
  +             {
  +                public void run()
  +                {
  +                   for (int i=0; i<loops; i++)
  +                   {
  +                      try
  +                      {
  +                         root.acquire(Thread.currentThread(), 10, DataNode.LOCK_TYPE_WRITE);
  +                      }
  +                      catch (TimeoutException te)
  +                      {
  +                         // expected
  +                         timeouts.add( te );
  +                      }
  +                      catch (Exception ex)
  +                      {
  +                         ex.printStackTrace();
  +                         exceptions.add(ex);
  +                      }
  +                   }
  +                }
  +             };
  +
  +             t[i].start();
  +          }
  +
  +          for (int i=0; i<t.length; i++) t[i].join();
  +          root.releaseAll(Thread.currentThread());
  +
  +          // we should have 0 exceptions
  +          assertEquals(0, exceptions.size());
  +       }
  +       finally
  +       {
  +          if (cache != null) cache.stopService();
  +       }
  +    }
  +
  +
  +    public void testCacheContentionOnNode() throws Exception
  +    {
  +       final int threads = 10, loops = 100;
  +       TreeCache cache = null;
  +       try
  +       {
  +          cache = new TreeCache();
  +          cache.startService();
  +          cache.put("/test/node", null);
  +          final DataNode node = cache.get("/test/node");
  +          final List exceptions = new ArrayList();
  +          final List timeouts = new ArrayList();
  +
  +
  +          // get a hold of the WL first
  +          node.acquire(Thread.currentThread(), 10, DataNode.LOCK_TYPE_WRITE);
  +
  +          Thread[] t = new Thread[threads];
  +
  +          for (int i=0; i<t.length; i++)
  +          {
  +             t[i] = new Thread()
  +             {
  +                public void run()
  +                {
  +                   for (int i=0; i<loops; i++)
  +                   {
  +                      try
  +                      {
  +                         node.acquire(Thread.currentThread(), 10, DataNode.LOCK_TYPE_WRITE);
  +                      }
  +                      catch (TimeoutException te)
  +                      {
  +                         // expected
  +                         timeouts.add( te );
  +                      }
  +                      catch (Exception ex)
  +                      {
  +                         ex.printStackTrace();
  +                         exceptions.add(ex);
  +                      }
  +                   }
  +                }
  +             };
  +
  +             t[i].start();
  +          }
  +
  +          for (int i=0; i<t.length; i++) t[i].join();
  +          node.releaseAll(Thread.currentThread());
  +
  +          // we should have 0 exceptions
  +          assertEquals(0, exceptions.size());
  +       }
  +       finally
  +       {
  +          if (cache != null) cache.stopService();
  +       }
  +    }
   }
   
  
  
  
  1.2.2.1   +2 -2      JBossCache/tests/functional/org/jboss/cache/lock/UpgradeLockTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: UpgradeLockTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/lock/UpgradeLockTest.java,v
  retrieving revision 1.2
  retrieving revision 1.2.2.1
  diff -u -b -r1.2 -r1.2.2.1
  --- UpgradeLockTest.java	5 May 2006 12:06:58 -0000	1.2
  +++ UpgradeLockTest.java	5 Dec 2006 15:27:52 -0000	1.2.2.1
  @@ -24,7 +24,7 @@
    * Tests upgrade locks from read -> write
    *
    * @author Bela Ban
  - * @version $Id: UpgradeLockTest.java,v 1.2 2006/05/05 12:06:58 msurtani Exp $
  + * @version $Id: UpgradeLockTest.java,v 1.2.2.1 2006/12/05 15:27:52 msurtani Exp $
    */
   public class UpgradeLockTest extends TestCase {
      TreeCache cache=null;
  @@ -123,7 +123,7 @@
         cache=createCache(l);
         tx.begin();
   
  -      int expected_num_locks=l == IsolationLevel.NONE? 0 : 1;
  +      int expected_num_locks=l == IsolationLevel.NONE? 0 : 2;
   
         cache.put(NODE1, null);
         assertEquals(expected_num_locks, cache.getNumberOfLocksHeld());
  
  
  
  1.1.20.1  +14 -15    JBossCache/tests/functional/org/jboss/cache/lock/LockReleaseTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: LockReleaseTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/lock/LockReleaseTest.java,v
  retrieving revision 1.1
  retrieving revision 1.1.20.1
  diff -u -b -r1.1 -r1.1.20.1
  --- LockReleaseTest.java	8 Jul 2005 05:58:11 -0000	1.1
  +++ LockReleaseTest.java	5 Dec 2006 15:27:52 -0000	1.1.20.1
  @@ -14,7 +14,6 @@
   import org.apache.commons.logging.Log;
   import org.jboss.cache.Fqn;
   import org.jboss.cache.TreeCache;
  -import org.jboss.cache.lock.IsolationLevel;
   import org.jboss.cache.transaction.DummyTransactionManager;
   
   import javax.naming.Context;
  @@ -27,7 +26,7 @@
    * Verifies that there are no read locks held when a transaction ends.
    *
    * @author Bela Ban
  - * @version $Id: LockReleaseTest.java,v 1.1 2005/07/08 05:58:11 msurtani Exp $
  + * @version $Id: LockReleaseTest.java,v 1.1.20.1 2006/12/05 15:27:52 msurtani Exp $
    */
   public class LockReleaseTest extends TestCase {
      TreeCache cache=null;
  @@ -142,11 +141,11 @@
   
         tx.begin();
         keys=cache.getKeys(NODE1);
  -      assertEquals("we should hold 1 read locks now: ", 1, cache.getNumberOfLocksHeld());
  +      assertEquals("we should hold 2 read locks now: ", 2, cache.getNumberOfLocksHeld());
         keys=cache.getKeys(NODE2);
  -      assertEquals("we should hold 3 read locks now: ", 3, cache.getNumberOfLocksHeld());
  +      assertEquals("we should hold 4 read locks now: ", 4, cache.getNumberOfLocksHeld());
         tx.commit();
  -      assertEquals("we should have released all 3 read locks: ", 0, cache.getNumberOfLocksHeld());
  +      assertEquals("we should have released all 4 read locks: ", 0, cache.getNumberOfLocksHeld());
      }
   
   
  @@ -164,11 +163,11 @@
   
         tx.begin();
         keys=cache.getChildrenNames(NODE1);
  -      assertEquals("we should hold 1 read locks now: ", 1, cache.getNumberOfLocksHeld());
  +      assertEquals("we should hold 2 read locks now: ", 2, cache.getNumberOfLocksHeld());
         keys=cache.getChildrenNames(NODE2);
  -      assertEquals("we should hold 3 read locks now: ", 3, cache.getNumberOfLocksHeld());
  +      assertEquals("we should hold 4 read locks now: ", 4, cache.getNumberOfLocksHeld());
         tx.commit();
  -      assertEquals("we should have released all 3 read locks: ", 0, cache.getNumberOfLocksHeld());
  +      assertEquals("we should have released all 4 read locks: ", 0, cache.getNumberOfLocksHeld());
      }
   
      public void testPrint() throws Exception {
  @@ -183,11 +182,11 @@
   
         tx.begin();
         cache.print(NODE1);
  -      assertEquals("we should hold 1 read locks now (for print()): ", 1, cache.getNumberOfLocksHeld());
  +      assertEquals("we should hold 2 read locks now (for print()): ", 2, cache.getNumberOfLocksHeld());
         cache.print(NODE2);
  -      assertEquals("we should hold 3 read locks now (for print()): ", 3, cache.getNumberOfLocksHeld());
  +      assertEquals("we should hold 4 read locks now (for print()): ", 4, cache.getNumberOfLocksHeld());
         tx.commit();
  -      assertEquals("we should have released all 3 read locks: ", 0, cache.getNumberOfLocksHeld());
  +      assertEquals("we should have released all 4 read locks: ", 0, cache.getNumberOfLocksHeld());
      }
   
   
  @@ -202,9 +201,9 @@
         tx.begin();
         assertEquals(VAL1, cache.get(NODE1, KEY));
         assertEquals(VAL1, cache.get(NODE2, KEY));
  -      assertEquals("we should hold 3 read locks now: ", 3, cache.getNumberOfLocksHeld());
  +      assertEquals("we should hold 4 read locks now: ", 4, cache.getNumberOfLocksHeld());
         tx.commit();
  -      assertEquals("we should have released all 3 read locks: ", 0, cache.getNumberOfLocksHeld());
  +      assertEquals("we should have released all 4 read locks: ", 0, cache.getNumberOfLocksHeld());
      }
   
      void testWriteLockRelease(IsolationLevel level) throws Exception {
  @@ -218,9 +217,9 @@
         tx.begin();
         cache.put(NODE1, KEY, VAL1);
         cache.put(NODE2, KEY, VAL1);
  -      assertEquals("we should hold 3 write locks now: ", 3, cache.getNumberOfLocksHeld());
  +      assertEquals("we should hold 4 write locks now: ", 4, cache.getNumberOfLocksHeld());
         tx.commit();
  -      assertEquals("we should have released all 3 write locks: ", 0, cache.getNumberOfLocksHeld());
  +      assertEquals("we should have released all 4 write locks: ", 0, cache.getNumberOfLocksHeld());
      }
   
      void log(String msg) {
  
  
  



More information about the jboss-cvs-commits mailing list