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.16 by jsr166, Mon Sep 16 00:48:00 2013 UTC vs.
Revision 1.26 by jsr166, Sat Nov 1 16:02:23 2014 UTC

# Line 1485 | Line 1485 | public class ForkJoinPool8Test extends J
1485      }
1486  
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 {
1491 >    public void testAwaitQuiescence1() throws Exception {
1492          final ForkJoinPool p = new ForkJoinPool();
1493          try {
1494              final long startTime = System.nanoTime();
# Line 1497 | Line 1497 | public class ForkJoinPool8Test extends J
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);
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()) {
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 +                    assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1512                      assertFalse(p.isQuiescent());
1513                      assertEquals(0, ForkJoinTask.getQueuedTaskCount());
1514 <                    try {
1514 <                        assertEquals(21, f.result);
1515 <                    } catch (Throwable fail) {
1516 <                        threadFail(fail.getMessage());
1517 <                    }
1514 >                    assertEquals(21, f.result);
1515                  }};
1516              p.execute(a);
1517              while (!a.isDone() || !p.isQuiescent()) {
1521                if (millisElapsedSince(startTime) > LONG_DELAY_MS)
1522                    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 1537 | public class ForkJoinPool8Test extends J
1537      }
1538  
1539      /**
1540 <     * awaitQuiescent returns when pool isQuiescent() or the indicated
1541 <     * timeout elapse
1540 >     * awaitQuiescence returns when pool isQuiescent() or the indicated
1541 >     * timeout elapsed
1542       */
1543 <    public void testAwaitQuiescent2() throws Exception {
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 <                            try {
1565 <                                assertEquals(21, f.result);
1566 <                            } catch (Throwable fail) { System.out.println("fail " + fail.getMessage()); }
1567 <                        }
1568 <                    };
1569 <                p.execute(a);
1570 <                if (a.isDone() || p.isQuiescent())
1571 <                    continue; // Already done so cannot test; retry
1572 <                while (!p.awaitQuiescence(LONG_DELAY_MS, MILLISECONDS)) {
1573 <                    if (millisElapsedSince(startTime) > LONG_DELAY_MS)
1574 <                        threadFail("timed out");
1575 <                    assertFalse(p.getAsyncMode());
1576 <                    assertFalse(p.isShutdown());
1577 <                    assertFalse(p.isTerminating());
1582 <                    assertFalse(p.isTerminated());
1583 <                    Thread.yield();
1584 <                }
1585 <                assertTrue(p.isQuiescent());
1586 <                assertTrue(a.isDone());
1587 <                assertEquals(0, p.getQueuedTaskCount());
1588 <                assertFalse(p.getAsyncMode());
1589 <                assertEquals(0, p.getActiveThreadCount());
1590 <                assertEquals(0, p.getQueuedTaskCount());
1591 <                assertEquals(0, p.getQueuedSubmissionCount());
1592 <                assertFalse(p.hasQueuedSubmissions());
1593 <                assertFalse(p.isShutdown());
1594 <                assertFalse(p.isTerminating());
1595 <                assertFalse(p.isTerminated());
1596 <                break;
1597 <            }
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          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines