--- jsr166/src/test/tck/AbstractExecutorServiceTest.java 2009/11/16 04:57:09 1.17 +++ jsr166/src/test/tck/AbstractExecutorServiceTest.java 2009/11/21 02:33:20 1.20 @@ -10,10 +10,11 @@ import junit.framework.*; import java.util.*; import java.util.concurrent.*; +import static java.util.concurrent.TimeUnit.MILLISECONDS; import java.math.BigInteger; import java.security.*; -public class AbstractExecutorServiceTest extends JSR166TestCase{ +public class AbstractExecutorServiceTest extends JSR166TestCase { public static void main(String[] args) { junit.textui.TestRunner.run (suite()); } @@ -38,83 +39,51 @@ public class AbstractExecutorServiceTest /** * execute(runnable) runs it to completion */ - public void testExecuteRunnable() { - try { - ExecutorService e = new DirectExecutorService(); - TrackedShortRunnable task = new TrackedShortRunnable(); - assertFalse(task.done); - Future future = e.submit(task); - future.get(); - assertTrue(task.done); - } - catch (ExecutionException ex) { - unexpectedException(); - } - catch (InterruptedException ex) { - unexpectedException(); - } + public void testExecuteRunnable() throws Exception { + ExecutorService e = new DirectExecutorService(); + TrackedShortRunnable task = new TrackedShortRunnable(); + assertFalse(task.done); + Future future = e.submit(task); + future.get(); + assertTrue(task.done); } /** * Completed submit(callable) returns result */ - public void testSubmitCallable() { - try { - ExecutorService e = new DirectExecutorService(); - Future future = e.submit(new StringTask()); - String result = future.get(); - assertSame(TEST_STRING, result); - } - catch (ExecutionException ex) { - unexpectedException(); - } - catch (InterruptedException ex) { - unexpectedException(); - } + public void testSubmitCallable() throws Exception { + ExecutorService e = new DirectExecutorService(); + Future future = e.submit(new StringTask()); + String result = future.get(); + assertSame(TEST_STRING, result); } /** * Completed submit(runnable) returns successfully */ - public void testSubmitRunnable() { - try { - ExecutorService e = new DirectExecutorService(); - Future future = e.submit(new NoOpRunnable()); - future.get(); - assertTrue(future.isDone()); - } - catch (ExecutionException ex) { - unexpectedException(); - } - catch (InterruptedException ex) { - unexpectedException(); - } + public void testSubmitRunnable() throws Exception { + ExecutorService e = new DirectExecutorService(); + Future future = e.submit(new NoOpRunnable()); + future.get(); + assertTrue(future.isDone()); } /** * Completed submit(runnable, result) returns result */ - public void testSubmitRunnable2() { - try { - ExecutorService e = new DirectExecutorService(); - Future future = e.submit(new NoOpRunnable(), TEST_STRING); - String result = future.get(); - assertSame(TEST_STRING, result); - } - catch (ExecutionException ex) { - unexpectedException(); - } - catch (InterruptedException ex) { - unexpectedException(); - } + public void testSubmitRunnable2() throws Exception { + ExecutorService e = new DirectExecutorService(); + Future future = e.submit(new NoOpRunnable(), TEST_STRING); + String result = future.get(); + assertSame(TEST_STRING, result); } /** * A submitted privileged action to completion */ - public void testSubmitPrivilegedAction() { + public void testSubmitPrivilegedAction() throws Exception { Policy savedPolicy = null; try { savedPolicy = Policy.getPolicy(); @@ -135,12 +104,6 @@ public class AbstractExecutorServiceTest Object result = future.get(); assertSame(TEST_STRING, result); } - catch (ExecutionException ex) { - unexpectedException(); - } - catch (InterruptedException ex) { - unexpectedException(); - } finally { try { Policy.setPolicy(savedPolicy); @@ -153,7 +116,7 @@ public class AbstractExecutorServiceTest /** * A submitted a privileged exception action runs to completion */ - public void testSubmitPrivilegedExceptionAction() { + public void testSubmitPrivilegedExceptionAction() throws Exception { Policy savedPolicy = null; try { savedPolicy = Policy.getPolicy(); @@ -175,12 +138,6 @@ public class AbstractExecutorServiceTest Object result = future.get(); assertSame(TEST_STRING, result); } - catch (ExecutionException ex) { - unexpectedException(); - } - catch (InterruptedException ex) { - unexpectedException(); - } finally { Policy.setPolicy(savedPolicy); } @@ -189,7 +146,7 @@ public class AbstractExecutorServiceTest /** * A submitted failed privileged exception action reports exception */ - public void testSubmitFailedPrivilegedExceptionAction() { + public void testSubmitFailedPrivilegedExceptionAction() throws Exception { Policy savedPolicy = null; try { savedPolicy = Policy.getPolicy(); @@ -201,7 +158,6 @@ public class AbstractExecutorServiceTest return; } - try { ExecutorService e = new DirectExecutorService(); Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() { @@ -209,13 +165,10 @@ public class AbstractExecutorServiceTest throw new IndexOutOfBoundsException(); }})); - Object result = future.get(); + future.get(); shouldThrow(); - } - catch (ExecutionException success) { - } - catch (InterruptedException ex) { - unexpectedException(); + } catch (ExecutionException success) { + assertTrue(success.getCause() instanceof IndexOutOfBoundsException); } finally { Policy.setPolicy(savedPolicy); @@ -228,15 +181,9 @@ public class AbstractExecutorServiceTest public void testExecuteNullRunnable() { try { ExecutorService e = new DirectExecutorService(); - TrackedShortRunnable task = null; - Future future = e.submit(task); + e.submit((Runnable) null); shouldThrow(); - } - catch (NullPointerException success) { - } - catch (Exception ex) { - unexpectedException(); - } + } catch (NullPointerException success) {} } @@ -246,15 +193,9 @@ public class AbstractExecutorServiceTest public void testSubmitNullCallable() { try { ExecutorService e = new DirectExecutorService(); - StringTask t = null; - Future future = e.submit(t); + e.submit((Callable) null); shouldThrow(); - } - catch (NullPointerException success) { - } - catch (Exception ex) { - unexpectedException(); - } + } catch (NullPointerException success) {} } /** @@ -262,15 +203,22 @@ public class AbstractExecutorServiceTest * executor is saturated. */ public void testExecute1() { - ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, 60, TimeUnit.SECONDS, new ArrayBlockingQueue(1)); + ThreadPoolExecutor p = + new ThreadPoolExecutor(1, 1, + 60, TimeUnit.SECONDS, + new ArrayBlockingQueue(1)); try { - - for (int i = 0; i < 5; ++i){ + 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) {} } - shouldThrow(); - } catch (RejectedExecutionException success){} - joinPool(p); + } finally { + joinPool(p); + } } /** @@ -278,14 +226,22 @@ public class AbstractExecutorServiceTest * if executor is saturated. */ public void testExecute2() { - ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, 60, TimeUnit.SECONDS, new ArrayBlockingQueue(1)); + ThreadPoolExecutor p = + new ThreadPoolExecutor(1, 1, + 60, TimeUnit.SECONDS, + new ArrayBlockingQueue(1)); try { - for (int i = 0; i < 5; ++i) { - p.submit(new SmallCallable()); + 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) {} } - shouldThrow(); - } catch (RejectedExecutionException e){} - joinPool(p); + } finally { + joinPool(p); + } } @@ -293,75 +249,43 @@ public class AbstractExecutorServiceTest * Blocking on submit(callable) throws InterruptedException if * caller interrupted. */ - public void testInterruptedSubmit() { + public void testInterruptedSubmit() throws InterruptedException { final ThreadPoolExecutor p = new ThreadPoolExecutor(1,1,60, TimeUnit.SECONDS, new ArrayBlockingQueue(10)); - Thread t = new Thread(new Runnable() { - public void run() { - try { - p.submit(new Callable() { - public Object call() { - try { - Thread.sleep(MEDIUM_DELAY_MS); - shouldThrow(); - } catch (InterruptedException e){ - } - return null; - } - }).get(); - } catch (InterruptedException success){ - } catch (Exception e) { - unexpectedException(); - } - - } - }); - try { - t.start(); - Thread.sleep(SHORT_DELAY_MS); - t.interrupt(); - } catch (Exception e){ - unexpectedException(); - } + 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 Exception if callable + * get of submitted callable throws InterruptedException if callable * interrupted */ - public void testSubmitIE() { - final ThreadPoolExecutor p = new ThreadPoolExecutor(1,1,60, TimeUnit.SECONDS, new ArrayBlockingQueue(10)); - - final Callable c = new Callable() { - public Object call() { - try { - p.submit(new SmallCallable()).get(); - shouldThrow(); - } catch (InterruptedException e){} - catch (RejectedExecutionException e2){} - catch (ExecutionException e3){} - return Boolean.TRUE; - } - }; - - - - Thread t = new Thread(new Runnable() { - public void run() { - try { - c.call(); - } catch (Exception e){} - } - }); - try { - t.start(); - Thread.sleep(SHORT_DELAY_MS); - t.interrupt(); - t.join(); - } catch (InterruptedException e){ - unexpectedException(); - } - + 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); } @@ -369,26 +293,20 @@ public class AbstractExecutorServiceTest * get of submit(callable) throws ExecutionException if callable * throws exception */ - public void testSubmitEE() { - ThreadPoolExecutor p = new ThreadPoolExecutor(1,1,60, TimeUnit.SECONDS, new ArrayBlockingQueue(10)); + public void testSubmitEE() throws InterruptedException { + ThreadPoolExecutor p = + new ThreadPoolExecutor(1, 1, + 60, TimeUnit.SECONDS, + new ArrayBlockingQueue(10)); - try { - Callable c = new Callable() { - public Object call() { - int i = 5/0; - return Boolean.TRUE; - } - }; - - for (int i =0; i < 5; i++){ - p.submit(c).get(); - } + Callable c = new Callable() { + public Object call() { return 5/0; }}; + try { + p.submit(c).get(); shouldThrow(); - } - catch (ExecutionException success){ - } catch (Exception e) { - unexpectedException(); + } catch (ExecutionException success) { + assertTrue(success.getCause() instanceof ArithmeticException); } joinPool(p); } @@ -396,13 +314,13 @@ public class AbstractExecutorServiceTest /** * invokeAny(null) throws NPE */ - public void testInvokeAny1() { + public void testInvokeAny1() + throws InterruptedException, ExecutionException { ExecutorService e = new DirectExecutorService(); try { e.invokeAny(null); + shouldThrow(); } catch (NullPointerException success) { - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -411,13 +329,13 @@ public class AbstractExecutorServiceTest /** * invokeAny(empty collection) throws IAE */ - public void testInvokeAny2() { + public void testInvokeAny2() + throws InterruptedException, ExecutionException { ExecutorService e = new DirectExecutorService(); try { e.invokeAny(new ArrayList>()); + shouldThrow(); } catch (IllegalArgumentException success) { - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -426,18 +344,20 @@ public class AbstractExecutorServiceTest /** * invokeAny(c) throws NPE if c has null elements */ - public void testInvokeAny3() { + public void testInvokeAny3() throws Exception { + final CountDownLatch latch = new CountDownLatch(1); ExecutorService e = new DirectExecutorService(); try { - ArrayList> l = new ArrayList>(); - l.add(new StringTask()); + ArrayList> l + = new ArrayList>(); + l.add(new Callable() { + public Integer call() { return 5/0; }}); l.add(null); e.invokeAny(l); + shouldThrow(); } catch (NullPointerException success) { - } catch (Exception ex) { - ex.printStackTrace(); - unexpectedException(); } finally { + latch.countDown(); joinPool(e); } } @@ -445,15 +365,15 @@ public class AbstractExecutorServiceTest /** * invokeAny(c) throws ExecutionException if no task in c completes */ - public void testInvokeAny4() { + public void testInvokeAny4() throws InterruptedException { ExecutorService e = new DirectExecutorService(); try { ArrayList> l = new ArrayList>(); l.add(new NPETask()); e.invokeAny(l); + shouldThrow(); } catch (ExecutionException success) { - } catch (Exception ex) { - unexpectedException(); + assertTrue(success.getCause() instanceof NullPointerException); } finally { joinPool(e); } @@ -462,7 +382,7 @@ public class AbstractExecutorServiceTest /** * invokeAny(c) returns result of some task in c if at least one completes */ - public void testInvokeAny5() { + public void testInvokeAny5() throws Exception { ExecutorService e = new DirectExecutorService(); try { ArrayList> l = new ArrayList>(); @@ -470,9 +390,6 @@ public class AbstractExecutorServiceTest l.add(new StringTask()); String result = e.invokeAny(l); assertSame(TEST_STRING, result); - } catch (ExecutionException success) { - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -481,13 +398,12 @@ public class AbstractExecutorServiceTest /** * invokeAll(null) throws NPE */ - public void testInvokeAll1() { + public void testInvokeAll1() throws InterruptedException { ExecutorService e = new DirectExecutorService(); try { e.invokeAll(null); + shouldThrow(); } catch (NullPointerException success) { - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -496,13 +412,11 @@ public class AbstractExecutorServiceTest /** * invokeAll(empty collection) returns empty collection */ - public void testInvokeAll2() { + public void testInvokeAll2() throws InterruptedException { ExecutorService e = new DirectExecutorService(); try { List> r = e.invokeAll(new ArrayList>()); assertTrue(r.isEmpty()); - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -511,16 +425,15 @@ public class AbstractExecutorServiceTest /** * invokeAll(c) throws NPE if c has null elements */ - public void testInvokeAll3() { + public void testInvokeAll3() throws InterruptedException { ExecutorService e = new DirectExecutorService(); try { ArrayList> l = new ArrayList>(); l.add(new StringTask()); l.add(null); e.invokeAll(l); + shouldThrow(); } catch (NullPointerException success) { - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -529,18 +442,22 @@ public class AbstractExecutorServiceTest /** * get of returned element of invokeAll(c) throws exception on failed task */ - public void testInvokeAll4() { + public void testInvokeAll4() throws Exception { ExecutorService e = new DirectExecutorService(); try { ArrayList> l = new ArrayList>(); l.add(new NPETask()); List> result = e.invokeAll(l); assertEquals(1, result.size()); - for (Iterator> it = result.iterator(); it.hasNext();) - it.next().get(); - } catch (ExecutionException success) { - } catch (Exception ex) { - unexpectedException(); + for (Future future : result) { + try { + future.get(); + shouldThrow(); + } catch (ExecutionException success) { + Throwable cause = success.getCause(); + assertTrue(cause instanceof NullPointerException); + } + } } finally { joinPool(e); } @@ -549,7 +466,7 @@ public class AbstractExecutorServiceTest /** * invokeAll(c) returns results of all completed tasks in c */ - public void testInvokeAll5() { + public void testInvokeAll5() throws Exception { ExecutorService e = new DirectExecutorService(); try { ArrayList> l = new ArrayList>(); @@ -557,11 +474,8 @@ public class AbstractExecutorServiceTest l.add(new StringTask()); List> result = e.invokeAll(l); assertEquals(2, result.size()); - for (Iterator> it = result.iterator(); it.hasNext();) - assertSame(TEST_STRING, it.next().get()); - } catch (ExecutionException success) { - } catch (Exception ex) { - unexpectedException(); + for (Future future : result) + assertSame(TEST_STRING, future.get()); } finally { joinPool(e); } @@ -571,13 +485,12 @@ public class AbstractExecutorServiceTest /** * timed invokeAny(null) throws NPE */ - public void testTimedInvokeAny1() { + public void testTimedInvokeAny1() throws Exception { ExecutorService e = new DirectExecutorService(); try { - e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); + e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS); + shouldThrow(); } catch (NullPointerException success) { - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -586,15 +499,14 @@ public class AbstractExecutorServiceTest /** * timed invokeAny(null time unit) throws NPE */ - public void testTimedInvokeAnyNullTimeUnit() { + public void testTimedInvokeAnyNullTimeUnit() throws Exception { ExecutorService e = new DirectExecutorService(); try { ArrayList> l = new ArrayList>(); l.add(new StringTask()); e.invokeAny(l, MEDIUM_DELAY_MS, null); + shouldThrow(); } catch (NullPointerException success) { - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -603,13 +515,12 @@ public class AbstractExecutorServiceTest /** * timed invokeAny(empty collection) throws IAE */ - public void testTimedInvokeAny2() { + public void testTimedInvokeAny2() throws Exception { ExecutorService e = new DirectExecutorService(); try { - e.invokeAny(new ArrayList>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); + e.invokeAny(new ArrayList>(), MEDIUM_DELAY_MS, MILLISECONDS); + shouldThrow(); } catch (IllegalArgumentException success) { - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -618,18 +529,20 @@ public class AbstractExecutorServiceTest /** * timed invokeAny(c) throws NPE if c has null elements */ - public void testTimedInvokeAny3() { + public void testTimedInvokeAny3() throws Exception { + final CountDownLatch latch = new CountDownLatch(1); ExecutorService e = new DirectExecutorService(); try { - ArrayList> l = new ArrayList>(); - l.add(new StringTask()); + ArrayList> l + = new ArrayList>(); + l.add(new Callable() { + public Integer call() { return 5/0; }}); l.add(null); - e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); + e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); + shouldThrow(); } catch (NullPointerException success) { - } catch (Exception ex) { - ex.printStackTrace(); - unexpectedException(); } finally { + latch.countDown(); joinPool(e); } } @@ -637,15 +550,15 @@ public class AbstractExecutorServiceTest /** * timed invokeAny(c) throws ExecutionException if no task completes */ - public void testTimedInvokeAny4() { + public void testTimedInvokeAny4() throws Exception { ExecutorService e = new DirectExecutorService(); try { ArrayList> l = new ArrayList>(); l.add(new NPETask()); - e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); + e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); + shouldThrow(); } catch (ExecutionException success) { - } catch (Exception ex) { - unexpectedException(); + assertTrue(success.getCause() instanceof NullPointerException); } finally { joinPool(e); } @@ -654,17 +567,14 @@ public class AbstractExecutorServiceTest /** * timed invokeAny(c) returns result of some task in c */ - public void testTimedInvokeAny5() { + public void testTimedInvokeAny5() throws Exception { ExecutorService e = new DirectExecutorService(); try { ArrayList> l = new ArrayList>(); l.add(new StringTask()); l.add(new StringTask()); - String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); + String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); assertSame(TEST_STRING, result); - } catch (ExecutionException success) { - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -673,13 +583,12 @@ public class AbstractExecutorServiceTest /** * timed invokeAll(null) throws NPE */ - public void testTimedInvokeAll1() { + public void testTimedInvokeAll1() throws InterruptedException { ExecutorService e = new DirectExecutorService(); try { - e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); + e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS); + shouldThrow(); } catch (NullPointerException success) { - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -688,15 +597,14 @@ public class AbstractExecutorServiceTest /** * timed invokeAll(null time unit) throws NPE */ - public void testTimedInvokeAllNullTimeUnit() { + public void testTimedInvokeAllNullTimeUnit() throws InterruptedException { ExecutorService e = new DirectExecutorService(); try { ArrayList> l = new ArrayList>(); l.add(new StringTask()); e.invokeAll(l, MEDIUM_DELAY_MS, null); + shouldThrow(); } catch (NullPointerException success) { - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -705,13 +613,11 @@ public class AbstractExecutorServiceTest /** * timed invokeAll(empty collection) returns empty collection */ - public void testTimedInvokeAll2() { + public void testTimedInvokeAll2() throws InterruptedException { ExecutorService e = new DirectExecutorService(); try { - List> r = e.invokeAll(new ArrayList>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); + List> r = e.invokeAll(new ArrayList>(), MEDIUM_DELAY_MS, MILLISECONDS); assertTrue(r.isEmpty()); - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -720,16 +626,15 @@ public class AbstractExecutorServiceTest /** * timed invokeAll(c) throws NPE if c has null elements */ - public void testTimedInvokeAll3() { + public void testTimedInvokeAll3() throws InterruptedException { ExecutorService e = new DirectExecutorService(); try { ArrayList> l = new ArrayList>(); l.add(new StringTask()); l.add(null); - e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); + e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); + shouldThrow(); } catch (NullPointerException success) { - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -738,18 +643,20 @@ public class AbstractExecutorServiceTest /** * get of returned element of invokeAll(c) throws exception on failed task */ - public void testTimedInvokeAll4() { + public void testTimedInvokeAll4() throws Exception { ExecutorService e = new DirectExecutorService(); try { ArrayList> l = new ArrayList>(); l.add(new NPETask()); - List> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); + List> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); assertEquals(1, result.size()); - for (Iterator> it = result.iterator(); it.hasNext();) - it.next().get(); - } catch (ExecutionException success) { - } catch (Exception ex) { - unexpectedException(); + for (Future future : result) { + try { + future.get(); + } catch (ExecutionException success) { + assertTrue(success.getCause() instanceof NullPointerException); + } + } } finally { joinPool(e); } @@ -758,19 +665,16 @@ public class AbstractExecutorServiceTest /** * timed invokeAll(c) returns results of all completed tasks in c */ - public void testTimedInvokeAll5() { + public void testTimedInvokeAll5() throws Exception { ExecutorService e = new DirectExecutorService(); try { ArrayList> l = new ArrayList>(); l.add(new StringTask()); l.add(new StringTask()); - List> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); + List> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); assertEquals(2, result.size()); - for (Iterator> it = result.iterator(); it.hasNext();) - assertSame(TEST_STRING, it.next().get()); - } catch (ExecutionException success) { - } catch (Exception ex) { - unexpectedException(); + for (Future future : result) + assertSame(TEST_STRING, future.get()); } finally { joinPool(e); } @@ -779,14 +683,14 @@ public class AbstractExecutorServiceTest /** * timed invokeAll cancels tasks not completed by timeout */ - public void testTimedInvokeAll6() { + public void testTimedInvokeAll6() throws InterruptedException { ExecutorService e = new DirectExecutorService(); try { ArrayList> l = new ArrayList>(); l.add(new StringTask()); l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING)); l.add(new StringTask()); - List> result = e.invokeAll(l, SMALL_DELAY_MS, TimeUnit.MILLISECONDS); + List> result = e.invokeAll(l, SMALL_DELAY_MS, MILLISECONDS); assertEquals(3, result.size()); Iterator> it = result.iterator(); Future f1 = it.next(); @@ -797,8 +701,6 @@ public class AbstractExecutorServiceTest assertTrue(f2.isDone()); assertTrue(f3.isDone()); assertTrue(f3.isCancelled()); - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); }