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.34 by jsr166, Thu Nov 18 19:14:34 2010 UTC vs.
Revision 1.36 by jsr166, Mon Nov 29 07:42:58 2010 UTC

# Line 328 | Line 328 | public class ForkJoinPoolTest extends JS
328       * pollSubmission returns unexecuted submitted task, if present
329       */
330      public void testPollSubmission() {
331 +        final CountDownLatch done = new CountDownLatch(1);
332          SubFJP p = new SubFJP();
333          try {
334 <            ForkJoinTask a = p.submit(new ShortRunnable());
335 <            ForkJoinTask b = p.submit(new ShortRunnable());
336 <            ForkJoinTask c = p.submit(new ShortRunnable());
334 >            ForkJoinTask a = p.submit(awaiter(done));
335 >            ForkJoinTask b = p.submit(awaiter(done));
336 >            ForkJoinTask c = p.submit(awaiter(done));
337              ForkJoinTask r = p.pollSubmission();
338              assertTrue(r == a || r == b || r == c);
339              assertFalse(r.isDone());
340          } finally {
341 +            done.countDown();
342              joinPool(p);
343          }
344      }
# Line 345 | Line 347 | public class ForkJoinPoolTest extends JS
347       * drainTasksTo transfers unexecuted submitted tasks, if present
348       */
349      public void testDrainTasksTo() {
350 +        final CountDownLatch done = new CountDownLatch(1);
351          SubFJP p = new SubFJP();
352          try {
353 <            ForkJoinTask a = p.submit(new ShortRunnable());
354 <            ForkJoinTask b = p.submit(new ShortRunnable());
355 <            ForkJoinTask c = p.submit(new ShortRunnable());
353 >            ForkJoinTask a = p.submit(awaiter(done));
354 >            ForkJoinTask b = p.submit(awaiter(done));
355 >            ForkJoinTask c = p.submit(awaiter(done));
356              ArrayList<ForkJoinTask> al = new ArrayList();
357              p.drainTasksTo(al);
358              assertTrue(al.size() > 0);
# Line 358 | Line 361 | public class ForkJoinPoolTest extends JS
361                  assertFalse(r.isDone());
362              }
363          } finally {
364 +            done.countDown();
365              joinPool(p);
366          }
367      }
# Line 375 | Line 379 | public class ForkJoinPoolTest extends JS
379              assertFalse(task.isDone());
380              Future<?> future = e.submit(task);
381              assertNull(future.get());
382 +            assertNull(future.get(MEDIUM_DELAY_MS, MILLISECONDS));
383              assertTrue(task.isDone());
384 +            assertTrue(future.isDone());
385              assertFalse(future.isCancelled());
386          } finally {
387              joinPool(e);
# Line 428 | Line 434 | public class ForkJoinPoolTest extends JS
434          }
435      }
436  
431
437      /**
438       * A submitted privileged action runs to completion
439       */
440 <    public void testSubmitPrivilegedAction() throws Throwable {
441 <        Policy savedPolicy = null;
442 <        try {
443 <            savedPolicy = Policy.getPolicy();
439 <            AdjustablePolicy policy = new AdjustablePolicy();
440 <            policy.addPermission(new RuntimePermission("getContextClassLoader"));
441 <            policy.addPermission(new RuntimePermission("setContextClassLoader"));
442 <            Policy.setPolicy(policy);
443 <        } catch (AccessControlException ok) {
444 <            return;
445 <        }
446 <
447 <        try {
448 <            ExecutorService e = new ForkJoinPool(1);
449 <            try {
440 >    public void testSubmitPrivilegedAction() throws Exception {
441 >        Runnable r = new CheckedRunnable() {
442 >            public void realRun() throws Exception {
443 >                ExecutorService e = new ForkJoinPool(1);
444                  Future future = e.submit(Executors.callable(new PrivilegedAction() {
445                      public Object run() {
446                          return TEST_STRING;
447                      }}));
448  
449 <                Object result = future.get();
450 <                assertSame(TEST_STRING, result);
451 <            } finally {
452 <                joinPool(e);
453 <            }
460 <        } finally {
461 <            Policy.setPolicy(savedPolicy);
462 <        }
449 >                assertSame(TEST_STRING, future.get());
450 >            }};
451 >
452 >        runWithPermissions(r,
453 >                           new RuntimePermission("modifyThread"));
454      }
455  
456      /**
457       * A submitted privileged exception action runs to completion
458       */
459 <    public void testSubmitPrivilegedExceptionAction() throws Throwable {
460 <        Policy savedPolicy = null;
461 <        try {
462 <            savedPolicy = Policy.getPolicy();
472 <            AdjustablePolicy policy = new AdjustablePolicy();
473 <            policy.addPermission(new RuntimePermission("getContextClassLoader"));
474 <            policy.addPermission(new RuntimePermission("setContextClassLoader"));
475 <            Policy.setPolicy(policy);
476 <        } catch (AccessControlException ok) {
477 <            return;
478 <        }
479 <
480 <        try {
481 <            ExecutorService e = new ForkJoinPool(1);
482 <            try {
459 >    public void testSubmitPrivilegedExceptionAction() throws Exception {
460 >        Runnable r = new CheckedRunnable() {
461 >            public void realRun() throws Exception {
462 >                ExecutorService e = new ForkJoinPool(1);
463                  Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
464                      public Object run() {
465                          return TEST_STRING;
466                      }}));
467  
468 <                Object result = future.get();
469 <                assertSame(TEST_STRING, result);
470 <            } finally {
471 <                joinPool(e);
492 <            }
493 <        } finally {
494 <            Policy.setPolicy(savedPolicy);
495 <        }
468 >                assertSame(TEST_STRING, future.get());
469 >            }};
470 >
471 >        runWithPermissions(r, new RuntimePermission("modifyThread"));
472      }
473  
474      /**
475       * A submitted failed privileged exception action reports exception
476       */
477 <    public void testSubmitFailedPrivilegedExceptionAction() throws Throwable {
478 <        Policy savedPolicy = null;
479 <        try {
480 <            savedPolicy = Policy.getPolicy();
505 <            AdjustablePolicy policy = new AdjustablePolicy();
506 <            policy.addPermission(new RuntimePermission("getContextClassLoader"));
507 <            policy.addPermission(new RuntimePermission("setContextClassLoader"));
508 <            Policy.setPolicy(policy);
509 <        } catch (AccessControlException ok) {
510 <            return;
511 <        }
512 <
513 <        try {
514 <            ExecutorService e = new ForkJoinPool(1);
515 <            try {
477 >    public void testSubmitFailedPrivilegedExceptionAction() throws Exception {
478 >        Runnable r = new CheckedRunnable() {
479 >            public void realRun() throws Exception {
480 >                ExecutorService e = new ForkJoinPool(1);
481                  Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
482                      public Object run() throws Exception {
483                          throw new IndexOutOfBoundsException();
484                      }}));
485  
486 <                Object result = future.get();
487 <                shouldThrow();
488 <            } catch (ExecutionException success) {
489 <                assertTrue(success.getCause() instanceof IndexOutOfBoundsException);
490 <            } finally {
491 <                joinPool(e);
492 <            }
493 <        } finally {
529 <            Policy.setPolicy(savedPolicy);
530 <        }
486 >                try {
487 >                    future.get();
488 >                    shouldThrow();
489 >                } catch (ExecutionException success) {
490 >                    assertTrue(success.getCause() instanceof IndexOutOfBoundsException);
491 >                }}};
492 >
493 >        runWithPermissions(r, new RuntimePermission("modifyThread"));
494      }
495  
496      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines