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

Comparing jsr166/src/test/tck/AbstractQueuedLongSynchronizerTest.java (file contents):
Revision 1.9 by jsr166, Wed Nov 18 08:22:57 2009 UTC vs.
Revision 1.10 by jsr166, Wed Nov 18 16:04:34 2009 UTC

# Line 68 | Line 68 | public class AbstractQueuedLongSynchroni
68      }
69  
70      /**
71 <     * A runnable calling acquireInterruptibly
71 >     * A runnable calling acquireInterruptibly that does not expect to
72 >     * be interrupted.
73       */
74 <    class InterruptibleSyncRunnable implements Runnable {
74 >    class InterruptibleSyncRunnable extends CheckedRunnable {
75          final Mutex sync;
76          InterruptibleSyncRunnable(Mutex l) { sync = l; }
77 <        public void run() {
78 <            try {
78 <                sync.acquireInterruptibly(1);
79 <            } catch (InterruptedException success) {}
77 >        public void realRun() throws InterruptedException {
78 >            sync.acquireInterruptibly(1);
79          }
80      }
81  
82  
83      /**
84       * A runnable calling acquireInterruptibly that expects to be
85 <     * interrupted
85 >     * interrupted.
86       */
87 <    class InterruptedSyncRunnable implements Runnable {
87 >    class InterruptedSyncRunnable extends CheckedInterruptedRunnable {
88          final Mutex sync;
89          InterruptedSyncRunnable(Mutex l) { sync = l; }
90 <        public void run() {
91 <            try {
93 <                sync.acquireInterruptibly(1);
94 <                threadShouldThrow();
95 <            } catch (InterruptedException success) {}
90 >        public void realRun() throws InterruptedException {
91 >            sync.acquireInterruptibly(1);
92          }
93      }
94  
# Line 331 | Line 327 | public class AbstractQueuedLongSynchroni
327      public void testInterruptedException2() throws InterruptedException {
328          final Mutex sync = new Mutex();
329          sync.acquire(1);
330 <        Thread t = new Thread(new Runnable() {
331 <                public void run() {
332 <                    try {
333 <                        sync.tryAcquireNanos(1, MEDIUM_DELAY_MS * 1000 * 1000);
338 <                        threadShouldThrow();
339 <                    } catch (InterruptedException success) {}
340 <                }
341 <            });
330 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
331 >            public void realRun() throws InterruptedException {
332 >                sync.tryAcquireNanos(1, MEDIUM_DELAY_MS * 1000 * 1000);
333 >            }});
334  
335          t.start();
336          t.interrupt();
# Line 352 | Line 344 | public class AbstractQueuedLongSynchroni
344      public void testTryAcquireWhenSynced() throws InterruptedException {
345          final Mutex sync = new Mutex();
346          sync.acquire(1);
347 <        Thread t = new Thread(new Runnable() {
348 <                public void run() {
349 <                    threadAssertFalse(sync.tryAcquire(1));
350 <                }
359 <            });
347 >        Thread t = new Thread(new CheckedRunnable() {
348 >            public void realRun() {
349 >                threadAssertFalse(sync.tryAcquire(1));
350 >            }});
351  
352          t.start();
353          t.join();
# Line 369 | Line 360 | public class AbstractQueuedLongSynchroni
360      public void testAcquireNanos_Timeout() throws InterruptedException {
361          final Mutex sync = new Mutex();
362          sync.acquire(1);
363 <        Thread t = new Thread(new Runnable() {
364 <                public void run() {
365 <                    try {
366 <                        threadAssertFalse(sync.tryAcquireNanos(1, 1000 * 1000));
376 <                    } catch (Exception ex) {
377 <                        threadUnexpectedException(ex);
378 <                    }
379 <                }
380 <            });
363 >        Thread t = new Thread(new CheckedRunnable() {
364 >            public void realRun() throws InterruptedException {
365 >                threadAssertFalse(sync.tryAcquireNanos(1, 1000 * 1000));
366 >            }});
367  
368          t.start();
369          t.join();
# Line 394 | Line 380 | public class AbstractQueuedLongSynchroni
380          assertTrue(sync.isHeldExclusively());
381          sync.release(1);
382          assertFalse(sync.isHeldExclusively());
383 <        Thread t = new Thread(new Runnable() {
384 <                public void run() {
385 <                    sync.acquire(1);
386 <                    try {
387 <                        Thread.sleep(SMALL_DELAY_MS);
388 <                    }
403 <                    catch (Exception e) {
404 <                        threadUnexpectedException(e);
405 <                    }
406 <                    sync.release(1);
407 <                }
408 <            });
383 >        Thread t = new Thread(new CheckedRunnable() {
384 >            public void realRun() throws InterruptedException {
385 >                sync.acquire(1);
386 >                Thread.sleep(SMALL_DELAY_MS);
387 >                sync.release(1);
388 >            }});
389  
390          t.start();
391          Thread.sleep(SHORT_DELAY_MS);
# Line 463 | Line 443 | public class AbstractQueuedLongSynchroni
443          try {
444              c.await();
445              shouldThrow();
446 <        }
467 <        catch (IllegalMonitorStateException success) {
468 <        }
446 >        } catch (IllegalMonitorStateException success) {}
447      }
448  
449      /**
# Line 477 | Line 455 | public class AbstractQueuedLongSynchroni
455          try {
456              c.signal();
457              shouldThrow();
458 <        }
481 <        catch (IllegalMonitorStateException success) {}
458 >        } catch (IllegalMonitorStateException success) {}
459      }
460  
461      /**
# Line 522 | Line 499 | public class AbstractQueuedLongSynchroni
499      public void testAwait() throws InterruptedException {
500          final Mutex sync = new Mutex();
501          final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition();
502 <        Thread t = new Thread(new Runnable() {
503 <                public void run() {
504 <                    try {
505 <                        sync.acquire(1);
506 <                        c.await();
507 <                        sync.release(1);
531 <                    }
532 <                    catch (InterruptedException e) {
533 <                        threadUnexpectedException(e);
534 <                    }
535 <                }
536 <            });
502 >        Thread t = new Thread(new CheckedRunnable() {
503 >            public void realRun() throws InterruptedException {
504 >                sync.acquire(1);
505 >                c.await();
506 >                sync.release(1);
507 >            }});
508  
509          t.start();
510          Thread.sleep(SHORT_DELAY_MS);
# Line 666 | Line 637 | public class AbstractQueuedLongSynchroni
637      public void testHasWaiters() throws InterruptedException {
638          final Mutex sync = new Mutex();
639          final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition();
640 <        Thread t = new Thread(new Runnable() {
641 <                public void run() {
642 <                    try {
643 <                        sync.acquire(1);
644 <                        threadAssertFalse(sync.hasWaiters(c));
645 <                        threadAssertEquals(0, sync.getWaitQueueLength(c));
646 <                        c.await();
647 <                        sync.release(1);
677 <                    }
678 <                    catch (InterruptedException e) {
679 <                        threadUnexpectedException(e);
680 <                    }
681 <                }
682 <            });
640 >        Thread t = new Thread(new CheckedRunnable() {
641 >            public void realRun() throws InterruptedException {
642 >                sync.acquire(1);
643 >                threadAssertFalse(sync.hasWaiters(c));
644 >                threadAssertEquals(0, sync.getWaitQueueLength(c));
645 >                c.await();
646 >                sync.release(1);
647 >            }});
648  
649          t.start();
650          Thread.sleep(SHORT_DELAY_MS);
# Line 703 | Line 668 | public class AbstractQueuedLongSynchroni
668      public void testGetWaitQueueLength() throws InterruptedException {
669          final Mutex sync = new Mutex();
670          final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition();
671 <        Thread t1 = new Thread(new Runnable() {
672 <                public void run() {
673 <                    try {
674 <                        sync.acquire(1);
675 <                        threadAssertFalse(sync.hasWaiters(c));
676 <                        threadAssertEquals(0, sync.getWaitQueueLength(c));
677 <                        c.await();
678 <                        sync.release(1);
679 <                    }
680 <                    catch (InterruptedException e) {
681 <                        threadUnexpectedException(e);
682 <                    }
683 <                }
684 <            });
685 <
686 <        Thread t2 = new Thread(new Runnable() {
687 <                public void run() {
723 <                    try {
724 <                        sync.acquire(1);
725 <                        threadAssertTrue(sync.hasWaiters(c));
726 <                        threadAssertEquals(1, sync.getWaitQueueLength(c));
727 <                        c.await();
728 <                        sync.release(1);
729 <                    }
730 <                    catch (InterruptedException e) {
731 <                        threadUnexpectedException(e);
732 <                    }
733 <                }
734 <            });
671 >        Thread t1 = new Thread(new CheckedRunnable() {
672 >            public void realRun() throws InterruptedException {
673 >                sync.acquire(1);
674 >                threadAssertFalse(sync.hasWaiters(c));
675 >                threadAssertEquals(0, sync.getWaitQueueLength(c));
676 >                c.await();
677 >                sync.release(1);
678 >            }});
679 >
680 >        Thread t2 = new Thread(new CheckedRunnable() {
681 >            public void realRun() throws InterruptedException {
682 >                sync.acquire(1);
683 >                threadAssertTrue(sync.hasWaiters(c));
684 >                threadAssertEquals(1, sync.getWaitQueueLength(c));
685 >                c.await();
686 >                sync.release(1);
687 >            }});
688  
689          t1.start();
690          Thread.sleep(SHORT_DELAY_MS);
# Line 759 | Line 712 | public class AbstractQueuedLongSynchroni
712      public void testGetWaitingThreads() throws InterruptedException {
713          final Mutex sync = new Mutex();
714          final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition();
715 <        Thread t1 = new Thread(new Runnable() {
716 <                public void run() {
717 <                    try {
718 <                        sync.acquire(1);
719 <                        threadAssertTrue(sync.getWaitingThreads(c).isEmpty());
720 <                        c.await();
721 <                        sync.release(1);
722 <                    }
723 <                    catch (InterruptedException e) {
724 <                        threadUnexpectedException(e);
725 <                    }
726 <                }
727 <            });
728 <
729 <        Thread t2 = new Thread(new Runnable() {
777 <                public void run() {
778 <                    try {
779 <                        sync.acquire(1);
780 <                        threadAssertFalse(sync.getWaitingThreads(c).isEmpty());
781 <                        c.await();
782 <                        sync.release(1);
783 <                    }
784 <                    catch (InterruptedException e) {
785 <                        threadUnexpectedException(e);
786 <                    }
787 <                }
788 <            });
715 >        Thread t1 = new Thread(new CheckedRunnable() {
716 >            public void realRun() throws InterruptedException {
717 >                sync.acquire(1);
718 >                threadAssertTrue(sync.getWaitingThreads(c).isEmpty());
719 >                c.await();
720 >                sync.release(1);
721 >            }});
722 >
723 >        Thread t2 = new Thread(new CheckedRunnable() {
724 >            public void realRun() throws InterruptedException {
725 >                sync.acquire(1);
726 >                threadAssertFalse(sync.getWaitingThreads(c).isEmpty());
727 >                c.await();
728 >                sync.release(1);
729 >            }});
730  
731              sync.acquire(1);
732              assertTrue(sync.getWaitingThreads(c).isEmpty());
# Line 819 | Line 760 | public class AbstractQueuedLongSynchroni
760      public void testAwaitUninterruptibly() throws InterruptedException {
761          final Mutex sync = new Mutex();
762          final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition();
763 <        Thread t = new Thread(new Runnable() {
764 <                public void run() {
765 <                    sync.acquire(1);
766 <                    c.awaitUninterruptibly();
767 <                    sync.release(1);
768 <                }
828 <            });
763 >        Thread t = new Thread(new CheckedRunnable() {
764 >            public void realRun() {
765 >                sync.acquire(1);
766 >                c.awaitUninterruptibly();
767 >                sync.release(1);
768 >            }});
769  
770          t.start();
771          Thread.sleep(SHORT_DELAY_MS);
# Line 843 | Line 783 | public class AbstractQueuedLongSynchroni
783      public void testAwait_Interrupt() throws InterruptedException {
784          final Mutex sync = new Mutex();
785          final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition();
786 <        Thread t = new Thread(new Runnable() {
787 <                public void run() {
788 <                    try {
789 <                        sync.acquire(1);
790 <                        c.await();
791 <                        sync.release(1);
852 <                        threadShouldThrow();
853 <                    }
854 <                    catch (InterruptedException success) {
855 <                    }
856 <                }
857 <            });
786 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
787 >            public void realRun() throws InterruptedException {
788 >                sync.acquire(1);
789 >                c.await();
790 >                sync.release(1);
791 >            }});
792  
793          t.start();
794          Thread.sleep(SHORT_DELAY_MS);
# Line 869 | Line 803 | public class AbstractQueuedLongSynchroni
803      public void testAwaitNanos_Interrupt() throws InterruptedException {
804          final Mutex sync = new Mutex();
805          final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition();
806 <        Thread t = new Thread(new Runnable() {
807 <                public void run() {
808 <                    try {
809 <                        sync.acquire(1);
810 <                        c.awaitNanos(1000 * 1000 * 1000); // 1 sec
811 <                        sync.release(1);
878 <                        threadShouldThrow();
879 <                    }
880 <                    catch (InterruptedException success) {
881 <                    }
882 <                }
883 <            });
806 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
807 >            public void realRun() throws InterruptedException {
808 >                sync.acquire(1);
809 >                c.awaitNanos(1000 * 1000 * 1000); // 1 sec
810 >                sync.release(1);
811 >            }});
812  
813          t.start();
814          Thread.sleep(SHORT_DELAY_MS);
# Line 895 | Line 823 | public class AbstractQueuedLongSynchroni
823      public void testAwaitUntil_Interrupt() throws InterruptedException {
824          final Mutex sync = new Mutex();
825          final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition();
826 <        Thread t = new Thread(new Runnable() {
827 <                public void run() {
828 <                    try {
829 <                        sync.acquire(1);
830 <                        java.util.Date d = new java.util.Date();
831 <                        c.awaitUntil(new java.util.Date(d.getTime() + 10000));
832 <                        sync.release(1);
905 <                        threadShouldThrow();
906 <                    }
907 <                    catch (InterruptedException success) {
908 <                    }
909 <                }
910 <            });
826 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
827 >            public void realRun() throws InterruptedException {
828 >                sync.acquire(1);
829 >                java.util.Date d = new java.util.Date();
830 >                c.awaitUntil(new java.util.Date(d.getTime() + 10000));
831 >                sync.release(1);
832 >            }});
833  
834          t.start();
835          Thread.sleep(SHORT_DELAY_MS);
# Line 922 | Line 844 | public class AbstractQueuedLongSynchroni
844      public void testSignalAll() throws InterruptedException {
845          final Mutex sync = new Mutex();
846          final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition();
847 <        Thread t1 = new Thread(new Runnable() {
848 <                public void run() {
849 <                    try {
850 <                        sync.acquire(1);
851 <                        c.await();
852 <                        sync.release(1);
853 <                    }
854 <                    catch (InterruptedException e) {
855 <                        threadUnexpectedException();
856 <                    }
857 <                }
858 <            });
859 <
938 <        Thread t2 = new Thread(new Runnable() {
939 <                public void run() {
940 <                    try {
941 <                        sync.acquire(1);
942 <                        c.await();
943 <                        sync.release(1);
944 <                    }
945 <                    catch (InterruptedException e) {
946 <                        threadUnexpectedException();
947 <                    }
948 <                }
949 <            });
847 >        Thread t1 = new Thread(new CheckedRunnable() {
848 >            public void realRun() throws InterruptedException {
849 >                sync.acquire(1);
850 >                c.await();
851 >                sync.release(1);
852 >            }});
853 >
854 >        Thread t2 = new Thread(new CheckedRunnable() {
855 >            public void realRun() throws InterruptedException {
856 >                sync.acquire(1);
857 >                c.await();
858 >                sync.release(1);
859 >            }});
860  
861          t1.start();
862          t2.start();
# Line 1021 | Line 931 | public class AbstractQueuedLongSynchroni
931      public void testAcquireSharedInterruptibly() throws InterruptedException {
932          final BooleanLatch l = new BooleanLatch();
933  
934 <        Thread t = new Thread(new Runnable() {
935 <                public void run() {
936 <                    try {
937 <                        threadAssertFalse(l.isSignalled());
938 <                        l.acquireSharedInterruptibly(0);
939 <                        threadAssertTrue(l.isSignalled());
1030 <                    } catch (InterruptedException e) {
1031 <                        threadUnexpectedException();
1032 <                    }
1033 <                }
1034 <            });
934 >        Thread t = new Thread(new CheckedRunnable() {
935 >            public void realRun() throws InterruptedException {
936 >                threadAssertFalse(l.isSignalled());
937 >                l.acquireSharedInterruptibly(0);
938 >                threadAssertTrue(l.isSignalled());
939 >            }});
940  
941          t.start();
942          assertFalse(l.isSignalled());
# Line 1048 | Line 953 | public class AbstractQueuedLongSynchroni
953      public void testAsquireSharedTimed() throws InterruptedException {
954          final BooleanLatch l = new BooleanLatch();
955  
956 <        Thread t = new Thread(new Runnable() {
957 <                public void run() {
958 <                    try {
959 <                        threadAssertFalse(l.isSignalled());
960 <                        threadAssertTrue(l.tryAcquireSharedNanos(0, MEDIUM_DELAY_MS* 1000 * 1000));
961 <                        threadAssertTrue(l.isSignalled());
1057 <
1058 <                    } catch (InterruptedException e) {
1059 <                        threadUnexpectedException();
1060 <                    }
1061 <                }
1062 <            });
956 >        Thread t = new Thread(new CheckedRunnable() {
957 >            public void realRun() throws InterruptedException {
958 >                threadAssertFalse(l.isSignalled());
959 >                threadAssertTrue(l.tryAcquireSharedNanos(0, MEDIUM_DELAY_MS* 1000 * 1000));
960 >                threadAssertTrue(l.isSignalled());
961 >            }});
962  
963          t.start();
964          assertFalse(l.isSignalled());
# Line 1074 | Line 973 | public class AbstractQueuedLongSynchroni
973       */
974      public void testAcquireSharedInterruptibly_InterruptedException() throws InterruptedException {
975          final BooleanLatch l = new BooleanLatch();
976 <        Thread t = new Thread(new Runnable() {
977 <                public void run() {
978 <                    try {
979 <                        threadAssertFalse(l.isSignalled());
980 <                        l.acquireSharedInterruptibly(0);
1082 <                        threadShouldThrow();
1083 <                    } catch (InterruptedException success) {}
1084 <                }
1085 <            });
976 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
977 >            public void realRun() throws InterruptedException {
978 >                threadAssertFalse(l.isSignalled());
979 >                l.acquireSharedInterruptibly(0);
980 >            }});
981  
982          t.start();
983          assertFalse(l.isSignalled());
# Line 1095 | Line 990 | public class AbstractQueuedLongSynchroni
990       */
991      public void testAcquireSharedNanos_InterruptedException() throws InterruptedException {
992          final BooleanLatch l = new BooleanLatch();
993 <        Thread t = new Thread(new Runnable() {
994 <                public void run() {
995 <                    try {
996 <                        threadAssertFalse(l.isSignalled());
997 <                        l.tryAcquireSharedNanos(0, SMALL_DELAY_MS* 1000 * 1000);
1103 <                        threadShouldThrow();
1104 <                    } catch (InterruptedException success) {}
1105 <                }
1106 <            });
993 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
994 >            public void realRun() throws InterruptedException {
995 >                threadAssertFalse(l.isSignalled());
996 >                l.tryAcquireSharedNanos(0, SMALL_DELAY_MS* 1000 * 1000);
997 >            }});
998  
999          t.start();
1000          Thread.sleep(SHORT_DELAY_MS);
# Line 1117 | Line 1008 | public class AbstractQueuedLongSynchroni
1008       */
1009      public void testAcquireSharedNanos_Timeout() throws InterruptedException {
1010          final BooleanLatch l = new BooleanLatch();
1011 <        Thread t = new Thread(new Runnable() {
1012 <                public void run() {
1013 <                    try {
1014 <                        threadAssertFalse(l.isSignalled());
1015 <                        threadAssertFalse(l.tryAcquireSharedNanos(0, SMALL_DELAY_MS* 1000 * 1000));
1125 <                    } catch (InterruptedException ie) {
1126 <                        threadUnexpectedException();
1127 <                    }
1128 <                }
1129 <            });
1011 >        Thread t = new Thread(new CheckedRunnable() {
1012 >            public void realRun() throws InterruptedException {
1013 >                threadAssertFalse(l.isSignalled());
1014 >                threadAssertFalse(l.tryAcquireSharedNanos(0, SMALL_DELAY_MS* 1000 * 1000));
1015 >            }});
1016  
1017          t.start();
1018          Thread.sleep(SHORT_DELAY_MS);
# Line 1134 | Line 1020 | public class AbstractQueuedLongSynchroni
1020          t.join();
1021      }
1022  
1137
1023   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines