--- jsr166/src/test/tck/CyclicBarrierTest.java 2003/09/14 20:42:40 1.2 +++ jsr166/src/test/tck/CyclicBarrierTest.java 2003/09/20 18:20:07 1.3 @@ -10,36 +10,50 @@ import java.util.*; import java.util.concurrent.*; public class CyclicBarrierTest extends JSR166TestCase{ - public static void main(String[] args) { junit.textui.TestRunner.run (suite()); } - - public static Test suite() { return new TestSuite(CyclicBarrierTest.class); } + + private volatile int countAction; + private class MyAction implements Runnable { + public void run() { ++countAction; } + } - public void testConstructor1(){ - try{ + /** + * + */ + public void testConstructor1() { + try { new CyclicBarrier(-1, (Runnable)null); - fail("should throw"); + shouldThrow(); } catch(IllegalArgumentException e){} } - public void testConstructor2(){ - try{ + /** + * + */ + public void testConstructor2() { + try { new CyclicBarrier(-1); - fail("should throw"); + shouldThrow(); } catch(IllegalArgumentException e){} } - public void testConstructor3(){ + /** + * + */ + public void testConstructor3() { CyclicBarrier b = new CyclicBarrier(2); assertEquals(2, b.getParties()); assertEquals(0, b.getNumberWaiting()); } + /** + * + */ public void testSingleParty() { try { CyclicBarrier b = new CyclicBarrier(1); @@ -50,15 +64,13 @@ public class CyclicBarrierTest extends J assertEquals(0, b.getNumberWaiting()); } catch(Exception e) { - fail("unexpected exception"); + unexpectedException(); } } - private volatile int countAction; - private class MyAction implements Runnable { - public void run() { ++countAction; } - } - + /** + * + */ public void testBarrierAction() { try { countAction = 0; @@ -71,22 +83,25 @@ public class CyclicBarrierTest extends J assertEquals(countAction, 2); } catch(Exception e) { - fail("unexpected exception"); + unexpectedException(); } } - public void testTwoParties(){ + /** + * + */ + public void testTwoParties() { final CyclicBarrier b = new CyclicBarrier(2); Thread t = new Thread(new Runnable() { - public void run(){ + public void run() { try { b.await(); b.await(); b.await(); b.await(); } catch(Exception e){ - threadFail("unexpected exception"); + threadUnexpectedException(); }}}); try { @@ -97,29 +112,32 @@ public class CyclicBarrierTest extends J b.await(); t.join(); } catch(Exception e){ - fail("unexpected exception"); + unexpectedException(); } } - public void testAwait1_Interrupted_BrokenBarrier(){ + /** + * + */ + public void testAwait1_Interrupted_BrokenBarrier() { final CyclicBarrier c = new CyclicBarrier(3); Thread t1 = new Thread(new Runnable() { - public void run(){ - try{ + public void run() { + try { c.await(); - threadFail("should throw"); + threadShouldThrow(); } catch(InterruptedException success){} catch(Exception b){ threadFail("should throw IE"); } } }); - Thread t2 = new Thread(new Runnable(){ - public void run(){ - try{ + Thread t2 = new Thread(new Runnable() { + public void run() { + try { c.await(); - threadFail("should throw"); + threadShouldThrow(); } catch(BrokenBarrierException success){ } catch(Exception i){ threadFail("should throw BBE"); @@ -134,28 +152,31 @@ public class CyclicBarrierTest extends J t1.join(); t2.join(); } catch(InterruptedException e){ - fail("unexpected exception"); + unexpectedException(); } } - public void testAwait2_Interrupted_BrokenBarrier(){ + /** + * + */ + public void testAwait2_Interrupted_BrokenBarrier() { final CyclicBarrier c = new CyclicBarrier(3); Thread t1 = new Thread(new Runnable() { - public void run(){ - try{ + public void run() { + try { c.await(MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); - threadFail("should throw"); + threadShouldThrow(); } catch(InterruptedException success){ } catch(Exception b){ threadFail("should throw IE"); } } }); - Thread t2 = new Thread(new Runnable(){ - public void run(){ - try{ + Thread t2 = new Thread(new Runnable() { + public void run() { + try { c.await(MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); - threadFail("should throw"); + threadShouldThrow(); } catch(BrokenBarrierException success){ } catch(Exception i){ threadFail("should throw BBE"); @@ -170,17 +191,20 @@ public class CyclicBarrierTest extends J t1.join(); t2.join(); } catch(InterruptedException e){ - fail("unexpected exception"); + unexpectedException(); } } - public void testAwait3_TimeOutException(){ + /** + * + */ + public void testAwait3_TimeOutException() { final CyclicBarrier c = new CyclicBarrier(2); Thread t = new Thread(new Runnable() { - public void run(){ - try{ + public void run() { + try { c.await(SHORT_DELAY_MS, TimeUnit.MILLISECONDS); - threadFail("should throw"); + threadShouldThrow(); } catch(TimeoutException success){ } catch(Exception b){ threadFail("should throw TOE"); @@ -192,7 +216,7 @@ public class CyclicBarrierTest extends J t.start(); t.join(); } catch(InterruptedException e){ - fail("unexpected exception"); + unexpectedException(); } }