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.24 by dl, Tue Aug 2 11:34:04 2005 UTC vs.
Revision 1.27 by dl, Thu May 18 10:29:23 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 +            Thread.sleep(SHORT_DELAY_MS);
209              lock.writeLock().unlock();
210              t.join();
211          } catch(Exception e){
# Line 230 | Line 251 | public class ReentrantReadWriteLockTest
251              });
252          try {
253              t.start();
254 +            Thread.sleep(SHORT_DELAY_MS);
255              t.interrupt();
256 +            Thread.sleep(SHORT_DELAY_MS);
257              lock.writeLock().unlock();
258              t.join();
259          } catch(Exception e){
# Line 815 | Line 838 | public class ReentrantReadWriteLockTest
838              });
839          try {
840              t.start();
841 +            Thread.sleep(SHORT_DELAY_MS);
842              t.interrupt();
843 +            Thread.sleep(SHORT_DELAY_MS);
844              t.join();
845              lock.writeLock().unlock();
846          } catch(Exception e){
# Line 845 | Line 870 | public class ReentrantReadWriteLockTest
870              });
871          try {
872              t.start();
873 +            Thread.sleep(SHORT_DELAY_MS);
874              t.interrupt();
875              t.join();
876              lock.writeLock().unlock();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines