ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ReentrantReadWriteLockTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ReentrantReadWriteLockTest.java (file contents):
Revision 1.23 by dl, Mon Aug 1 19:53:01 2005 UTC vs.
Revision 1.25 by dl, Sun Jan 29 21:17:38 2006 UTC

# Line 84 | Line 84 | public class ReentrantReadWriteLockTest
84          rl.writeLock().lock();
85          assertTrue(rl.isWriteLocked());
86          assertTrue(rl.isWriteLockedByCurrentThread());
87 +        assertTrue(rl.writeLock().isHeldByCurrentThread());
88          assertEquals(0, rl.getReadLockCount());
89          rl.writeLock().unlock();
90          assertFalse(rl.isWriteLocked());
91          assertFalse(rl.isWriteLockedByCurrentThread());
92 +        assertFalse(rl.writeLock().isHeldByCurrentThread());
93          assertEquals(0, rl.getReadLockCount());
94          rl.readLock().lock();
95          assertFalse(rl.isWriteLocked());
# Line 108 | Line 110 | public class ReentrantReadWriteLockTest
110          rl.writeLock().lock();
111          assertTrue(rl.isWriteLocked());
112          assertTrue(rl.isWriteLockedByCurrentThread());
113 +        assertTrue(rl.writeLock().isHeldByCurrentThread());
114          assertEquals(0, rl.getReadLockCount());
115          rl.writeLock().unlock();
116          assertFalse(rl.isWriteLocked());
117          assertFalse(rl.isWriteLockedByCurrentThread());
118 +        assertFalse(rl.writeLock().isHeldByCurrentThread());
119          assertEquals(0, rl.getReadLockCount());
120          rl.readLock().lock();
121          assertFalse(rl.isWriteLocked());
# Line 139 | Line 143 | public class ReentrantReadWriteLockTest
143      }
144  
145      /**
146 +     * WriteLock.getHoldCount returns number of recursive holds
147 +     */
148 +    public void testGetHoldCount() {
149 +        ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
150 +        for(int i = 1; i <= SIZE; i++) {
151 +            lock.writeLock().lock();
152 +            assertEquals(i,lock.writeLock().getHoldCount());
153 +        }
154 +        for(int i = SIZE; i > 0; i--) {
155 +            lock.writeLock().unlock();
156 +            assertEquals(i-1,lock.writeLock().getHoldCount());
157 +        }
158 +    }
159 +
160 +    /**
161       * getReadHoldCount returns number of recursive holds
162       */
163      public void testGetReadHoldCount() {
# Line 686 | Line 705 | public class ReentrantReadWriteLockTest
705          lock.readLock().lock();
706          Thread t = new Thread(new Runnable() {
707                  public void run() {
708 +                    threadAssertFalse(lock.writeLock().tryLock());
709 +                }
710 +            });
711 +        try {
712 +            t.start();
713 +            t.join();
714 +            lock.readLock().unlock();
715 +        } catch(Exception e){
716 +            unexpectedException();
717 +        }
718 +    }
719 +
720 +
721 +    /**
722 +     * Fair Read tryLock succeeds if readlocked but not writelocked
723 +     */
724 +    public void testTryLockWhenReadLockedFair() {
725 +        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
726 +        lock.readLock().lock();
727 +        Thread t = new Thread(new Runnable() {
728 +                public void run() {
729 +                    threadAssertTrue(lock.readLock().tryLock());
730 +                    lock.readLock().unlock();
731 +                }
732 +            });
733 +        try {
734 +            t.start();
735 +            t.join();
736 +            lock.readLock().unlock();
737 +        } catch(Exception e){
738 +            unexpectedException();
739 +        }
740 +    }
741 +
742 +    
743 +
744 +    /**
745 +     * Fair write tryLock fails when readlocked
746 +     */
747 +    public void testWriteTryLockWhenReadLockedFair() {
748 +        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
749 +        lock.readLock().lock();
750 +        Thread t = new Thread(new Runnable() {
751 +                public void run() {
752                      threadAssertFalse(lock.writeLock().tryLock());
753                  }
754              });

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines