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.32 by jsr166, Tue Nov 17 14:18:28 2009 UTC vs.
Revision 1.33 by jsr166, Tue Nov 17 14:33:55 2009 UTC

# Line 189 | Line 189 | public class ReentrantReadWriteLockTest
189       */
190      public void testWriteLockInterruptibly_Interrupted() throws Exception {
191          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
192 <        Thread t = new Thread(new Runnable() {
193 <                public void run() {
194 <                    try {
195 <                        lock.writeLock().lockInterruptibly();
196 <                        lock.writeLock().unlock();
197 <                        lock.writeLock().lockInterruptibly();
198 <                        lock.writeLock().unlock();
199 <                    } catch (InterruptedException success) {}
200 <                }
201 <            });
192 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
193 >            public void realRun() throws InterruptedException {
194 >                lock.writeLock().lockInterruptibly();
195 >                lock.writeLock().unlock();
196 >                lock.writeLock().lockInterruptibly();
197 >                lock.writeLock().unlock();
198 >            }});
199  
200          lock.writeLock().lock();
201          t.start();
# Line 215 | Line 212 | public class ReentrantReadWriteLockTest
212      public void testWriteTryLock_Interrupted() throws InterruptedException {
213          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
214          lock.writeLock().lock();
215 <        Thread t = new Thread(new Runnable() {
216 <                public void run() {
217 <                    try {
218 <                        lock.writeLock().tryLock(1000,TimeUnit.MILLISECONDS);
222 <                    } catch (InterruptedException success) {}
223 <                }
224 <            });
215 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
216 >            public void realRun() throws InterruptedException {
217 >                lock.writeLock().tryLock(1000,TimeUnit.MILLISECONDS);
218 >            }});
219  
220          t.start();
221          t.interrupt();
# Line 235 | Line 229 | public class ReentrantReadWriteLockTest
229      public void testReadLockInterruptibly_Interrupted() throws InterruptedException {
230          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
231          lock.writeLock().lock();
232 <        Thread t = new Thread(new Runnable() {
233 <                public void run() {
234 <                    try {
235 <                        lock.readLock().lockInterruptibly();
242 <                    } catch (InterruptedException success) {}
243 <                }
244 <            });
232 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
233 >            public void realRun() throws InterruptedException {
234 >                lock.readLock().lockInterruptibly();
235 >            }});
236  
237          t.start();
238          Thread.sleep(SHORT_DELAY_MS);
# Line 257 | Line 248 | public class ReentrantReadWriteLockTest
248      public void testReadTryLock_Interrupted() throws InterruptedException {
249          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
250          lock.writeLock().lock();
251 <        Thread t = new Thread(new Runnable() {
252 <                public void run() {
253 <                    try {
254 <                        lock.readLock().tryLock(1000,TimeUnit.MILLISECONDS);
264 <                        threadShouldThrow();
265 <                    } catch (InterruptedException success) {}
266 <                }
267 <            });
251 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
252 >            public void realRun() throws InterruptedException {
253 >                lock.readLock().tryLock(1000,TimeUnit.MILLISECONDS);
254 >            }});
255  
256          t.start();
257          t.interrupt();
# Line 699 | Line 686 | public class ReentrantReadWriteLockTest
686      public void testWriteTryLock_Timeout() throws InterruptedException {
687          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
688          lock.writeLock().lock();
689 <        Thread t = new Thread(new Runnable() {
690 <                public void run() {
691 <                    try {
692 <                        threadAssertFalse(lock.writeLock().tryLock(1, TimeUnit.MILLISECONDS));
706 <                    } catch (Exception ex) {
707 <                        threadUnexpectedException();
708 <                    }
709 <                }
710 <            });
689 >        Thread t = new Thread(new CheckedRunnable() {
690 >            public void realRun() throws InterruptedException {
691 >                threadAssertFalse(lock.writeLock().tryLock(1, TimeUnit.MILLISECONDS));
692 >            }});
693  
694          t.start();
695          t.join();
# Line 720 | Line 702 | public class ReentrantReadWriteLockTest
702      public void testReadTryLock_Timeout() throws InterruptedException {
703          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
704          lock.writeLock().lock();
705 <        Thread t = new Thread(new Runnable() {
706 <                public void run() {
707 <                    try {
708 <                        threadAssertFalse(lock.readLock().tryLock(1, TimeUnit.MILLISECONDS));
727 <                    } catch (Exception ex) {
728 <                        threadUnexpectedException();
729 <                    }
730 <                }
731 <            });
705 >        Thread t = new Thread(new CheckedRunnable() {
706 >            public void realRun() throws InterruptedException {
707 >                threadAssertFalse(lock.readLock().tryLock(1, TimeUnit.MILLISECONDS));
708 >            }});
709  
710          t.start();
711          t.join();
# Line 742 | Line 719 | public class ReentrantReadWriteLockTest
719      public void testWriteLockInterruptibly() throws InterruptedException {
720          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
721          lock.writeLock().lockInterruptibly();
722 <        Thread t = new Thread(new Runnable() {
723 <                public void run() {
724 <                    try {
725 <                        lock.writeLock().lockInterruptibly();
749 <                        threadShouldThrow();
750 <                    }
751 <                    catch (InterruptedException success) {
752 <                    }
753 <                }
754 <            });
722 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
723 >            public void realRun() throws InterruptedException {
724 >                lock.writeLock().lockInterruptibly();
725 >            }});
726  
727          t.start();
728          Thread.sleep(SHORT_DELAY_MS);
# Line 767 | Line 738 | public class ReentrantReadWriteLockTest
738      public void testReadLockInterruptibly() throws InterruptedException {
739          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
740          lock.writeLock().lockInterruptibly();
741 <        Thread t = new Thread(new Runnable() {
742 <                public void run() {
743 <                    try {
744 <                        lock.readLock().lockInterruptibly();
774 <                        threadShouldThrow();
775 <                    }
776 <                    catch (InterruptedException success) {
777 <                    }
778 <                }
779 <            });
741 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
742 >            public void realRun() throws InterruptedException {
743 >                lock.readLock().lockInterruptibly();
744 >            }});
745  
746          t.start();
747          Thread.sleep(SHORT_DELAY_MS);
# Line 850 | Line 815 | public class ReentrantReadWriteLockTest
815      public void testAwait() throws InterruptedException {
816          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
817          final Condition c = lock.writeLock().newCondition();
818 <        Thread t = new Thread(new Runnable() {
819 <                public void run() {
820 <                    try {
821 <                        lock.writeLock().lock();
822 <                        c.await();
823 <                        lock.writeLock().unlock();
859 <                    }
860 <                    catch (InterruptedException e) {
861 <                        threadUnexpectedException();
862 <                    }
863 <                }
864 <            });
818 >        Thread t = new Thread(new CheckedRunnable() {
819 >            public void realRun() throws InterruptedException {
820 >                lock.writeLock().lock();
821 >                c.await();
822 >                lock.writeLock().unlock();
823 >            }});
824  
825          t.start();
826          Thread.sleep(SHORT_DELAY_MS);
# Line 933 | Line 892 | public class ReentrantReadWriteLockTest
892      public void testAwait_Interrupt() throws InterruptedException {
893          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
894          final Condition c = lock.writeLock().newCondition();
895 <        Thread t = new Thread(new Runnable() {
896 <                public void run() {
897 <                    try {
898 <                        lock.writeLock().lock();
899 <                        c.await();
900 <                        lock.writeLock().unlock();
942 <                        threadShouldThrow();
943 <                    }
944 <                    catch (InterruptedException success) {
945 <                    }
946 <                }
947 <            });
895 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
896 >            public void realRun() throws InterruptedException {
897 >                lock.writeLock().lock();
898 >                c.await();
899 >                lock.writeLock().unlock();
900 >            }});
901  
902          t.start();
903          Thread.sleep(SHORT_DELAY_MS);
# Line 959 | Line 912 | public class ReentrantReadWriteLockTest
912      public void testAwaitNanos_Interrupt() throws InterruptedException {
913          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
914          final Condition c = lock.writeLock().newCondition();
915 <        Thread t = new Thread(new Runnable() {
916 <                public void run() {
917 <                    try {
918 <                        lock.writeLock().lock();
919 <                        c.awaitNanos(SHORT_DELAY_MS * 2 * 1000000);
920 <                        lock.writeLock().unlock();
968 <                        threadShouldThrow();
969 <                    }
970 <                    catch (InterruptedException success) {
971 <                    }
972 <                }
973 <            });
915 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
916 >            public void realRun() throws InterruptedException {
917 >                lock.writeLock().lock();
918 >                c.awaitNanos(SHORT_DELAY_MS * 2 * 1000000);
919 >                lock.writeLock().unlock();
920 >            }});
921  
922          t.start();
923          Thread.sleep(SHORT_DELAY_MS);
# Line 985 | Line 932 | public class ReentrantReadWriteLockTest
932      public void testAwaitUntil_Interrupt() throws InterruptedException {
933          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
934          final Condition c = lock.writeLock().newCondition();
935 <        Thread t = new Thread(new Runnable() {
936 <                public void run() {
937 <                    try {
938 <                        lock.writeLock().lock();
939 <                        java.util.Date d = new java.util.Date();
940 <                        c.awaitUntil(new java.util.Date(d.getTime() + 10000));
941 <                        lock.writeLock().unlock();
995 <                        threadShouldThrow();
996 <                    }
997 <                    catch (InterruptedException success) {
998 <                    }
999 <                }
1000 <            });
935 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
936 >            public void realRun() throws InterruptedException {
937 >                lock.writeLock().lock();
938 >                java.util.Date d = new java.util.Date();
939 >                c.awaitUntil(new java.util.Date(d.getTime() + 10000));
940 >                lock.writeLock().unlock();
941 >            }});
942  
943          t.start();
944          Thread.sleep(SHORT_DELAY_MS);
# Line 1012 | Line 953 | public class ReentrantReadWriteLockTest
953      public void testSignalAll() throws InterruptedException {
954          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
955          final Condition c = lock.writeLock().newCondition();
956 <        Thread t1 = new Thread(new Runnable() {
957 <                public void run() {
958 <                    try {
959 <                        lock.writeLock().lock();
960 <                        c.await();
961 <                        lock.writeLock().unlock();
962 <                    }
963 <                    catch (InterruptedException e) {
964 <                        threadUnexpectedException();
965 <                    }
966 <                }
967 <            });
968 <
1028 <        Thread t2 = new Thread(new Runnable() {
1029 <                public void run() {
1030 <                    try {
1031 <                        lock.writeLock().lock();
1032 <                        c.await();
1033 <                        lock.writeLock().unlock();
1034 <                    }
1035 <                    catch (InterruptedException e) {
1036 <                        threadUnexpectedException();
1037 <                    }
1038 <                }
1039 <            });
956 >        Thread t1 = new Thread(new CheckedRunnable() {
957 >            public void realRun() throws InterruptedException {
958 >                lock.writeLock().lock();
959 >                c.await();
960 >                lock.writeLock().unlock();
961 >            }});
962 >
963 >        Thread t2 = new Thread(new CheckedRunnable() {
964 >            public void realRun() throws InterruptedException {
965 >                lock.writeLock().lock();
966 >                c.await();
967 >                lock.writeLock().unlock();
968 >            }});
969  
970          t1.start();
971          t2.start();
# Line 1103 | Line 1032 | public class ReentrantReadWriteLockTest
1032          try {
1033              sync.hasQueuedThread(null);
1034              shouldThrow();
1035 <        } catch (NullPointerException success) {
1107 <        }
1035 >        } catch (NullPointerException success) {}
1036      }
1037  
1038      /**
# Line 1309 | Line 1237 | public class ReentrantReadWriteLockTest
1237      public void testHasWaiters() throws InterruptedException {
1238          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
1239          final Condition c = lock.writeLock().newCondition();
1240 <        Thread t = new Thread(new Runnable() {
1241 <                public void run() {
1242 <                    try {
1243 <                        lock.writeLock().lock();
1244 <                        threadAssertFalse(lock.hasWaiters(c));
1245 <                        threadAssertEquals(0, lock.getWaitQueueLength(c));
1246 <                        c.await();
1247 <                        lock.writeLock().unlock();
1320 <                    }
1321 <                    catch (InterruptedException e) {
1322 <                        threadUnexpectedException();
1323 <                    }
1324 <                }
1325 <            });
1240 >        Thread t = new Thread(new CheckedRunnable() {
1241 >            public void realRun() throws InterruptedException {
1242 >                lock.writeLock().lock();
1243 >                threadAssertFalse(lock.hasWaiters(c));
1244 >                threadAssertEquals(0, lock.getWaitQueueLength(c));
1245 >                c.await();
1246 >                lock.writeLock().unlock();
1247 >            }});
1248  
1249          t.start();
1250          Thread.sleep(SHORT_DELAY_MS);
# Line 1346 | Line 1268 | public class ReentrantReadWriteLockTest
1268      public void testGetWaitQueueLength() throws InterruptedException {
1269          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
1270          final Condition c = lock.writeLock().newCondition();
1271 <        Thread t = new Thread(new Runnable() {
1272 <                public void run() {
1273 <                    try {
1274 <                        lock.writeLock().lock();
1275 <                        threadAssertFalse(lock.hasWaiters(c));
1276 <                        threadAssertEquals(0, lock.getWaitQueueLength(c));
1277 <                        c.await();
1278 <                        lock.writeLock().unlock();
1357 <                    }
1358 <                    catch (InterruptedException e) {
1359 <                        threadUnexpectedException();
1360 <                    }
1361 <                }
1362 <            });
1271 >        Thread t = new Thread(new CheckedRunnable() {
1272 >            public void realRun() throws InterruptedException {
1273 >                lock.writeLock().lock();
1274 >                threadAssertFalse(lock.hasWaiters(c));
1275 >                threadAssertEquals(0, lock.getWaitQueueLength(c));
1276 >                c.await();
1277 >                lock.writeLock().unlock();
1278 >            }});
1279  
1280          t.start();
1281          Thread.sleep(SHORT_DELAY_MS);
# Line 1384 | Line 1300 | public class ReentrantReadWriteLockTest
1300      public void testGetWaitingThreads() throws InterruptedException {
1301          final PublicReentrantReadWriteLock lock = new PublicReentrantReadWriteLock();
1302          final Condition c = lock.writeLock().newCondition();
1303 <        Thread t1 = new Thread(new Runnable() {
1304 <                public void run() {
1305 <                    try {
1306 <                        lock.writeLock().lock();
1307 <                        threadAssertTrue(lock.getWaitingThreads(c).isEmpty());
1308 <                        c.await();
1309 <                        lock.writeLock().unlock();
1310 <                    }
1311 <                    catch (InterruptedException e) {
1312 <                        threadUnexpectedException();
1313 <                    }
1314 <                }
1315 <            });
1316 <
1317 <        Thread t2 = new Thread(new Runnable() {
1402 <                public void run() {
1403 <                    try {
1404 <                        lock.writeLock().lock();
1405 <                        threadAssertFalse(lock.getWaitingThreads(c).isEmpty());
1406 <                        c.await();
1407 <                        lock.writeLock().unlock();
1408 <                    }
1409 <                    catch (InterruptedException e) {
1410 <                        threadUnexpectedException();
1411 <                    }
1412 <                }
1413 <            });
1303 >        Thread t1 = new Thread(new CheckedRunnable() {
1304 >            public void realRun() throws InterruptedException {
1305 >                lock.writeLock().lock();
1306 >                threadAssertTrue(lock.getWaitingThreads(c).isEmpty());
1307 >                c.await();
1308 >                lock.writeLock().unlock();
1309 >            }});
1310 >
1311 >        Thread t2 = new Thread(new CheckedRunnable() {
1312 >            public void realRun() throws InterruptedException {
1313 >                lock.writeLock().lock();
1314 >                threadAssertFalse(lock.getWaitingThreads(c).isEmpty());
1315 >                c.await();
1316 >                lock.writeLock().unlock();
1317 >            }});
1318  
1319          lock.writeLock().lock();
1320          assertTrue(lock.getWaitingThreads(c).isEmpty());

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines