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 |
|
|
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); |
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); |
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()); |
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(); |
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)); |
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()); |
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()); |
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()); |
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()); |
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()); |
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); |
333 |
|
}}); |
342 |
|
* TryAcquire on exclusively held sync fails |
343 |
|
*/ |
344 |
|
public void testTryAcquireWhenSynced() throws InterruptedException { |
345 |
< |
final Mutex sync = new Mutex(); |
346 |
< |
sync.acquire(1); |
347 |
< |
Thread t = new Thread(new CheckedRunnable() { |
345 |
> |
final Mutex sync = new Mutex(); |
346 |
> |
sync.acquire(1); |
347 |
> |
Thread t = new Thread(new CheckedRunnable() { |
348 |
|
public void realRun() { |
349 |
|
threadAssertFalse(sync.tryAcquire(1)); |
350 |
|
}}); |
358 |
|
* tryAcquireNanos on an exclusively held sync times out |
359 |
|
*/ |
360 |
|
public void testAcquireNanos_Timeout() throws InterruptedException { |
361 |
< |
final Mutex sync = new Mutex(); |
362 |
< |
sync.acquire(1); |
363 |
< |
Thread t = new Thread(new CheckedRunnable() { |
361 |
> |
final Mutex sync = new Mutex(); |
362 |
> |
sync.acquire(1); |
363 |
> |
Thread t = new Thread(new CheckedRunnable() { |
364 |
|
public void realRun() throws InterruptedException { |
365 |
|
threadAssertFalse(sync.tryAcquireNanos(1, 1000 * 1000)); |
366 |
|
}}); |
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); |
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 |
|
t.start(); |
406 |
|
Thread.sleep(SHORT_DELAY_MS); |
407 |
|
t.interrupt(); |
414 |
|
* acquireInterruptibly succeeds when released, else is interruptible |
415 |
|
*/ |
416 |
|
public void testAcquireInterruptibly2() throws InterruptedException { |
417 |
< |
final Mutex sync = new Mutex(); |
417 |
> |
final Mutex sync = new Mutex(); |
418 |
|
sync.acquireInterruptibly(1); |
419 |
< |
Thread t = new Thread(new InterruptedSyncRunnable(sync)); |
419 |
> |
Thread t = new Thread(new InterruptedSyncRunnable(sync)); |
420 |
|
t.start(); |
421 |
|
t.interrupt(); |
422 |
|
assertTrue(sync.isHeldExclusively()); |
427 |
|
* owns is true for a condition created by sync else false |
428 |
|
*/ |
429 |
|
public void testOwns() { |
430 |
< |
final Mutex sync = new Mutex(); |
430 |
> |
final Mutex sync = new Mutex(); |
431 |
|
final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); |
432 |
|
final Mutex sync2 = new Mutex(); |
433 |
|
assertTrue(sync.owns(c)); |
438 |
|
* Calling await without holding sync throws IllegalMonitorStateException |
439 |
|
*/ |
440 |
|
public void testAwait_IllegalMonitor() throws InterruptedException { |
441 |
< |
final Mutex sync = new Mutex(); |
441 |
> |
final Mutex sync = new Mutex(); |
442 |
|
final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); |
443 |
|
try { |
444 |
|
c.await(); |
450 |
|
* Calling signal without holding sync throws IllegalMonitorStateException |
451 |
|
*/ |
452 |
|
public void testSignal_IllegalMonitor() throws InterruptedException { |
453 |
< |
final Mutex sync = new Mutex(); |
453 |
> |
final Mutex sync = new Mutex(); |
454 |
|
final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); |
455 |
|
try { |
456 |
|
c.signal(); |
462 |
|
* awaitNanos without a signal times out |
463 |
|
*/ |
464 |
|
public void testAwaitNanos_Timeout() throws InterruptedException { |
465 |
< |
final Mutex sync = new Mutex(); |
465 |
> |
final Mutex sync = new Mutex(); |
466 |
|
final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); |
467 |
|
sync.acquire(1); |
468 |
|
long t = c.awaitNanos(100); |
474 |
|
* Timed await without a signal times out |
475 |
|
*/ |
476 |
|
public void testAwait_Timeout() throws InterruptedException { |
477 |
< |
final Mutex sync = new Mutex(); |
477 |
> |
final Mutex sync = new Mutex(); |
478 |
|
final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); |
479 |
|
sync.acquire(1); |
480 |
|
assertFalse(c.await(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
485 |
|
* awaitUntil without a signal times out |
486 |
|
*/ |
487 |
|
public void testAwaitUntil_Timeout() throws InterruptedException { |
488 |
< |
final Mutex sync = new Mutex(); |
488 |
> |
final Mutex sync = new Mutex(); |
489 |
|
final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); |
490 |
|
sync.acquire(1); |
491 |
|
java.util.Date d = new java.util.Date(); |
497 |
|
* await returns when signalled |
498 |
|
*/ |
499 |
|
public void testAwait() throws InterruptedException { |
500 |
< |
final Mutex sync = new Mutex(); |
500 |
> |
final Mutex sync = new Mutex(); |
501 |
|
final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); |
502 |
< |
Thread t = new Thread(new CheckedRunnable() { |
502 |
> |
Thread t = new Thread(new CheckedRunnable() { |
503 |
|
public void realRun() throws InterruptedException { |
504 |
|
sync.acquire(1); |
505 |
|
c.await(); |
521 |
|
* hasWaiters throws NPE if null |
522 |
|
*/ |
523 |
|
public void testHasWaitersNPE() { |
524 |
< |
final Mutex sync = new Mutex(); |
524 |
> |
final Mutex sync = new Mutex(); |
525 |
|
try { |
526 |
|
sync.hasWaiters(null); |
527 |
|
shouldThrow(); |
532 |
|
* getWaitQueueLength throws NPE if null |
533 |
|
*/ |
534 |
|
public void testGetWaitQueueLengthNPE() { |
535 |
< |
final Mutex sync = new Mutex(); |
535 |
> |
final Mutex sync = new Mutex(); |
536 |
|
try { |
537 |
|
sync.getWaitQueueLength(null); |
538 |
|
shouldThrow(); |
544 |
|
* getWaitingThreads throws NPE if null |
545 |
|
*/ |
546 |
|
public void testGetWaitingThreadsNPE() { |
547 |
< |
final Mutex sync = new Mutex(); |
547 |
> |
final Mutex sync = new Mutex(); |
548 |
|
try { |
549 |
|
sync.getWaitingThreads(null); |
550 |
|
shouldThrow(); |
556 |
|
* hasWaiters throws IAE if not owned |
557 |
|
*/ |
558 |
|
public void testHasWaitersIAE() { |
559 |
< |
final Mutex sync = new Mutex(); |
559 |
> |
final Mutex sync = new Mutex(); |
560 |
|
final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); |
561 |
< |
final Mutex sync2 = new Mutex(); |
561 |
> |
final Mutex sync2 = new Mutex(); |
562 |
|
try { |
563 |
|
sync2.hasWaiters(c); |
564 |
|
shouldThrow(); |
569 |
|
* hasWaiters throws IMSE if not synced |
570 |
|
*/ |
571 |
|
public void testHasWaitersIMSE() { |
572 |
< |
final Mutex sync = new Mutex(); |
572 |
> |
final Mutex sync = new Mutex(); |
573 |
|
final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); |
574 |
|
try { |
575 |
|
sync.hasWaiters(c); |
582 |
|
* getWaitQueueLength throws IAE if not owned |
583 |
|
*/ |
584 |
|
public void testGetWaitQueueLengthIAE() { |
585 |
< |
final Mutex sync = new Mutex(); |
585 |
> |
final Mutex sync = new Mutex(); |
586 |
|
final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); |
587 |
< |
final Mutex sync2 = new Mutex(); |
587 |
> |
final Mutex sync2 = new Mutex(); |
588 |
|
try { |
589 |
|
sync2.getWaitQueueLength(c); |
590 |
|
shouldThrow(); |
595 |
|
* getWaitQueueLength throws IMSE if not synced |
596 |
|
*/ |
597 |
|
public void testGetWaitQueueLengthIMSE() { |
598 |
< |
final Mutex sync = new Mutex(); |
598 |
> |
final Mutex sync = new Mutex(); |
599 |
|
final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); |
600 |
|
try { |
601 |
|
sync.getWaitQueueLength(c); |
608 |
|
* getWaitingThreads throws IAE if not owned |
609 |
|
*/ |
610 |
|
public void testGetWaitingThreadsIAE() { |
611 |
< |
final Mutex sync = new Mutex(); |
611 |
> |
final Mutex sync = new Mutex(); |
612 |
|
final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); |
613 |
< |
final Mutex sync2 = new Mutex(); |
613 |
> |
final Mutex sync2 = new Mutex(); |
614 |
|
try { |
615 |
|
sync2.getWaitingThreads(c); |
616 |
|
shouldThrow(); |
621 |
|
* getWaitingThreads throws IMSE if not synced |
622 |
|
*/ |
623 |
|
public void testGetWaitingThreadsIMSE() { |
624 |
< |
final Mutex sync = new Mutex(); |
624 |
> |
final Mutex sync = new Mutex(); |
625 |
|
final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); |
626 |
|
try { |
627 |
|
sync.getWaitingThreads(c); |
635 |
|
* hasWaiters returns true when a thread is waiting, else false |
636 |
|
*/ |
637 |
|
public void testHasWaiters() throws InterruptedException { |
638 |
< |
final Mutex sync = new Mutex(); |
638 |
> |
final Mutex sync = new Mutex(); |
639 |
|
final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); |
640 |
< |
Thread t = new Thread(new CheckedRunnable() { |
640 |
> |
Thread t = new Thread(new CheckedRunnable() { |
641 |
|
public void realRun() throws InterruptedException { |
642 |
|
sync.acquire(1); |
643 |
|
threadAssertFalse(sync.hasWaiters(c)); |
666 |
|
* getWaitQueueLength returns number of waiting threads |
667 |
|
*/ |
668 |
|
public void testGetWaitQueueLength() throws InterruptedException { |
669 |
< |
final Mutex sync = new Mutex(); |
669 |
> |
final Mutex sync = new Mutex(); |
670 |
|
final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); |
671 |
< |
Thread t1 = new Thread(new CheckedRunnable() { |
671 |
> |
Thread t1 = new Thread(new CheckedRunnable() { |
672 |
|
public void realRun() throws InterruptedException { |
673 |
|
sync.acquire(1); |
674 |
|
threadAssertFalse(sync.hasWaiters(c)); |
677 |
|
sync.release(1); |
678 |
|
}}); |
679 |
|
|
680 |
< |
Thread t2 = new Thread(new CheckedRunnable() { |
680 |
> |
Thread t2 = new Thread(new CheckedRunnable() { |
681 |
|
public void realRun() throws InterruptedException { |
682 |
|
sync.acquire(1); |
683 |
|
threadAssertTrue(sync.hasWaiters(c)); |
710 |
|
* getWaitingThreads returns only and all waiting threads |
711 |
|
*/ |
712 |
|
public void testGetWaitingThreads() throws InterruptedException { |
713 |
< |
final Mutex sync = new Mutex(); |
713 |
> |
final Mutex sync = new Mutex(); |
714 |
|
final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); |
715 |
< |
Thread t1 = new Thread(new CheckedRunnable() { |
715 |
> |
Thread t1 = new Thread(new CheckedRunnable() { |
716 |
|
public void realRun() throws InterruptedException { |
717 |
|
sync.acquire(1); |
718 |
|
threadAssertTrue(sync.getWaitingThreads(c).isEmpty()); |
720 |
|
sync.release(1); |
721 |
|
}}); |
722 |
|
|
723 |
< |
Thread t2 = new Thread(new CheckedRunnable() { |
723 |
> |
Thread t2 = new Thread(new CheckedRunnable() { |
724 |
|
public void realRun() throws InterruptedException { |
725 |
|
sync.acquire(1); |
726 |
|
threadAssertFalse(sync.getWaitingThreads(c).isEmpty()); |
758 |
|
* awaitUninterruptibly doesn't abort on interrupt |
759 |
|
*/ |
760 |
|
public void testAwaitUninterruptibly() throws InterruptedException { |
761 |
< |
final Mutex sync = new Mutex(); |
761 |
> |
final Mutex sync = new Mutex(); |
762 |
|
final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); |
763 |
< |
Thread t = new Thread(new CheckedRunnable() { |
763 |
> |
Thread t = new Thread(new CheckedRunnable() { |
764 |
|
public void realRun() { |
765 |
|
sync.acquire(1); |
766 |
|
c.awaitUninterruptibly(); |
781 |
|
* await is interruptible |
782 |
|
*/ |
783 |
|
public void testAwait_Interrupt() throws InterruptedException { |
784 |
< |
final Mutex sync = new Mutex(); |
784 |
> |
final Mutex sync = new Mutex(); |
785 |
|
final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); |
786 |
< |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
787 |
< |
public void realRun() throws InterruptedException { |
786 |
> |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
787 |
> |
public void realRun() throws InterruptedException { |
788 |
|
sync.acquire(1); |
789 |
|
c.await(); |
790 |
|
sync.release(1); |
801 |
|
* awaitNanos is interruptible |
802 |
|
*/ |
803 |
|
public void testAwaitNanos_Interrupt() throws InterruptedException { |
804 |
< |
final Mutex sync = new Mutex(); |
804 |
> |
final Mutex sync = new Mutex(); |
805 |
|
final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); |
806 |
< |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
807 |
< |
public void realRun() throws InterruptedException { |
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); |
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 AbstractQueuedLongSynchronizer.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)); |
842 |
|
* signalAll wakes up all threads |
843 |
|
*/ |
844 |
|
public void testSignalAll() throws InterruptedException { |
845 |
< |
final Mutex sync = new Mutex(); |
845 |
> |
final Mutex sync = new Mutex(); |
846 |
|
final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); |
847 |
< |
Thread t1 = new Thread(new CheckedRunnable() { |
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() { |
854 |
> |
Thread t2 = new Thread(new CheckedRunnable() { |
855 |
|
public void realRun() throws InterruptedException { |
856 |
|
sync.acquire(1); |
857 |
|
c.await(); |
907 |
|
* tryReleaseShared setting state changes getState |
908 |
|
*/ |
909 |
|
public void testGetStateWithReleaseShared() { |
910 |
< |
final BooleanLatch l = new BooleanLatch(); |
911 |
< |
assertFalse(l.isSignalled()); |
912 |
< |
l.releaseShared(0); |
913 |
< |
assertTrue(l.isSignalled()); |
910 |
> |
final BooleanLatch l = new BooleanLatch(); |
911 |
> |
assertFalse(l.isSignalled()); |
912 |
> |
l.releaseShared(0); |
913 |
> |
assertTrue(l.isSignalled()); |
914 |
|
} |
915 |
|
|
916 |
|
/** |
917 |
|
* releaseShared has no effect when already signalled |
918 |
|
*/ |
919 |
|
public void testReleaseShared() { |
920 |
< |
final BooleanLatch l = new BooleanLatch(); |
921 |
< |
assertFalse(l.isSignalled()); |
922 |
< |
l.releaseShared(0); |
923 |
< |
assertTrue(l.isSignalled()); |
924 |
< |
l.releaseShared(0); |
925 |
< |
assertTrue(l.isSignalled()); |
920 |
> |
final BooleanLatch l = new BooleanLatch(); |
921 |
> |
assertFalse(l.isSignalled()); |
922 |
> |
l.releaseShared(0); |
923 |
> |
assertTrue(l.isSignalled()); |
924 |
> |
l.releaseShared(0); |
925 |
> |
assertTrue(l.isSignalled()); |
926 |
|
} |
927 |
|
|
928 |
|
/** |
929 |
|
* acquireSharedInterruptibly returns after release, but not before |
930 |
|
*/ |
931 |
|
public void testAcquireSharedInterruptibly() throws InterruptedException { |
932 |
< |
final BooleanLatch l = new BooleanLatch(); |
932 |
> |
final BooleanLatch l = new BooleanLatch(); |
933 |
|
|
934 |
< |
Thread t = new Thread(new CheckedRunnable() { |
934 |
> |
Thread t = new Thread(new CheckedRunnable() { |
935 |
|
public void realRun() throws InterruptedException { |
936 |
|
threadAssertFalse(l.isSignalled()); |
937 |
|
l.acquireSharedInterruptibly(0); |
951 |
|
* acquireSharedTimed returns after release |
952 |
|
*/ |
953 |
|
public void testAsquireSharedTimed() throws InterruptedException { |
954 |
< |
final BooleanLatch l = new BooleanLatch(); |
954 |
> |
final BooleanLatch l = new BooleanLatch(); |
955 |
|
|
956 |
< |
Thread t = new Thread(new CheckedRunnable() { |
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)); |
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(); |
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 { |
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 |
|
}}); |
1008 |
|
*/ |
1009 |
|
public void testAcquireSharedNanos_Timeout() throws InterruptedException { |
1010 |
|
final BooleanLatch l = new BooleanLatch(); |
1011 |
< |
Thread t = new Thread(new CheckedRunnable() { |
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)); |