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

Comparing jsr166/src/test/tck/ForkJoinPool8Test.java (file contents):
Revision 1.10 by jsr166, Sun Jul 14 16:36:37 2013 UTC vs.
Revision 1.21 by jsr166, Mon Sep 16 01:43:29 2013 UTC

# Line 1462 | Line 1462 | public class ForkJoinPool8Test extends J
1462      }
1463  
1464      /**
1465 <     * invokeAll(collection)  throws exception if any task does
1465 >     * invokeAll(collection) throws exception if any task does
1466       */
1467      public void testAbnormalInvokeAllCollectionCC() {
1468          ForkJoinTask a = new CheckedRecursiveAction() {
# Line 1484 | Line 1484 | public class ForkJoinPool8Test extends J
1484          checkInvoke(a);
1485      }
1486  
1487 +    /**
1488 +     * awaitQuiescence by a worker is equivalent in effect to
1489 +     * ForkJoinTask.helpQuiesce()
1490 +     */
1491 +    public void testAwaitQuiescence1() throws Exception {
1492 +        final ForkJoinPool p = new ForkJoinPool();
1493 +        try {
1494 +            final long startTime = System.nanoTime();
1495 +            assertTrue(p.isQuiescent());
1496 +            ForkJoinTask a = new CheckedRecursiveAction() {
1497 +                protected void realCompute() {
1498 +                    FibAction f = new FibAction(8);
1499 +                    assertSame(f, f.fork());
1500 +                    boolean quiescent = ForkJoinTask.getPool().awaitQuiescence(MEDIUM_DELAY_MS, MILLISECONDS);
1501 +                    assertTrue(quiescent);
1502 +                    while (!f.isDone()) {
1503 +                        if (millisElapsedSince(startTime) > LONG_DELAY_MS)
1504 +                            threadFail("timed out");
1505 +                        assertFalse(p.getAsyncMode());
1506 +                        assertFalse(p.isShutdown());
1507 +                        assertFalse(p.isTerminating());
1508 +                        assertFalse(p.isTerminated());
1509 +                        Thread.yield();
1510 +                    }
1511 +                    assertFalse(p.isQuiescent());
1512 +                    assertEquals(0, ForkJoinTask.getQueuedTaskCount());
1513 +                    assertEquals(21, f.result);
1514 +                }};
1515 +            p.execute(a);
1516 +            while (!a.isDone() || !p.isQuiescent()) {
1517 +                if (millisElapsedSince(startTime) > LONG_DELAY_MS)
1518 +                    throw new AssertionFailedError("timed out");
1519 +                assertFalse(p.getAsyncMode());
1520 +                assertFalse(p.isShutdown());
1521 +                assertFalse(p.isTerminating());
1522 +                assertFalse(p.isTerminated());
1523 +                Thread.yield();
1524 +            }
1525 +            assertEquals(0, p.getQueuedTaskCount());
1526 +            assertFalse(p.getAsyncMode());
1527 +            assertEquals(0, p.getActiveThreadCount());
1528 +            assertEquals(0, p.getQueuedTaskCount());
1529 +            assertEquals(0, p.getQueuedSubmissionCount());
1530 +            assertFalse(p.hasQueuedSubmissions());
1531 +            assertFalse(p.isShutdown());
1532 +            assertFalse(p.isTerminating());
1533 +            assertFalse(p.isTerminated());
1534 +        } finally {
1535 +            joinPool(p);
1536 +        }
1537 +    }
1538 +
1539 +    /**
1540 +     * awaitQuiescence returns when pool isQuiescent() or the indicated
1541 +     * timeout elapsed
1542 +     */
1543 +    public void testAwaitQuiescence2() throws Exception {
1544 +        final ForkJoinPool p = new ForkJoinPool();
1545 +        try {
1546 +            assertTrue(p.isQuiescent());
1547 +            for (;;) {
1548 +                final long startTime = System.nanoTime();
1549 +                ForkJoinTask a = new CheckedRecursiveAction() {
1550 +                    protected void realCompute() {
1551 +                        FibAction f = new FibAction(8);
1552 +                        assertSame(f, f.fork());
1553 +                        ForkJoinTask.helpQuiesce();
1554 +                        while (!f.isDone()) {
1555 +                            if (millisElapsedSince(startTime) > LONG_DELAY_MS)
1556 +                                threadFail("timed out");
1557 +                            assertFalse(p.getAsyncMode());
1558 +                            assertFalse(p.isShutdown());
1559 +                            assertFalse(p.isTerminating());
1560 +                            assertFalse(p.isTerminated());
1561 +                            Thread.yield();
1562 +                        }
1563 +                        assertEquals(0, ForkJoinTask.getQueuedTaskCount());
1564 +                        assertEquals(21, f.result);
1565 +                    }};
1566 +                p.execute(a);
1567 +                if (a.isDone() || p.isQuiescent())
1568 +                    continue; // Already done so cannot test; retry
1569 +                while (!p.awaitQuiescence(LONG_DELAY_MS, MILLISECONDS)) {
1570 +                    if (millisElapsedSince(startTime) > LONG_DELAY_MS)
1571 +                        threadFail("timed out");
1572 +                    assertFalse(p.getAsyncMode());
1573 +                    assertFalse(p.isShutdown());
1574 +                    assertFalse(p.isTerminating());
1575 +                    assertFalse(p.isTerminated());
1576 +                    Thread.yield();
1577 +                }
1578 +                assertTrue(p.isQuiescent());
1579 +                assertTrue(a.isDone());
1580 +                assertEquals(0, p.getQueuedTaskCount());
1581 +                assertFalse(p.getAsyncMode());
1582 +                assertEquals(0, p.getActiveThreadCount());
1583 +                assertEquals(0, p.getQueuedTaskCount());
1584 +                assertEquals(0, p.getQueuedSubmissionCount());
1585 +                assertFalse(p.hasQueuedSubmissions());
1586 +                assertFalse(p.isShutdown());
1587 +                assertFalse(p.isTerminating());
1588 +                assertFalse(p.isTerminated());
1589 +                break;
1590 +            }
1591 +        } finally {
1592 +            joinPool(p);
1593 +        }
1594 +    }
1595 +
1596   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines