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.26 by dl, Fri Feb 24 00:03:16 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 184 | Line 203 | public class ReentrantReadWriteLockTest
203          try {
204              lock.writeLock().lock();
205              t.start();
206 +            Thread.sleep(SHORT_DELAY_MS);
207              t.interrupt();
208              lock.writeLock().unlock();
209              t.join();
# Line 230 | Line 250 | public class ReentrantReadWriteLockTest
250              });
251          try {
252              t.start();
253 +            Thread.sleep(SHORT_DELAY_MS);
254              t.interrupt();
255              lock.writeLock().unlock();
256              t.join();
# Line 698 | Line 719 | public class ReentrantReadWriteLockTest
719          }
720      }
721  
722 +
723 +    /**
724 +     * Fair Read tryLock succeeds if readlocked but not writelocked
725 +     */
726 +    public void testTryLockWhenReadLockedFair() {
727 +        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
728 +        lock.readLock().lock();
729 +        Thread t = new Thread(new Runnable() {
730 +                public void run() {
731 +                    threadAssertTrue(lock.readLock().tryLock());
732 +                    lock.readLock().unlock();
733 +                }
734 +            });
735 +        try {
736 +            t.start();
737 +            t.join();
738 +            lock.readLock().unlock();
739 +        } catch(Exception e){
740 +            unexpectedException();
741 +        }
742 +    }
743 +
744 +    
745 +
746 +    /**
747 +     * Fair write tryLock fails when readlocked
748 +     */
749 +    public void testWriteTryLockWhenReadLockedFair() {
750 +        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
751 +        lock.readLock().lock();
752 +        Thread t = new Thread(new Runnable() {
753 +                public void run() {
754 +                    threadAssertFalse(lock.writeLock().tryLock());
755 +                }
756 +            });
757 +        try {
758 +            t.start();
759 +            t.join();
760 +            lock.readLock().unlock();
761 +        } catch(Exception e){
762 +            unexpectedException();
763 +        }
764 +    }
765 +
766      
767  
768      /**
# Line 771 | Line 836 | public class ReentrantReadWriteLockTest
836              });
837          try {
838              t.start();
839 +            Thread.sleep(SHORT_DELAY_MS);
840              t.interrupt();
841              t.join();
842              lock.writeLock().unlock();
# Line 801 | Line 867 | public class ReentrantReadWriteLockTest
867              });
868          try {
869              t.start();
870 +            Thread.sleep(SHORT_DELAY_MS);
871              t.interrupt();
872              t.join();
873              lock.writeLock().unlock();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines