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.26 by jsr166, Sat Nov 1 16:02:23 2014 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 +                    assertSame(p, ForkJoinTask.getPool());
1501 +                    boolean quiescent = p.awaitQuiescence(LONG_DELAY_MS, MILLISECONDS);
1502 +                    assertTrue(quiescent);
1503 +                    assertFalse(p.isQuiescent());
1504 +                    while (!f.isDone()) {
1505 +                        assertFalse(p.getAsyncMode());
1506 +                        assertFalse(p.isShutdown());
1507 +                        assertFalse(p.isTerminating());
1508 +                        assertFalse(p.isTerminated());
1509 +                        Thread.yield();
1510 +                    }
1511 +                    assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1512 +                    assertFalse(p.isQuiescent());
1513 +                    assertEquals(0, ForkJoinTask.getQueuedTaskCount());
1514 +                    assertEquals(21, f.result);
1515 +                }};
1516 +            p.execute(a);
1517 +            while (!a.isDone() || !p.isQuiescent()) {
1518 +                assertFalse(p.getAsyncMode());
1519 +                assertFalse(p.isShutdown());
1520 +                assertFalse(p.isTerminating());
1521 +                assertFalse(p.isTerminated());
1522 +                Thread.yield();
1523 +            }
1524 +            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
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 +            final long startTime = System.nanoTime();
1548 +            ForkJoinTask a = new CheckedRecursiveAction() {
1549 +                protected void realCompute() {
1550 +                    FibAction f = new FibAction(8);
1551 +                    assertSame(f, f.fork());
1552 +                    while (!f.isDone()
1553 +                           && millisElapsedSince(startTime) < LONG_DELAY_MS) {
1554 +                        assertFalse(p.getAsyncMode());
1555 +                        assertFalse(p.isShutdown());
1556 +                        assertFalse(p.isTerminating());
1557 +                        assertFalse(p.isTerminated());
1558 +                        Thread.yield();
1559 +                    }
1560 +                    assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1561 +                    assertEquals(0, ForkJoinTask.getQueuedTaskCount());
1562 +                    assertEquals(21, f.result);
1563 +                }};
1564 +            p.execute(a);
1565 +            assertTrue(p.awaitQuiescence(LONG_DELAY_MS, MILLISECONDS));
1566 +            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1567 +            assertTrue(p.isQuiescent());
1568 +            assertTrue(a.isDone());
1569 +            assertEquals(0, p.getQueuedTaskCount());
1570 +            assertFalse(p.getAsyncMode());
1571 +            assertEquals(0, p.getActiveThreadCount());
1572 +            assertEquals(0, p.getQueuedTaskCount());
1573 +            assertEquals(0, p.getQueuedSubmissionCount());
1574 +            assertFalse(p.hasQueuedSubmissions());
1575 +            assertFalse(p.isShutdown());
1576 +            assertFalse(p.isTerminating());
1577 +            assertFalse(p.isTerminated());
1578 +        } finally {
1579 +            joinPool(p);
1580 +        }
1581 +    }
1582 +
1583   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines