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

Manik Surtani msurtani at jboss.com
Thu Jan 4 00:35:36 EST 2007


  User: msurtani
  Date: 07/01/04 00:35:36

  Modified:    tests/functional/org/jboss/cache/lock    AcquireAllTest.java
                        IdentityLockTest.java
                        ReadWriteLockWithUpgradeTest.java
  Log:
  Major changes around nodes, and the way they interact with the interceptor stack.
  Also removed redundant methods in NodeSPI and removed the need for casting to NodeSPI in most cases.
  
  Revision  Changes    Path
  1.9       +4 -5      JBossCache/tests/functional/org/jboss/cache/lock/AcquireAllTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: AcquireAllTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/lock/AcquireAllTest.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -b -r1.8 -r1.9
  --- AcquireAllTest.java	30 Dec 2006 17:49:58 -0000	1.8
  +++ AcquireAllTest.java	4 Jan 2007 05:35:36 -0000	1.9
  @@ -5,7 +5,6 @@
   import junit.framework.TestSuite;
   import org.jboss.cache.CacheImpl;
   import org.jboss.cache.Fqn;
  -import org.jboss.cache.Node;
   import org.jboss.cache.NodeSPI;
   import org.jboss.cache.config.Configuration;
   import org.jboss.cache.transaction.DummyTransactionManager;
  @@ -14,7 +13,7 @@
   
   /**
    * @author Bela Ban
  - * @version $Id: AcquireAllTest.java,v 1.8 2006/12/30 17:49:58 msurtani Exp $
  + * @version $Id: AcquireAllTest.java,v 1.9 2007/01/04 05:35:36 msurtani Exp $
    */
   public class AcquireAllTest extends TestCase
   {
  @@ -56,7 +55,7 @@
         cache.put("/a/b/c", null);
         cache.put("/1/2/3", null);
   
  -      root = cache.getRoot().getNodeSPI();
  +      root = cache.getRoot();
         NodeLock lock = root.getLock();
   
         lock.acquireAll(owner, 2000, NodeLock.LockType.READ);
  @@ -73,7 +72,7 @@
   
      public void testAcquireAllReplicated() throws Exception
      {
  -      Node root;
  +      NodeSPI root;
         Object owner = Thread.currentThread();
   
         cache2 = createCache(Configuration.CacheMode.REPL_ASYNC, IsolationLevel.SERIALIZABLE);
  @@ -82,7 +81,7 @@
   
         cache = createCache(Configuration.CacheMode.REPL_ASYNC, IsolationLevel.SERIALIZABLE);
         root = cache.getRoot();
  -      NodeLock lock = root.getNodeSPI().getLock();
  +      NodeLock lock = root.getLock();
   
         lock.acquireAll(owner, 2000, NodeLock.LockType.READ);
         lock.releaseAll(owner);
  
  
  
  1.8       +24 -21    JBossCache/tests/functional/org/jboss/cache/lock/IdentityLockTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: IdentityLockTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/lock/IdentityLockTest.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -b -r1.7 -r1.8
  --- IdentityLockTest.java	20 Nov 2006 03:53:56 -0000	1.7
  +++ IdentityLockTest.java	4 Jan 2007 05:35:36 -0000	1.8
  @@ -12,9 +12,8 @@
   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.GlobalTransaction;
  -import org.jboss.cache.Node;
  +import org.jboss.cache.NodeSPI;
   import org.jboss.cache.misc.TestingUtil;
   
   
  @@ -23,7 +22,7 @@
    *
    * @author Bela Ban
    * @author Ben Wang
  - * @version $Revision: 1.7 $
  + * @version $Revision: 1.8 $
    */
   public class IdentityLockTest extends TestCase
   {
  @@ -31,7 +30,7 @@
      Object other_ = new Object();
      Log logger_ = LogFactory.getLog(IdentityLockTest.class);
      static Throwable thread_ex = null;
  -   final Node NODE = null;
  +   final NodeSPI NODE = null;
   
   
      public IdentityLockTest(String name)
  @@ -44,8 +43,8 @@
         super.setUp();
         lock_ = new IdentityLock(NODE);
   
  -//        try { Thread.TestingUtil.sleepThread(10000); } catch (Exception e) {
  -//        }
  +      //        try { Thread.TestingUtil.sleepThread(10000); } catch (Exception e) {
  +      //        }
      }
   
      protected void tearDown() throws Exception
  @@ -128,7 +127,7 @@
         {
            GlobalTransaction gtx = getGlobalTransactionFromThread();
            lock_.acquireReadLock(gtx, 50);
  -         lock_.acquireWriteLock(gtx, 50); // this should succeed
  +         lock_.acquireWriteLock(gtx, 50);// this should succeed
            lock_.release(gtx);
         }
         catch (LockingException e)
  @@ -160,7 +159,7 @@
         {
            GlobalTransaction gtx = getGlobalTransactionFromThread();
            lock_.acquireWriteLock(gtx, 50);
  -         lock_.acquireReadLock(gtx, 50); // this should succeed
  +         lock_.acquireReadLock(gtx, 50);// this should succeed
            lock_.release(gtx);
         }
         catch (LockingException e)
  @@ -194,11 +193,11 @@
            assertTrue("Is the lock owner", lock_.isOwner(this));
            assertTrue(lock_.getReaderOwners().contains(this));
   
  -         lock_.acquireReadLock(this, 50); // this should succeed
  +         lock_.acquireReadLock(this, 50);// this should succeed
            assertTrue("Is the lock owner", lock_.isOwner(this));
            assertTrue(lock_.getReaderOwners().contains(this));
   
  -         lock_.acquireWriteLock(this, 50); // this should succeed
  +         lock_.acquireWriteLock(this, 50);// this should succeed
            assertTrue("Is the lock owner", lock_.isOwner(this));
            assertTrue(!lock_.getReaderOwners().contains(this));
            assertTrue(lock_.getWriterOwner().equals(this));
  @@ -235,7 +234,7 @@
   
         try
         {
  -         lock_.acquireReadLock(other_, 10); // should succeed
  +         lock_.acquireReadLock(other_, 10);// should succeed
         }
         catch (LockingException e)
         {
  @@ -248,7 +247,7 @@
   
         try
         {
  -         lock_.acquireWriteLock(other_, 50); // should fail
  +         lock_.acquireWriteLock(other_, 50);// should fail
         }
         catch (LockingException e)
         {
  @@ -263,7 +262,7 @@
   
         try
         {
  -         lock_.acquireWriteLock(other_, 10); // should succeed
  +         lock_.acquireWriteLock(other_, 10);// should succeed
         }
         catch (LockingException e)
         {
  @@ -297,7 +296,7 @@
   
         try
         {
  -         lock_.acquireReadLock(other_, 10); // should fail
  +         lock_.acquireReadLock(other_, 10);// should fail
            fail("Acquire read lock for other. Should fail.");
         }
         catch (LockingException e)
  @@ -312,7 +311,7 @@
   
         try
         {
  -         lock_.acquireWriteLock(other_, 50); // should fail
  +         lock_.acquireWriteLock(other_, 50);// should fail
            fail("Acquire read lock for other. Should fail.");
         }
         catch (LockingException e)
  @@ -328,7 +327,7 @@
   
         try
         {
  -         lock_.acquireWriteLock(other_, 10); // should succeed
  +         lock_.acquireWriteLock(other_, 10);// should succeed
         }
         catch (LockingException e)
         {
  @@ -429,15 +428,17 @@
   
         TestingUtil.sleepThread(200);
         //log("o2: " + o2.hashCode() + ", lock_.getOwner()=" + lock_.getOwner());
  -//        assertTrue(lock_.isOwner(o2));
  -//        lock_.release(o2);
  +      //        assertTrue(lock_.isOwner(o2));
  +      //        lock_.release(o2);
   
         t1.join(20000);
         t2.join(20000);
         t3.join(20000);
         if (thread_ex != null)
  +      {
            throw thread_ex;
      }
  +   }
   
   
      public void testThreadedAccess_SimpleLock() throws Throwable
  @@ -527,15 +528,17 @@
   
         TestingUtil.sleepThread(200);
         //log("o2: " + o2.hashCode() + ", lock_.getOwner()=" + lock_.getOwner());
  -//        assertTrue(lock_.isOwner(o2));
  -//        lock_.release(o2);
  +      //        assertTrue(lock_.isOwner(o2));
  +      //        lock_.release(o2);
   
         t1.join(20000);
         t2.join(20000);
         t3.join(20000);
         if (thread_ex != null)
  +      {
            throw thread_ex;
      }
  +   }
   
      public void testReadAndReleaseAll()
      {
  @@ -652,7 +655,7 @@
   
      void log(String msg)
      {
  -//        System.out.println("-- [" + Thread.currentThread() + "]: " + msg);
  +      //        System.out.println("-- [" + Thread.currentThread() + "]: " + msg);
         logger_.info("-- [" + Thread.currentThread() + "]: " + msg);
      }
   
  
  
  
  1.4       +272 -190  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.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- ReadWriteLockWithUpgradeTest.java	8 Dec 2006 18:50:49 -0000	1.3
  +++ ReadWriteLockWithUpgradeTest.java	4 Jan 2007 05:35:36 -0000	1.4
  @@ -80,10 +80,10 @@
      public static void logX(String str)
      {
         log(str);
  -//       try {
  -//          logToFile(str);
  -//       } catch (IOException ioe) {
  -//       }
  +      //       try {
  +      //          logToFile(str);
  +      //       } catch (IOException ioe) {
  +      //       }
      }
   
      // Debugging intrnal function
  @@ -116,22 +116,23 @@
       * <DD> 0  - indicating the locking request failed.
       * <DD> 1  - indicating the locking request succeeded.
       * </DL>
  -    * <p>
  +    * <p/>
       * After all threads in each test case terminate, the test case
       * should make the following call to verify the test result:
       * <DL>
       * <DD> asssertTrue(checkLockingResult(expected-result-string);
       * </DL>
  -    * <p>
  +    * <p/>
       * 'expected-result-string' is the locking result string
       * described above. For example, "8-t1-RL-0" means that thread
       * t1 in test case #8 doing a Read Lock request expects the
       * operation to fail. If the expected result string can't be
       * found then the test case is considered FAILED (ie, either
       * the read lock request was successful or did not complete).
  -    * <p>
  +    * <p/>
       * Each test case should also call cleanLockingResult() to reset
       * result vector for the next test cases.
  +    *
       * @param caseNum Arbitrary string for the test case number.
       * @param name    Arbitrary string for the calling thread name.
       * @param msecs   Milliseconds that the thread should sleep after
  @@ -152,29 +153,39 @@
            public void run()
            {
                  Lock rlock = lock_.readLock();
  -            try {
  -               if (! rlock.tryLock(msecs, TimeUnit.MILLISECONDS)) {
  -                  logX(caseNum+"-"+name+" requesting read lock failed!\n");
  +            try
  +            {
  +               if (!rlock.tryLock(msecs, TimeUnit.MILLISECONDS))
  +               {
  +                  logX(caseNum + "-" + name + " requesting read lock failed!\n");
                     String str = caseNum + "-" + name + "-RL-0";
                     postLockingResult(str);
                     return;
                  }
                  // OK, read lock obtained, sleep and release it.
  -               logX(caseNum+"-"+name+" requesting read lock succeeded!\n");
  +               logX(caseNum + "-" + name + " requesting read lock succeeded!\n");
                  String str = caseNum + "-" + name + "-RL-1";
                  postLockingResult(str);
                  TestingUtil.sleepThread(sleepSecs);
   
   	       if (secondOP == INVOKE_READ)
  +               {
                      acquireReadLock(caseNum, name, msecs, errMsg);
  +               }
                  else if (secondOP == INVOKE_WRITE)
  +               {
                      acquireWriteLock(caseNum, name, msecs, errMsg);
  +               }
                  else if (secondOP == INVOKE_UPGRADE)
  +               {
                      acquireUpgradeLock(caseNum, name, msecs, errMsg);
  +               }
                    
                  rlock.unlock();
  -               logX(caseNum+"-"+name+" releasing read lock.\n");
  -            } catch (Exception ex) {
  +               logX(caseNum + "-" + name + " releasing read lock.\n");
  +            }
  +            catch (Exception ex)
  +            {
               }
            }
         };
  @@ -184,6 +195,7 @@
       * Creates a new thread and acquires a write lock with a timeout
       * value specified by the caller. Similar to {@link #readThread readThread()}
       * except it's used for write locks.
  +    *
       * @see #readThread readThread()
       */
      protected Thread writeThread(final String caseNum, final String name,
  @@ -194,30 +206,40 @@
         {
            public void run()
            {
  -            try {
  +            try
  +            {
                  Lock wlock = lock_.writeLock();
  -               if (! wlock.tryLock(msecs, TimeUnit.MILLISECONDS)) {
  -                  logX(caseNum+"-"+name+" requesting write lock failed!\n");
  +               if (!wlock.tryLock(msecs, TimeUnit.MILLISECONDS))
  +               {
  +                  logX(caseNum + "-" + name + " requesting write lock failed!\n");
                     String str = caseNum + "-" + name + "-WL-0";
                     postLockingResult(str);
                     return;
                  }
                  // OK, write lock obtained, sleep and release it.
  -               logX(caseNum+"-"+name+" requesting write lock succeeded!\n");
  +               logX(caseNum + "-" + name + " requesting write lock succeeded!\n");
                  String str = caseNum + "-" + name + "-WL-1";
                  postLockingResult(str);
                  TestingUtil.sleepThread(sleepSecs);
   
   	       if (secondOP == INVOKE_READ)
  +               {
                      acquireReadLock(caseNum, name, msecs, errMsg);
  +               }
                  else if (secondOP == INVOKE_WRITE)
  +               {
                      acquireWriteLock(caseNum, name, msecs, errMsg);
  +               }
                  else if (secondOP == INVOKE_UPGRADE)
  +               {
                      acquireUpgradeLock(caseNum, name, msecs, errMsg);
  +               }
   
                  wlock.unlock();
  -               logX(caseNum+"-"+name+" releasing write lock.\n");
  -            } catch (Exception ex) {
  +               logX(caseNum + "-" + name + " releasing write lock.\n");
  +            }
  +            catch (Exception ex)
  +            {
               }
            }
         };
  @@ -228,6 +250,7 @@
       * and then tries to upgrade the read lock to a write one. Similar
       * to {@link #readThread readThread()} except it's used for upgrading
       * locks.
  +    *
       * @see #readThread readThread()
       */
      protected Thread upgradeThread(final String caseNum, final String name,
  @@ -237,27 +260,29 @@
         {
            public void run()
            {
  -            try {
  +            try
  +            {
                  Lock rlock = lock_.readLock();
                  Lock wlock = null;
  -               if (! rlock.tryLock(msecs, TimeUnit.MILLISECONDS)) {
  -                  logX(caseNum+"-"+name+" requesting read lock failed!\n");
  +               if (!rlock.tryLock(msecs, TimeUnit.MILLISECONDS))
  +               {
  +                  logX(caseNum + "-" + name + " requesting read lock failed!\n");
                     String str = caseNum + "-" + name + "-RL-0";
                     postLockingResult(str);
                     return;
                  }
                  // OK, read lock obtained, sleep and upgrade it later.
  -               logX(caseNum+"-"+name+" requesting read lock succeeded (upgrade later)!\n");
  -               TestingUtil.sleepThread(SLEEP_MSECS/2);
  +               logX(caseNum + "-" + name + " requesting read lock succeeded (upgrade later)!\n");
  +               TestingUtil.sleepThread(SLEEP_MSECS / 2);
                  String str = caseNum + "-" + name + "-UL-";
                  if ((wlock = lock_.upgradeLockAttempt(msecs)) == null)
                  {
  -                 logX(caseNum+"-"+name+" requesting upgrade lock failed!\n");
  +                  logX(caseNum + "-" + name + " requesting upgrade lock failed!\n");
                    str += "0";
                  }
                  else
                  {
  -                 logX(caseNum+"-"+name+" requesting upgrade lock succeeded!\n");
  +                  logX(caseNum + "-" + name + " requesting upgrade lock succeeded!\n");
                    str += "1";
                  }
                  postLockingResult(str);
  @@ -266,10 +291,12 @@
                  if (wlock != null)
                  {
                    wlock.unlock();
  -                 logX(caseNum+"-"+name+" releasing upgrade lock.\n");
  +                  logX(caseNum + "-" + name + " releasing upgrade lock.\n");
                  }
                  rlock.unlock();
  -            } catch (Exception ex) {
  +            }
  +            catch (Exception ex)
  +            {
               }
            }
         };
  @@ -288,22 +315,26 @@
      protected void acquireReadLock(final String caseNum, final String name, 
                                     final long msecs, final String errMsg)
      {
  -            try {
  +      try
  +      {
                  Lock rlock = lock_.readLock();
  -               if (! rlock.tryLock(msecs, TimeUnit.MILLISECONDS)) {
  -                  logX(caseNum+"-"+name+" requesting read lock failed!\n");
  +         if (!rlock.tryLock(msecs, TimeUnit.MILLISECONDS))
  +         {
  +            logX(caseNum + "-" + name + " requesting read lock failed!\n");
                     String str = caseNum + "-" + name + "-RL-0";
                     postLockingResult(str);
                     return;
                  }
                  // OK, read lock obtained, sleep and release it.
  -               logX(caseNum+"-"+name+" requesting read lock succeeded!\n");
  +         logX(caseNum + "-" + name + " requesting read lock succeeded!\n");
                  String str = caseNum + "-" + name + "-RL-1";
                  postLockingResult(str);
                  TestingUtil.sleepThread(SLEEP_MSECS);
                  rlock.unlock();
  -               logX(caseNum+"-"+name+" releasing read lock.\n");
  -            } catch (Exception ex) {
  +         logX(caseNum + "-" + name + " releasing read lock.\n");
  +      }
  +      catch (Exception ex)
  +      {
               }
      }
   
  @@ -314,22 +345,26 @@
      protected void acquireWriteLock(final String caseNum, final String name, 
                                      final long msecs, final String errMsg)
      {
  -            try {
  +      try
  +      {
                  Lock wlock = lock_.writeLock();
  -               if (! wlock.tryLock(msecs, TimeUnit.MILLISECONDS)) {
  -                  logX(caseNum+"-"+name+" requesting write lock failed!\n");
  +         if (!wlock.tryLock(msecs, TimeUnit.MILLISECONDS))
  +         {
  +            logX(caseNum + "-" + name + " requesting write lock failed!\n");
                     String str = caseNum + "-" + name + "-WL-0";
                     postLockingResult(str);
                     return;
                  }
                  // OK, write lock obtained, sleep and release it.
  -               logX(caseNum+"-"+name+" requesting write lock succeeded!\n");
  +         logX(caseNum + "-" + name + " requesting write lock succeeded!\n");
                  String str = caseNum + "-" + name + "-WL-1";
                  postLockingResult(str);
                  TestingUtil.sleepThread(SLEEP_MSECS);
                  wlock.unlock();
  -               logX(caseNum+"-"+name+" releasing write lock.\n");
  -            } catch (Exception ex) {
  +         logX(caseNum + "-" + name + " releasing write lock.\n");
  +      }
  +      catch (Exception ex)
  +      {
               }
      }
   
  @@ -340,22 +375,26 @@
      protected void acquireUpgradeLock(final String caseNum, final String name, 
                                        final long msecs, final String errMsg)
      {
  -            try {
  +      try
  +      {
                  Lock ulock = null;
  -               if ((ulock = lock_.upgradeLockAttempt(msecs)) == null) {
  -                  logX(caseNum+"-"+name+" requesting upgrade lock failed!\n");
  +         if ((ulock = lock_.upgradeLockAttempt(msecs)) == null)
  +         {
  +            logX(caseNum + "-" + name + " requesting upgrade lock failed!\n");
                     String str = caseNum + "-" + name + "-UL-0";
                     postLockingResult(str);
                     return;
                  }
                  // OK, write lock obtained, sleep and release it.
  -               logX(caseNum+"-"+name+" requesting upgrade lock succeeded!\n");
  +         logX(caseNum + "-" + name + " requesting upgrade lock succeeded!\n");
                  String str = caseNum + "-" + name + "-UL-1";
                  postLockingResult(str);
                  TestingUtil.sleepThread(SLEEP_MSECS);
                  ulock.unlock();
  -               logX(caseNum+"-"+name+" releasing upgrade lock.\n");
  -            } catch (Exception ex) {
  +         logX(caseNum + "-" + name + " releasing upgrade lock.\n");
  +      }
  +      catch (Exception ex)
  +      {
               }
      }
   
  @@ -375,7 +414,7 @@
       */
      protected synchronized void postLockingResult(Object obj)
      {
  -       logX("  Added *" + (String)obj + "* to the result vector\n");
  +      logX("  Added *" + obj + "* to the result vector\n");
          // Make sure we only have one in the vector
          //if (!checkLockingResult((String)obj))
            lockResult.addElement(obj);
  @@ -387,10 +426,10 @@
      protected synchronized boolean checkLockingResult(String expected)
      {
          boolean rc = false;
  -       for (int i=0; i<lockResult.size(); i++)
  +      for (int i = 0; i < lockResult.size(); i++)
          {
            Object ele = lockResult.elementAt(i);
  -         String str = (String)ele;
  +         String str = (String) ele;
            if (expected.equals(str))
            {
               rc = true;
  @@ -398,223 +437,266 @@
            }
          }
          if (rc)
  +      {
            logX("  Searching for *" + expected + "* SUCCEEDED.\n");
  +      }
          else
  +      {
            logX("  Searching for *" + expected + "* FAILED.\n");
  +      }
          return rc;
      }
   
      /***************************************************************/
      /*                   T e s t  C a s e s                        */
      /***************************************************************/
  -   /** Case #10 - T1 acquires RL, T2 acquires RL followed by WL. */
  +   /**
  +    * Case #10 - T1 acquires RL, T2 acquires RL followed by WL.
  +    */
      public void testWriteWithMultipleReaders() throws Exception
      {
         String caseNum = "10";
  -      Thread t1=readThread(caseNum, "t1", 0, SLEEP_MSECS*2,
  +      Thread t1 = readThread(caseNum, "t1", 0, SLEEP_MSECS * 2,
                              "1st read lock attempt failed", NO_MORE_OP);
  -      Thread t2=readThread(caseNum, "t2", 0, SLEEP_MSECS,
  +      Thread t2 = readThread(caseNum, "t2", 0, SLEEP_MSECS,
                              "2nd read lock attempt failed", INVOKE_WRITE);
   
         t1.start();
         t2.start();
         t1.join(3000);
         t2.join(3000);
  -      assertTrue(checkLockingResult(caseNum+"-t1-RL-1") &&
  -                 checkLockingResult(caseNum+"-t2-RL-1") &&
  -                 checkLockingResult(caseNum+"-t2-WL-0"));
  +      assertTrue(checkLockingResult(caseNum + "-t1-RL-1") &&
  +              checkLockingResult(caseNum + "-t2-RL-1") &&
  +              checkLockingResult(caseNum + "-t2-WL-0"));
         cleanLockingResult();
         // possilbe deadlock check
         if (t1.isAlive() || t2.isAlive())
  +      {
            fail("Possible deadlock resulted in testRead.");
      }
  +   }
   
  -   /** Case #11 - T1 acquires RL followed by WL, T2 acquires RL. */
  +   /**
  +    * Case #11 - T1 acquires RL followed by WL, T2 acquires RL.
  +    */
      public void testUpgradeWithMultipleReadersOn1() throws Exception
      {
         String caseNum = "11";
  -      Thread t1=readThread(caseNum, "t1", 0, SLEEP_MSECS,
  +      Thread t1 = readThread(caseNum, "t1", 0, SLEEP_MSECS,
                              "1st read lock attempt failed", INVOKE_WRITE);
  -      Thread t2=readThread(caseNum, "t2", 0, SLEEP_MSECS*2,
  +      Thread t2 = readThread(caseNum, "t2", 0, SLEEP_MSECS * 2,
                              "2nd read lock attempt failed", NO_MORE_OP);
   
         t1.start();
         t2.start();
         t1.join(3000);
         t2.join(3000);
  -      assertTrue(checkLockingResult(caseNum+"-t1-RL-1") &&
  -                 checkLockingResult(caseNum+"-t2-RL-1") &&
  -                 checkLockingResult(caseNum+"-t1-WL-0"));
  +      assertTrue(checkLockingResult(caseNum + "-t1-RL-1") &&
  +              checkLockingResult(caseNum + "-t2-RL-1") &&
  +              checkLockingResult(caseNum + "-t1-WL-0"));
         cleanLockingResult();
         // possilbe deadlock check
         if (t1.isAlive() || t2.isAlive())
  +      {
            fail("Possible deadlock resulted in testRead.");
      }
  +   }
   
  -   /** Case #2 - T1 acquires RL followed by UL. */
  +   /**
  +    * Case #2 - T1 acquires RL followed by UL.
  +    */
      public void testUpgradeReadLock() throws Exception
      {
         String caseNum = "2";
  -      Thread t1=readThread(caseNum, "t1", 0, SLEEP_MSECS,
  +      Thread t1 = readThread(caseNum, "t1", 0, SLEEP_MSECS,
                              "1st read lock attempt failed", INVOKE_UPGRADE);
   
         t1.start();
         t1.join(3000);
  -      assertTrue(checkLockingResult(caseNum+"-t1-RL-1") &&
  -                 checkLockingResult(caseNum+"-t1-UL-1"));
  +      assertTrue(checkLockingResult(caseNum + "-t1-RL-1") &&
  +              checkLockingResult(caseNum + "-t1-UL-1"));
         cleanLockingResult();
      }
   
  -   /** Case #3 - T1 acquires RL followed by WL. */
  +   /**
  +    * Case #3 - T1 acquires RL followed by WL.
  +    */
   
      public void testReadThenWrite() throws Exception
      {
         String caseNum = "3";
         acquireReadLock(caseNum, "t1", 0, "1st read lock attempt failed");
         acquireWriteLock(caseNum, "t1.1", 0, "2nd write lock attempt failed");
  -      assertTrue(checkLockingResult(caseNum+"-t1-RL-1") &&
  -                 checkLockingResult(caseNum+"-t1.1-WL-1"));
  +      assertTrue(checkLockingResult(caseNum + "-t1-RL-1") &&
  +              checkLockingResult(caseNum + "-t1.1-WL-1"));
         cleanLockingResult();
      }
   
   
  -   /** Case #5 - T1 acquires WL followed by RL.*/
  +   /**
  +    * Case #5 - T1 acquires WL followed by RL.
  +    */
   
      public void testWriteThenRead() throws Exception
      {
         String caseNum = "5";
         acquireWriteLock(caseNum, "t1", 0, "1st write lock attempt failed");
         acquireReadLock(caseNum, "t1.1", 0, "2nd read lock attempt failed");
  -      assertTrue(checkLockingResult(caseNum+"-t1-WL-1") &&
  -                 checkLockingResult(caseNum+"-t1.1-RL-1"));
  +      assertTrue(checkLockingResult(caseNum + "-t1-WL-1") &&
  +              checkLockingResult(caseNum + "-t1.1-RL-1"));
         cleanLockingResult();
      }
   
  -   /** Case #6 - T1 acquires RL, T2 acquires RL.*/
  +   /**
  +    * Case #6 - T1 acquires RL, T2 acquires RL.
  +    */
      public void testMultipleReadlock() throws Exception
      {
         String caseNum = "6";
  -      Thread t1=readThread(caseNum, "t1", 0, SLEEP_MSECS,
  +      Thread t1 = readThread(caseNum, "t1", 0, SLEEP_MSECS,
                              "1st read lock attempt failed", NO_MORE_OP);
  -      Thread t2=readThread(caseNum, "t2", 0, SLEEP_MSECS,
  +      Thread t2 = readThread(caseNum, "t2", 0, SLEEP_MSECS,
                              "2nd read lock attempt failed", NO_MORE_OP);
   
         t1.start();
         t2.start();
         t1.join(3000);
         t2.join(3000);
  -      assertTrue(checkLockingResult(caseNum+"-t1-RL-1") &&
  -                 checkLockingResult(caseNum+"-t2-RL-1"));
  +      assertTrue(checkLockingResult(caseNum + "-t1-RL-1") &&
  +              checkLockingResult(caseNum + "-t2-RL-1"));
         cleanLockingResult();
         // possilbe deadlock check
         if (t1.isAlive() || t2.isAlive())
  +      {
            fail("Possible deadlock resulted in testRead.");
      }
  +   }
   
  -   /** Case #8 - T1 acquires WL, T2 acquires RL.*/
  +   /**
  +    * Case #8 - T1 acquires WL, T2 acquires RL.
  +    */
      public void testWriteWithExistingReader() throws Exception
      {
         String caseNum = "8";
  -      Thread t1=readThread(caseNum, "t1", 0, SLEEP_MSECS,
  +      Thread t1 = readThread(caseNum, "t1", 0, SLEEP_MSECS,
                              "1st write lock attempt failed", NO_MORE_OP);
  -      Thread t2=writeThread(caseNum, "t2", 0, SLEEP_MSECS,
  +      Thread t2 = writeThread(caseNum, "t2", 0, SLEEP_MSECS,
                              "2nd read lock attempt failed", NO_MORE_OP);
   
         t1.start();
         t2.start();
         t1.join(3000);
         t2.join(3000);
  -      assertTrue(checkLockingResult(caseNum+"-t1-RL-1") &&
  -                 checkLockingResult(caseNum+"-t2-WL-0"));
  +      assertTrue(checkLockingResult(caseNum + "-t1-RL-1") &&
  +              checkLockingResult(caseNum + "-t2-WL-0"));
         cleanLockingResult();
         // possilbe deadlock check
         if (t1.isAlive() || t2.isAlive())
  +      {
            fail("Possible deadlock resulted in testRead.");
      }
  +   }
   
  -   /** Case #13 - T1 acquires RL, T2 acquires WL.*/
  +   /**
  +    * Case #13 - T1 acquires RL, T2 acquires WL.
  +    */
      public void testReadWithExistingWriter() throws Exception
      {
         String caseNum = "13";
  -      Thread t1=writeThread(caseNum, "t1", 0, SLEEP_MSECS,
  +      Thread t1 = writeThread(caseNum, "t1", 0, SLEEP_MSECS,
                              "1st write lock attempt failed", NO_MORE_OP);
  -      Thread t2=readThread(caseNum, "t2", 0, SLEEP_MSECS,
  +      Thread t2 = readThread(caseNum, "t2", 0, SLEEP_MSECS,
                              "2nd read lock attempt failed", NO_MORE_OP);
   
         t1.start();
         t2.start();
         t1.join(3000);
         t2.join(3000);
  -      assertTrue(checkLockingResult(caseNum+"-t1-WL-1") &&
  -                 checkLockingResult(caseNum+"-t2-RL-0"));
  +      assertTrue(checkLockingResult(caseNum + "-t1-WL-1") &&
  +              checkLockingResult(caseNum + "-t2-RL-0"));
         cleanLockingResult();
         // possilbe deadlock check
         if (t1.isAlive() || t2.isAlive())
  +      {
            fail("Possible deadlock resulted in testRead.");
      }
  +   }
   
  -   /** Case #14 - T1 acquires WL, T2 acquires WL.*/
  +   /**
  +    * Case #14 - T1 acquires WL, T2 acquires WL.
  +    */
      public void testMultipleWritelocks() throws Exception
      {
         String caseNum = "14";
  -      Thread t1=writeThread(caseNum, "t1", 0, SLEEP_MSECS,
  +      Thread t1 = writeThread(caseNum, "t1", 0, SLEEP_MSECS,
                              "1st write lock attempt failed", NO_MORE_OP);
  -      Thread t2=writeThread(caseNum, "t2", 0, SLEEP_MSECS,
  +      Thread t2 = writeThread(caseNum, "t2", 0, SLEEP_MSECS,
                              "2nd write lock attempt failed", NO_MORE_OP);
   
         t1.start();
         t2.start();
         t1.join(3000);
         t2.join(3000);
  -      assertTrue(checkLockingResult(caseNum+"-t1-WL-1") &&
  -                 checkLockingResult(caseNum+"-t2-WL-0"));
  +      assertTrue(checkLockingResult(caseNum + "-t1-WL-1") &&
  +              checkLockingResult(caseNum + "-t2-WL-0"));
         cleanLockingResult();
         // possilbe deadlock check
         if (t1.isAlive() || t2.isAlive())
  +      {
            fail("Possible deadlock resulted in testRead.");
      }
  -   /** Case #7 - T1 acquires RL, T2 acquires UL.*/
  +   }
  +
  +   /**
  +    * Case #7 - T1 acquires RL, T2 acquires UL.
  +    */
   
      public void testUpgradeWithExistingReader() throws Exception
      {
         String caseNum = "7";
  -      Thread t1=readThread(caseNum, "t1", 0, SLEEP_MSECS,
  +      Thread t1 = readThread(caseNum, "t1", 0, SLEEP_MSECS,
                              "1st read lock attempt failed", NO_MORE_OP);
  -      Thread t2=upgradeThread(caseNum, "t2", 0, 
  +      Thread t2 = upgradeThread(caseNum, "t2", 0,
                              "2nd upgrade lock attempt failed");
   
         t1.start();
         t2.start();
         t1.join(3000);
         t2.join(3000);
  -      assertTrue(checkLockingResult(caseNum+"-t1-RL-1") &&
  -                 checkLockingResult(caseNum+"-t2-UL-0"));
  +      assertTrue(checkLockingResult(caseNum + "-t1-RL-1") &&
  +              checkLockingResult(caseNum + "-t2-UL-0"));
         cleanLockingResult();
         // possilbe deadlock check
         if (t1.isAlive() || t2.isAlive())
  +      {
            fail("Possible deadlock resulted in testRead.");
      }
  +   }
   
  -   /** Case #9 - T1 acquires RL, T2 acquires RL followed by UL.*/
  +   /**
  +    * Case #9 - T1 acquires RL, T2 acquires RL followed by UL.
  +    */
      public void testUpgradeWithMultipleReaders() throws Exception
      {
         String caseNum = "9";
  -      Thread t1=readThread(caseNum, "t1", 0, SLEEP_MSECS*2,
  +      Thread t1 = readThread(caseNum, "t1", 0, SLEEP_MSECS * 2,
                              "1st read lock attempt failed", NO_MORE_OP);
  -      Thread t2=readThread(caseNum, "t2", 0, SLEEP_MSECS,
  +      Thread t2 = readThread(caseNum, "t2", 0, SLEEP_MSECS,
                              "2nd read lock attempt failed", INVOKE_UPGRADE);
   
         t1.start();
         t2.start();
         t1.join(3000);
         t2.join(3000);
  -      assertTrue(checkLockingResult(caseNum+"-t1-RL-1") &&
  -                 checkLockingResult(caseNum+"-t2-RL-1") &&
  -                 checkLockingResult(caseNum+"-t2-UL-0"));
  +      assertTrue(checkLockingResult(caseNum + "-t1-RL-1") &&
  +              checkLockingResult(caseNum + "-t2-RL-1") &&
  +              checkLockingResult(caseNum + "-t2-UL-0"));
         cleanLockingResult();
         // possilbe deadlock check
         if (t1.isAlive() || t2.isAlive())
  +      {
            fail("Possible deadlock resulted in testRead.");
      }
  +   }
   }
   
  
  
  



More information about the jboss-cvs-commits mailing list