ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/CyclicBarrierTest.java
(Generate patch)

Comparing jsr166/src/test/tck/CyclicBarrierTest.java (file contents):
Revision 1.15 by jsr166, Wed Aug 25 00:07:03 2010 UTC vs.
Revision 1.20 by jsr166, Fri May 27 20:07:24 2011 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   * Other contributors include Andrew Wright, Jeffrey Hayes,
6   * Pat Fisher, Mike Judd.
7   */
# Line 102 | Line 102 | public class CyclicBarrierTest extends J
102          t.join();
103      }
104  
105
105      /**
106       * An interruption in one party causes others waiting in await to
107       * throw BrokenBarrierException
# Line 120 | Line 119 | public class CyclicBarrierTest extends J
119  
120          t1.start();
121          t2.start();
122 <        Thread.sleep(SHORT_DELAY_MS);
122 >        delay(SHORT_DELAY_MS);
123          t1.interrupt();
124          t1.join();
125          t2.join();
# Line 143 | Line 142 | public class CyclicBarrierTest extends J
142  
143          t1.start();
144          t2.start();
145 <        Thread.sleep(SHORT_DELAY_MS);
145 >        delay(SHORT_DELAY_MS);
146          t1.interrupt();
147          t1.join();
148          t2.join();
# Line 152 | Line 151 | public class CyclicBarrierTest extends J
151      /**
152       * A timeout in timed await throws TimeoutException
153       */
154 <    public void testAwait3_TimeOutException() throws InterruptedException {
154 >    public void testAwait3_TimeoutException() throws InterruptedException {
155          final CyclicBarrier c = new CyclicBarrier(2);
156          Thread t = new ThreadShouldThrow(TimeoutException.class) {
157              public void realRun() throws Exception {
# Line 222 | Line 221 | public class CyclicBarrierTest extends J
221  
222          t1.start();
223          t2.start();
224 <        Thread.sleep(SHORT_DELAY_MS);
224 >        delay(SHORT_DELAY_MS);
225          c.reset();
226          t1.join();
227          t2.join();
# Line 257 | Line 256 | public class CyclicBarrierTest extends J
256      public void testReset_Leakage() throws InterruptedException {
257          final CyclicBarrier c = new CyclicBarrier(2);
258          final AtomicBoolean done = new AtomicBoolean();
259 <        Thread t = new Thread() {
260 <                public void run() {
261 <                    while (!done.get()) {
262 <                        try {
263 <                            while (c.isBroken())
264 <                                c.reset();
265 <
266 <                            c.await();
267 <                            threadFail("await should not return");
269 <                        }
270 <                        catch (BrokenBarrierException e) {
271 <                        }
272 <                        catch (InterruptedException ie) {
273 <                        }
259 >        Thread t = new Thread(new CheckedRunnable() {
260 >            public void realRun() {
261 >                while (!done.get()) {
262 >                    try {
263 >                        while (c.isBroken())
264 >                            c.reset();
265 >
266 >                        c.await();
267 >                        shouldThrow();
268                      }
269 <                }
270 <            };
269 >                    catch (BrokenBarrierException ok) {}
270 >                    catch (InterruptedException ok) {}
271 >                }}});
272  
273          t.start();
274          for (int i = 0; i < 4; i++) {
275 <            Thread.sleep(SHORT_DELAY_MS);
275 >            delay(timeoutMillis());
276              t.interrupt();
277          }
278          done.set(true);
279          t.interrupt();
280 <        t.join();
280 >        awaitTermination(t);
281      }
282  
283      /**
# Line 355 | Line 350 | public class CyclicBarrierTest extends J
350       * Reset of a barrier after timeout reinitializes it.
351       */
352      public void testResetAfterTimeout() throws Exception {
353 <        final CyclicBarrier start = new CyclicBarrier(3);
353 >        final CyclicBarrier start = new CyclicBarrier(2);
354          final CyclicBarrier barrier = new CyclicBarrier(3);
355          for (int i = 0; i < 2; i++) {
356              Thread t1 = new ThreadShouldThrow(TimeoutException.class) {
357                      public void realRun() throws Exception {
358                          start.await();
359 <                        barrier.await(MEDIUM_DELAY_MS, MILLISECONDS);
359 >                        barrier.await(SHORT_DELAY_MS, MILLISECONDS);
360                      }};
361  
362              Thread t2 = new ThreadShouldThrow(BrokenBarrierException.class) {
# Line 372 | Line 367 | public class CyclicBarrierTest extends J
367  
368              t1.start();
369              t2.start();
375            start.await();
370              t1.join();
371              t2.join();
372              assertTrue(barrier.isBroken());
# Line 383 | Line 377 | public class CyclicBarrierTest extends J
377          }
378      }
379  
386
380      /**
381       * Reset of a barrier after a failed command reinitializes it.
382       */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines