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

Comparing jsr166/src/test/tck/AbstractQueuedSynchronizerTest.java (file contents):
Revision 1.28 by jsr166, Wed Nov 18 16:04:34 2009 UTC vs.
Revision 1.33 by jsr166, Tue Dec 1 06:03:49 2009 UTC

# Line 10 | Line 10
10   import junit.framework.*;
11   import java.util.*;
12   import java.util.concurrent.*;
13 + import static java.util.concurrent.TimeUnit.MILLISECONDS;
14   import java.util.concurrent.locks.*;
15   import java.io.*;
16  
# Line 93 | Line 94 | public class AbstractQueuedSynchronizerT
94       * isHeldExclusively is false upon construction
95       */
96      public void testIsHeldExclusively() {
97 <        Mutex rl = new Mutex();
97 >        Mutex rl = new Mutex();
98          assertFalse(rl.isHeldExclusively());
99      }
100  
# Line 101 | Line 102 | public class AbstractQueuedSynchronizerT
102       * acquiring released sync succeeds
103       */
104      public void testAcquire() {
105 <        Mutex rl = new Mutex();
105 >        Mutex rl = new Mutex();
106          rl.acquire(1);
107          assertTrue(rl.isHeldExclusively());
108          rl.release(1);
# Line 112 | Line 113 | public class AbstractQueuedSynchronizerT
113       * tryAcquire on an released sync succeeds
114       */
115      public void testTryAcquire() {
116 <        Mutex rl = new Mutex();
116 >        Mutex rl = new Mutex();
117          assertTrue(rl.tryAcquire(1));
118          assertTrue(rl.isHeldExclusively());
119          rl.release(1);
# Line 122 | Line 123 | public class AbstractQueuedSynchronizerT
123       * hasQueuedThreads reports whether there are waiting threads
124       */
125      public void testhasQueuedThreads() throws InterruptedException {
126 <        final Mutex sync = new Mutex();
126 >        final Mutex sync = new Mutex();
127          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
128          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
129          assertFalse(sync.hasQueuedThreads());
# Line 147 | Line 148 | public class AbstractQueuedSynchronizerT
148       * isQueued(null) throws NPE
149       */
150      public void testIsQueuedNPE() {
151 <        final Mutex sync = new Mutex();
151 >        final Mutex sync = new Mutex();
152          try {
153              sync.isQueued(null);
154              shouldThrow();
# Line 158 | Line 159 | public class AbstractQueuedSynchronizerT
159       * isQueued reports whether a thread is queued.
160       */
161      public void testIsQueued() throws InterruptedException {
162 <        final Mutex sync = new Mutex();
162 >        final Mutex sync = new Mutex();
163          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
164          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
165          assertFalse(sync.isQueued(t1));
# Line 188 | Line 189 | public class AbstractQueuedSynchronizerT
189       * getFirstQueuedThread returns first waiting thread or null if none
190       */
191      public void testGetFirstQueuedThread() throws InterruptedException {
192 <        final Mutex sync = new Mutex();
192 >        final Mutex sync = new Mutex();
193          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
194          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
195          assertNull(sync.getFirstQueuedThread());
# Line 215 | Line 216 | public class AbstractQueuedSynchronizerT
216       * hasContended reports false if no thread has ever blocked, else true
217       */
218      public void testHasContended() throws InterruptedException {
219 <        final Mutex sync = new Mutex();
219 >        final Mutex sync = new Mutex();
220          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
221          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
222          assertFalse(sync.hasContended());
# Line 240 | Line 241 | public class AbstractQueuedSynchronizerT
241       * getQueuedThreads includes waiting threads
242       */
243      public void testGetQueuedThreads() throws InterruptedException {
244 <        final Mutex sync = new Mutex();
244 >        final Mutex sync = new Mutex();
245          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
246          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
247          assertTrue(sync.getQueuedThreads().isEmpty());
# Line 268 | Line 269 | public class AbstractQueuedSynchronizerT
269       * getExclusiveQueuedThreads includes waiting threads
270       */
271      public void testGetExclusiveQueuedThreads() throws InterruptedException {
272 <        final Mutex sync = new Mutex();
272 >        final Mutex sync = new Mutex();
273          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
274          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
275          assertTrue(sync.getExclusiveQueuedThreads().isEmpty());
# Line 296 | Line 297 | public class AbstractQueuedSynchronizerT
297       * getSharedQueuedThreads does not include exclusively waiting threads
298       */
299      public void testGetSharedQueuedThreads() throws InterruptedException {
300 <        final Mutex sync = new Mutex();
300 >        final Mutex sync = new Mutex();
301          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
302          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
303          assertTrue(sync.getSharedQueuedThreads().isEmpty());
# Line 322 | Line 323 | public class AbstractQueuedSynchronizerT
323       * tryAcquireNanos is interruptible.
324       */
325      public void testInterruptedException2() throws InterruptedException {
326 <        final Mutex sync = new Mutex();
327 <        sync.acquire(1);
328 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
326 >        final Mutex sync = new Mutex();
327 >        sync.acquire(1);
328 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
329              public void realRun() throws InterruptedException {
330 <                sync.tryAcquireNanos(1, MEDIUM_DELAY_MS * 1000 * 1000);
330 >                sync.tryAcquireNanos(1, MILLISECONDS.toNanos(MEDIUM_DELAY_MS));
331              }});
332  
333          t.start();
334 +        Thread.sleep(SHORT_DELAY_MS);
335          t.interrupt();
336          t.join();
337      }
# Line 339 | Line 341 | public class AbstractQueuedSynchronizerT
341       * TryAcquire on exclusively held sync fails
342       */
343      public void testTryAcquireWhenSynced() throws InterruptedException {
344 <        final Mutex sync = new Mutex();
345 <        sync.acquire(1);
346 <        Thread t = new Thread(new CheckedRunnable() {
344 >        final Mutex sync = new Mutex();
345 >        sync.acquire(1);
346 >        Thread t = new Thread(new CheckedRunnable() {
347              public void realRun() {
348                  threadAssertFalse(sync.tryAcquire(1));
349              }});
# Line 355 | Line 357 | public class AbstractQueuedSynchronizerT
357       * tryAcquireNanos on an exclusively held sync times out
358       */
359      public void testAcquireNanos_Timeout() throws InterruptedException {
360 <        final Mutex sync = new Mutex();
361 <        sync.acquire(1);
362 <        Thread t = new Thread(new CheckedRunnable() {
360 >        final Mutex sync = new Mutex();
361 >        sync.acquire(1);
362 >        Thread t = new Thread(new CheckedRunnable() {
363              public void realRun() throws InterruptedException {
364 <                threadAssertFalse(sync.tryAcquireNanos(1, 1000 * 1000));
364 >                long nanos = MILLISECONDS.toNanos(SHORT_DELAY_MS);
365 >                assertFalse(sync.tryAcquireNanos(1, nanos));
366              }});
367  
368          t.start();
# Line 372 | Line 375 | public class AbstractQueuedSynchronizerT
375       * getState is true when acquired and false when not
376       */
377      public void testGetState() throws InterruptedException {
378 <        final Mutex sync = new Mutex();
379 <        sync.acquire(1);
380 <        assertTrue(sync.isHeldExclusively());
381 <        sync.release(1);
382 <        assertFalse(sync.isHeldExclusively());
383 <        Thread t = new Thread(new CheckedRunnable() {
378 >        final Mutex sync = new Mutex();
379 >        sync.acquire(1);
380 >        assertTrue(sync.isHeldExclusively());
381 >        sync.release(1);
382 >        assertFalse(sync.isHeldExclusively());
383 >        Thread t = new Thread(new CheckedRunnable() {
384              public void realRun() throws InterruptedException {
385                  sync.acquire(1);
386                  Thread.sleep(SMALL_DELAY_MS);
# Line 396 | Line 399 | public class AbstractQueuedSynchronizerT
399       * acquireInterruptibly is interruptible.
400       */
401      public void testAcquireInterruptibly1() throws InterruptedException {
402 <        final Mutex sync = new Mutex();
403 <        sync.acquire(1);
404 <        Thread t = new Thread(new InterruptedSyncRunnable(sync));
402 >        final Mutex sync = new Mutex();
403 >        sync.acquire(1);
404 >        Thread t = new Thread(new InterruptedSyncRunnable(sync));
405  
406          t.start();
407          Thread.sleep(SHORT_DELAY_MS);
# Line 412 | Line 415 | public class AbstractQueuedSynchronizerT
415       * acquireInterruptibly succeeds when released, else is interruptible
416       */
417      public void testAcquireInterruptibly2() throws InterruptedException {
418 <        final Mutex sync = new Mutex();
418 >        final Mutex sync = new Mutex();
419          sync.acquireInterruptibly(1);
420 <        Thread t = new Thread(new InterruptedSyncRunnable(sync));
420 >        Thread t = new Thread(new InterruptedSyncRunnable(sync));
421          t.start();
422 +        Thread.sleep(SHORT_DELAY_MS);
423          t.interrupt();
424          assertTrue(sync.isHeldExclusively());
425          t.join();
# Line 425 | Line 429 | public class AbstractQueuedSynchronizerT
429       * owns is true for a condition created by sync else false
430       */
431      public void testOwns() {
432 <        final Mutex sync = new Mutex();
432 >        final Mutex sync = new Mutex();
433          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
434          final Mutex sync2 = new Mutex();
435          assertTrue(sync.owns(c));
# Line 436 | Line 440 | public class AbstractQueuedSynchronizerT
440       * Calling await without holding sync throws IllegalMonitorStateException
441       */
442      public void testAwait_IllegalMonitor() throws InterruptedException {
443 <        final Mutex sync = new Mutex();
443 >        final Mutex sync = new Mutex();
444          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
445          try {
446              c.await();
# Line 448 | Line 452 | public class AbstractQueuedSynchronizerT
452       * Calling signal without holding sync throws IllegalMonitorStateException
453       */
454      public void testSignal_IllegalMonitor() {
455 <        final Mutex sync = new Mutex();
455 >        final Mutex sync = new Mutex();
456          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
457          try {
458              c.signal();
# Line 460 | Line 464 | public class AbstractQueuedSynchronizerT
464       * awaitNanos without a signal times out
465       */
466      public void testAwaitNanos_Timeout() throws InterruptedException {
467 <        final Mutex sync = new Mutex();
467 >        final Mutex sync = new Mutex();
468          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
469          sync.acquire(1);
470          long t = c.awaitNanos(100);
# Line 472 | Line 476 | public class AbstractQueuedSynchronizerT
476       *  Timed await without a signal times out
477       */
478      public void testAwait_Timeout() throws InterruptedException {
479 <        final Mutex sync = new Mutex();
479 >        final Mutex sync = new Mutex();
480          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
481          sync.acquire(1);
482 <        assertFalse(c.await(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
482 >        assertFalse(c.await(SHORT_DELAY_MS, MILLISECONDS));
483          sync.release(1);
484      }
485  
# Line 483 | Line 487 | public class AbstractQueuedSynchronizerT
487       * awaitUntil without a signal times out
488       */
489      public void testAwaitUntil_Timeout() throws InterruptedException {
490 <        final Mutex sync = new Mutex();
490 >        final Mutex sync = new Mutex();
491          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
492          sync.acquire(1);
493          java.util.Date d = new java.util.Date();
# Line 495 | Line 499 | public class AbstractQueuedSynchronizerT
499       * await returns when signalled
500       */
501      public void testAwait() throws InterruptedException {
502 <        final Mutex sync = new Mutex();
502 >        final Mutex sync = new Mutex();
503          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
504 <        Thread t = new Thread(new CheckedRunnable() {
504 >        Thread t = new Thread(new CheckedRunnable() {
505              public void realRun() throws InterruptedException {
506                  sync.acquire(1);
507                  c.await();
# Line 519 | Line 523 | public class AbstractQueuedSynchronizerT
523       * hasWaiters throws NPE if null
524       */
525      public void testHasWaitersNPE() {
526 <        final Mutex sync = new Mutex();
526 >        final Mutex sync = new Mutex();
527          try {
528              sync.hasWaiters(null);
529              shouldThrow();
# Line 530 | Line 534 | public class AbstractQueuedSynchronizerT
534       * getWaitQueueLength throws NPE if null
535       */
536      public void testGetWaitQueueLengthNPE() {
537 <        final Mutex sync = new Mutex();
537 >        final Mutex sync = new Mutex();
538          try {
539              sync.getWaitQueueLength(null);
540              shouldThrow();
# Line 542 | Line 546 | public class AbstractQueuedSynchronizerT
546       * getWaitingThreads throws NPE if null
547       */
548      public void testGetWaitingThreadsNPE() {
549 <        final Mutex sync = new Mutex();
549 >        final Mutex sync = new Mutex();
550          try {
551              sync.getWaitingThreads(null);
552              shouldThrow();
# Line 554 | Line 558 | public class AbstractQueuedSynchronizerT
558       * hasWaiters throws IAE if not owned
559       */
560      public void testHasWaitersIAE() {
561 <        final Mutex sync = new Mutex();
561 >        final Mutex sync = new Mutex();
562          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
563 <        final Mutex sync2 = new Mutex();
563 >        final Mutex sync2 = new Mutex();
564          try {
565              sync2.hasWaiters(c);
566              shouldThrow();
# Line 567 | Line 571 | public class AbstractQueuedSynchronizerT
571       * hasWaiters throws IMSE if not synced
572       */
573      public void testHasWaitersIMSE() {
574 <        final Mutex sync = new Mutex();
574 >        final Mutex sync = new Mutex();
575          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
576          try {
577              sync.hasWaiters(c);
# Line 580 | Line 584 | public class AbstractQueuedSynchronizerT
584       * getWaitQueueLength throws IAE if not owned
585       */
586      public void testGetWaitQueueLengthIAE() {
587 <        final Mutex sync = new Mutex();
587 >        final Mutex sync = new Mutex();
588          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
589 <        final Mutex sync2 = new Mutex();
589 >        final Mutex sync2 = new Mutex();
590          try {
591              sync2.getWaitQueueLength(c);
592              shouldThrow();
# Line 593 | Line 597 | public class AbstractQueuedSynchronizerT
597       * getWaitQueueLength throws IMSE if not synced
598       */
599      public void testGetWaitQueueLengthIMSE() {
600 <        final Mutex sync = new Mutex();
600 >        final Mutex sync = new Mutex();
601          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
602          try {
603              sync.getWaitQueueLength(c);
# Line 606 | Line 610 | public class AbstractQueuedSynchronizerT
610       * getWaitingThreads throws IAE if not owned
611       */
612      public void testGetWaitingThreadsIAE() {
613 <        final Mutex sync = new Mutex();
613 >        final Mutex sync = new Mutex();
614          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
615 <        final Mutex sync2 = new Mutex();
615 >        final Mutex sync2 = new Mutex();
616          try {
617              sync2.getWaitingThreads(c);
618              shouldThrow();
# Line 619 | Line 623 | public class AbstractQueuedSynchronizerT
623       * getWaitingThreads throws IMSE if not synced
624       */
625      public void testGetWaitingThreadsIMSE() {
626 <        final Mutex sync = new Mutex();
626 >        final Mutex sync = new Mutex();
627          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
628          try {
629              sync.getWaitingThreads(c);
# Line 633 | Line 637 | public class AbstractQueuedSynchronizerT
637       * hasWaiters returns true when a thread is waiting, else false
638       */
639      public void testHasWaiters() throws InterruptedException {
640 <        final Mutex sync = new Mutex();
640 >        final Mutex sync = new Mutex();
641          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
642 <        Thread t = new Thread(new CheckedRunnable() {
642 >        Thread t = new Thread(new CheckedRunnable() {
643              public void realRun() throws InterruptedException {
644                  sync.acquire(1);
645                  threadAssertFalse(sync.hasWaiters(c));
# Line 664 | Line 668 | public class AbstractQueuedSynchronizerT
668       * getWaitQueueLength returns number of waiting threads
669       */
670      public void testGetWaitQueueLength() throws InterruptedException {
671 <        final Mutex sync = new Mutex();
671 >        final Mutex sync = new Mutex();
672          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
673 <        Thread t1 = new Thread(new CheckedRunnable() {
673 >        Thread t1 = new Thread(new CheckedRunnable() {
674              public void realRun() throws InterruptedException {
675                  sync.acquire(1);
676                  threadAssertFalse(sync.hasWaiters(c));
# Line 675 | Line 679 | public class AbstractQueuedSynchronizerT
679                  sync.release(1);
680              }});
681  
682 <        Thread t2 = new Thread(new CheckedRunnable() {
682 >        Thread t2 = new Thread(new CheckedRunnable() {
683              public void realRun() throws InterruptedException {
684                  sync.acquire(1);
685                  threadAssertTrue(sync.hasWaiters(c));
# Line 708 | Line 712 | public class AbstractQueuedSynchronizerT
712       * getWaitingThreads returns only and all waiting threads
713       */
714      public void testGetWaitingThreads() throws InterruptedException {
715 <        final Mutex sync = new Mutex();
715 >        final Mutex sync = new Mutex();
716          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
717 <        Thread t1 = new Thread(new CheckedRunnable() {
717 >        Thread t1 = new Thread(new CheckedRunnable() {
718              public void realRun() throws InterruptedException {
719                  sync.acquire(1);
720                  threadAssertTrue(sync.getWaitingThreads(c).isEmpty());
# Line 718 | Line 722 | public class AbstractQueuedSynchronizerT
722                  sync.release(1);
723              }});
724  
725 <        Thread t2 = new Thread(new CheckedRunnable() {
725 >        Thread t2 = new Thread(new CheckedRunnable() {
726              public void realRun() throws InterruptedException {
727                  sync.acquire(1);
728                  threadAssertFalse(sync.getWaitingThreads(c).isEmpty());
# Line 756 | Line 760 | public class AbstractQueuedSynchronizerT
760       * awaitUninterruptibly doesn't abort on interrupt
761       */
762      public void testAwaitUninterruptibly() throws InterruptedException {
763 <        final Mutex sync = new Mutex();
763 >        final Mutex sync = new Mutex();
764          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
765 <        Thread t = new Thread(new CheckedRunnable() {
765 >        Thread t = new Thread(new CheckedRunnable() {
766              public void realRun() {
767                  sync.acquire(1);
768                  c.awaitUninterruptibly();
# Line 779 | Line 783 | public class AbstractQueuedSynchronizerT
783       * await is interruptible
784       */
785      public void testAwait_Interrupt() throws InterruptedException {
786 <        final Mutex sync = new Mutex();
786 >        final Mutex sync = new Mutex();
787          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
788 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
789 <            public void realRun() throws InterruptedException {
788 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
789 >            public void realRun() throws InterruptedException {
790                  sync.acquire(1);
791                  c.await();
788                sync.release(1);
792              }});
793  
794          t.start();
# Line 799 | Line 802 | public class AbstractQueuedSynchronizerT
802       * awaitNanos is interruptible
803       */
804      public void testAwaitNanos_Interrupt() throws InterruptedException {
805 <        final Mutex sync = new Mutex();
805 >        final Mutex sync = new Mutex();
806          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
807 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
808 <            public void realRun() throws InterruptedException {
807 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
808 >            public void realRun() throws InterruptedException {
809                  sync.acquire(1);
810 <                c.awaitNanos(1000 * 1000 * 1000); // 1 sec
808 <                sync.release(1);
810 >                c.awaitNanos(MILLISECONDS.toNanos(LONG_DELAY_MS));
811              }});
812  
813          t.start();
# Line 819 | Line 821 | public class AbstractQueuedSynchronizerT
821       * awaitUntil is interruptible
822       */
823      public void testAwaitUntil_Interrupt() throws InterruptedException {
824 <        final Mutex sync = new Mutex();
824 >        final Mutex sync = new Mutex();
825          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
826 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
827 <            public void realRun() throws InterruptedException {
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));
829                sync.release(1);
831              }});
832  
833          t.start();
# Line 840 | Line 841 | public class AbstractQueuedSynchronizerT
841       * signalAll wakes up all threads
842       */
843      public void testSignalAll() throws InterruptedException {
844 <        final Mutex sync = new Mutex();
844 >        final Mutex sync = new Mutex();
845          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
846 <        Thread t1 = new Thread(new CheckedRunnable() {
846 >        Thread t1 = new Thread(new CheckedRunnable() {
847              public void realRun() throws InterruptedException {
848                  sync.acquire(1);
849                  c.await();
850                  sync.release(1);
851              }});
852  
853 <        Thread t2 = new Thread(new CheckedRunnable() {
853 >        Thread t2 = new Thread(new CheckedRunnable() {
854              public void realRun() throws InterruptedException {
855                  sync.acquire(1);
856                  c.await();
# Line 905 | Line 906 | public class AbstractQueuedSynchronizerT
906       * tryReleaseShared setting state changes getState
907       */
908      public void testGetStateWithReleaseShared() {
909 <        final BooleanLatch l = new BooleanLatch();
910 <        assertFalse(l.isSignalled());
911 <        l.releaseShared(0);
912 <        assertTrue(l.isSignalled());
909 >        final BooleanLatch l = new BooleanLatch();
910 >        assertFalse(l.isSignalled());
911 >        l.releaseShared(0);
912 >        assertTrue(l.isSignalled());
913      }
914  
915      /**
916       * releaseShared has no effect when already signalled
917       */
918      public void testReleaseShared() {
919 <        final BooleanLatch l = new BooleanLatch();
920 <        assertFalse(l.isSignalled());
921 <        l.releaseShared(0);
922 <        assertTrue(l.isSignalled());
923 <        l.releaseShared(0);
924 <        assertTrue(l.isSignalled());
919 >        final BooleanLatch l = new BooleanLatch();
920 >        assertFalse(l.isSignalled());
921 >        l.releaseShared(0);
922 >        assertTrue(l.isSignalled());
923 >        l.releaseShared(0);
924 >        assertTrue(l.isSignalled());
925      }
926  
927      /**
928       * acquireSharedInterruptibly returns after release, but not before
929       */
930      public void testAcquireSharedInterruptibly() throws InterruptedException {
931 <        final BooleanLatch l = new BooleanLatch();
931 >        final BooleanLatch l = new BooleanLatch();
932  
933 <        Thread t = new Thread(new CheckedRunnable() {
933 >        Thread t = new Thread(new CheckedRunnable() {
934              public void realRun() throws InterruptedException {
935                  threadAssertFalse(l.isSignalled());
936                  l.acquireSharedInterruptibly(0);
# Line 949 | Line 950 | public class AbstractQueuedSynchronizerT
950       * acquireSharedTimed returns after release
951       */
952      public void testAsquireSharedTimed() throws InterruptedException {
953 <        final BooleanLatch l = new BooleanLatch();
953 >        final BooleanLatch l = new BooleanLatch();
954  
955 <        Thread t = new Thread(new CheckedRunnable() {
955 >        Thread t = new Thread(new CheckedRunnable() {
956              public void realRun() throws InterruptedException {
957 <                threadAssertFalse(l.isSignalled());
958 <                threadAssertTrue(l.tryAcquireSharedNanos(0, MEDIUM_DELAY_MS* 1000 * 1000));
959 <                threadAssertTrue(l.isSignalled());
957 >                assertFalse(l.isSignalled());
958 >                long nanos = MILLISECONDS.toNanos(MEDIUM_DELAY_MS);
959 >                assertTrue(l.tryAcquireSharedNanos(0, nanos));
960 >                assertTrue(l.isSignalled());
961              }});
962  
963          t.start();
# Line 971 | Line 973 | public class AbstractQueuedSynchronizerT
973       */
974      public void testAcquireSharedInterruptibly_InterruptedException() throws InterruptedException {
975          final BooleanLatch l = new BooleanLatch();
976 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
977 <            public void realRun() throws InterruptedException {
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();
982 >        t.start();
983          assertFalse(l.isSignalled());
984          t.interrupt();
985          t.join();
# Line 988 | Line 990 | public class AbstractQueuedSynchronizerT
990       */
991      public void testAcquireSharedNanos_InterruptedException() throws InterruptedException {
992          final BooleanLatch l = new BooleanLatch();
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);
993 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
994 >            public void realRun() throws InterruptedException {
995 >                assertFalse(l.isSignalled());
996 >                long nanos = MILLISECONDS.toNanos(SMALL_DELAY_MS);
997 >                l.tryAcquireSharedNanos(0, nanos);
998              }});
999  
1000          t.start();
# Line 1006 | Line 1009 | public class AbstractQueuedSynchronizerT
1009       */
1010      public void testAcquireSharedNanos_Timeout() throws InterruptedException {
1011          final BooleanLatch l = new BooleanLatch();
1012 <        Thread t = new Thread(new CheckedRunnable() {
1012 >        Thread t = new Thread(new CheckedRunnable() {
1013              public void realRun() throws InterruptedException {
1014 <                threadAssertFalse(l.isSignalled());
1015 <                threadAssertFalse(l.tryAcquireSharedNanos(0, SMALL_DELAY_MS* 1000 * 1000));
1014 >                assertFalse(l.isSignalled());
1015 >                long nanos = MILLISECONDS.toNanos(SMALL_DELAY_MS);
1016 >                assertFalse(l.tryAcquireSharedNanos(0, nanos));
1017              }});
1018  
1019          t.start();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines