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

Manik Surtani msurtani at jboss.com
Sun Nov 26 11:10:47 EST 2006


  User: msurtani
  Date: 06/11/26 11:10:47

  Modified:    tests/functional/org/jboss/cache/lock  Tag:
                        Branch_JBossCache_1_3_0
                        ReadWriteLockWithUpgradeTest.java
  Log:
  Added a test depicting behaviour difference when locking root
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.16.1  +130 -1    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.1
  retrieving revision 1.1.16.1
  diff -u -b -r1.1 -r1.1.16.1
  --- ReadWriteLockWithUpgradeTest.java	8 Jul 2005 05:58:11 -0000	1.1
  +++ ReadWriteLockWithUpgradeTest.java	26 Nov 2006 16:10:47 -0000	1.1.16.1
  @@ -4,12 +4,15 @@
   import junit.framework.Test;
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
  -import org.jboss.cache.lock.ReadWriteLockWithUpgrade;
  +import org.jboss.cache.DataNode;
  +import org.jboss.cache.TreeCache;
   
   import java.io.FileWriter;
   import java.io.IOException;
   import java.io.Writer;
   import java.util.Vector;
  +import java.util.List;
  +import java.util.ArrayList;
   
   /**
    * NonBlockingWriterLock is a read/write lock (with upgrade) that has
  @@ -623,5 +626,131 @@
         if (t1.isAlive() || t2.isAlive())
            fail("Possible deadlock resulted in testRead.");
      }
  +
  +   public void testCacheContentionOnRoot() throws Exception
  +   {
  +      final int threads = 3, loops = 10;
  +      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());
  +         // and t.length * loops timeouts
  +         assertEquals(t.length * loops, timeouts.size());
  +      }
  +      finally
  +      {
  +         if (cache != null) cache.stopService();
  +      }
  +   }
  +
  +
  +   public void testCacheContentionOnNode() throws Exception
  +   {
  +      final int threads = 3, loops = 10;
  +      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());
  +         // and t.length * loops timeouts
  +         assertEquals(t.length * loops, timeouts.size());
  +      }
  +      finally
  +      {
  +         if (cache != null) cache.stopService();
  +      }
  +   }
  +
  +
   }
   
  
  
  



More information about the jboss-cvs-commits mailing list