235 |
|
ForkJoinPool p = null; |
236 |
|
try { |
237 |
|
p = new ForkJoinPool(1); |
238 |
< |
assertTrue(p.getPoolSize() == 0); |
238 |
> |
assertTrue(p.getActiveThreadCount() == 0); |
239 |
|
Future<String> future = p.submit(new StringTask()); |
240 |
|
assertTrue(p.getPoolSize() == 1); |
241 |
|
|
320 |
|
Thread.sleep(MEDIUM_DELAY_MS); |
321 |
|
assertTrue(eh.catches > 0); |
322 |
|
} finally { |
323 |
+ |
p.shutdownNow(); |
324 |
|
joinPool(p); |
325 |
|
} |
326 |
|
} |
505 |
|
assertSame(TEST_STRING, result); |
506 |
|
} |
507 |
|
|
507 |
– |
|
508 |
|
/** |
509 |
< |
* A submitted privileged action to completion |
509 |
> |
* A submitted privileged action runs to completion |
510 |
|
*/ |
511 |
|
public void testSubmitPrivilegedAction() throws Throwable { |
512 |
< |
Policy savedPolicy = null; |
513 |
< |
try { |
514 |
< |
savedPolicy = Policy.getPolicy(); |
515 |
< |
AdjustablePolicy policy = new AdjustablePolicy(); |
516 |
< |
policy.addPermission(new RuntimePermission("getContextClassLoader")); |
517 |
< |
policy.addPermission(new RuntimePermission("setContextClassLoader")); |
518 |
< |
Policy.setPolicy(policy); |
519 |
< |
} catch (AccessControlException ok) { |
520 |
< |
return; |
521 |
< |
} |
522 |
< |
try { |
523 |
< |
ExecutorService e = new ForkJoinPool(1); |
524 |
< |
Future future = e.submit(Executors.callable(new PrivilegedAction() { |
512 |
> |
Runnable r = new CheckedRunnable() { |
513 |
> |
public void realRun() throws Exception { |
514 |
> |
ExecutorService e = new ForkJoinPool(1); |
515 |
> |
Future future = e.submit(Executors.callable(new PrivilegedAction() { |
516 |
|
public Object run() { |
517 |
|
return TEST_STRING; |
518 |
|
}})); |
519 |
|
|
520 |
< |
Object result = future.get(); |
521 |
< |
assertSame(TEST_STRING, result); |
522 |
< |
} |
523 |
< |
finally { |
524 |
< |
Policy.setPolicy(savedPolicy); |
534 |
< |
} |
520 |
> |
Object result = future.get(); |
521 |
> |
assertSame(TEST_STRING, result); |
522 |
> |
}}; |
523 |
> |
|
524 |
> |
runWithPermissions(r, new RuntimePermission("modifyThread")); |
525 |
|
} |
526 |
|
|
527 |
|
/** |
528 |
< |
* A submitted a privileged exception action runs to completion |
528 |
> |
* A submitted privileged exception action runs to completion |
529 |
|
*/ |
530 |
|
public void testSubmitPrivilegedExceptionAction() throws Throwable { |
531 |
< |
Policy savedPolicy = null; |
532 |
< |
try { |
533 |
< |
savedPolicy = Policy.getPolicy(); |
534 |
< |
AdjustablePolicy policy = new AdjustablePolicy(); |
545 |
< |
policy.addPermission(new RuntimePermission("getContextClassLoader")); |
546 |
< |
policy.addPermission(new RuntimePermission("setContextClassLoader")); |
547 |
< |
Policy.setPolicy(policy); |
548 |
< |
} catch (AccessControlException ok) { |
549 |
< |
return; |
550 |
< |
} |
551 |
< |
|
552 |
< |
try { |
553 |
< |
ExecutorService e = new ForkJoinPool(1); |
554 |
< |
Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() { |
531 |
> |
Runnable r = new CheckedRunnable() { |
532 |
> |
public void realRun() throws Exception { |
533 |
> |
ExecutorService e = new ForkJoinPool(1); |
534 |
> |
Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() { |
535 |
|
public Object run() { |
536 |
|
return TEST_STRING; |
537 |
|
}})); |
538 |
|
|
539 |
< |
Object result = future.get(); |
540 |
< |
assertSame(TEST_STRING, result); |
541 |
< |
} |
542 |
< |
finally { |
543 |
< |
Policy.setPolicy(savedPolicy); |
564 |
< |
} |
539 |
> |
Object result = future.get(); |
540 |
> |
assertSame(TEST_STRING, result); |
541 |
> |
}}; |
542 |
> |
|
543 |
> |
runWithPermissions(r, new RuntimePermission("modifyThread")); |
544 |
|
} |
545 |
|
|
546 |
|
/** |
547 |
|
* A submitted failed privileged exception action reports exception |
548 |
|
*/ |
549 |
|
public void testSubmitFailedPrivilegedExceptionAction() throws Throwable { |
550 |
< |
Policy savedPolicy = null; |
551 |
< |
try { |
552 |
< |
savedPolicy = Policy.getPolicy(); |
553 |
< |
AdjustablePolicy policy = new AdjustablePolicy(); |
575 |
< |
policy.addPermission(new RuntimePermission("getContextClassLoader")); |
576 |
< |
policy.addPermission(new RuntimePermission("setContextClassLoader")); |
577 |
< |
Policy.setPolicy(policy); |
578 |
< |
} catch (AccessControlException ok) { |
579 |
< |
return; |
580 |
< |
} |
581 |
< |
|
582 |
< |
|
583 |
< |
try { |
584 |
< |
ExecutorService e = new ForkJoinPool(1); |
585 |
< |
Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() { |
550 |
> |
Runnable r = new CheckedRunnable() { |
551 |
> |
public void realRun() throws Exception { |
552 |
> |
ExecutorService e = new ForkJoinPool(1); |
553 |
> |
Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() { |
554 |
|
public Object run() throws Exception { |
555 |
|
throw new IndexOutOfBoundsException(); |
556 |
|
}})); |
557 |
|
|
558 |
< |
Object result = future.get(); |
559 |
< |
shouldThrow(); |
560 |
< |
} catch (ExecutionException success) { |
561 |
< |
assertTrue(success.getCause() instanceof IndexOutOfBoundsException); |
562 |
< |
} finally { |
563 |
< |
Policy.setPolicy(savedPolicy); |
564 |
< |
} |
558 |
> |
try { |
559 |
> |
Object result = future.get(); |
560 |
> |
shouldThrow(); |
561 |
> |
} catch (ExecutionException success) { |
562 |
> |
assertTrue(success.getCause() instanceof IndexOutOfBoundsException); |
563 |
> |
}}}; |
564 |
> |
|
565 |
> |
runWithPermissions(r, new RuntimePermission("modifyThread")); |
566 |
|
} |
567 |
|
|
568 |
|
/** |