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

Comparing jsr166/src/test/tck/FutureTaskTest.java (file contents):
Revision 1.32 by jsr166, Sun Dec 16 18:52:27 2012 UTC vs.
Revision 1.33 by jsr166, Thu Dec 20 04:58:53 2012 UTC

# Line 406 | Line 406 | public class FutureTaskTest extends JSR1
406      }
407  
408      /**
409 <     * cancel(true) interrupts a running task that subsequently
410 <     * succeeds, with a security manager that does not permit
411 <     * Thread.interrupt
409 >     * cancel(true) tries to interrupt a running task, but
410 >     * Thread.interrupt throws (simulating a restrictive security
411 >     * manager)
412       */
413      public void testCancelInterrupt_ThrowsSecurityException() {
414        if (System.getSecurityManager() != null)
415            return;
416
414          final CountDownLatch pleaseCancel = new CountDownLatch(1);
415          final CountDownLatch cancelled = new CountDownLatch(1);
416          final PublicFutureTask task =
# Line 424 | Line 421 | public class FutureTaskTest extends JSR1
421                      assertFalse(Thread.interrupted());
422                  }});
423  
424 <        final Thread t = newStartedThread(task);
424 >        final Thread t = new Thread(task) {
425 >            // Simulate a restrictive security manager.
426 >            @Override public void interrupt() {
427 >                throw new SecurityException();
428 >            }};
429 >        t.setDaemon(true);
430 >        t.start();
431 >
432          await(pleaseCancel);
429        System.setSecurityManager(new SecurityManager() {
430            public void checkAccess(Thread t) { throw new SecurityException(); }
431            public void checkPermission(Permission p) {}});
433          try {
434 <            try {
435 <                task.cancel(true);
436 <                shouldThrow();
437 <            }
438 <            catch (SecurityException expected) {}
439 <        } finally {
439 <            System.setSecurityManager(null);
440 <        }
434 >            task.cancel(true);
435 >            shouldThrow();
436 >        } catch (SecurityException expected) {}
437 >
438 >        // We failed to deliver the interrupt, but the world retains
439 >        // its sanity, as if we had done task.cancel(false)
440          assertTrue(task.isCancelled());
441          assertTrue(task.isDone());
442          assertEquals(1, task.runCount());

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines