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

Comparing jsr166/src/test/tck/RecursiveActionTest.java (file contents):
Revision 1.24 by jsr166, Mon Nov 22 20:19:47 2010 UTC vs.
Revision 1.26 by jsr166, Tue Nov 23 07:38:40 2010 UTC

# Line 6 | Line 6
6  
7   import junit.framework.*;
8   import java.util.concurrent.CancellationException;
9 + import java.util.concurrent.SynchronousQueue;
10   import java.util.concurrent.ExecutionException;
11   import java.util.concurrent.ForkJoinPool;
12   import java.util.concurrent.ForkJoinWorkerThread;
# Line 247 | Line 248 | public class RecursiveActionTest extends
248      }
249  
250      /**
251 <     * join/quietlyJoin of a forked task ignores interrupts
251 >     * join/quietlyJoin of a forked task succeeds in the presence of interrupts
252       */
253      public void testJoinIgnoresInterrupts() {
254          RecursiveAction a = new CheckedRecursiveAction() {
# Line 258 | Line 259 | public class RecursiveActionTest extends
259                  assertSame(f, f.fork());
260                  Thread.currentThread().interrupt();
261                  assertNull(f.join());
262 <                assertTrue(Thread.interrupted());
262 >                Thread.interrupted();
263                  assertEquals(21, f.result);
264                  checkCompletedNormally(f);
265  
# Line 270 | Line 271 | public class RecursiveActionTest extends
271                      f.join();
272                      shouldThrow();
273                  } catch (CancellationException success) {
274 <                    assertTrue(Thread.interrupted());
274 >                    Thread.interrupted();
275                      checkCancelled(f);
276                  }
277  
# Line 282 | Line 283 | public class RecursiveActionTest extends
283                      f.join();
284                      shouldThrow();
285                  } catch (FJException success) {
286 <                    assertTrue(Thread.interrupted());
286 >                    Thread.interrupted();
287                      checkCompletedAbnormally(f, success);
288                  }
289  
# Line 291 | Line 292 | public class RecursiveActionTest extends
292                  assertSame(f, f.fork());
293                  Thread.currentThread().interrupt();
294                  f.quietlyJoin();
295 <                assertTrue(Thread.interrupted());
295 >                Thread.interrupted();
296                  assertEquals(21, f.result);
297                  checkCompletedNormally(f);
298  
# Line 300 | Line 301 | public class RecursiveActionTest extends
301                  assertSame(f, f.fork());
302                  Thread.currentThread().interrupt();
303                  f.quietlyJoin();
304 <                assertTrue(Thread.interrupted());
304 >                Thread.interrupted();
305                  checkCancelled(f);
306  
307                  f.reinitialize();
# Line 308 | Line 309 | public class RecursiveActionTest extends
309                  assertSame(f, f.fork());
310                  Thread.currentThread().interrupt();
311                  f.quietlyJoin();
312 +                Thread.interrupted();
313 +                checkCompletedAbnormally(f, f.getException());
314 +            }};
315 +        testInvokeOnPool(mainPool(), a);
316 +        a.reinitialize();
317 +        testInvokeOnPool(singletonPool(), a);
318 +    }
319 +
320 +    /**
321 +     * join/quietlyJoin of a forked task when not in ForkJoinPool
322 +     * succeeds in the presence of interrupts
323 +     */
324 +    public void testJoinIgnoresInterruptsOutsideForkJoinPool() {
325 +        final SynchronousQueue<FibAction[]> sq =
326 +            new SynchronousQueue<FibAction[]>();
327 +        RecursiveAction a = new CheckedRecursiveAction() {
328 +            public void realCompute() throws InterruptedException {
329 +                FibAction[] fibActions = new FibAction[6];
330 +                for (int i = 0; i < fibActions.length; i++)
331 +                    fibActions[i] = new FibAction(8);
332 +
333 +                fibActions[1].cancel(false);
334 +                fibActions[2].completeExceptionally(new FJException());
335 +                fibActions[4].cancel(true);
336 +                fibActions[5].completeExceptionally(new FJException());
337 +
338 +                for (int i = 0; i < fibActions.length; i++)
339 +                    fibActions[i].fork();
340 +
341 +                sq.put(fibActions);
342 +
343 +                helpQuiesce();
344 +            }};
345 +
346 +        Runnable r = new CheckedRunnable() {
347 +            public void realRun() throws InterruptedException {
348 +                FibAction[] fibActions = sq.take();
349 +                FibAction f;
350 +
351 +                // test join() ------------
352 +
353 +                f = fibActions[0];
354 +                assertFalse(f.inForkJoinPool());
355 +                Thread.currentThread().interrupt();
356 +                assertNull(f.join());
357                  assertTrue(Thread.interrupted());
358 +                assertEquals(21, f.result);
359 +                checkCompletedNormally(f);
360 +
361 +                f = fibActions[1];
362 +                Thread.currentThread().interrupt();
363 +                try {
364 +                    f.join();
365 +                    shouldThrow();
366 +                } catch (CancellationException success) {
367 +                    assertTrue(Thread.interrupted());
368 +                    checkCancelled(f);
369 +                }
370 +
371 +                f = fibActions[2];
372 +                Thread.currentThread().interrupt();
373 +                try {
374 +                    f.join();
375 +                    shouldThrow();
376 +                } catch (FJException success) {
377 +                    assertTrue(Thread.interrupted());
378 +                    checkCompletedAbnormally(f, success);
379 +                }
380 +
381 +                // test quietlyJoin() ---------
382 +
383 +                f = fibActions[3];
384 +                Thread.currentThread().interrupt();
385 +                f.quietlyJoin();
386 +                assertTrue(Thread.interrupted());
387 +                assertEquals(21, f.result);
388 +                checkCompletedNormally(f);
389 +
390 +                f = fibActions[4];
391 +                Thread.currentThread().interrupt();
392 +                f.quietlyJoin();
393 +                assertTrue(Thread.interrupted());
394 +                checkCancelled(f);
395 +
396 +                f = fibActions[5];
397 +                Thread.currentThread().interrupt();
398 +                f.quietlyJoin();
399 +                assertTrue(Thread.interrupted());
400 +                assertTrue(f.getException() instanceof FJException);
401                  checkCompletedAbnormally(f, f.getException());
402              }};
403 +
404 +        Thread t;
405 +
406 +        t = newStartedThread(r);
407          testInvokeOnPool(mainPool(), a);
408 +        awaitTermination(t, LONG_DELAY_MS);
409 +
410          a.reinitialize();
411 +        t = newStartedThread(r);
412          testInvokeOnPool(singletonPool(), a);
413 +        awaitTermination(t, LONG_DELAY_MS);
414      }
415  
416      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines