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

Elias Ross genman at noderunner.net
Fri Dec 8 13:50:49 EST 2006


  User: genman  
  Date: 06/12/08 13:50:49

  Modified:    tests/functional/org/jboss/cache/lock     
                        ReentrantWriterPreferenceReadWriteLockTest.java
                        ReentrantWriterPreference2Readers1WriterLockTest.java
                        ReadWriteLockWithUpgradeTest.java
                        NonBlockingWriterLockTest.java LockTest.java
  Log:
  JBCACHE-891 Use JDK 1.5 lock classes
  
  Revision  Changes    Path
  1.4       +48 -42    JBossCache/tests/functional/org/jboss/cache/lock/ReentrantWriterPreferenceReadWriteLockTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ReentrantWriterPreferenceReadWriteLockTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/lock/ReentrantWriterPreferenceReadWriteLockTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- ReentrantWriterPreferenceReadWriteLockTest.java	5 May 2006 12:06:58 -0000	1.3
  +++ ReentrantWriterPreferenceReadWriteLockTest.java	8 Dec 2006 18:50:49 -0000	1.4
  @@ -1,6 +1,8 @@
   package org.jboss.cache.lock;
   
  -import EDU.oswego.cs.dl.util.concurrent.Sync;
  +import java.util.concurrent.TimeUnit;
  +import java.util.concurrent.locks.Lock;
  +
   import junit.framework.Test;
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
  @@ -9,12 +11,12 @@
   /**
    * Tests ReentrantWriterPreferenceReadWriteLock
    * @author Bela Ban
  - * @version $Id: ReentrantWriterPreferenceReadWriteLockTest.java,v 1.3 2006/05/05 12:06:58 msurtani Exp $
  + * @version $Id: ReentrantWriterPreferenceReadWriteLockTest.java,v 1.4 2006/12/08 18:50:49 genman Exp $
    */
   public class ReentrantWriterPreferenceReadWriteLockTest extends TestCase {
      // ReentrantWriterPreferenceReadWriteLock lock;
      SimpleReadWriteLock lock;
  -   Sync rl, wl;
  +   Lock rl, wl;
      Exception thread_ex=null;
   
      protected void setUp() throws Exception {
  @@ -34,78 +36,82 @@
      }
   
      public void testMultipleReadLockAcquisitions() throws InterruptedException {
  -      rl.acquire();
  -      rl.acquire();
  +      rl.lock();
  +      rl.lock();
      }
   
      public void testInterruptedLockAcquisition() {
         Thread.currentThread().interrupt();
         try {
  -         rl.acquire();
  +         rl.lockInterruptibly();
            fail("thread should be in interrupted status");
         }
         catch(InterruptedException e) {
         }
         finally {
            try {
  -            rl.release();
  -            fail("release() should throw an IllegalStateException");
  +            rl.unlock();
  +            fail("unlock() should throw an IllegalStateException");
            }
  -         catch(IllegalStateException illegalStateEx) {
  +         catch(IllegalMonitorStateException illegalStateEx) {
               assertTrue(true);
            }
         }
      }
   
      public void testMultipleWriteLockAcquisitions() throws InterruptedException {
  -      wl.acquire();
  -      wl.acquire();
  +      wl.lock();
  +      wl.lock();
      }
   
      public void testMultipleReadLockReleases() throws InterruptedException {
  -      rl.acquire();
  -      rl.release();
  +      rl.lock();
  +      rl.unlock();
         try {
  -         rl.release();
  -         fail("we should not get here, cannot acquire RL once but release twice");
  +         rl.unlock();
  +         fail("we should not get here, cannot lock RL once but unlock twice");
         }
  -      catch(IllegalStateException illegalState) {
  +      catch(IllegalMonitorStateException illegalState) {
            // this is as expected
         }
      }
   
   
      public void acquireReadAndWriteLocks() throws InterruptedException {
  -      rl.acquire();
  -      rl.acquire();
  -      boolean fl=wl.attempt(4000);
  +      rl.lock();
  +      rl.lock();
  +      boolean fl=wl.tryLock(4000, TimeUnit.MILLISECONDS);
         assertTrue(fl);
      }
   
   
      public void acquireWriteThenReadLock() throws InterruptedException {
  -      wl.acquire();
  -      rl.acquire();
  -      wl.release();
  -      rl.release();
  +      wl.lock();
  +      rl.lock();
  +      wl.unlock();
  +      rl.unlock();
      }
   
      public void testMultipleWriteLockReleases() throws InterruptedException {
  -      wl.acquire();
  -      wl.release();
  -      wl.release();
  +      wl.lock();
  +      wl.unlock();
  +      try {
  +         wl.unlock();
  +         fail("expected");
  +      } catch (IllegalMonitorStateException e) {}
      }
   
      public void testAcquireWriteLockAfterReadLock() throws InterruptedException {
  -      rl.acquire();
  -      wl.acquire();
  +      rl.lock();
  +      rl.unlock();
  +      wl.lock();
      }
   
   
      public void testAcquiringReadLockedLockWithRead() throws InterruptedException {
         new Thread() {
            public void run() {
  -            try {rl.acquire();}
  +            try {rl.lockInterruptibly();}
               catch(InterruptedException e) {}
            }
         }.start();
  @@ -114,16 +120,16 @@
   
         // now we have a RL by another thread
   
  -      boolean flag=rl.attempt(3000);
  +      boolean flag=rl.tryLock(3000, TimeUnit.MILLISECONDS);
         assertTrue(flag);
  -      flag=wl.attempt(3000);
  +      flag=wl.tryLock(3000, TimeUnit.MILLISECONDS);
         assertFalse(flag);
      }
   
      public void testAcquiringReadLockedLock() throws InterruptedException {
         new Thread() {
            public void run() {
  -            try {rl.acquire();}
  +            try {rl.lockInterruptibly();}
               catch(InterruptedException e) {}
            }
         }.start();
  @@ -131,7 +137,7 @@
         TestingUtil.sleepThread(500);
   
         // now we have a RL by another thread
  -      boolean flag=wl.attempt(3000);
  +      boolean flag=wl.tryLock(3000, TimeUnit.MILLISECONDS);
         assertFalse(flag);
      }
   
  @@ -193,13 +199,13 @@
         public void run() {
            try {
               log("acquiring RL");
  -            rl.acquire();
  +            rl.lock();
               log("acquired RL");
               synchronized(this) {
                  this.wait();
               }
               log("releasing RL");
  -            rl.release();
  +            rl.unlock();
               log("released RL");
            }
            catch(InterruptedException e) {
  @@ -218,13 +224,13 @@
         public void run() {
            try {
               log("acquiring WL");
  -            wl.acquire();
  +            wl.lock();
               log("acquired WL");
               synchronized(this) {
                  this.wait();
               }
               log("releasing WL");
  -            wl.release();
  +            wl.unlock();
               log("released WL");
            }
            catch(InterruptedException e) {
  @@ -248,18 +254,18 @@
         public void run() {
            try {
               log("acquiring RL");
  -            rl.acquire();
  +            rl.lock();
               log("acquired RL");
               synchronized(this) {
                  this.wait();
               }
  -            log("attempting to acquire WL");
  -            // rl.release();
  -            wl.acquire();
  +            log("attempting to lock WL");
  +            // rl.unlock();
  +            wl.lock();
               upgradeSuccessful=true;
               log("acquired WL");
               log("releasing WL/RL");
  -            wl.release();
  +            wl.unlock();
               log("released WL/RL");
            }
            catch(InterruptedException e) {
  
  
  
  1.6       +1 -2      JBossCache/tests/functional/org/jboss/cache/lock/ReentrantWriterPreference2Readers1WriterLockTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ReentrantWriterPreference2Readers1WriterLockTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/lock/ReentrantWriterPreference2Readers1WriterLockTest.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -b -r1.5 -r1.6
  --- ReentrantWriterPreference2Readers1WriterLockTest.java	4 Dec 2006 12:33:40 -0000	1.5
  +++ ReentrantWriterPreference2Readers1WriterLockTest.java	8 Dec 2006 18:50:49 -0000	1.6
  @@ -13,11 +13,10 @@
   import java.util.concurrent.locks.ReentrantReadWriteLock;
   import java.util.concurrent.TimeUnit;
   
  -
   /**
    * Tests ReentrantWriterPreferenceReadWriteLock
    * @author Bela Ban
  - * @version $Id: ReentrantWriterPreference2Readers1WriterLockTest.java,v 1.5 2006/12/04 12:33:40 bela Exp $
  + * @version $Id: ReentrantWriterPreference2Readers1WriterLockTest.java,v 1.6 2006/12/08 18:50:49 genman Exp $
    */
   public class ReentrantWriterPreference2Readers1WriterLockTest extends TestCase {
      ReentrantReadWriteLock lock;
  
  
  
  1.3       +21 -20    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.3
  diff -u -b -r1.2 -r1.3
  --- ReadWriteLockWithUpgradeTest.java	5 May 2006 12:06:58 -0000	1.2
  +++ ReadWriteLockWithUpgradeTest.java	8 Dec 2006 18:50:49 -0000	1.3
  @@ -1,6 +1,5 @@
   package org.jboss.cache.lock;
   
  -import EDU.oswego.cs.dl.util.concurrent.Sync;
   import junit.framework.Test;
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
  @@ -10,6 +9,8 @@
   import java.io.IOException;
   import java.io.Writer;
   import java.util.Vector;
  +import java.util.concurrent.TimeUnit;
  +import java.util.concurrent.locks.Lock;
   
   /**
    * NonBlockingWriterLock is a read/write lock (with upgrade) that has
  @@ -150,9 +151,9 @@
         {
            public void run()
            {
  -               Sync rlock = lock_.readLock();
  +               Lock rlock = lock_.readLock();
               try {
  -               if (! rlock.attempt(msecs)) {
  +               if (! rlock.tryLock(msecs, TimeUnit.MILLISECONDS)) {
                     logX(caseNum+"-"+name+" requesting read lock failed!\n");
                     String str = caseNum + "-" + name + "-RL-0";
                     postLockingResult(str);
  @@ -171,7 +172,7 @@
                  else if (secondOP == INVOKE_UPGRADE)
                      acquireUpgradeLock(caseNum, name, msecs, errMsg);
                    
  -               rlock.release();
  +               rlock.unlock();
                  logX(caseNum+"-"+name+" releasing read lock.\n");
               } catch (Exception ex) {
               }
  @@ -194,8 +195,8 @@
            public void run()
            {
               try {
  -               Sync wlock = lock_.writeLock();
  -               if (! wlock.attempt(msecs)) {
  +               Lock wlock = lock_.writeLock();
  +               if (! wlock.tryLock(msecs, TimeUnit.MILLISECONDS)) {
                     logX(caseNum+"-"+name+" requesting write lock failed!\n");
                     String str = caseNum + "-" + name + "-WL-0";
                     postLockingResult(str);
  @@ -214,7 +215,7 @@
                  else if (secondOP == INVOKE_UPGRADE)
                      acquireUpgradeLock(caseNum, name, msecs, errMsg);
   
  -               wlock.release();
  +               wlock.unlock();
                  logX(caseNum+"-"+name+" releasing write lock.\n");
               } catch (Exception ex) {
               }
  @@ -237,9 +238,9 @@
            public void run()
            {
               try {
  -               Sync rlock = lock_.readLock();
  -               Sync wlock = null;
  -               if (! rlock.attempt(msecs)) {
  +               Lock rlock = lock_.readLock();
  +               Lock wlock = null;
  +               if (! rlock.tryLock(msecs, TimeUnit.MILLISECONDS)) {
                     logX(caseNum+"-"+name+" requesting read lock failed!\n");
                     String str = caseNum + "-" + name + "-RL-0";
                     postLockingResult(str);
  @@ -264,10 +265,10 @@
                  TestingUtil.sleepThread(SLEEP_MSECS);
                  if (wlock != null)
                  {
  -                 wlock.release();
  +                 wlock.unlock();
                    logX(caseNum+"-"+name+" releasing upgrade lock.\n");
                  }
  -               rlock.release();
  +               rlock.unlock();
               } catch (Exception ex) {
               }
            }
  @@ -288,8 +289,8 @@
                                     final long msecs, final String errMsg)
      {
               try {
  -               Sync rlock = lock_.readLock();
  -               if (! rlock.attempt(msecs)) {
  +               Lock rlock = lock_.readLock();
  +               if (! rlock.tryLock(msecs, TimeUnit.MILLISECONDS)) {
                     logX(caseNum+"-"+name+" requesting read lock failed!\n");
                     String str = caseNum + "-" + name + "-RL-0";
                     postLockingResult(str);
  @@ -300,7 +301,7 @@
                  String str = caseNum + "-" + name + "-RL-1";
                  postLockingResult(str);
                  TestingUtil.sleepThread(SLEEP_MSECS);
  -               rlock.release();
  +               rlock.unlock();
                  logX(caseNum+"-"+name+" releasing read lock.\n");
               } catch (Exception ex) {
               }
  @@ -314,8 +315,8 @@
                                      final long msecs, final String errMsg)
      {
               try {
  -               Sync wlock = lock_.writeLock();
  -               if (! wlock.attempt(msecs)) {
  +               Lock wlock = lock_.writeLock();
  +               if (! wlock.tryLock(msecs, TimeUnit.MILLISECONDS)) {
                     logX(caseNum+"-"+name+" requesting write lock failed!\n");
                     String str = caseNum + "-" + name + "-WL-0";
                     postLockingResult(str);
  @@ -326,7 +327,7 @@
                  String str = caseNum + "-" + name + "-WL-1";
                  postLockingResult(str);
                  TestingUtil.sleepThread(SLEEP_MSECS);
  -               wlock.release();
  +               wlock.unlock();
                  logX(caseNum+"-"+name+" releasing write lock.\n");
               } catch (Exception ex) {
               }
  @@ -340,7 +341,7 @@
                                        final long msecs, final String errMsg)
      {
               try {
  -               Sync ulock = null;
  +               Lock ulock = null;
                  if ((ulock = lock_.upgradeLockAttempt(msecs)) == null) {
                     logX(caseNum+"-"+name+" requesting upgrade lock failed!\n");
                     String str = caseNum + "-" + name + "-UL-0";
  @@ -352,7 +353,7 @@
                  String str = caseNum + "-" + name + "-UL-1";
                  postLockingResult(str);
                  TestingUtil.sleepThread(SLEEP_MSECS);
  -               ulock.release();
  +               ulock.unlock();
                  logX(caseNum+"-"+name+" releasing upgrade lock.\n");
               } catch (Exception ex) {
               }
  
  
  
  1.3       +21 -20    JBossCache/tests/functional/org/jboss/cache/lock/NonBlockingWriterLockTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: NonBlockingWriterLockTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/lock/NonBlockingWriterLockTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- NonBlockingWriterLockTest.java	5 May 2006 12:06:58 -0000	1.2
  +++ NonBlockingWriterLockTest.java	8 Dec 2006 18:50:49 -0000	1.3
  @@ -1,6 +1,7 @@
   package org.jboss.cache.lock;
   
  -import EDU.oswego.cs.dl.util.concurrent.Sync;
  +import java.util.concurrent.TimeUnit;
  +import java.util.concurrent.locks.Lock;
   import junit.framework.Test;
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
  @@ -150,9 +151,9 @@
         {
            public void run()
            {
  -               Sync rlock = lock_.readLock();
  +               Lock rlock = lock_.readLock();
               try {
  -               if (! rlock.attempt(msecs)) {
  +               if (! rlock.tryLock(msecs, TimeUnit.MILLISECONDS)) {
                     logX(caseNum+"-"+name+" requesting read lock failed!\n");
                     String str = caseNum + "-" + name + "-RL-0";
                     postLockingResult(str);
  @@ -171,7 +172,7 @@
                  else if (secondOP == INVOKE_UPGRADE)
                      acquireUpgradeLock(caseNum, name, msecs, errMsg);
                    
  -               rlock.release();
  +               rlock.unlock();
                  logX(caseNum+"-"+name+" releasing read lock.\n");
               } catch (Exception ex) {
               }
  @@ -194,8 +195,8 @@
            public void run()
            {
               try {
  -               Sync wlock = lock_.writeLock();
  -               if (! wlock.attempt(msecs)) {
  +               Lock wlock = lock_.writeLock();
  +               if (! wlock.tryLock(msecs, TimeUnit.MILLISECONDS)) {
                     logX(caseNum+"-"+name+" requesting write lock failed!\n");
                     String str = caseNum + "-" + name + "-WL-0";
                     postLockingResult(str);
  @@ -214,7 +215,7 @@
                  else if (secondOP == INVOKE_UPGRADE)
                      acquireUpgradeLock(caseNum, name, msecs, errMsg);
   
  -               wlock.release();
  +               wlock.unlock();
                  logX(caseNum+"-"+name+" releasing write lock.\n");
               } catch (Exception ex) {
               }
  @@ -237,9 +238,9 @@
            public void run()
            {
               try {
  -               Sync rlock = lock_.readLock();
  -               Sync wlock = null;
  -               if (! rlock.attempt(msecs)) {
  +               Lock rlock = lock_.readLock();
  +               Lock wlock = null;
  +               if (! rlock.tryLock(msecs, TimeUnit.MILLISECONDS)) {
                     logX(caseNum+"-"+name+" requesting read lock failed!\n");
                     String str = caseNum + "-" + name + "-RL-0";
                     postLockingResult(str);
  @@ -264,10 +265,10 @@
                  TestingUtil.sleepThread(SLEEP_MSECS);
                  if (wlock != null)
                  {
  -                 wlock.release();
  +                 wlock.unlock();
                    logX(caseNum+"-"+name+" releasing upgrade lock.\n");
                  }
  -               rlock.release();
  +               rlock.unlock();
               } catch (Exception ex) {
               }
            }
  @@ -288,8 +289,8 @@
                                     final long msecs, final String errMsg)
      {
               try {
  -               Sync rlock = lock_.readLock();
  -               if (! rlock.attempt(msecs)) {
  +               Lock rlock = lock_.readLock();
  +               if (! rlock.tryLock(msecs, TimeUnit.MILLISECONDS)) {
                     logX(caseNum+"-"+name+" requesting read lock failed!\n");
                     String str = caseNum + "-" + name + "-RL-0";
                     postLockingResult(str);
  @@ -300,7 +301,7 @@
                  String str = caseNum + "-" + name + "-RL-1";
                  postLockingResult(str);
                  TestingUtil.sleepThread(SLEEP_MSECS);
  -               rlock.release();
  +               rlock.unlock();
                  logX(caseNum+"-"+name+" releasing read lock.\n");
               } catch (Exception ex) {
               }
  @@ -314,8 +315,8 @@
                                      final long msecs, final String errMsg)
      {
               try {
  -               Sync wlock = lock_.writeLock();
  -               if (! wlock.attempt(msecs)) {
  +               Lock wlock = lock_.writeLock();
  +               if (! wlock.tryLock(msecs, TimeUnit.MILLISECONDS)) {
                     logX(caseNum+"-"+name+" requesting write lock failed!\n");
                     String str = caseNum + "-" + name + "-WL-0";
                     postLockingResult(str);
  @@ -326,7 +327,7 @@
                  String str = caseNum + "-" + name + "-WL-1";
                  postLockingResult(str);
                  TestingUtil.sleepThread(SLEEP_MSECS);
  -               wlock.release();
  +               wlock.unlock();
                  logX(caseNum+"-"+name+" releasing write lock.\n");
               } catch (Exception ex) {
               }
  @@ -340,7 +341,7 @@
                                        final long msecs, final String errMsg)
      {
               try {
  -               Sync ulock = null;
  +               Lock ulock = null;
                  if ((ulock = lock_.upgradeLockAttempt(msecs)) == null) {
                     logX(caseNum+"-"+name+" requesting upgrade lock failed!\n");
                     String str = caseNum + "-" + name + "-UL-0";
  @@ -352,7 +353,7 @@
                  String str = caseNum + "-" + name + "-UL-1";
                  postLockingResult(str);
                  TestingUtil.sleepThread(SLEEP_MSECS);
  -               ulock.release();
  +               ulock.unlock();
                  logX(caseNum+"-"+name+" releasing upgrade lock.\n");
               } catch (Exception ex) {
               }
  
  
  
  1.9       +47 -46    JBossCache/tests/functional/org/jboss/cache/lock/LockTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: LockTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/lock/LockTest.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -b -r1.8 -r1.9
  --- LockTest.java	5 May 2006 12:06:58 -0000	1.8
  +++ LockTest.java	8 Dec 2006 18:50:49 -0000	1.9
  @@ -1,8 +1,9 @@
   package org.jboss.cache.lock;
   
  -import EDU.oswego.cs.dl.util.concurrent.CyclicBarrier;
  -import EDU.oswego.cs.dl.util.concurrent.FIFOSemaphore;
  -import EDU.oswego.cs.dl.util.concurrent.Sync;
  +import java.util.concurrent.CyclicBarrier;
  +import java.util.concurrent.Semaphore;
  +import java.util.concurrent.TimeUnit;
  +import java.util.concurrent.locks.Lock;
   import junit.framework.Test;
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
  @@ -12,7 +13,7 @@
    * Various tests that test isolation level semantics provided by locks
    *
    * @author Bela Ban
  - * @version $Id: LockTest.java,v 1.8 2006/05/05 12:06:58 msurtani Exp $
  + * @version $Id: LockTest.java,v 1.9 2006/12/08 18:50:49 genman Exp $
    */
   public class LockTest extends TestCase {
      int  value=10;
  @@ -36,9 +37,9 @@
      }
   
   
  -   static class MyFIFOSemaphore extends FIFOSemaphore {
  -      public MyFIFOSemaphore(long l) {
  -         super(l);
  +   static class MyFIFOSemaphore extends Semaphore {
  +      public MyFIFOSemaphore(int permits) {
  +         super(permits);
         }
   
         public void acquire() throws InterruptedException {
  @@ -64,21 +65,21 @@
       */
      public void testReadUncommitted() throws Throwable {
         final LockStrategy s=new LockStrategyReadUncommitted();
  -      final FIFOSemaphore sem=new MyFIFOSemaphore(1);
  +      final Semaphore sem=new MyFIFOSemaphore(1);
         final CyclicBarrier barrier=new CyclicBarrier(2);
   
         Thread t1=new Thread("t1") {
  -         Sync lock=null;
  +         Lock lock=null;
   
            public void run() {
               try {
                  sem.acquire(); // we're first to the semaphore
   
                  // log("waiting on barrier");
  -               barrier.barrier(); // wait until t2 joins us
  +               barrier.await(); // wait until t2 joins us
                  // log("passed barrier");
                  lock=s.readLock();
  -               lock.attempt(TIMEOUT);
  +               lock.tryLock(TIMEOUT, TimeUnit.MILLISECONDS);
                  log("1st read: value is " + value);
                  assertEquals(10, value);
                  sem.release(); // give t2 time to make the modification
  @@ -99,7 +100,7 @@
               }
               finally {
                  if(lock != null)
  -                  lock.release();
  +                  lock.unlock();
                  sem.release();
               }
            }
  @@ -107,30 +108,30 @@
   
   
         Thread t2=new Thread("t2") {
  -         Sync lock=null;
  +         Lock lock=null;
   
            public void run() {
               try {
                  TestingUtil.sleepThread(100);
  -               barrier.barrier();
  +               barrier.await();
                  sem.acquire();
                  lock=s.writeLock();
  -               lock.attempt(TIMEOUT);
  +               lock.tryLock(TIMEOUT, TimeUnit.MILLISECONDS);
                  log("changing value from " + value + " to 20");
                  value=20;
                  sem.release(); // now t1 can read the uncommitted modification
                  TestingUtil.sleepThread(100);
   
  -               sem.acquire(); // to release the lock
  +               sem.acquire(); // to unlock the lock
                  log("committing the TX");
  -               lock.release();
  +               lock.unlock();
               }
               catch(Throwable ex) {
                  t2_ex=ex;
               }
               finally {
                  if(lock != null)
  -                  lock.release();
  +                  lock.unlock();
                  sem.release();
               }
            }
  @@ -192,7 +193,7 @@
                  t1_ex=ex;
               }
               finally {
  -               identity_lock.release(this);
  +               identity_lock.unlock(this);
               }
            }
         };
  @@ -209,13 +210,13 @@
                  TestingUtil.sleepThread(SLEEP * 2);
   
                  log("committing the TX");
  -               identity_lock.release(this);
  +               identity_lock.unlock(this);
               }
               catch(Throwable ex) {
                  t2_ex=ex;
               }
               finally {
  -               identity_lock.release(this);
  +               identity_lock.unlock(this);
               }
            }
         };
  @@ -236,13 +237,13 @@
          final LockStrategy s=new LockStrategyReadCommitted();
   
          Thread t1=new Thread("t1") {
  -          Sync lock=null;
  +          Lock lock=null;
   
             public void run() {
                try {
                   TestingUtil.sleepThread(100);
                   lock=s.readLock();
  -                lock.attempt(TIMEOUT);
  +                lock.tryLock(TIMEOUT, TimeUnit.MILLISECONDS);
                   log("1st read: value is " + value);
                   assertEquals(20, value);
                   TestingUtil.sleepThread(SLEEP);
  @@ -255,31 +256,31 @@
                   t1_ex=ex;
                }
                finally {
  -                lock.release();
  +                lock.unlock();
                }
             }
          };
   
   
          Thread t2=new Thread("t2") {
  -          Sync lock=null;
  +          Lock lock=null;
   
             public void run() {
                try {
                   lock=s.writeLock();
  -                lock.attempt(TIMEOUT);
  +                lock.tryLock(TIMEOUT, TimeUnit.MILLISECONDS);
                   log("changing value from " + value + " to 20");
                   value=20;
                   TestingUtil.sleepThread(SLEEP);
   
                   log("committing the TX");
  -                lock.release();
  +                lock.unlock();
                }
                catch(Throwable ex) {
                   t2_ex=ex;
                }
                finally {
  -                lock.release();
  +                lock.unlock();
                }
             }
          };
  @@ -318,12 +319,12 @@
         final LockStrategy s=new LockStrategyRepeatableRead();
   
         Thread t1=new Thread("t1") {
  -         Sync lock=null;
  +         Lock lock=null;
   
            public void run() {
               try {
                  lock=s.readLock();
  -               lock.attempt(TIMEOUT);
  +               lock.tryLock(TIMEOUT, TimeUnit.MILLISECONDS);
                  log("1st read: value is " + value);
                  assertEquals(10, value);
                  TestingUtil.sleepThread(SLEEP);
  @@ -334,10 +335,10 @@
   
                  log("3rd read: value is still " + value + "; we should not see t2's committed change");
                  assertEquals(10, value);
  -               lock.release();
  +               lock.unlock();
   
                  TestingUtil.sleepThread(SLEEP);
  -               lock.attempt(TIMEOUT);
  +               lock.tryLock(TIMEOUT, TimeUnit.MILLISECONDS);
                  log("4th read: value is now " + value + "; we should see t2's committed change in our new TX");
                  assertEquals(20, value);
               }
  @@ -345,32 +346,32 @@
                  t1_ex=ex;
               }
               finally {
  -               lock.release();
  +               lock.unlock();
               }
            }
         };
   
   
         Thread t2=new Thread("t2") {
  -         Sync lock=null;
  +         Lock lock=null;
   
            public void run() {
               try {
                  TestingUtil.sleepThread(100);
                  lock=s.writeLock();
  -               lock.attempt(TIMEOUT);
  +               lock.tryLock(TIMEOUT, TimeUnit.MILLISECONDS);
                  log("changing value from " + value + " to 20");
                  value=20;
                  TestingUtil.sleepThread(SLEEP);
   
                  log("committing the TX");
  -               lock.release();
  +               lock.unlock();
               }
               catch(Throwable ex) {
                  t2_ex=ex;
               }
               finally {
  -               lock.release();
  +               lock.unlock();
               }
            }
         };
  @@ -403,18 +404,18 @@
         final LockStrategy s=new LockStrategySerializable();
   
         Thread t1=new Thread("t1") {
  -         Sync lock=null;
  +         Lock lock=null;
   
            public void run() {
               try {
                  lock=s.readLock();
  -               lock.attempt(TIMEOUT);
  +               lock.tryLock(TIMEOUT, TimeUnit.MILLISECONDS);
                  log("1st read: value is " + value);
                  assertEquals(10, value);
  -               lock.release();
  +               lock.unlock();
                  TestingUtil.sleepThread(SLEEP);
   
  -               lock.attempt(TIMEOUT);
  +               lock.tryLock(TIMEOUT, TimeUnit.MILLISECONDS);
                  log("2nd read: value is " + value + "; we should see t2's committed change (20)");
                  assertEquals(20, value);
               }
  @@ -422,30 +423,30 @@
                  t1_ex=ex;
               }
               finally {
  -               lock.release();
  +               lock.unlock();
               }
            }
         };
   
   
         Thread t2=new Thread("t2") {
  -         Sync lock=null;
  +         Lock lock=null;
   
            public void run() {
               try {
                  TestingUtil.sleepThread(100);
                  lock=s.writeLock();
  -               lock.attempt(TIMEOUT);
  +               lock.tryLock(TIMEOUT, TimeUnit.MILLISECONDS);
                  log("changing value from " + value + " to 20");
                  value=20;
                  log("committing the TX");
  -               lock.release();
  +               lock.unlock();
               }
               catch(Throwable ex) {
                  t2_ex=ex;
               }
               finally {
  -               lock.release();
  +               lock.unlock();
               }
            }
         };
  
  
  



More information about the jboss-cvs-commits mailing list