--- jsr166/src/test/tck/AbstractQueuedSynchronizerTest.java 2004/01/09 14:45:58 1.12 +++ jsr166/src/test/tck/AbstractQueuedSynchronizerTest.java 2004/01/10 01:41:59 1.14 @@ -254,7 +254,7 @@ public class AbstractQueuedSynchronizerT } /** - * timed tryAcquireExclusive is interruptible. + * acquireExclusiveNanos is interruptible. */ public void testInterruptedException2() { final Mutex lock = new Mutex(); @@ -297,9 +297,9 @@ public class AbstractQueuedSynchronizerT } /** - * acquireExclusiveTimed on a locked lock times out + * acquireExclusiveNanos on a locked lock times out */ - public void testacquireExclusiveTimed_Timeout() { + public void testAcquireExclusiveNanos_Timeout() { final Mutex lock = new Mutex(); lock.acquireExclusiveUninterruptibly(1); Thread t = new Thread(new Runnable() { @@ -322,9 +322,9 @@ public class AbstractQueuedSynchronizerT /** - * isLocked is true when locked and false when not + * getState is true when acquired and false when not */ - public void testIsLocked() { + public void testGetState() { final Mutex lock = new Mutex(); lock.acquireExclusiveUninterruptibly(1); assertTrue(lock.isLocked()); @@ -520,6 +520,42 @@ public class AbstractQueuedSynchronizerT } } + /** + * toString indicates current state + */ + public void testToString() { + Mutex lock = new Mutex(); + String us = lock.toString(); + assertTrue(us.indexOf("State = 0") >= 0); + lock.acquireExclusiveUninterruptibly(1); + String ls = lock.toString(); + assertTrue(ls.indexOf("State = 1") >= 0); + } + + /** + * A serialized AQS deserializes with current state + */ + public void testSerialization() { + Mutex l = new Mutex(); + l.acquireExclusiveUninterruptibly(1); + assertTrue(l.isLocked()); + + try { + ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); + ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); + out.writeObject(l); + out.close(); + + ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); + ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); + Mutex r = (Mutex) in.readObject(); + assertTrue(r.isLocked()); + } catch(Exception e){ + e.printStackTrace(); + unexpectedException(); + } + } + /** * Latch isSignalled initially returns false, then true after release @@ -534,7 +570,7 @@ public class AbstractQueuedSynchronizerT /** * release and has no effect when already signalled */ - public void testLatchBoolean() { + public void testReleaseShared() { final BooleanLatch l = new BooleanLatch(); assertFalse(l.isSignalled()); l.releaseShared(0); @@ -546,7 +582,7 @@ public class AbstractQueuedSynchronizerT /** * acquireSharedInterruptibly returns after release, but not before */ - public void testLatchAcquireSharedInterruptibly() { + public void testAcquireSharedInterruptibly() { final BooleanLatch l = new BooleanLatch(); Thread t = new Thread(new Runnable() { @@ -576,7 +612,7 @@ public class AbstractQueuedSynchronizerT /** * acquireSharedTimed returns after release */ - public void testLatchTimedacquireSharedInterruptibly() { + public void testAsquireSharedTimed() { final BooleanLatch l = new BooleanLatch(); Thread t = new Thread(new Runnable() { @@ -606,7 +642,7 @@ public class AbstractQueuedSynchronizerT /** * acquireSharedInterruptibly throws IE if interrupted before released */ - public void testLatchAcquireSharedInterruptibly_InterruptedException() { + public void testAcquireSharedInterruptibly_InterruptedException() { final BooleanLatch l = new BooleanLatch(); Thread t = new Thread(new Runnable() { public void run() { @@ -630,7 +666,7 @@ public class AbstractQueuedSynchronizerT /** * acquireSharedTimed throws IE if interrupted before released */ - public void testLatchTimedAwait_InterruptedException() { + public void testAcquireSharedNanos_InterruptedException() { final BooleanLatch l = new BooleanLatch(); Thread t = new Thread(new Runnable() { public void run() { @@ -655,7 +691,7 @@ public class AbstractQueuedSynchronizerT /** * acquireSharedTimed times out if not released before timeout */ - public void testLatchAwaitTimeout() { + public void testAcquireSharedNanos_Timeout() { final BooleanLatch l = new BooleanLatch(); Thread t = new Thread(new Runnable() { public void run() { @@ -676,5 +712,6 @@ public class AbstractQueuedSynchronizerT unexpectedException(); } } + }