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.28 by jsr166, Wed Dec 31 16:44:01 2014 UTC vs.
Revision 1.34 by jsr166, Tue Aug 16 23:17:13 2016 UTC

# Line 4 | Line 4
4   * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7 < import junit.framework.*;
7 > import static java.util.concurrent.TimeUnit.MILLISECONDS;
8 > import static java.util.concurrent.TimeUnit.SECONDS;
9 >
10 > import java.util.HashSet;
11   import java.util.concurrent.CancellationException;
12 + import java.util.concurrent.CountedCompleter;
13   import java.util.concurrent.ExecutionException;
14   import java.util.concurrent.ForkJoinPool;
15   import java.util.concurrent.ForkJoinTask;
16   import java.util.concurrent.RecursiveAction;
13 import java.util.concurrent.CountedCompleter;
17   import java.util.concurrent.TimeoutException;
18 < import static java.util.concurrent.TimeUnit.SECONDS;
19 < import static java.util.concurrent.TimeUnit.MILLISECONDS;
20 < import java.util.HashSet;
18 >
19 > import junit.framework.Test;
20 > import junit.framework.TestSuite;
21  
22   public class ForkJoinPool8Test extends JSR166TestCase {
23      public static void main(String[] args) {
24 <        junit.textui.TestRunner.run(suite());
24 >        main(suite(), args);
25      }
26  
27      public static Test suite() {
# Line 266 | Line 269 | public class ForkJoinPool8Test extends J
269          RecursiveAction a = new CheckedRecursiveAction() {
270              protected void realCompute() {
271                  FibAction f = new FibAction(8);
272 <                final Thread myself = Thread.currentThread();
272 >                final Thread currentThread = Thread.currentThread();
273  
274                  // test join()
275                  assertSame(f, f.fork());
276 <                myself.interrupt();
274 <                assertTrue(myself.isInterrupted());
276 >                currentThread.interrupt();
277                  assertNull(f.join());
278                  Thread.interrupted();
279                  assertEquals(21, f.result);
# Line 280 | Line 282 | public class ForkJoinPool8Test extends J
282                  f = new FibAction(8);
283                  f.cancel(true);
284                  assertSame(f, f.fork());
285 <                myself.interrupt();
284 <                assertTrue(myself.isInterrupted());
285 >                currentThread.interrupt();
286                  try {
287                      f.join();
288                      shouldThrow();
# Line 293 | Line 294 | public class ForkJoinPool8Test extends J
294                  f = new FibAction(8);
295                  f.completeExceptionally(new FJException());
296                  assertSame(f, f.fork());
297 <                myself.interrupt();
297 <                assertTrue(myself.isInterrupted());
297 >                currentThread.interrupt();
298                  try {
299                      f.join();
300                      shouldThrow();
# Line 306 | Line 306 | public class ForkJoinPool8Test extends J
306                  // test quietlyJoin()
307                  f = new FibAction(8);
308                  assertSame(f, f.fork());
309 <                myself.interrupt();
310 <                assertTrue(myself.isInterrupted());
309 >                currentThread.interrupt();
310                  f.quietlyJoin();
311                  Thread.interrupted();
312                  assertEquals(21, f.result);
# Line 316 | Line 315 | public class ForkJoinPool8Test extends J
315                  f = new FibAction(8);
316                  f.cancel(true);
317                  assertSame(f, f.fork());
318 <                myself.interrupt();
320 <                assertTrue(myself.isInterrupted());
318 >                currentThread.interrupt();
319                  f.quietlyJoin();
320                  Thread.interrupted();
321                  checkCancelled(f);
# Line 325 | Line 323 | public class ForkJoinPool8Test extends J
323                  f = new FibAction(8);
324                  f.completeExceptionally(new FJException());
325                  assertSame(f, f.fork());
326 <                myself.interrupt();
329 <                assertTrue(myself.isInterrupted());
326 >                currentThread.interrupt();
327                  f.quietlyJoin();
328                  Thread.interrupted();
329                  checkCompletedAbnormally(f, f.getException());
# Line 1486 | Line 1483 | public class ForkJoinPool8Test extends J
1483       */
1484      public void testAwaitQuiescence1() throws Exception {
1485          final ForkJoinPool p = new ForkJoinPool();
1486 <        try {
1486 >        try (PoolCleaner cleaner = cleaner(p)) {
1487              final long startTime = System.nanoTime();
1488              assertTrue(p.isQuiescent());
1489              ForkJoinTask a = new CheckedRecursiveAction() {
# Line 1517 | Line 1514 | public class ForkJoinPool8Test extends J
1514                  assertFalse(p.isTerminated());
1515                  Thread.yield();
1516              }
1520            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1517              assertEquals(0, p.getQueuedTaskCount());
1518              assertFalse(p.getAsyncMode());
1523            assertEquals(0, p.getActiveThreadCount());
1524            assertEquals(0, p.getQueuedTaskCount());
1519              assertEquals(0, p.getQueuedSubmissionCount());
1520              assertFalse(p.hasQueuedSubmissions());
1521 +            while (p.getActiveThreadCount() != 0
1522 +                   && millisElapsedSince(startTime) < LONG_DELAY_MS)
1523 +                Thread.yield();
1524              assertFalse(p.isShutdown());
1525              assertFalse(p.isTerminating());
1526              assertFalse(p.isTerminated());
1527 <        } finally {
1531 <            joinPool(p);
1527 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1528          }
1529      }
1530  
# Line 1546 | Line 1542 | public class ForkJoinPool8Test extends J
1542               "java.util.concurrent.ForkJoinPool.common.parallelism")))
1543              return;
1544          final ForkJoinPool p = new ForkJoinPool();
1545 <        try {
1545 >        try (PoolCleaner cleaner = cleaner(p)) {
1546              assertTrue(p.isQuiescent());
1547              final long startTime = System.nanoTime();
1548              ForkJoinTask a = new CheckedRecursiveAction() {
# Line 1567 | Line 1563 | public class ForkJoinPool8Test extends J
1563                  }};
1564              p.execute(a);
1565              assertTrue(p.awaitQuiescence(LONG_DELAY_MS, MILLISECONDS));
1570            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1566              assertTrue(p.isQuiescent());
1567              assertTrue(a.isDone());
1568              assertEquals(0, p.getQueuedTaskCount());
1569              assertFalse(p.getAsyncMode());
1575            assertEquals(0, p.getActiveThreadCount());
1576            assertEquals(0, p.getQueuedTaskCount());
1570              assertEquals(0, p.getQueuedSubmissionCount());
1571              assertFalse(p.hasQueuedSubmissions());
1572 +            while (p.getActiveThreadCount() != 0
1573 +                   && millisElapsedSince(startTime) < LONG_DELAY_MS)
1574 +                Thread.yield();
1575              assertFalse(p.isShutdown());
1576              assertFalse(p.isTerminating());
1577              assertFalse(p.isTerminated());
1578 <        } finally {
1583 <            joinPool(p);
1578 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1579          }
1580      }
1581  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines