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.15 by dl, Sun Sep 15 22:35:46 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 +     * awaitQuiescent by a worker is equivalent in effect to
1489 +     * ForkJoinTask.helpQuiesce()
1490 +     */
1491 +    public void testAwaitQuiescent1() 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 t = ForkJoinTask.getPool().awaitQuiescence(MEDIUM_DELAY_MS, TimeUnit.SECONDS);
1501 +                        assertTrue(t);
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 +                        try {
1514 +                            assertEquals(21, f.result);
1515 +                        } catch (Throwable fail) {
1516 +                            threadFail(fail.getMessage());
1517 +                        }
1518 +                    }
1519 +                };
1520 +            p.execute(a);
1521 +            while (!a.isDone() || !p.isQuiescent()) {
1522 +                if (millisElapsedSince(startTime) > LONG_DELAY_MS)
1523 +                    throw new AssertionFailedError("timed out");
1524 +                assertFalse(p.getAsyncMode());
1525 +                assertFalse(p.isShutdown());
1526 +                assertFalse(p.isTerminating());
1527 +                assertFalse(p.isTerminated());
1528 +                Thread.yield();
1529 +            }
1530 +            assertEquals(0, p.getQueuedTaskCount());
1531 +            assertFalse(p.getAsyncMode());
1532 +            assertEquals(0, p.getActiveThreadCount());
1533 +            assertEquals(0, p.getQueuedTaskCount());
1534 +            assertEquals(0, p.getQueuedSubmissionCount());
1535 +            assertFalse(p.hasQueuedSubmissions());
1536 +            assertFalse(p.isShutdown());
1537 +            assertFalse(p.isTerminating());
1538 +            assertFalse(p.isTerminated());
1539 +        } finally {
1540 +            joinPool(p);
1541 +        }
1542 +    }
1543 +
1544 +    /**
1545 +     * awaitQuiescent returns when pool isQuiescent() or the indicated
1546 +     * timeout elapse
1547 +     */
1548 +    public void testAwaitQuiescent2() throws Exception {
1549 +        final ForkJoinPool p = new ForkJoinPool();
1550 +        try {
1551 +            assertTrue(p.isQuiescent());
1552 +            for (;;) {
1553 +                final long startTime = System.nanoTime();
1554 +                ForkJoinTask a = new CheckedRecursiveAction() {
1555 +                        protected void realCompute() {
1556 +                            FibAction f = new FibAction(8);
1557 +                            assertSame(f, f.fork());
1558 +                            ForkJoinTask.helpQuiesce();
1559 +                            while (!f.isDone()) {
1560 +                                if (millisElapsedSince(startTime) > LONG_DELAY_MS)
1561 +                                    threadFail("timed out");
1562 +                                assertFalse(p.getAsyncMode());
1563 +                                assertFalse(p.isShutdown());
1564 +                                assertFalse(p.isTerminating());
1565 +                                assertFalse(p.isTerminated());
1566 +                                Thread.yield();
1567 +                            }
1568 +                            assertEquals(0, ForkJoinTask.getQueuedTaskCount());
1569 +                            try {
1570 +                                assertEquals(21, f.result);
1571 +                            } catch (Throwable fail) { System.out.println("fail " + fail.getMessage()); }
1572 +                        }
1573 +                    };
1574 +                p.execute(a);
1575 +                if (a.isDone() || p.isQuiescent())
1576 +                    continue; // Already done so cannot test; retry
1577 +                while (!p.awaitQuiescence(LONG_DELAY_MS, MILLISECONDS)) {
1578 +                    if (millisElapsedSince(startTime) > LONG_DELAY_MS)
1579 +                        threadFail("timed out");
1580 +                    assertFalse(p.getAsyncMode());
1581 +                    assertFalse(p.isShutdown());
1582 +                    assertFalse(p.isTerminating());
1583 +                    assertFalse(p.isTerminated());
1584 +                    Thread.yield();
1585 +                }
1586 +                assertTrue(p.isQuiescent());
1587 +                assertTrue(a.isDone());
1588 +                assertEquals(0, p.getQueuedTaskCount());
1589 +                assertFalse(p.getAsyncMode());
1590 +                assertEquals(0, p.getActiveThreadCount());
1591 +                assertEquals(0, p.getQueuedTaskCount());
1592 +                assertEquals(0, p.getQueuedSubmissionCount());
1593 +                assertFalse(p.hasQueuedSubmissions());
1594 +                assertFalse(p.isShutdown());
1595 +                assertFalse(p.isTerminating());
1596 +                assertFalse(p.isTerminated());
1597 +                break;
1598 +            }
1599 +        } finally {
1600 +            joinPool(p);
1601 +        }
1602 +    }
1603 +
1604   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines