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 |
712 |
|
unexpectedException(); |
713 |
|
} |
714 |
|
} |
715 |
+ |
|
716 |
|
|
717 |
|
} |