--- jsr166/src/test/tck/AbstractExecutorServiceTest.java 2010/08/25 00:07:02 1.24 +++ jsr166/src/test/tck/AbstractExecutorServiceTest.java 2010/10/11 07:21:32 1.28 @@ -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; } @@ -165,99 +170,39 @@ public class AbstractExecutorServiceTest } /** - * submit(runnable) throws RejectedExecutionException if - * executor is saturated. + * submit(callable).get() throws InterruptedException if interrupted */ - public void testExecute1() { - ThreadPoolExecutor p = - new ThreadPoolExecutor(1, 1, - 60, TimeUnit.SECONDS, - new ArrayBlockingQueue(1)); - try { - for (int i = 0; i < 2; ++i) - p.submit(new MediumRunnable()); - for (int i = 0; i < 2; ++i) { - try { - p.submit(new MediumRunnable()); - shouldThrow(); - } catch (RejectedExecutionException success) {} - } - } finally { - joinPool(p); - } - } - - /** - * submit(callable) throws RejectedExecutionException - * if executor is saturated. - */ - public void testExecute2() { - ThreadPoolExecutor p = - new ThreadPoolExecutor(1, 1, - 60, TimeUnit.SECONDS, - new ArrayBlockingQueue(1)); + public void testInterruptedSubmit() throws InterruptedException { + 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 { - for (int i = 0; i < 2; ++i) - p.submit(new MediumRunnable()); - for (int i = 0; i < 2; ++i) { - try { - p.submit(new SmallCallable()); - shouldThrow(); - } catch (RejectedExecutionException success) {} - } + 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); } } - - /** - * Blocking on submit(callable) throws InterruptedException if - * caller 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); - } - - /** - * get of submitted callable throws InterruptedException if callable - * interrupted - */ - public void testSubmitIE() 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 SmallCallable()).get(); - }}); - - t.start(); - Thread.sleep(SHORT_DELAY_MS); - t.interrupt(); - t.join(); - joinPool(p); - } - /** - * get of submit(callable) throws ExecutionException if callable - * throws exception + * get of submit(callable) throws ExecutionException if callable + * throws exception */ public void testSubmitEE() throws InterruptedException { ThreadPoolExecutor p = @@ -280,8 +225,7 @@ public class AbstractExecutorServiceTest /** * invokeAny(null) throws NPE */ - public void testInvokeAny1() - throws InterruptedException, ExecutionException { + public void testInvokeAny1() throws Exception { ExecutorService e = new DirectExecutorService(); try { e.invokeAny(null); @@ -295,8 +239,7 @@ public class AbstractExecutorServiceTest /** * invokeAny(empty collection) throws IAE */ - public void testInvokeAny2() - throws InterruptedException, ExecutionException { + public void testInvokeAny2() throws Exception { ExecutorService e = new DirectExecutorService(); try { e.invokeAny(new ArrayList>());