< prev index next >

test/jdk/java/util/concurrent/tck/ForkJoinPoolTest.java

Print this page
8234131: Miscellaneous changes imported from jsr166 CVS 2021-01
Reviewed-by: martin


 358     /**
 359      * Completed submit(ForkJoinTask) returns result
 360      */
 361     public void testSubmitForkJoinTask() throws Throwable {
 362         ForkJoinPool p = new ForkJoinPool(1);
 363         try (PoolCleaner cleaner = cleaner(p)) {
 364             ForkJoinTask<Integer> f = p.submit(new FibTask(8));
 365             assertEquals(21, (int) f.get());
 366         }
 367     }
 368 
 369     /**
 370      * A task submitted after shutdown is rejected
 371      */
 372     public void testSubmitAfterShutdown() {
 373         ForkJoinPool p = new ForkJoinPool(1);
 374         try (PoolCleaner cleaner = cleaner(p)) {
 375             p.shutdown();
 376             assertTrue(p.isShutdown());
 377             try {
 378                 ForkJoinTask<Integer> f = p.submit(new FibTask(8));
 379                 shouldThrow();
 380             } catch (RejectedExecutionException success) {}
 381         }
 382     }
 383 
 384     /**
 385      * Pool maintains parallelism when using ManagedBlocker
 386      */
 387     public void testBlockingForkJoinTask() throws Throwable {
 388         ForkJoinPool p = new ForkJoinPool(4);
 389         try {
 390             ReentrantLock lock = new ReentrantLock();
 391             ManagedLocker locker = new ManagedLocker(lock);
 392             ForkJoinTask<Integer> f = new LockingFibTask(20, locker, lock);
 393             p.execute(f);
 394             assertEquals(6765, (int) f.get());
 395         } finally {
 396             p.shutdownNow(); // don't wait out shutdown
 397         }
 398     }


 546                 Future future = e.submit(callable);
 547                 try {
 548                     future.get();
 549                     shouldThrow();
 550                 } catch (ExecutionException success) {
 551                     assertTrue(success.getCause() instanceof IndexOutOfBoundsException);
 552                 }
 553             }
 554         }};
 555 
 556         runWithPermissions(r, new RuntimePermission("modifyThread"));
 557     }
 558 
 559     /**
 560      * execute(null runnable) throws NullPointerException
 561      */
 562     public void testExecuteNullRunnable() {
 563         ExecutorService e = new ForkJoinPool(1);
 564         try (PoolCleaner cleaner = cleaner(e)) {
 565             try {
 566                 Future<?> future = e.submit((Runnable) null);
 567                 shouldThrow();
 568             } catch (NullPointerException success) {}
 569         }
 570     }
 571 
 572     /**
 573      * submit(null callable) throws NullPointerException
 574      */
 575     public void testSubmitNullCallable() {
 576         ExecutorService e = new ForkJoinPool(1);
 577         try (PoolCleaner cleaner = cleaner(e)) {
 578             try {
 579                 Future<String> future = e.submit((Callable) null);
 580                 shouldThrow();
 581             } catch (NullPointerException success) {}
 582         }
 583     }
 584 
 585     /**
 586      * submit(callable).get() throws InterruptedException if interrupted
 587      */
 588     public void testInterruptedSubmit() throws InterruptedException {
 589         final CountDownLatch submitted    = new CountDownLatch(1);
 590         final CountDownLatch quittingTime = new CountDownLatch(1);
 591         final Callable<Void> awaiter = new CheckedCallable<Void>() {
 592             public Void realCall() throws InterruptedException {
 593                 assertTrue(quittingTime.await(2*LONG_DELAY_MS, MILLISECONDS));
 594                 return null;
 595             }};
 596         final ExecutorService p = new ForkJoinPool(1);
 597         try (PoolCleaner cleaner = cleaner(p, quittingTime)) {
 598             Thread t = new Thread(new CheckedInterruptedRunnable() {
 599                 public void realRun() throws Exception {




 358     /**
 359      * Completed submit(ForkJoinTask) returns result
 360      */
 361     public void testSubmitForkJoinTask() throws Throwable {
 362         ForkJoinPool p = new ForkJoinPool(1);
 363         try (PoolCleaner cleaner = cleaner(p)) {
 364             ForkJoinTask<Integer> f = p.submit(new FibTask(8));
 365             assertEquals(21, (int) f.get());
 366         }
 367     }
 368 
 369     /**
 370      * A task submitted after shutdown is rejected
 371      */
 372     public void testSubmitAfterShutdown() {
 373         ForkJoinPool p = new ForkJoinPool(1);
 374         try (PoolCleaner cleaner = cleaner(p)) {
 375             p.shutdown();
 376             assertTrue(p.isShutdown());
 377             try {
 378                 ForkJoinTask<Integer> unused = p.submit(new FibTask(8));
 379                 shouldThrow();
 380             } catch (RejectedExecutionException success) {}
 381         }
 382     }
 383 
 384     /**
 385      * Pool maintains parallelism when using ManagedBlocker
 386      */
 387     public void testBlockingForkJoinTask() throws Throwable {
 388         ForkJoinPool p = new ForkJoinPool(4);
 389         try {
 390             ReentrantLock lock = new ReentrantLock();
 391             ManagedLocker locker = new ManagedLocker(lock);
 392             ForkJoinTask<Integer> f = new LockingFibTask(20, locker, lock);
 393             p.execute(f);
 394             assertEquals(6765, (int) f.get());
 395         } finally {
 396             p.shutdownNow(); // don't wait out shutdown
 397         }
 398     }


 546                 Future future = e.submit(callable);
 547                 try {
 548                     future.get();
 549                     shouldThrow();
 550                 } catch (ExecutionException success) {
 551                     assertTrue(success.getCause() instanceof IndexOutOfBoundsException);
 552                 }
 553             }
 554         }};
 555 
 556         runWithPermissions(r, new RuntimePermission("modifyThread"));
 557     }
 558 
 559     /**
 560      * execute(null runnable) throws NullPointerException
 561      */
 562     public void testExecuteNullRunnable() {
 563         ExecutorService e = new ForkJoinPool(1);
 564         try (PoolCleaner cleaner = cleaner(e)) {
 565             try {
 566                 Future<?> unused = e.submit((Runnable) null);
 567                 shouldThrow();
 568             } catch (NullPointerException success) {}
 569         }
 570     }
 571 
 572     /**
 573      * submit(null callable) throws NullPointerException
 574      */
 575     public void testSubmitNullCallable() {
 576         ExecutorService e = new ForkJoinPool(1);
 577         try (PoolCleaner cleaner = cleaner(e)) {
 578             try {
 579                 Future<String> unused = e.submit((Callable) null);
 580                 shouldThrow();
 581             } catch (NullPointerException success) {}
 582         }
 583     }
 584 
 585     /**
 586      * submit(callable).get() throws InterruptedException if interrupted
 587      */
 588     public void testInterruptedSubmit() throws InterruptedException {
 589         final CountDownLatch submitted    = new CountDownLatch(1);
 590         final CountDownLatch quittingTime = new CountDownLatch(1);
 591         final Callable<Void> awaiter = new CheckedCallable<Void>() {
 592             public Void realCall() throws InterruptedException {
 593                 assertTrue(quittingTime.await(2*LONG_DELAY_MS, MILLISECONDS));
 594                 return null;
 595             }};
 596         final ExecutorService p = new ForkJoinPool(1);
 597         try (PoolCleaner cleaner = cleaner(p, quittingTime)) {
 598             Thread t = new Thread(new CheckedInterruptedRunnable() {
 599                 public void realRun() throws Exception {


< prev index next >