455 |
|
* A submitted privileged action runs to completion |
456 |
|
*/ |
457 |
|
public void testSubmitPrivilegedAction() throws Exception { |
458 |
+ |
final Callable callable = Executors.callable(new PrivilegedAction() { |
459 |
+ |
public Object run() { return TEST_STRING; }}); |
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 PrivilegedAction() { |
464 |
< |
public Object run() { |
463 |
< |
return TEST_STRING; |
464 |
< |
}})); |
465 |
< |
|
461 |
> |
public void realRun() throws Exception { |
462 |
> |
ExecutorService e = new ForkJoinPool(1); |
463 |
> |
try { |
464 |
> |
Future future = e.submit(callable); |
465 |
|
assertSame(TEST_STRING, future.get()); |
466 |
< |
}}; |
466 |
> |
} finally { |
467 |
> |
joinPool(e); |
468 |
> |
} |
469 |
> |
}}; |
470 |
|
|
471 |
< |
runWithPermissions(r, |
470 |
< |
new RuntimePermission("modifyThread")); |
471 |
> |
runWithPermissions(r, new RuntimePermission("modifyThread")); |
472 |
|
} |
473 |
|
|
474 |
|
/** |
475 |
|
* A submitted privileged exception action runs to completion |
476 |
|
*/ |
477 |
|
public void testSubmitPrivilegedExceptionAction() throws Exception { |
478 |
+ |
final Callable callable = |
479 |
+ |
Executors.callable(new PrivilegedExceptionAction() { |
480 |
+ |
public Object run() { return TEST_STRING; }}); |
481 |
|
Runnable r = new CheckedRunnable() { |
482 |
< |
public void realRun() throws Exception { |
483 |
< |
ExecutorService e = new ForkJoinPool(1); |
484 |
< |
Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() { |
485 |
< |
public Object run() { |
482 |
< |
return TEST_STRING; |
483 |
< |
}})); |
484 |
< |
|
482 |
> |
public void realRun() throws Exception { |
483 |
> |
ExecutorService e = new ForkJoinPool(1); |
484 |
> |
try { |
485 |
> |
Future future = e.submit(callable); |
486 |
|
assertSame(TEST_STRING, future.get()); |
487 |
< |
}}; |
487 |
> |
} finally { |
488 |
> |
joinPool(e); |
489 |
> |
} |
490 |
> |
}}; |
491 |
|
|
492 |
|
runWithPermissions(r, new RuntimePermission("modifyThread")); |
493 |
|
} |
496 |
|
* A submitted failed privileged exception action reports exception |
497 |
|
*/ |
498 |
|
public void testSubmitFailedPrivilegedExceptionAction() throws Exception { |
499 |
+ |
final Callable callable = |
500 |
+ |
Executors.callable(new PrivilegedExceptionAction() { |
501 |
+ |
public Object run() { throw new IndexOutOfBoundsException(); }}); |
502 |
|
Runnable r = new CheckedRunnable() { |
503 |
< |
public void realRun() throws Exception { |
504 |
< |
ExecutorService e = new ForkJoinPool(1); |
505 |
< |
Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() { |
506 |
< |
public Object run() throws Exception { |
500 |
< |
throw new IndexOutOfBoundsException(); |
501 |
< |
}})); |
502 |
< |
|
503 |
> |
public void realRun() throws Exception { |
504 |
> |
ExecutorService e = new ForkJoinPool(1); |
505 |
> |
try { |
506 |
> |
Future future = e.submit(callable); |
507 |
|
try { |
508 |
|
future.get(); |
509 |
|
shouldThrow(); |
510 |
|
} catch (ExecutionException success) { |
511 |
|
assertTrue(success.getCause() instanceof IndexOutOfBoundsException); |
512 |
< |
}}}; |
512 |
> |
} |
513 |
> |
} finally { |
514 |
> |
joinPool(e); |
515 |
> |
} |
516 |
> |
}}; |
517 |
|
|
518 |
|
runWithPermissions(r, new RuntimePermission("modifyThread")); |
519 |
|
} |