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.21 by jsr166, Mon Sep 16 01:43:29 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
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 >                    boolean quiescent = ForkJoinTask.getPool().awaitQuiescence(MEDIUM_DELAY_MS, MILLISECONDS);
1501 >                    assertTrue(quiescent);
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 <                };
1511 >                    assertFalse(p.isQuiescent());
1512 >                    assertEquals(0, ForkJoinTask.getQueuedTaskCount());
1513 >                    assertEquals(21, f.result);
1514 >                }};
1515              p.execute(a);
1516              while (!a.isDone() || !p.isQuiescent()) {
1517                  if (millisElapsedSince(startTime) > LONG_DELAY_MS)
# 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 <            ForkJoinTask a = new CheckedRecursiveAction() {
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());
# Line 1566 | Line 1561 | public class ForkJoinPool8Test extends J
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 <            while (!p.awaitQuiescence(LONG_DELAY_MS, MILLISECONDS)) {
1571 <                if (millisElapsedSince(startTime) > LONG_DELAY_MS)
1572 <                    threadFail("timed out");
1564 >                        assertEquals(21, f.result);
1565 >                    }};
1566 >                p.execute(a);
1567 >                if (a.isDone() || p.isQuiescent())
1568 >                    continue; // Already done so cannot test; retry
1569 >                while (!p.awaitQuiescence(LONG_DELAY_MS, MILLISECONDS)) {
1570 >                    if (millisElapsedSince(startTime) > LONG_DELAY_MS)
1571 >                        threadFail("timed out");
1572 >                    assertFalse(p.getAsyncMode());
1573 >                    assertFalse(p.isShutdown());
1574 >                    assertFalse(p.isTerminating());
1575 >                    assertFalse(p.isTerminated());
1576 >                    Thread.yield();
1577 >                }
1578 >                assertTrue(p.isQuiescent());
1579 >                assertTrue(a.isDone());
1580 >                assertEquals(0, p.getQueuedTaskCount());
1581                  assertFalse(p.getAsyncMode());
1582 +                assertEquals(0, p.getActiveThreadCount());
1583 +                assertEquals(0, p.getQueuedTaskCount());
1584 +                assertEquals(0, p.getQueuedSubmissionCount());
1585 +                assertFalse(p.hasQueuedSubmissions());
1586                  assertFalse(p.isShutdown());
1587                  assertFalse(p.isTerminating());
1588                  assertFalse(p.isTerminated());
1589 <                Thread.yield();
1589 >                break;
1590              }
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());
1591          } finally {
1592              joinPool(p);
1593          }
1594      }
1595  
1600
1596   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines