--- jsr166/src/test/tck/AbstractExecutorServiceTest.java 2010/01/05 02:08:37 1.23 +++ jsr166/src/test/tck/AbstractExecutorServiceTest.java 2010/09/17 00:53:15 1.26 @@ -16,7 +16,7 @@ import java.security.*; public class AbstractExecutorServiceTest extends JSR166TestCase { public static void main(String[] args) { - junit.textui.TestRunner.run (suite()); + junit.textui.TestRunner.run(suite()); } public static Test suite() { return new TestSuite(AbstractExecutorServiceTest.class); @@ -29,10 +29,15 @@ public class AbstractExecutorServiceTest static class DirectExecutorService extends AbstractExecutorService { public void execute(Runnable r) { r.run(); } public void shutdown() { shutdown = true; } - public List shutdownNow() { shutdown = true; return Collections.EMPTY_LIST; } + public List shutdownNow() { + shutdown = true; + return Collections.EMPTY_LIST; + } public boolean isShutdown() { return shutdown; } public boolean isTerminated() { return isShutdown(); } - public boolean awaitTermination(long timeout, TimeUnit unit) { return isShutdown(); } + public boolean awaitTermination(long timeout, TimeUnit unit) { + return isShutdown(); + } private volatile boolean shutdown = false; } @@ -212,25 +217,34 @@ public class AbstractExecutorServiceTest /** - * Blocking on submit(callable) throws InterruptedException if - * caller interrupted. + * submit(callable).get() throws InterruptedException if interrupted */ public void testInterruptedSubmit() throws InterruptedException { - final ThreadPoolExecutor p = new ThreadPoolExecutor(1,1,60, TimeUnit.SECONDS, new ArrayBlockingQueue(10)); - Thread t = new Thread(new CheckedInterruptedRunnable() { - public void realRun() throws Exception { - p.submit(new CheckedCallable() { - public Object realCall() - throws InterruptedException { - Thread.sleep(SMALL_DELAY_MS); - return null; - }}).get(); - }}); - - t.start(); - Thread.sleep(SHORT_DELAY_MS); - t.interrupt(); - joinPool(p); + final CountDownLatch submitted = new CountDownLatch(1); + final CountDownLatch quittingTime = new CountDownLatch(1); + final ExecutorService p + = new ThreadPoolExecutor(1,1,60, TimeUnit.SECONDS, + new ArrayBlockingQueue(10)); + final Callable awaiter = new CheckedCallable() { + public Void realCall() throws InterruptedException { + quittingTime.await(); + return null; + }}; + try { + Thread t = new Thread(new CheckedInterruptedRunnable() { + public void realRun() throws Exception { + Future future = p.submit(awaiter); + submitted.countDown(); + future.get(); + }}); + t.start(); + submitted.await(); + t.interrupt(); + t.join(); + } finally { + quittingTime.countDown(); + joinPool(p); + } } /**