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

Manik Surtani msurtani at belmont.prod.atl2.jboss.com
Wed Aug 30 15:09:56 EDT 2006


  User: msurtani
  Date: 06/08/30 15:09:56

  Modified:    tests/functional/org/jboss/cache/lock  IdentityLockTest.java
  Log:
  removed unnenessary (IDE-generated) TODOs that were becoming noisy
  refactored identity lock constructors
  
  Revision  Changes    Path
  1.6       +198 -92   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.5
  retrieving revision 1.6
  diff -u -b -r1.5 -r1.6
  --- IdentityLockTest.java	5 May 2006 12:06:58 -0000	1.5
  +++ IdentityLockTest.java	30 Aug 2006 19:09:56 -0000	1.6
  @@ -17,18 +17,20 @@
   import org.jboss.cache.misc.TestingUtil;
   
   
  -/** Testing of different locking semantics.
  +/**
  + * Testing of different locking semantics.
  + *
    * @author Bela Ban
    * @author Ben Wang
  - * @version $Revision: 1.5 $
  + * @version $Revision: 1.6 $
    */
   public class IdentityLockTest extends TestCase
   {
      IdentityLock lock_;
      Object other_ = new Object();
  -   Log logger_=LogFactory.getLog(IdentityLockTest.class);
  -   static Throwable thread_ex=null;
  -   final Fqn FQN=Fqn.fromString("/dummyfqn");
  +   Log logger_ = LogFactory.getLog(IdentityLockTest.class);
  +   static Throwable thread_ex = null;
  +   final Fqn FQN = Fqn.fromString("/dummyfqn");
   
   
      public IdentityLockTest(String name)
  @@ -39,7 +41,7 @@
      protected void setUp() throws Exception
      {
         super.setUp();
  -      lock_ = new IdentityLock(null, FQN);
  +      lock_ = new IdentityLock(FQN);
   
   //        try { Thread.TestingUtil.sleepThread(10000); } catch (Exception e) {
   //        }
  @@ -50,21 +52,21 @@
         super.tearDown();
         lock_.releaseAll();
         lock_ = null;
  -      thread_ex=null;
  +      thread_ex = null;
      }
   
      protected void setLevelRW()
      {
         log("set lock level to RWUpgrade ...");
         LockStrategyFactory.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
  -      lock_ = new IdentityLock(null, FQN);
  +      lock_ = new IdentityLock(FQN);
      }
   
      protected void setLevelSerial()
      {
         log("set lock level to SimpleLock ...");
         LockStrategyFactory.setIsolationLevel(IsolationLevel.SERIALIZABLE);
  -      lock_ = new IdentityLock(null, FQN);
  +      lock_ = new IdentityLock(FQN);
      }
   
      protected GlobalTransaction getGlobalTransactionFromThread()
  @@ -72,93 +74,121 @@
       return GlobalTransaction.create(null);
      }
   
  -   public void testNullOwner_RWLock() throws InterruptedException {
  +   public void testNullOwner_RWLock() throws InterruptedException
  +   {
         setLevelRW();
         nullOwner();
      }
   
  -   public void testNullOwner_SimpleLock() throws InterruptedException {
  +   public void testNullOwner_SimpleLock() throws InterruptedException
  +   {
         setLevelSerial();
         nullOwner();
      }
   
  -   protected void nullOwner() throws InterruptedException {
  +   protected void nullOwner() throws InterruptedException
  +   {
         log("testNullOwner ...");
  -      try {
  +      try
  +      {
            GlobalTransaction gtx = getGlobalTransactionFromThread();
            lock_.acquireWriteLock(gtx, 50);
            lock_.release(gtx);
   
            lock_.acquireReadLock(gtx, 50);
            lock_.release(gtx);
  -      } catch (LockingException e) {
  +      }
  +      catch (LockingException e)
  +      {
            fail(e.toString());
  -      } catch (TimeoutException e) {
  +      }
  +      catch (TimeoutException e)
  +      {
            fail(e.toString());
         }
      }
   
  -   public void testNullOwner2_RWLock() throws InterruptedException {
  +   public void testNullOwner2_RWLock() throws InterruptedException
  +   {
         setLevelRW();
         nullOwner2();
      }
   
  -   public void testNullOwner2_SimpleLock() throws InterruptedException {
  +   public void testNullOwner2_SimpleLock() throws InterruptedException
  +   {
         setLevelSerial();
         nullOwner2();
      }
   
  -   protected void nullOwner2() throws InterruptedException {
  +   protected void nullOwner2() throws InterruptedException
  +   {
         log("testNullOwner2 ...");
  -      try {
  +      try
  +      {
            GlobalTransaction gtx = getGlobalTransactionFromThread();
            lock_.acquireReadLock(gtx, 50);
            lock_.acquireWriteLock(gtx, 50); // this should succeed
            lock_.release(gtx);
  -      } catch (LockingException e) {
  +      }
  +      catch (LockingException e)
  +      {
            fail(e.toString());
  -      } catch (TimeoutException e2) {
  +      }
  +      catch (TimeoutException e2)
  +      {
            fail(e2.toString());
         }
      }
   
  -   public void testNullOwner3_RWLock() throws InterruptedException {
  +   public void testNullOwner3_RWLock() throws InterruptedException
  +   {
         setLevelRW();
         nullOwner3();
      }
   
  -   public void testNullOwner3_SimpleLock() throws InterruptedException {
  +   public void testNullOwner3_SimpleLock() throws InterruptedException
  +   {
         setLevelSerial();
         nullOwner3();
      }
   
  -   public void nullOwner3() throws InterruptedException {
  +   public void nullOwner3() throws InterruptedException
  +   {
         log("testNullOwner3 ...");
  -      try {
  +      try
  +      {
            GlobalTransaction gtx = getGlobalTransactionFromThread();
            lock_.acquireWriteLock(gtx, 50);
            lock_.acquireReadLock(gtx, 50); // this should succeed
            lock_.release(gtx);
  -      } catch (LockingException e) {
  +      }
  +      catch (LockingException e)
  +      {
            fail(e.toString());
  -      } catch (TimeoutException e2) {
  +      }
  +      catch (TimeoutException e2)
  +      {
            fail(e2.toString());
         }
      }
   
  -   public void testAcquireAndRelease_RWLock() throws InterruptedException {
  +   public void testAcquireAndRelease_RWLock() throws InterruptedException
  +   {
         setLevelRW();
         acquireAndRelease();
      }
   
  -   public void testAcquireAndRelease_SimpleLock() throws InterruptedException {
  +   public void testAcquireAndRelease_SimpleLock() throws InterruptedException
  +   {
         setLevelSerial();
         acquireAndRelease();
      }
   
  -   public void acquireAndRelease() throws InterruptedException {
  +   public void acquireAndRelease() throws InterruptedException
  +   {
         log("testAcquireAndRelease ...");
  -      try {
  +      try
  +      {
            lock_.acquireReadLock(this, 50);
            assertTrue("Is the lock owner", lock_.isOwner(this));
            assertTrue(lock_.getReaderOwners().contains(this));
  @@ -174,47 +204,72 @@
   
            lock_.release(this);
            assertTrue(!lock_.isOwner(this));
  -      } catch (LockingException e) {
  +      }
  +      catch (LockingException e)
  +      {
            fail(e.toString());
  -      } catch (TimeoutException e2) {
  +      }
  +      catch (TimeoutException e2)
  +      {
            fail(e2.toString());
         }
      }
   
  -   public void acquireAndRelease2_RWLock() throws InterruptedException {
  +   public void acquireAndRelease2_RWLock() throws InterruptedException
  +   {
         setLevelRW();
         log("testAcquireAndRelease2 ...");
  -      try {
  +      try
  +      {
            lock_.acquireReadLock(this, 10);
  -      } catch (LockingException e) {
  +      }
  +      catch (LockingException e)
  +      {
            fail(e.toString());
  -      } catch (TimeoutException e2) {
  +      }
  +      catch (TimeoutException e2)
  +      {
            fail(e2.toString());
         }
   
  -      try {
  +      try
  +      {
            lock_.acquireReadLock(other_, 10); // should succeed
  -      } catch (LockingException e) {
  +      }
  +      catch (LockingException e)
  +      {
            fail(e.toString());
  -      } catch (TimeoutException e2) {
  +      }
  +      catch (TimeoutException e2)
  +      {
            fail(e2.toString());
         }
   
  -      try {
  +      try
  +      {
            lock_.acquireWriteLock(other_, 50); // should fail
  -      } catch (LockingException e) {
  +      }
  +      catch (LockingException e)
  +      {
            fail(e.toString());
  -      } catch (TimeoutException e2) {
  +      }
  +      catch (TimeoutException e2)
  +      {
            assertTrue(true);
         }
   
         lock_.release(this);
   
  -      try {
  +      try
  +      {
            lock_.acquireWriteLock(other_, 10); // should succeed
  -      } catch (LockingException e) {
  +      }
  +      catch (LockingException e)
  +      {
            fail(e.toString());
  -      } catch (TimeoutException e2) {
  +      }
  +      catch (TimeoutException e2)
  +      {
            fail(e2.toString());
         }
   
  @@ -222,50 +277,72 @@
      }
   
   
  -   public void acquireAndRelease2_SimpleLock() throws InterruptedException {
  +   public void acquireAndRelease2_SimpleLock() throws InterruptedException
  +   {
         setLevelSerial();
         log("testAcquireAndRelease2 ...");
  -      try {
  +      try
  +      {
            lock_.acquireReadLock(this, 10);
  -      } catch (LockingException e) {
  +      }
  +      catch (LockingException e)
  +      {
            fail(e.toString());
  -      } catch (TimeoutException e2) {
  +      }
  +      catch (TimeoutException e2)
  +      {
            fail(e2.toString());
         }
   
  -      try {
  +      try
  +      {
            lock_.acquireReadLock(other_, 10); // should fail
            fail("Acquire read lock for other. Should fail.");
  -      } catch (LockingException e) {
  +      }
  +      catch (LockingException e)
  +      {
            fail(e.toString());
  -      } catch (TimeoutException e2) {
  +      }
  +      catch (TimeoutException e2)
  +      {
            // Expected
            assertTrue(true);
         }
   
  -      try {
  +      try
  +      {
            lock_.acquireWriteLock(other_, 50); // should fail
            fail("Acquire read lock for other. Should fail.");
  -      } catch (LockingException e) {
  +      }
  +      catch (LockingException e)
  +      {
            fail(e.toString());
  -      } catch (TimeoutException e2) {
  +      }
  +      catch (TimeoutException e2)
  +      {
            assertTrue(true);
         }
   
         lock_.release(this);
   
  -      try {
  +      try
  +      {
            lock_.acquireWriteLock(other_, 10); // should succeed
  -      } catch (LockingException e) {
  +      }
  +      catch (LockingException e)
  +      {
            fail(e.toString());
  -      } catch (TimeoutException e2) {
  +      }
  +      catch (TimeoutException e2)
  +      {
            fail(e2.toString());
         }
   
         lock_.releaseAll();
      }
   
  -   public void testThreadedAccess_RWLock() throws Throwable {
  +   public void testThreadedAccess_RWLock() throws Throwable
  +   {
         setLevelRW();
         log("testThreadedAccess_RWLock ...");
         final Object o1 = new Object();
  @@ -277,13 +354,16 @@
         {
            public void run()
            {
  -            try {
  +            try
  +            {
                  log("o1 acquiring lock");
                  lock_.acquireReadLock(o1, 50);
                  log("o1: OK");
  -            } catch (Throwable e) {
  +            }
  +            catch (Throwable e)
  +            {
                  log("o1: FAIL");
  -               thread_ex=e;
  +               thread_ex = e;
               }
            }
         };
  @@ -293,13 +373,16 @@
         {
            public void run()
            {
  -            try {
  +            try
  +            {
                  log("o2 acquiring lock");
                  lock_.acquireWriteLock(o2, 2000);
                  log("o2: OK");
  -            } catch (Throwable e) {
  +            }
  +            catch (Throwable e)
  +            {
                  log("o2: FAIL");
  -               thread_ex=e;
  +               thread_ex = e;
               }
            }
         };
  @@ -309,13 +392,16 @@
         {
            public void run()
            {
  -            try {
  +            try
  +            {
                  log("o1 acquiring lock");
                  lock_.acquireWriteLock(o1, 10);
                  log("o1: OK");
  -            } catch (Throwable e) {
  +            }
  +            catch (Throwable e)
  +            {
                  log("o1: FAIL");
  -               thread_ex=e;
  +               thread_ex = e;
               }
            }
         };
  @@ -348,12 +434,13 @@
         t1.join(20000);
         t2.join(20000);
         t3.join(20000);
  -      if(thread_ex != null)
  +      if (thread_ex != null)
            throw thread_ex;
      }
   
   
  -   public void testThreadedAccess_SimpleLock() throws Throwable {
  +   public void testThreadedAccess_SimpleLock() throws Throwable
  +   {
         setLevelSerial();
         log("testThreadedAccess_SimpleLock() ...");
         final Object o1 = new Object();
  @@ -365,13 +452,16 @@
         {
            public void run()
            {
  -            try {
  +            try
  +            {
                  log("o1 acquiring lock");
                  lock_.acquireReadLock(o1, 50);
                  log("o1: OK");
  -            } catch (Throwable e) {
  +            }
  +            catch (Throwable e)
  +            {
                  log("o1: FAIL");
  -               thread_ex=e;
  +               thread_ex = e;
               }
            }
         };
  @@ -381,13 +471,16 @@
         {
            public void run()
            {
  -            try {
  +            try
  +            {
                  log("o2 acquiring lock");
                  lock_.acquireWriteLock(o2, 2000);
                  log("o2: OK");
  -            } catch (Throwable e) {
  +            }
  +            catch (Throwable e)
  +            {
                  log("o2: FAIL");
  -               thread_ex=e;
  +               thread_ex = e;
               }
            }
         };
  @@ -397,13 +490,16 @@
         {
            public void run()
            {
  -            try {
  +            try
  +            {
                  log("o1 acquiring lock");
                  lock_.acquireWriteLock(o1, 10);
                  log("o1: OK");
  -            } catch (Throwable e) {
  +            }
  +            catch (Throwable e)
  +            {
                  log("o1: FAIL");
  -               thread_ex=e;
  +               thread_ex = e;
               }
            }
         };
  @@ -436,7 +532,7 @@
         t1.join(20000);
         t2.join(20000);
         t3.join(20000);
  -      if(thread_ex != null)
  +      if (thread_ex != null)
            throw thread_ex;
      }
   
  @@ -468,25 +564,30 @@
         {
            public void run()
            {
  -            try {
  +            try
  +            {
                  log("calling releaseAll()");
                  lock_.releaseAll();
                  log("releaseAll(): OK");
  -            } catch (Throwable e) {
  +            }
  +            catch (Throwable e)
  +            {
                  log("releaseAll(): FAIL");
  -               thread_ex=e;
  +               thread_ex = e;
               }
            }
         };
   
  -      try {
  +      try
  +      {
            t1.setDaemon(true);
            t1.start();
            TestingUtil.sleepThread(1000);
   
            assertFalse("Lock map cleared", lock_.isReadLocked());
         }
  -      finally {
  +      finally
  +      {
            // Manually release the locks so tearDown() will not fail
            // if there is a problem with releaseAll()
            lock_.release(o1);
  @@ -518,25 +619,30 @@
         {
            public void run()
            {
  -            try {
  +            try
  +            {
                  log("calling releaseAll()");
                  lock_.releaseAll();
                  log("releaseAll(): OK");
  -            } catch (Throwable e) {
  +            }
  +            catch (Throwable e)
  +            {
                  log("releaseAll(): FAIL");
  -               thread_ex=e;
  +               thread_ex = e;
               }
            }
         };
   
  -      try {
  +      try
  +      {
            t1.setDaemon(true);
            t1.start();
            TestingUtil.sleepThread(1000);
   
            assertFalse("Lock map cleared", lock_.isReadLocked());
         }
  -      finally {
  +      finally
  +      {
            // Manually release the lock so tearDown() will not fail
            // if there is a problem with releaseAll()
            lock_.release(o1);
  
  
  



More information about the jboss-cvs-commits mailing list