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.38 by jsr166, Tue Oct 19 00:43:49 2010 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  
17   public class AbstractQueuedSynchronizerTest extends JSR166TestCase {
18      public static void main(String[] args) {
19 <        junit.textui.TestRunner.run (suite());
19 >        junit.textui.TestRunner.run(suite());
20      }
21      public static Test suite() {
22          return new TestSuite(AbstractQueuedSynchronizerTest.class);
# Line 33 | Line 34 | public class AbstractQueuedSynchronizerT
34          public boolean isHeldExclusively() { return getState() == 1; }
35  
36          public boolean tryAcquire(int acquires) {
37 <            assertTrue(acquires == 1);
37 >            assertEquals(1, acquires);
38              return compareAndSetState(0, 1);
39          }
40  
# Line 43 | Line 44 | public class AbstractQueuedSynchronizerT
44              return true;
45          }
46  
47 <        public AbstractQueuedSynchronizer.ConditionObject newCondition() { return new AbstractQueuedSynchronizer.ConditionObject(); }
47 >        public AbstractQueuedSynchronizer.ConditionObject newCondition() {
48 >            return new AbstractQueuedSynchronizer.ConditionObject();
49 >        }
50  
51      }
52  
# Line 55 | Line 58 | public class AbstractQueuedSynchronizerT
58          public boolean isSignalled() { return getState() != 0; }
59  
60          public int tryAcquireShared(int ignore) {
61 <            return isSignalled()? 1 : -1;
61 >            return isSignalled() ? 1 : -1;
62          }
63  
64          public boolean tryReleaseShared(int ignore) {
# Line 93 | Line 96 | public class AbstractQueuedSynchronizerT
96       * isHeldExclusively is false upon construction
97       */
98      public void testIsHeldExclusively() {
99 <        Mutex rl = new Mutex();
99 >        Mutex rl = new Mutex();
100          assertFalse(rl.isHeldExclusively());
101      }
102  
# Line 101 | Line 104 | public class AbstractQueuedSynchronizerT
104       * acquiring released sync succeeds
105       */
106      public void testAcquire() {
107 <        Mutex rl = new Mutex();
107 >        Mutex rl = new Mutex();
108          rl.acquire(1);
109          assertTrue(rl.isHeldExclusively());
110          rl.release(1);
# Line 112 | Line 115 | public class AbstractQueuedSynchronizerT
115       * tryAcquire on an released sync succeeds
116       */
117      public void testTryAcquire() {
118 <        Mutex rl = new Mutex();
118 >        Mutex rl = new Mutex();
119          assertTrue(rl.tryAcquire(1));
120          assertTrue(rl.isHeldExclusively());
121          rl.release(1);
# Line 122 | Line 125 | public class AbstractQueuedSynchronizerT
125       * hasQueuedThreads reports whether there are waiting threads
126       */
127      public void testhasQueuedThreads() throws InterruptedException {
128 <        final Mutex sync = new Mutex();
128 >        final Mutex sync = new Mutex();
129          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
130          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
131          assertFalse(sync.hasQueuedThreads());
# Line 147 | Line 150 | public class AbstractQueuedSynchronizerT
150       * isQueued(null) throws NPE
151       */
152      public void testIsQueuedNPE() {
153 <        final Mutex sync = new Mutex();
153 >        final Mutex sync = new Mutex();
154          try {
155              sync.isQueued(null);
156              shouldThrow();
# Line 158 | Line 161 | public class AbstractQueuedSynchronizerT
161       * isQueued reports whether a thread is queued.
162       */
163      public void testIsQueued() throws InterruptedException {
164 <        final Mutex sync = new Mutex();
164 >        final Mutex sync = new Mutex();
165          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
166          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
167          assertFalse(sync.isQueued(t1));
# Line 188 | Line 191 | public class AbstractQueuedSynchronizerT
191       * getFirstQueuedThread returns first waiting thread or null if none
192       */
193      public void testGetFirstQueuedThread() throws InterruptedException {
194 <        final Mutex sync = new Mutex();
194 >        final Mutex sync = new Mutex();
195          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
196          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
197          assertNull(sync.getFirstQueuedThread());
# Line 215 | Line 218 | public class AbstractQueuedSynchronizerT
218       * hasContended reports false if no thread has ever blocked, else true
219       */
220      public void testHasContended() throws InterruptedException {
221 <        final Mutex sync = new Mutex();
221 >        final Mutex sync = new Mutex();
222          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
223          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
224          assertFalse(sync.hasContended());
# Line 240 | Line 243 | public class AbstractQueuedSynchronizerT
243       * getQueuedThreads includes waiting threads
244       */
245      public void testGetQueuedThreads() throws InterruptedException {
246 <        final Mutex sync = new Mutex();
246 >        final Mutex sync = new Mutex();
247          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
248          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
249          assertTrue(sync.getQueuedThreads().isEmpty());
# Line 268 | Line 271 | public class AbstractQueuedSynchronizerT
271       * getExclusiveQueuedThreads includes waiting threads
272       */
273      public void testGetExclusiveQueuedThreads() throws InterruptedException {
274 <        final Mutex sync = new Mutex();
274 >        final Mutex sync = new Mutex();
275          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
276          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
277          assertTrue(sync.getExclusiveQueuedThreads().isEmpty());
# Line 296 | Line 299 | public class AbstractQueuedSynchronizerT
299       * getSharedQueuedThreads does not include exclusively waiting threads
300       */
301      public void testGetSharedQueuedThreads() throws InterruptedException {
302 <        final Mutex sync = new Mutex();
302 >        final Mutex sync = new Mutex();
303          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
304          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
305          assertTrue(sync.getSharedQueuedThreads().isEmpty());
# Line 322 | Line 325 | public class AbstractQueuedSynchronizerT
325       * tryAcquireNanos is interruptible.
326       */
327      public void testInterruptedException2() throws InterruptedException {
328 <        final Mutex sync = new Mutex();
329 <        sync.acquire(1);
330 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
328 >        final Mutex sync = new Mutex();
329 >        sync.acquire(1);
330 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
331              public void realRun() throws InterruptedException {
332 <                sync.tryAcquireNanos(1, MEDIUM_DELAY_MS * 1000 * 1000);
332 >                sync.tryAcquireNanos(1, MILLISECONDS.toNanos(MEDIUM_DELAY_MS));
333              }});
334  
335          t.start();
336 +        Thread.sleep(SHORT_DELAY_MS);
337          t.interrupt();
338          t.join();
339      }
# Line 339 | Line 343 | public class AbstractQueuedSynchronizerT
343       * TryAcquire on exclusively held sync fails
344       */
345      public void testTryAcquireWhenSynced() throws InterruptedException {
346 <        final Mutex sync = new Mutex();
347 <        sync.acquire(1);
348 <        Thread t = new Thread(new CheckedRunnable() {
346 >        final Mutex sync = new Mutex();
347 >        sync.acquire(1);
348 >        Thread t = new Thread(new CheckedRunnable() {
349              public void realRun() {
350 <                threadAssertFalse(sync.tryAcquire(1));
350 >                assertFalse(sync.tryAcquire(1));
351              }});
352  
353          t.start();
# Line 355 | Line 359 | public class AbstractQueuedSynchronizerT
359       * tryAcquireNanos on an exclusively held sync times out
360       */
361      public void testAcquireNanos_Timeout() throws InterruptedException {
362 <        final Mutex sync = new Mutex();
363 <        sync.acquire(1);
364 <        Thread t = new Thread(new CheckedRunnable() {
362 >        final Mutex sync = new Mutex();
363 >        sync.acquire(1);
364 >        Thread t = new Thread(new CheckedRunnable() {
365              public void realRun() throws InterruptedException {
366 <                threadAssertFalse(sync.tryAcquireNanos(1, 1000 * 1000));
366 >                long nanos = MILLISECONDS.toNanos(SHORT_DELAY_MS);
367 >                assertFalse(sync.tryAcquireNanos(1, nanos));
368              }});
369  
370          t.start();
# Line 372 | Line 377 | public class AbstractQueuedSynchronizerT
377       * getState is true when acquired and false when not
378       */
379      public void testGetState() throws InterruptedException {
380 <        final Mutex sync = new Mutex();
381 <        sync.acquire(1);
382 <        assertTrue(sync.isHeldExclusively());
383 <        sync.release(1);
384 <        assertFalse(sync.isHeldExclusively());
385 <        Thread t = new Thread(new CheckedRunnable() {
380 >        final Mutex sync = new Mutex();
381 >        sync.acquire(1);
382 >        assertTrue(sync.isHeldExclusively());
383 >        sync.release(1);
384 >        assertFalse(sync.isHeldExclusively());
385 >        Thread t = new Thread(new CheckedRunnable() {
386              public void realRun() throws InterruptedException {
387                  sync.acquire(1);
388                  Thread.sleep(SMALL_DELAY_MS);
# Line 396 | Line 401 | public class AbstractQueuedSynchronizerT
401       * acquireInterruptibly is interruptible.
402       */
403      public void testAcquireInterruptibly1() throws InterruptedException {
404 <        final Mutex sync = new Mutex();
405 <        sync.acquire(1);
406 <        Thread t = new Thread(new InterruptedSyncRunnable(sync));
404 >        final Mutex sync = new Mutex();
405 >        sync.acquire(1);
406 >        Thread t = new Thread(new InterruptedSyncRunnable(sync));
407  
408          t.start();
409          Thread.sleep(SHORT_DELAY_MS);
# Line 412 | Line 417 | public class AbstractQueuedSynchronizerT
417       * acquireInterruptibly succeeds when released, else is interruptible
418       */
419      public void testAcquireInterruptibly2() throws InterruptedException {
420 <        final Mutex sync = new Mutex();
420 >        final Mutex sync = new Mutex();
421          sync.acquireInterruptibly(1);
422 <        Thread t = new Thread(new InterruptedSyncRunnable(sync));
422 >        Thread t = new Thread(new InterruptedSyncRunnable(sync));
423          t.start();
424 +        Thread.sleep(SHORT_DELAY_MS);
425          t.interrupt();
426          assertTrue(sync.isHeldExclusively());
427          t.join();
# Line 425 | Line 431 | public class AbstractQueuedSynchronizerT
431       * owns is true for a condition created by sync else false
432       */
433      public void testOwns() {
434 <        final Mutex sync = new Mutex();
434 >        final Mutex sync = new Mutex();
435          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
436          final Mutex sync2 = new Mutex();
437          assertTrue(sync.owns(c));
# Line 436 | Line 442 | public class AbstractQueuedSynchronizerT
442       * Calling await without holding sync throws IllegalMonitorStateException
443       */
444      public void testAwait_IllegalMonitor() throws InterruptedException {
445 <        final Mutex sync = new Mutex();
445 >        final Mutex sync = new Mutex();
446          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
447          try {
448              c.await();
# Line 448 | Line 454 | public class AbstractQueuedSynchronizerT
454       * Calling signal without holding sync throws IllegalMonitorStateException
455       */
456      public void testSignal_IllegalMonitor() {
457 <        final Mutex sync = new Mutex();
457 >        final Mutex sync = new Mutex();
458          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
459          try {
460              c.signal();
# Line 460 | Line 466 | public class AbstractQueuedSynchronizerT
466       * awaitNanos without a signal times out
467       */
468      public void testAwaitNanos_Timeout() throws InterruptedException {
469 <        final Mutex sync = new Mutex();
469 >        final Mutex sync = new Mutex();
470          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
471          sync.acquire(1);
472          long t = c.awaitNanos(100);
# Line 469 | Line 475 | public class AbstractQueuedSynchronizerT
475      }
476  
477      /**
478 <     *  Timed await without a signal times out
478 >     * Timed await without a signal times out
479       */
480      public void testAwait_Timeout() throws InterruptedException {
481 <        final Mutex sync = new Mutex();
481 >        final Mutex sync = new Mutex();
482          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
483          sync.acquire(1);
484 <        assertFalse(c.await(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
484 >        assertFalse(c.await(SHORT_DELAY_MS, MILLISECONDS));
485          sync.release(1);
486      }
487  
# Line 483 | Line 489 | public class AbstractQueuedSynchronizerT
489       * awaitUntil without a signal times out
490       */
491      public void testAwaitUntil_Timeout() throws InterruptedException {
492 <        final Mutex sync = new Mutex();
492 >        final Mutex sync = new Mutex();
493          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
494          sync.acquire(1);
495          java.util.Date d = new java.util.Date();
# Line 495 | Line 501 | public class AbstractQueuedSynchronizerT
501       * await returns when signalled
502       */
503      public void testAwait() throws InterruptedException {
504 <        final Mutex sync = new Mutex();
504 >        final Mutex sync = new Mutex();
505          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
506 <        Thread t = new Thread(new CheckedRunnable() {
506 >        Thread t = new Thread(new CheckedRunnable() {
507              public void realRun() throws InterruptedException {
508                  sync.acquire(1);
509                  c.await();
# Line 519 | Line 525 | public class AbstractQueuedSynchronizerT
525       * hasWaiters throws NPE if null
526       */
527      public void testHasWaitersNPE() {
528 <        final Mutex sync = new Mutex();
528 >        final Mutex sync = new Mutex();
529          try {
530              sync.hasWaiters(null);
531              shouldThrow();
# Line 530 | Line 536 | public class AbstractQueuedSynchronizerT
536       * getWaitQueueLength throws NPE if null
537       */
538      public void testGetWaitQueueLengthNPE() {
539 <        final Mutex sync = new Mutex();
539 >        final Mutex sync = new Mutex();
540          try {
541              sync.getWaitQueueLength(null);
542              shouldThrow();
# Line 542 | Line 548 | public class AbstractQueuedSynchronizerT
548       * getWaitingThreads throws NPE if null
549       */
550      public void testGetWaitingThreadsNPE() {
551 <        final Mutex sync = new Mutex();
551 >        final Mutex sync = new Mutex();
552          try {
553              sync.getWaitingThreads(null);
554              shouldThrow();
# Line 554 | Line 560 | public class AbstractQueuedSynchronizerT
560       * hasWaiters throws IAE if not owned
561       */
562      public void testHasWaitersIAE() {
563 <        final Mutex sync = new Mutex();
563 >        final Mutex sync = new Mutex();
564          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
565 <        final Mutex sync2 = new Mutex();
565 >        final Mutex sync2 = new Mutex();
566          try {
567              sync2.hasWaiters(c);
568              shouldThrow();
# Line 567 | Line 573 | public class AbstractQueuedSynchronizerT
573       * hasWaiters throws IMSE if not synced
574       */
575      public void testHasWaitersIMSE() {
576 <        final Mutex sync = new Mutex();
576 >        final Mutex sync = new Mutex();
577          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
578          try {
579              sync.hasWaiters(c);
# Line 580 | Line 586 | public class AbstractQueuedSynchronizerT
586       * getWaitQueueLength throws IAE if not owned
587       */
588      public void testGetWaitQueueLengthIAE() {
589 <        final Mutex sync = new Mutex();
589 >        final Mutex sync = new Mutex();
590          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
591 <        final Mutex sync2 = new Mutex();
591 >        final Mutex sync2 = new Mutex();
592          try {
593              sync2.getWaitQueueLength(c);
594              shouldThrow();
# Line 593 | Line 599 | public class AbstractQueuedSynchronizerT
599       * getWaitQueueLength throws IMSE if not synced
600       */
601      public void testGetWaitQueueLengthIMSE() {
602 <        final Mutex sync = new Mutex();
602 >        final Mutex sync = new Mutex();
603          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
604          try {
605              sync.getWaitQueueLength(c);
# Line 606 | Line 612 | public class AbstractQueuedSynchronizerT
612       * getWaitingThreads throws IAE if not owned
613       */
614      public void testGetWaitingThreadsIAE() {
615 <        final Mutex sync = new Mutex();
615 >        final Mutex sync = new Mutex();
616          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
617 <        final Mutex sync2 = new Mutex();
617 >        final Mutex sync2 = new Mutex();
618          try {
619              sync2.getWaitingThreads(c);
620              shouldThrow();
# Line 619 | Line 625 | public class AbstractQueuedSynchronizerT
625       * getWaitingThreads throws IMSE if not synced
626       */
627      public void testGetWaitingThreadsIMSE() {
628 <        final Mutex sync = new Mutex();
628 >        final Mutex sync = new Mutex();
629          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
630          try {
631              sync.getWaitingThreads(c);
# Line 633 | Line 639 | public class AbstractQueuedSynchronizerT
639       * hasWaiters returns true when a thread is waiting, else false
640       */
641      public void testHasWaiters() throws InterruptedException {
642 <        final Mutex sync = new Mutex();
642 >        final Mutex sync = new Mutex();
643          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
644 <        Thread t = new Thread(new CheckedRunnable() {
644 >        Thread t = new Thread(new CheckedRunnable() {
645              public void realRun() throws InterruptedException {
646                  sync.acquire(1);
647 <                threadAssertFalse(sync.hasWaiters(c));
648 <                threadAssertEquals(0, sync.getWaitQueueLength(c));
647 >                assertFalse(sync.hasWaiters(c));
648 >                assertEquals(0, sync.getWaitQueueLength(c));
649                  c.await();
650                  sync.release(1);
651              }});
# Line 664 | Line 670 | public class AbstractQueuedSynchronizerT
670       * getWaitQueueLength returns number of waiting threads
671       */
672      public void testGetWaitQueueLength() throws InterruptedException {
673 <        final Mutex sync = new Mutex();
673 >        final Mutex sync = new Mutex();
674          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
675 <        Thread t1 = new Thread(new CheckedRunnable() {
675 >        Thread t1 = new Thread(new CheckedRunnable() {
676              public void realRun() throws InterruptedException {
677                  sync.acquire(1);
678 <                threadAssertFalse(sync.hasWaiters(c));
679 <                threadAssertEquals(0, sync.getWaitQueueLength(c));
678 >                assertFalse(sync.hasWaiters(c));
679 >                assertEquals(0, sync.getWaitQueueLength(c));
680                  c.await();
681                  sync.release(1);
682              }});
683  
684 <        Thread t2 = new Thread(new CheckedRunnable() {
684 >        Thread t2 = new Thread(new CheckedRunnable() {
685              public void realRun() throws InterruptedException {
686                  sync.acquire(1);
687 <                threadAssertTrue(sync.hasWaiters(c));
688 <                threadAssertEquals(1, sync.getWaitQueueLength(c));
687 >                assertTrue(sync.hasWaiters(c));
688 >                assertEquals(1, sync.getWaitQueueLength(c));
689                  c.await();
690                  sync.release(1);
691              }});
# Line 708 | Line 714 | public class AbstractQueuedSynchronizerT
714       * getWaitingThreads returns only and all waiting threads
715       */
716      public void testGetWaitingThreads() throws InterruptedException {
717 <        final Mutex sync = new Mutex();
717 >        final Mutex sync = new Mutex();
718          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
719 <        Thread t1 = new Thread(new CheckedRunnable() {
719 >        Thread t1 = new Thread(new CheckedRunnable() {
720              public void realRun() throws InterruptedException {
721                  sync.acquire(1);
722 <                threadAssertTrue(sync.getWaitingThreads(c).isEmpty());
722 >                assertTrue(sync.getWaitingThreads(c).isEmpty());
723                  c.await();
724                  sync.release(1);
725              }});
726  
727 <        Thread t2 = new Thread(new CheckedRunnable() {
727 >        Thread t2 = new Thread(new CheckedRunnable() {
728              public void realRun() throws InterruptedException {
729                  sync.acquire(1);
730 <                threadAssertFalse(sync.getWaitingThreads(c).isEmpty());
730 >                assertFalse(sync.getWaitingThreads(c).isEmpty());
731                  c.await();
732                  sync.release(1);
733              }});
# Line 756 | Line 762 | public class AbstractQueuedSynchronizerT
762       * awaitUninterruptibly doesn't abort on interrupt
763       */
764      public void testAwaitUninterruptibly() throws InterruptedException {
765 <        final Mutex sync = new Mutex();
765 >        final Mutex sync = new Mutex();
766          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
767 <        Thread t = new Thread(new CheckedRunnable() {
767 >        Thread t = new Thread(new CheckedRunnable() {
768              public void realRun() {
769                  sync.acquire(1);
770                  c.awaitUninterruptibly();
# Line 779 | Line 785 | public class AbstractQueuedSynchronizerT
785       * await is interruptible
786       */
787      public void testAwait_Interrupt() throws InterruptedException {
788 <        final Mutex sync = new Mutex();
788 >        final Mutex sync = new Mutex();
789          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
790 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
791 <            public void realRun() throws InterruptedException {
790 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
791 >            public void realRun() throws InterruptedException {
792                  sync.acquire(1);
793                  c.await();
788                sync.release(1);
794              }});
795  
796          t.start();
# Line 799 | Line 804 | public class AbstractQueuedSynchronizerT
804       * awaitNanos is interruptible
805       */
806      public void testAwaitNanos_Interrupt() throws InterruptedException {
807 <        final Mutex sync = new Mutex();
807 >        final Mutex sync = new Mutex();
808          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
809 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
810 <            public void realRun() throws InterruptedException {
809 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
810 >            public void realRun() throws InterruptedException {
811                  sync.acquire(1);
812 <                c.awaitNanos(1000 * 1000 * 1000); // 1 sec
808 <                sync.release(1);
812 >                c.awaitNanos(MILLISECONDS.toNanos(LONG_DELAY_MS));
813              }});
814  
815          t.start();
# Line 819 | Line 823 | public class AbstractQueuedSynchronizerT
823       * awaitUntil is interruptible
824       */
825      public void testAwaitUntil_Interrupt() throws InterruptedException {
826 <        final Mutex sync = new Mutex();
826 >        final Mutex sync = new Mutex();
827          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
828 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
829 <            public void realRun() throws InterruptedException {
828 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
829 >            public void realRun() throws InterruptedException {
830                  sync.acquire(1);
831                  java.util.Date d = new java.util.Date();
832                  c.awaitUntil(new java.util.Date(d.getTime() + 10000));
829                sync.release(1);
833              }});
834  
835          t.start();
# Line 840 | Line 843 | public class AbstractQueuedSynchronizerT
843       * signalAll wakes up all threads
844       */
845      public void testSignalAll() throws InterruptedException {
846 <        final Mutex sync = new Mutex();
846 >        final Mutex sync = new Mutex();
847          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
848 <        Thread t1 = new Thread(new CheckedRunnable() {
848 >        Thread t1 = new Thread(new CheckedRunnable() {
849              public void realRun() throws InterruptedException {
850                  sync.acquire(1);
851                  c.await();
852                  sync.release(1);
853              }});
854  
855 <        Thread t2 = new Thread(new CheckedRunnable() {
855 >        Thread t2 = new Thread(new CheckedRunnable() {
856              public void realRun() throws InterruptedException {
857                  sync.acquire(1);
858                  c.await();
# Line 905 | Line 908 | public class AbstractQueuedSynchronizerT
908       * tryReleaseShared setting state changes getState
909       */
910      public void testGetStateWithReleaseShared() {
911 <        final BooleanLatch l = new BooleanLatch();
912 <        assertFalse(l.isSignalled());
913 <        l.releaseShared(0);
914 <        assertTrue(l.isSignalled());
911 >        final BooleanLatch l = new BooleanLatch();
912 >        assertFalse(l.isSignalled());
913 >        l.releaseShared(0);
914 >        assertTrue(l.isSignalled());
915      }
916  
917      /**
918       * releaseShared has no effect when already signalled
919       */
920      public void testReleaseShared() {
921 <        final BooleanLatch l = new BooleanLatch();
922 <        assertFalse(l.isSignalled());
923 <        l.releaseShared(0);
924 <        assertTrue(l.isSignalled());
925 <        l.releaseShared(0);
926 <        assertTrue(l.isSignalled());
921 >        final BooleanLatch l = new BooleanLatch();
922 >        assertFalse(l.isSignalled());
923 >        l.releaseShared(0);
924 >        assertTrue(l.isSignalled());
925 >        l.releaseShared(0);
926 >        assertTrue(l.isSignalled());
927      }
928  
929      /**
930       * acquireSharedInterruptibly returns after release, but not before
931       */
932      public void testAcquireSharedInterruptibly() throws InterruptedException {
933 <        final BooleanLatch l = new BooleanLatch();
933 >        final BooleanLatch l = new BooleanLatch();
934  
935 <        Thread t = new Thread(new CheckedRunnable() {
935 >        Thread t = new Thread(new CheckedRunnable() {
936              public void realRun() throws InterruptedException {
937 <                threadAssertFalse(l.isSignalled());
937 >                assertFalse(l.isSignalled());
938                  l.acquireSharedInterruptibly(0);
939 <                threadAssertTrue(l.isSignalled());
939 >                assertTrue(l.isSignalled());
940              }});
941  
942          t.start();
# Line 948 | Line 951 | public class AbstractQueuedSynchronizerT
951      /**
952       * acquireSharedTimed returns after release
953       */
954 <    public void testAsquireSharedTimed() throws InterruptedException {
955 <        final BooleanLatch l = new BooleanLatch();
954 >    public void testAcquireSharedTimed() throws InterruptedException {
955 >        final BooleanLatch l = new BooleanLatch();
956  
957 <        Thread t = new Thread(new CheckedRunnable() {
957 >        Thread t = new Thread(new CheckedRunnable() {
958              public void realRun() throws InterruptedException {
959 <                threadAssertFalse(l.isSignalled());
960 <                threadAssertTrue(l.tryAcquireSharedNanos(0, MEDIUM_DELAY_MS* 1000 * 1000));
961 <                threadAssertTrue(l.isSignalled());
959 >                assertFalse(l.isSignalled());
960 >                long nanos = MILLISECONDS.toNanos(MEDIUM_DELAY_MS);
961 >                assertTrue(l.tryAcquireSharedNanos(0, nanos));
962 >                assertTrue(l.isSignalled());
963              }});
964  
965          t.start();
# Line 971 | Line 975 | public class AbstractQueuedSynchronizerT
975       */
976      public void testAcquireSharedInterruptibly_InterruptedException() throws InterruptedException {
977          final BooleanLatch l = new BooleanLatch();
978 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
979 <            public void realRun() throws InterruptedException {
980 <                threadAssertFalse(l.isSignalled());
978 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
979 >            public void realRun() throws InterruptedException {
980 >                assertFalse(l.isSignalled());
981                  l.acquireSharedInterruptibly(0);
982              }});
983  
984 <        t.start();
984 >        t.start();
985          assertFalse(l.isSignalled());
986          t.interrupt();
987          t.join();
# Line 988 | Line 992 | public class AbstractQueuedSynchronizerT
992       */
993      public void testAcquireSharedNanos_InterruptedException() throws InterruptedException {
994          final BooleanLatch l = new BooleanLatch();
995 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
996 <            public void realRun() throws InterruptedException {
997 <                threadAssertFalse(l.isSignalled());
998 <                l.tryAcquireSharedNanos(0, SMALL_DELAY_MS* 1000 * 1000);
995 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
996 >            public void realRun() throws InterruptedException {
997 >                assertFalse(l.isSignalled());
998 >                long nanos = MILLISECONDS.toNanos(SMALL_DELAY_MS);
999 >                l.tryAcquireSharedNanos(0, nanos);
1000              }});
1001  
1002          t.start();
# Line 1006 | Line 1011 | public class AbstractQueuedSynchronizerT
1011       */
1012      public void testAcquireSharedNanos_Timeout() throws InterruptedException {
1013          final BooleanLatch l = new BooleanLatch();
1014 <        Thread t = new Thread(new CheckedRunnable() {
1014 >        Thread t = new Thread(new CheckedRunnable() {
1015              public void realRun() throws InterruptedException {
1016 <                threadAssertFalse(l.isSignalled());
1017 <                threadAssertFalse(l.tryAcquireSharedNanos(0, SMALL_DELAY_MS* 1000 * 1000));
1016 >                assertFalse(l.isSignalled());
1017 >                long nanos = MILLISECONDS.toNanos(SMALL_DELAY_MS);
1018 >                assertFalse(l.tryAcquireSharedNanos(0, nanos));
1019              }});
1020  
1021          t.start();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines