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.13 by dl, Sun Dec 28 21:56:18 2003 UTC vs.
Revision 1.18 by dl, Sat Jan 10 01:41:59 2004 UTC

# Line 156 | Line 156 | public class ReentrantReadWriteLockTest
156       */
157      public void testWriteLockInterruptibly_Interrupted() {
158          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
159        lock.writeLock().lock();
159          Thread t = new Thread(new Runnable() {
160                  public void run() {
161                      try {
162                          lock.writeLock().lockInterruptibly();
163 <                        threadShouldThrow();
163 >                        lock.writeLock().unlock();
164 >                        lock.writeLock().lockInterruptibly();
165 >                        lock.writeLock().unlock();
166                      } catch(InterruptedException success){}
167                  }
168              });
169          try {
170 +            lock.writeLock().lock();
171              t.start();
172              t.interrupt();
173              lock.writeLock().unlock();
# Line 176 | Line 178 | public class ReentrantReadWriteLockTest
178      }
179  
180      /**
181 <     * timed write-trylock is interruptible
181 >     * timed write-tryLock is interruptible
182       */
183      public void testWriteTryLock_Interrupted() {
184          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
# Line 185 | Line 187 | public class ReentrantReadWriteLockTest
187                  public void run() {
188                      try {
189                          lock.writeLock().tryLock(1000,TimeUnit.MILLISECONDS);
188                        threadShouldThrow();
190                      } catch(InterruptedException success){}
191                  }
192              });
# Line 209 | Line 210 | public class ReentrantReadWriteLockTest
210                  public void run() {
211                      try {
212                          lock.readLock().lockInterruptibly();
212                        threadShouldThrow();
213                      } catch(InterruptedException success){}
214                  }
215              });
# Line 224 | Line 224 | public class ReentrantReadWriteLockTest
224      }
225  
226      /**
227 <     * timed read-trylock is interruptible
227 >     * timed read-tryLock is interruptible
228       */
229      public void testReadTryLock_Interrupted() {
230          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
# Line 248 | Line 248 | public class ReentrantReadWriteLockTest
248  
249      
250      /**
251 <     * write-trylock fails if locked
251 >     * write-tryLock fails if locked
252       */
253      public void testWriteTryLockWhenLocked() {
254          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
# Line 268 | Line 268 | public class ReentrantReadWriteLockTest
268      }
269  
270      /**
271 <     * read-trylock fails if locked
271 >     * read-tryLock fails if locked
272       */
273      public void testReadTryLockWhenLocked() {
274          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
# Line 378 | Line 378 | public class ReentrantReadWriteLockTest
378  
379  
380      /**
381 <     * Read trylock succeeds if readlocked but not writelocked
381 >     * Read tryLock succeeds if readlocked but not writelocked
382       */
383      public void testTryLockWhenReadLocked() {
384          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
# Line 401 | Line 401 | public class ReentrantReadWriteLockTest
401      
402  
403      /**
404 <     * write trylock fails when readlocked
404 >     * write tryLock fails when readlocked
405       */
406      public void testWriteTryLockWhenReadLocked() {
407          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
# Line 423 | Line 423 | public class ReentrantReadWriteLockTest
423      
424  
425      /**
426 <     * write timed trylock times out if locked
426 >     * write timed tryLock times out if locked
427       */
428      public void testWriteTryLock_Timeout() {
429          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
# Line 447 | Line 447 | public class ReentrantReadWriteLockTest
447      }
448  
449      /**
450 <     * read timed trylock times out if write-locked
450 >     * read timed tryLock times out if write-locked
451       */
452      public void testReadTryLock_Timeout() {
453          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
# Line 938 | Line 938 | public class ReentrantReadWriteLockTest
938      }
939  
940      /**
941 +     * hasWaiters throws NPE if null
942 +     */
943 +    public void testHasWaitersNPE() {
944 +        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
945 +        try {
946 +            lock.hasWaiters(null);
947 +            shouldThrow();
948 +        } catch (NullPointerException success) {
949 +        } catch (Exception ex) {
950 +            unexpectedException();
951 +        }
952 +    }
953 +
954 +    /**
955 +     * getWaitQueueLength throws NPE if null
956 +     */
957 +    public void testGetWaitQueueLengthNPE() {
958 +        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
959 +        try {
960 +            lock.getWaitQueueLength(null);
961 +            shouldThrow();
962 +        } catch (NullPointerException success) {
963 +        } catch (Exception ex) {
964 +            unexpectedException();
965 +        }
966 +    }
967 +
968 +
969 +    /**
970 +     * getWaitingThreads throws NPE if null
971 +     */
972 +    public void testGetWaitingThreadsNPE() {
973 +        final PublicReentrantReadWriteLock lock = new PublicReentrantReadWriteLock();
974 +        try {
975 +            lock.getWaitingThreads(null);
976 +            shouldThrow();
977 +        } catch (NullPointerException success) {
978 +        } catch (Exception ex) {
979 +            unexpectedException();
980 +        }
981 +    }
982 +
983 +    /**
984       * hasWaiters throws IAE if not owned
985       */
986      public void testHasWaitersIAE() {
# Line 1181 | Line 1224 | public class ReentrantReadWriteLockTest
1224          }
1225      }
1226  
1227 +    /**
1228 +     * toString indicates current lock state
1229 +     */
1230 +    public void testToString() {
1231 +        ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
1232 +        String us = lock.toString();
1233 +        assertTrue(us.indexOf("Write locks = 0") >= 0);
1234 +        assertTrue(us.indexOf("Read locks = 0") >= 0);
1235 +        lock.writeLock().lock();
1236 +        String ws = lock.toString();
1237 +        assertTrue(ws.indexOf("Write locks = 1") >= 0);
1238 +        assertTrue(ws.indexOf("Read locks = 0") >= 0);
1239 +        lock.writeLock().unlock();
1240 +        lock.readLock().lock();
1241 +        lock.readLock().lock();
1242 +        String rs = lock.toString();
1243 +        assertTrue(rs.indexOf("Write locks = 0") >= 0);
1244 +        assertTrue(rs.indexOf("Read locks = 2") >= 0);
1245 +    }
1246 +
1247 +    /**
1248 +     * readLock.toString indicates current lock state
1249 +     */
1250 +    public void testReadLockToString() {
1251 +        ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
1252 +        String us = lock.readLock().toString();
1253 +        assertTrue(us.indexOf("Read locks = 0") >= 0);
1254 +        lock.readLock().lock();
1255 +        lock.readLock().lock();
1256 +        String rs = lock.readLock().toString();
1257 +        assertTrue(rs.indexOf("Read locks = 2") >= 0);
1258 +    }
1259 +
1260 +    /**
1261 +     * writeLock.toString indicates current lock state
1262 +     */
1263 +    public void testWriteLockToString() {
1264 +        ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
1265 +        String us = lock.writeLock().toString();
1266 +        assertTrue(us.indexOf("Unlocked") >= 0);
1267 +        lock.writeLock().lock();
1268 +        String ls = lock.writeLock().toString();
1269 +        assertTrue(ls.indexOf("Locked") >= 0);
1270 +    }
1271 +
1272   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines