--- jsr166/src/test/tck/ScheduledExecutorTest.java 2009/11/20 22:58:48 1.25 +++ jsr166/src/test/tck/ScheduledExecutorTest.java 2010/10/09 18:40:41 1.31 @@ -14,10 +14,10 @@ import java.util.concurrent.atomic.*; public class ScheduledExecutorTest 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(ScheduledExecutorTest.class); + return new TestSuite(ScheduledExecutorTest.class); } @@ -25,7 +25,7 @@ public class ScheduledExecutorTest exten * execute successfully executes a runnable */ public void testExecute() throws InterruptedException { - TrackedShortRunnable runnable =new TrackedShortRunnable(); + TrackedShortRunnable runnable = new TrackedShortRunnable(); ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); p1.execute(runnable); assertFalse(runnable.done); @@ -137,30 +137,30 @@ public class ScheduledExecutorTest exten /** - * execute (null) throws NPE + * execute(null) throws NPE */ public void testExecuteNull() throws InterruptedException { ScheduledThreadPoolExecutor se = null; try { - se = new ScheduledThreadPoolExecutor(1); - se.execute(null); + se = new ScheduledThreadPoolExecutor(1); + se.execute(null); shouldThrow(); - } catch (NullPointerException success) {} + } catch (NullPointerException success) {} - joinPool(se); + joinPool(se); } /** - * schedule (null) throws NPE + * schedule(null) throws NPE */ public void testScheduleNull() throws InterruptedException { ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1); - try { + try { TrackedCallable callable = null; - Future f = se.schedule(callable, SHORT_DELAY_MS, MILLISECONDS); + Future f = se.schedule(callable, SHORT_DELAY_MS, MILLISECONDS); shouldThrow(); - } catch (NullPointerException success) {} - joinPool(se); + } catch (NullPointerException success) {} + joinPool(se); } /** @@ -178,7 +178,6 @@ public class ScheduledExecutorTest exten } joinPool(se); - } /** @@ -325,7 +324,7 @@ public class ScheduledExecutorTest exten */ public void testGetThreadFactory() throws InterruptedException { ThreadFactory tf = new SimpleThreadFactory(); - ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1, tf); + ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1, tf); assertSame(tf, p.getThreadFactory()); joinPool(p); } @@ -335,7 +334,7 @@ public class ScheduledExecutorTest exten */ public void testSetThreadFactory() throws InterruptedException { ThreadFactory tf = new SimpleThreadFactory(); - ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); + ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); p.setThreadFactory(tf); assertSame(tf, p.getThreadFactory()); joinPool(p); @@ -345,7 +344,7 @@ public class ScheduledExecutorTest exten * setThreadFactory(null) throws NPE */ public void testSetThreadFactoryNull() throws InterruptedException { - ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); + ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); try { p.setThreadFactory(null); shouldThrow(); @@ -360,14 +359,14 @@ public class ScheduledExecutorTest exten */ public void testIsShutdown() { - ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); + ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); try { assertFalse(p1.isShutdown()); } finally { try { p1.shutdown(); } catch (SecurityException ok) { return; } } - assertTrue(p1.isShutdown()); + assertTrue(p1.isShutdown()); } @@ -375,7 +374,7 @@ public class ScheduledExecutorTest exten * isTerminated is false before termination, true after */ public void testIsTerminated() throws InterruptedException { - ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); + ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); try { p1.execute(new SmallRunnable()); } finally { @@ -389,7 +388,7 @@ public class ScheduledExecutorTest exten * isTerminating is not true when running or when terminated */ public void testIsTerminating() throws InterruptedException { - ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); + ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); assertFalse(p1.isTerminating()); try { p1.execute(new SmallRunnable()); @@ -481,7 +480,7 @@ public class ScheduledExecutorTest exten * shutDownNow returns a list containing tasks that were not run */ public void testShutDownNow() throws InterruptedException { - ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); + ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); for (int i = 0; i < 5; i++) p1.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, MILLISECONDS); List l; @@ -490,8 +489,8 @@ public class ScheduledExecutorTest exten } catch (SecurityException ok) { return; } - assertTrue(p1.isShutdown()); - assertTrue(l.size() > 0 && l.size() <= 5); + assertTrue(p1.isShutdown()); + assertTrue(l.size() > 0 && l.size() <= 5); joinPool(p1); } @@ -659,18 +658,12 @@ public class ScheduledExecutorTest exten * invokeAny(c) throws NPE if c has null elements */ public void testInvokeAny3() throws Exception { - final CountDownLatch latch = new CountDownLatch(1); + CountDownLatch latch = new CountDownLatch(1); ExecutorService e = new ScheduledThreadPoolExecutor(2); + List> l = new ArrayList>(); + l.add(latchAwaitingStringTask(latch)); + l.add(null); try { - ArrayList> l = new ArrayList>(); - l.add(new Callable() { - public String call() { - try { - latch.await(); - } catch (InterruptedException ok) {} - return TEST_STRING; - }}); - l.add(null); e.invokeAny(l); shouldThrow(); } catch (NullPointerException success) { @@ -685,9 +678,9 @@ public class ScheduledExecutorTest exten */ public void testInvokeAny4() throws Exception { ExecutorService e = new ScheduledThreadPoolExecutor(2); + List> l = new ArrayList>(); + l.add(new NPETask()); try { - ArrayList> l = new ArrayList>(); - l.add(new NPETask()); e.invokeAny(l); shouldThrow(); } catch (ExecutionException success) { @@ -703,7 +696,7 @@ public class ScheduledExecutorTest exten public void testInvokeAny5() throws Exception { ExecutorService e = new ScheduledThreadPoolExecutor(2); try { - ArrayList> l = new ArrayList>(); + List> l = new ArrayList>(); l.add(new StringTask()); l.add(new StringTask()); String result = e.invokeAny(l); @@ -745,10 +738,10 @@ public class ScheduledExecutorTest exten */ public void testInvokeAll3() throws Exception { ExecutorService e = new ScheduledThreadPoolExecutor(2); + List> l = new ArrayList>(); + l.add(new StringTask()); + l.add(null); try { - ArrayList> l = new ArrayList>(); - l.add(new StringTask()); - l.add(null); e.invokeAll(l); shouldThrow(); } catch (NullPointerException success) { @@ -762,13 +755,12 @@ public class ScheduledExecutorTest exten */ public void testInvokeAll4() throws Exception { ExecutorService e = new ScheduledThreadPoolExecutor(2); + List> l = new ArrayList>(); + l.add(new NPETask()); + List> futures = e.invokeAll(l); + assertEquals(1, futures.size()); try { - ArrayList> l = new ArrayList>(); - l.add(new NPETask()); - List> result = e.invokeAll(l); - assertEquals(1, result.size()); - for (Future future : result) - future.get(); + futures.get(0).get(); shouldThrow(); } catch (ExecutionException success) { assertTrue(success.getCause() instanceof NullPointerException); @@ -783,12 +775,12 @@ public class ScheduledExecutorTest exten public void testInvokeAll5() throws Exception { ExecutorService e = new ScheduledThreadPoolExecutor(2); try { - ArrayList> l = new ArrayList>(); + List> l = new ArrayList>(); l.add(new StringTask()); l.add(new StringTask()); - List> result = e.invokeAll(l); - assertEquals(2, result.size()); - for (Future future : result) + List> futures = e.invokeAll(l); + assertEquals(2, futures.size()); + for (Future future : futures) assertSame(TEST_STRING, future.get()); } finally { joinPool(e); @@ -814,9 +806,9 @@ public class ScheduledExecutorTest exten */ public void testTimedInvokeAnyNullTimeUnit() throws Exception { ExecutorService e = new ScheduledThreadPoolExecutor(2); + List> l = new ArrayList>(); + l.add(new StringTask()); try { - ArrayList> l = new ArrayList>(); - l.add(new StringTask()); e.invokeAny(l, MEDIUM_DELAY_MS, null); shouldThrow(); } catch (NullPointerException success) { @@ -843,18 +835,12 @@ public class ScheduledExecutorTest exten * timed invokeAny(c) throws NPE if c has null elements */ public void testTimedInvokeAny3() throws Exception { - final CountDownLatch latch = new CountDownLatch(1); + CountDownLatch latch = new CountDownLatch(1); ExecutorService e = new ScheduledThreadPoolExecutor(2); + List> l = new ArrayList>(); + l.add(latchAwaitingStringTask(latch)); + l.add(null); try { - ArrayList> l = new ArrayList>(); - l.add(new Callable() { - public String call() { - try { - latch.await(); - } catch (InterruptedException ok) {} - return TEST_STRING; - }}); - l.add(null); e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (NullPointerException success) { @@ -869,9 +855,9 @@ public class ScheduledExecutorTest exten */ public void testTimedInvokeAny4() throws Exception { ExecutorService e = new ScheduledThreadPoolExecutor(2); + List> l = new ArrayList>(); + l.add(new NPETask()); try { - ArrayList> l = new ArrayList>(); - l.add(new NPETask()); e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (ExecutionException success) { @@ -887,7 +873,7 @@ public class ScheduledExecutorTest exten public void testTimedInvokeAny5() throws Exception { ExecutorService e = new ScheduledThreadPoolExecutor(2); try { - ArrayList> l = new ArrayList>(); + List> l = new ArrayList>(); l.add(new StringTask()); l.add(new StringTask()); String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); @@ -916,9 +902,9 @@ public class ScheduledExecutorTest exten */ public void testTimedInvokeAllNullTimeUnit() throws Exception { ExecutorService e = new ScheduledThreadPoolExecutor(2); + List> l = new ArrayList>(); + l.add(new StringTask()); try { - ArrayList> l = new ArrayList>(); - l.add(new StringTask()); e.invokeAll(l, MEDIUM_DELAY_MS, null); shouldThrow(); } catch (NullPointerException success) { @@ -945,10 +931,10 @@ public class ScheduledExecutorTest exten */ public void testTimedInvokeAll3() throws Exception { ExecutorService e = new ScheduledThreadPoolExecutor(2); + List> l = new ArrayList>(); + l.add(new StringTask()); + l.add(null); try { - ArrayList> l = new ArrayList>(); - l.add(new StringTask()); - l.add(null); e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (NullPointerException success) { @@ -962,13 +948,13 @@ public class ScheduledExecutorTest exten */ public void testTimedInvokeAll4() throws Exception { ExecutorService e = new ScheduledThreadPoolExecutor(2); + List> l = new ArrayList>(); + l.add(new NPETask()); + List> futures = + e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); + assertEquals(1, futures.size()); try { - ArrayList> l = new ArrayList>(); - l.add(new NPETask()); - List> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); - assertEquals(1, result.size()); - for (Future future : result) - future.get(); + futures.get(0).get(); shouldThrow(); } catch (ExecutionException success) { assertTrue(success.getCause() instanceof NullPointerException); @@ -983,12 +969,13 @@ public class ScheduledExecutorTest exten public void testTimedInvokeAll5() throws Exception { ExecutorService e = new ScheduledThreadPoolExecutor(2); try { - ArrayList> l = new ArrayList>(); + List> l = new ArrayList>(); l.add(new StringTask()); l.add(new StringTask()); - List> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); - assertEquals(2, result.size()); - for (Future future : result) + List> futures = + e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); + assertEquals(2, futures.size()); + for (Future future : futures) assertSame(TEST_STRING, future.get()); } finally { joinPool(e); @@ -1001,13 +988,14 @@ public class ScheduledExecutorTest exten public void testTimedInvokeAll6() throws Exception { ExecutorService e = new ScheduledThreadPoolExecutor(2); try { - ArrayList> l = new ArrayList>(); + List> l = new ArrayList>(); l.add(new StringTask()); l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING)); l.add(new StringTask()); - List> result = e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS); - assertEquals(3, result.size()); - Iterator> it = result.iterator(); + List> futures = + e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS); + assertEquals(3, futures.size()); + Iterator> it = futures.iterator(); Future f1 = it.next(); Future f2 = it.next(); Future f3 = it.next();