--- jsr166/src/test/tck/LockSupportTest.java 2009/11/16 04:57:10 1.9 +++ jsr166/src/test/tck/LockSupportTest.java 2009/11/21 02:07:27 1.12 @@ -11,156 +11,102 @@ import java.util.*; import java.util.concurrent.*; import java.util.concurrent.locks.*; -public class LockSupportTest extends JSR166TestCase{ +public class LockSupportTest extends JSR166TestCase { public static void main(String[] args) { - junit.textui.TestRunner.run (suite()); + junit.textui.TestRunner.run (suite()); } public static Test suite() { - return new TestSuite(LockSupportTest.class); + return new TestSuite(LockSupportTest.class); } /** * park is released by unpark occurring after park */ - public void testPark() { - Thread t = new Thread(new Runnable() { - public void run() { - try { - LockSupport.park(); - } catch (Exception e){ - threadUnexpectedException(); - } - } - }); - try { - t.start(); - Thread.sleep(SHORT_DELAY_MS); - LockSupport.unpark(t); - t.join(); - } - catch (Exception e) { - unexpectedException(); - } + public void testPark() throws InterruptedException { + Thread t = new Thread(new CheckedRunnable() { + public void realRun() { + LockSupport.park(); + }}); + + t.start(); + Thread.sleep(SHORT_DELAY_MS); + LockSupport.unpark(t); + t.join(); } /** * park is released by unpark occurring 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(); - } + public void testPark2() throws InterruptedException { + Thread t = new Thread(new CheckedRunnable() { + public void realRun() throws InterruptedException { + Thread.sleep(SHORT_DELAY_MS); + LockSupport.park(); + }}); + + t.start(); + LockSupport.unpark(t); + t.join(); } /** * park is released by interrupt */ - public void testPark3() { - Thread t = new Thread(new Runnable() { - public void run() { - try { - LockSupport.park(); - } catch (Exception e){ - threadUnexpectedException(); - } - } - }); - try { - t.start(); - Thread.sleep(SHORT_DELAY_MS); - t.interrupt(); - t.join(); - } - catch (Exception e) { - unexpectedException(); - } + public void testPark3() throws InterruptedException { + Thread t = new Thread(new CheckedRunnable() { + public void realRun() { + LockSupport.park(); + }}); + + t.start(); + Thread.sleep(SHORT_DELAY_MS); + t.interrupt(); + t.join(); } /** * park returns if interrupted before park */ - public void testPark4() { + public void testPark4() throws InterruptedException { 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(); - } + Thread t = new Thread(new CheckedRunnable() { + public void realRun() { + lock.lock(); + LockSupport.park(); + }}); + + t.start(); + t.interrupt(); + lock.unlock(); + t.join(); } /** * parkNanos times out if not unparked */ - public void testParkNanos() { - Thread t = new Thread(new Runnable() { - public void run() { - try { - LockSupport.parkNanos(1000); - } catch (Exception e){ - threadUnexpectedException(); - } - } - }); - try { - t.start(); - t.join(); - } - catch (Exception e) { - unexpectedException(); - } + public void testParkNanos() throws InterruptedException { + Thread t = new Thread(new CheckedRunnable() { + public void realRun() { + LockSupport.parkNanos(1000); + }}); + + t.start(); + t.join(); } /** * parkUntil times out if not unparked */ - public void testParkUntil() { - Thread t = new Thread(new Runnable() { - public void run() { - try { - long d = new Date().getTime() + 100; - LockSupport.parkUntil(d); - } catch (Exception e){ - threadUnexpectedException(); - } - } - }); - try { - t.start(); - t.join(); - } - catch (Exception e) { - unexpectedException(); - } + public void testParkUntil() throws InterruptedException { + Thread t = new Thread(new CheckedRunnable() { + public void realRun() { + long d = new Date().getTime() + 100; + LockSupport.parkUntil(d); + }}); + + t.start(); + t.join(); } }