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.11 by dl, Sun Jul 21 22:24:18 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
1487      /**
1488 <     * awaitQuiescent by a worker is equivalent in effect to
1488 >     * awaitQuiescence by a worker is equivalent in effect to
1489       * ForkJoinTask.helpQuiesce()
1490 <     */
1491 <    public void testAwaitQuiescent1() throws Exception {
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 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();
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 <                        }
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 <                };
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()) {
1523                if (millisElapsedSince(startTime) > LONG_DELAY_MS)
1524                    throw new AssertionFailedError("timed out");
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());
# Line 1541 | Line 1535 | public class ForkJoinPool8Test extends J
1535              joinPool(p);
1536          }
1537      }
1538 <
1538 >
1539      /**
1540 <     * awaitQuiescent returns when pool isQuiescent() or the indicated
1541 <     * timeout elapse
1542 <     */  
1543 <    public void testAwaitQuiescent2() throws Exception {
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 {
1552            final long startTime = System.nanoTime();
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 <                        ForkJoinTask.helpQuiesce();
1553 <                        while (!f.isDone()) {
1554 <                            if (millisElapsedSince(startTime) > LONG_DELAY_MS)
1555 <                                threadFail("timed out");
1556 <                            assertFalse(p.getAsyncMode());
1557 <                            assertFalse(p.isShutdown());
1558 <                            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()); }
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 <                };
1560 >                    assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1561 >                    assertEquals(0, ForkJoinTask.getQueuedTaskCount());
1562 >                    assertEquals(21, f.result);
1563 >                }};
1564              p.execute(a);
1565 <            while (!p.awaitQuiescence(LONG_DELAY_MS, MILLISECONDS)) {
1566 <                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 <            }
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());
# Line 1597 | Line 1580 | public class ForkJoinPool8Test extends J
1580          }
1581      }
1582  
1600
1583   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines