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.11 by dl, Sun Jul 21 22:24:18 2013 UTC

# Line 1484 | Line 1484 | public class ForkJoinPool8Test extends J
1484          checkInvoke(a);
1485      }
1486  
1487 +
1488 +    /**
1489 +     * awaitQuiescent by a worker is equivalent in effect to
1490 +     * ForkJoinTask.helpQuiesce()
1491 +     */
1492 +    public void testAwaitQuiescent1() throws Exception {
1493 +        final ForkJoinPool p = new ForkJoinPool();
1494 +        try {
1495 +            final long startTime = System.nanoTime();
1496 +            assertTrue(p.isQuiescent());
1497 +            ForkJoinTask a = new CheckedRecursiveAction() {
1498 +                    protected void realCompute() {
1499 +                        FibAction f = new FibAction(8);
1500 +                        assertSame(f, f.fork());
1501 +                        boolean t = ForkJoinTask.getPool().awaitQuiescence(MEDIUM_DELAY_MS, TimeUnit.SECONDS);
1502 +                        assertTrue(t);
1503 +                        while (!f.isDone()) {
1504 +                            if (millisElapsedSince(startTime) > LONG_DELAY_MS)
1505 +                                threadFail("timed out");
1506 +                            assertFalse(p.getAsyncMode());
1507 +                            assertFalse(p.isShutdown());
1508 +                            assertFalse(p.isTerminating());
1509 +                            assertFalse(p.isTerminated());
1510 +                            Thread.yield();
1511 +                        }
1512 +                        assertFalse(p.isQuiescent());
1513 +                        assertEquals(0, ForkJoinTask.getQueuedTaskCount());
1514 +                        try {
1515 +                            assertEquals(21, f.result);
1516 +                        } catch (Throwable fail) {
1517 +                            threadFail(fail.getMessage());
1518 +                        }
1519 +                    }
1520 +                };
1521 +            p.execute(a);
1522 +            while (!a.isDone() || !p.isQuiescent()) {
1523 +                if (millisElapsedSince(startTime) > LONG_DELAY_MS)
1524 +                    throw new AssertionFailedError("timed out");
1525 +                assertFalse(p.getAsyncMode());
1526 +                assertFalse(p.isShutdown());
1527 +                assertFalse(p.isTerminating());
1528 +                assertFalse(p.isTerminated());
1529 +                Thread.yield();
1530 +            }
1531 +            assertEquals(0, p.getQueuedTaskCount());
1532 +            assertFalse(p.getAsyncMode());
1533 +            assertEquals(0, p.getActiveThreadCount());
1534 +            assertEquals(0, p.getQueuedTaskCount());
1535 +            assertEquals(0, p.getQueuedSubmissionCount());
1536 +            assertFalse(p.hasQueuedSubmissions());
1537 +            assertFalse(p.isShutdown());
1538 +            assertFalse(p.isTerminating());
1539 +            assertFalse(p.isTerminated());
1540 +        } finally {
1541 +            joinPool(p);
1542 +        }
1543 +    }
1544 +
1545 +    /**
1546 +     * awaitQuiescent returns when pool isQuiescent() or the indicated
1547 +     * timeout elapse
1548 +     */  
1549 +    public void testAwaitQuiescent2() throws Exception {
1550 +        final ForkJoinPool p = new ForkJoinPool();
1551 +        try {
1552 +            final long startTime = System.nanoTime();
1553 +            assertTrue(p.isQuiescent());
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 +            while (!p.awaitQuiescence(LONG_DELAY_MS, MILLISECONDS)) {
1576 +                if (millisElapsedSince(startTime) > LONG_DELAY_MS)
1577 +                    threadFail("timed out");
1578 +                assertFalse(p.getAsyncMode());
1579 +                assertFalse(p.isShutdown());
1580 +                assertFalse(p.isTerminating());
1581 +                assertFalse(p.isTerminated());
1582 +                Thread.yield();
1583 +            }
1584 +            assertTrue(p.isQuiescent());
1585 +            assertTrue(a.isDone());
1586 +            assertEquals(0, p.getQueuedTaskCount());
1587 +            assertFalse(p.getAsyncMode());
1588 +            assertEquals(0, p.getActiveThreadCount());
1589 +            assertEquals(0, p.getQueuedTaskCount());
1590 +            assertEquals(0, p.getQueuedSubmissionCount());
1591 +            assertFalse(p.hasQueuedSubmissions());
1592 +            assertFalse(p.isShutdown());
1593 +            assertFalse(p.isTerminating());
1594 +            assertFalse(p.isTerminated());
1595 +        } finally {
1596 +            joinPool(p);
1597 +        }
1598 +    }
1599 +
1600 +
1601   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines