254 |
|
} |
255 |
|
|
256 |
|
/** |
257 |
< |
* timed tryAcquireExclusive is interruptible. |
257 |
> |
* acquireExclusiveNanos is interruptible. |
258 |
|
*/ |
259 |
|
public void testInterruptedException2() { |
260 |
|
final Mutex lock = new Mutex(); |
297 |
|
} |
298 |
|
|
299 |
|
/** |
300 |
< |
* acquireExclusiveTimed on a locked lock times out |
300 |
> |
* acquireExclusiveNanos on a locked lock times out |
301 |
|
*/ |
302 |
< |
public void testacquireExclusiveTimed_Timeout() { |
302 |
> |
public void testAcquireExclusiveNanos_Timeout() { |
303 |
|
final Mutex lock = new Mutex(); |
304 |
|
lock.acquireExclusiveUninterruptibly(1); |
305 |
|
Thread t = new Thread(new Runnable() { |
322 |
|
|
323 |
|
|
324 |
|
/** |
325 |
< |
* isLocked is true when locked and false when not |
325 |
> |
* getState is true when acquired and false when not |
326 |
|
*/ |
327 |
< |
public void testIsLocked() { |
327 |
> |
public void testGetState() { |
328 |
|
final Mutex lock = new Mutex(); |
329 |
|
lock.acquireExclusiveUninterruptibly(1); |
330 |
|
assertTrue(lock.isLocked()); |
520 |
|
} |
521 |
|
} |
522 |
|
|
523 |
+ |
/** |
524 |
+ |
* toString indicates current state |
525 |
+ |
*/ |
526 |
+ |
public void testToString() { |
527 |
+ |
Mutex lock = new Mutex(); |
528 |
+ |
String us = lock.toString(); |
529 |
+ |
assertTrue(us.indexOf("State = 0") >= 0); |
530 |
+ |
lock.acquireExclusiveUninterruptibly(1); |
531 |
+ |
String ls = lock.toString(); |
532 |
+ |
assertTrue(ls.indexOf("State = 1") >= 0); |
533 |
+ |
} |
534 |
+ |
|
535 |
+ |
/** |
536 |
+ |
* A serialized AQS deserializes with current state |
537 |
+ |
*/ |
538 |
+ |
public void testSerialization() { |
539 |
+ |
Mutex l = new Mutex(); |
540 |
+ |
l.acquireExclusiveUninterruptibly(1); |
541 |
+ |
assertTrue(l.isLocked()); |
542 |
+ |
|
543 |
+ |
try { |
544 |
+ |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
545 |
+ |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
546 |
+ |
out.writeObject(l); |
547 |
+ |
out.close(); |
548 |
+ |
|
549 |
+ |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
550 |
+ |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
551 |
+ |
Mutex r = (Mutex) in.readObject(); |
552 |
+ |
assertTrue(r.isLocked()); |
553 |
+ |
} catch(Exception e){ |
554 |
+ |
e.printStackTrace(); |
555 |
+ |
unexpectedException(); |
556 |
+ |
} |
557 |
+ |
} |
558 |
+ |
|
559 |
|
|
560 |
|
/** |
561 |
|
* Latch isSignalled initially returns false, then true after release |
570 |
|
/** |
571 |
|
* release and has no effect when already signalled |
572 |
|
*/ |
573 |
< |
public void testLatchBoolean() { |
573 |
> |
public void testReleaseShared() { |
574 |
|
final BooleanLatch l = new BooleanLatch(); |
575 |
|
assertFalse(l.isSignalled()); |
576 |
|
l.releaseShared(0); |
582 |
|
/** |
583 |
|
* acquireSharedInterruptibly returns after release, but not before |
584 |
|
*/ |
585 |
< |
public void testLatchAcquireSharedInterruptibly() { |
585 |
> |
public void testAcquireSharedInterruptibly() { |
586 |
|
final BooleanLatch l = new BooleanLatch(); |
587 |
|
|
588 |
|
Thread t = new Thread(new Runnable() { |
612 |
|
/** |
613 |
|
* acquireSharedTimed returns after release |
614 |
|
*/ |
615 |
< |
public void testLatchTimedacquireSharedInterruptibly() { |
615 |
> |
public void testAsquireSharedTimed() { |
616 |
|
final BooleanLatch l = new BooleanLatch(); |
617 |
|
|
618 |
|
Thread t = new Thread(new Runnable() { |
642 |
|
/** |
643 |
|
* acquireSharedInterruptibly throws IE if interrupted before released |
644 |
|
*/ |
645 |
< |
public void testLatchAcquireSharedInterruptibly_InterruptedException() { |
645 |
> |
public void testAcquireSharedInterruptibly_InterruptedException() { |
646 |
|
final BooleanLatch l = new BooleanLatch(); |
647 |
|
Thread t = new Thread(new Runnable() { |
648 |
|
public void run() { |
666 |
|
/** |
667 |
|
* acquireSharedTimed throws IE if interrupted before released |
668 |
|
*/ |
669 |
< |
public void testLatchTimedAwait_InterruptedException() { |
669 |
> |
public void testAcquireSharedNanos_InterruptedException() { |
670 |
|
final BooleanLatch l = new BooleanLatch(); |
671 |
|
Thread t = new Thread(new Runnable() { |
672 |
|
public void run() { |
691 |
|
/** |
692 |
|
* acquireSharedTimed times out if not released before timeout |
693 |
|
*/ |
694 |
< |
public void testLatchAwaitTimeout() { |
694 |
> |
public void testAcquireSharedNanos_Timeout() { |
695 |
|
final BooleanLatch l = new BooleanLatch(); |
696 |
|
Thread t = new Thread(new Runnable() { |
697 |
|
public void run() { |
712 |
|
unexpectedException(); |
713 |
|
} |
714 |
|
} |
715 |
+ |
|
716 |
|
|
717 |
|
} |