ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ForkJoinPoolTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ForkJoinPoolTest.java (file contents):
Revision 1.35 by dl, Fri Nov 19 00:20:47 2010 UTC vs.
Revision 1.41 by jsr166, Fri May 27 19:42:42 2011 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7   import junit.framework.*;
# Line 164 | Line 164 | public class ForkJoinPoolTest extends JS
164          try {
165              assertSame(ForkJoinPool.defaultForkJoinWorkerThreadFactory,
166                         p.getFactory());
167            assertTrue(p.isQuiescent());
167              assertFalse(p.getAsyncMode());
168              assertEquals(0, p.getActiveThreadCount());
169              assertEquals(0, p.getStealCount());
# Line 199 | Line 198 | public class ForkJoinPoolTest extends JS
198          } catch (NullPointerException success) {}
199      }
200  
202
201      /**
202       * getParallelism returns size set in constructor
203       */
# Line 252 | Line 250 | public class ForkJoinPoolTest extends JS
250      }
251  
252      /**
253 <     * After invoking a single task, isQuiescent is true,
254 <     * queues are empty, threads are not active, and
255 <     * construction parameters continue to hold
253 >     * After invoking a single task, isQuiescent eventually becomes
254 >     * true, at which time queues are empty, threads are not active,
255 >     * the task has completed successfully, and construction
256 >     * parameters continue to hold
257       */
258 <    public void testisQuiescent() throws InterruptedException {
258 >    public void testisQuiescent() throws Exception {
259          ForkJoinPool p = new ForkJoinPool(2);
260          try {
261              assertTrue(p.isQuiescent());
262 <            p.invoke(new FibTask(20));
262 >            long startTime = System.nanoTime();
263 >            FibTask f = new FibTask(20);
264 >            p.invoke(f);
265              assertSame(ForkJoinPool.defaultForkJoinWorkerThreadFactory,
266                         p.getFactory());
267 <            Thread.sleep(SMALL_DELAY_MS);
267 >            while (! p.isQuiescent()) {
268 >                if (millisElapsedSince(startTime) > LONG_DELAY_MS)
269 >                    throw new AssertionFailedError("timed out");
270 >                assertFalse(p.getAsyncMode());
271 >                assertFalse(p.isShutdown());
272 >                assertFalse(p.isTerminating());
273 >                assertFalse(p.isTerminated());
274 >                Thread.yield();
275 >            }
276 >
277              assertTrue(p.isQuiescent());
278              assertFalse(p.getAsyncMode());
279              assertEquals(0, p.getActiveThreadCount());
# Line 273 | Line 283 | public class ForkJoinPoolTest extends JS
283              assertFalse(p.isShutdown());
284              assertFalse(p.isTerminating());
285              assertFalse(p.isTerminated());
286 +            assertTrue(f.isDone());
287 +            assertEquals(6765, (int) f.get());
288          } finally {
289              joinPool(p);
290          }
# Line 328 | Line 340 | public class ForkJoinPoolTest extends JS
340       * pollSubmission returns unexecuted submitted task, if present
341       */
342      public void testPollSubmission() {
343 +        final CountDownLatch done = new CountDownLatch(1);
344          SubFJP p = new SubFJP();
345          try {
346 <            ForkJoinTask a = p.submit(new ShortRunnable());
347 <            ForkJoinTask b = p.submit(new ShortRunnable());
348 <            ForkJoinTask c = p.submit(new ShortRunnable());
346 >            ForkJoinTask a = p.submit(awaiter(done));
347 >            ForkJoinTask b = p.submit(awaiter(done));
348 >            ForkJoinTask c = p.submit(awaiter(done));
349              ForkJoinTask r = p.pollSubmission();
350              assertTrue(r == a || r == b || r == c);
351              assertFalse(r.isDone());
352          } finally {
353 +            done.countDown();
354              joinPool(p);
355          }
356      }
# Line 345 | Line 359 | public class ForkJoinPoolTest extends JS
359       * drainTasksTo transfers unexecuted submitted tasks, if present
360       */
361      public void testDrainTasksTo() {
362 +        final CountDownLatch done = new CountDownLatch(1);
363          SubFJP p = new SubFJP();
364          try {
365 <            ForkJoinTask a = p.submit(new ShortRunnable());
366 <            ForkJoinTask b = p.submit(new ShortRunnable());
367 <            ForkJoinTask c = p.submit(new ShortRunnable());
365 >            ForkJoinTask a = p.submit(awaiter(done));
366 >            ForkJoinTask b = p.submit(awaiter(done));
367 >            ForkJoinTask c = p.submit(awaiter(done));
368              ArrayList<ForkJoinTask> al = new ArrayList();
369              p.drainTasksTo(al);
370              assertTrue(al.size() > 0);
# Line 358 | Line 373 | public class ForkJoinPoolTest extends JS
373                  assertFalse(r.isDone());
374              }
375          } finally {
376 +            done.countDown();
377              joinPool(p);
378          }
379      }
380  
365
381      // FJ Versions of AbstractExecutorService tests
382  
383      /**
# Line 375 | Line 390 | public class ForkJoinPoolTest extends JS
390              assertFalse(task.isDone());
391              Future<?> future = e.submit(task);
392              assertNull(future.get());
393 +            assertNull(future.get(MEDIUM_DELAY_MS, MILLISECONDS));
394              assertTrue(task.isDone());
395 +            assertTrue(future.isDone());
396              assertFalse(future.isCancelled());
397          } finally {
398              joinPool(e);
399          }
400      }
401  
385
402      /**
403       * Completed submit(callable) returns result
404       */
# Line 501 | Line 517 | public class ForkJoinPoolTest extends JS
517          }
518      }
519  
504
520      /**
521       * submit(null callable) throws NullPointerException
522       */
# Line 516 | Line 531 | public class ForkJoinPoolTest extends JS
531          }
532      }
533  
519
534      /**
535       * submit(callable).get() throws InterruptedException if interrupted
536       */
# Line 745 | Line 759 | public class ForkJoinPoolTest extends JS
759          }
760      }
761  
748
762      /**
763       * timed invokeAny(null) throws NullPointerException
764       */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines