--- jsr166/src/test/tck/LockSupportTest.java 2003/09/20 18:20:08 1.3 +++ jsr166/src/test/tck/LockSupportTest.java 2003/09/25 11:02:41 1.4 @@ -19,9 +19,9 @@ public class LockSupportTest extends JSR } /** - * + * park is released by unpark occuring after park */ - public void testUnpark() { + public void testPark() { Thread t = new Thread(new Runnable() { public void run() { try { @@ -31,8 +31,9 @@ public class LockSupportTest extends JSR } } }); - t.start(); try { + t.start(); + Thread.sleep(SHORT_DELAY_MS); LockSupport.unpark(t); t.join(); } @@ -42,7 +43,83 @@ public class LockSupportTest extends JSR } /** - * + * park is released by unpark occuring before park + */ + public void testPark2() { + Thread t = new Thread(new Runnable() { + public void run() { + try { + Thread.sleep(SHORT_DELAY_MS); + LockSupport.park(); + } catch(Exception e){ + threadUnexpectedException(); + } + } + }); + try { + t.start(); + LockSupport.unpark(t); + t.join(); + } + catch(Exception e) { + unexpectedException(); + } + } + + /** + * park is released by interrupt + */ + public void testPark3() { + Thread t = new Thread(new Runnable() { + public void run() { + try { + LockSupport.park(); + threadAssertTrue(Thread.interrupted()); + } catch(Exception e){ + threadUnexpectedException(); + } + } + }); + try { + t.start(); + Thread.sleep(SHORT_DELAY_MS); + t.interrupt(); + t.join(); + } + catch(Exception e) { + unexpectedException(); + } + } + + /** + * park returns if interrupted before park + */ + public void testPark4() { + final ReentrantLock lock = new ReentrantLock(); + lock.lock(); + Thread t = new Thread(new Runnable() { + public void run() { + try { + lock.lock(); + LockSupport.park(); + } catch(Exception e){ + threadUnexpectedException(); + } + } + }); + try { + t.start(); + t.interrupt(); + lock.unlock(); + t.join(); + } + catch(Exception e) { + unexpectedException(); + } + } + + /** + * parkNanos times out if not unparked */ public void testParkNanos() { Thread t = new Thread(new Runnable() { @@ -65,7 +142,7 @@ public class LockSupportTest extends JSR /** - * + * parkUntil times out if not unparked */ public void testParkUntil() { Thread t = new Thread(new Runnable() {