--- jsr166/src/test/tck/FutureTaskTest.java 2009/11/20 00:58:01 1.15 +++ jsr166/src/test/tck/FutureTaskTest.java 2009/11/21 02:07:26 1.16 @@ -14,10 +14,10 @@ import java.util.*; public class FutureTaskTest 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(FutureTaskTest.class); + return new TestSuite(FutureTaskTest.class); } /** @@ -55,9 +55,9 @@ public class FutureTaskTest extends JSR1 */ public void testIsDone() { FutureTask task = new FutureTask(new NoOpCallable()); - task.run(); - assertTrue(task.isDone()); - assertFalse(task.isCancelled()); + task.run(); + assertTrue(task.isDone()); + assertFalse(task.isCancelled()); } /** @@ -65,7 +65,7 @@ public class FutureTaskTest extends JSR1 */ public void testRunAndReset() { PublicFutureTask task = new PublicFutureTask(new NoOpCallable()); - assertTrue(task.runAndReset()); + assertTrue(task.runAndReset()); assertFalse(task.isDone()); } @@ -75,9 +75,9 @@ public class FutureTaskTest extends JSR1 public void testResetAfterCancel() { PublicFutureTask task = new PublicFutureTask(new NoOpCallable()); assertTrue(task.cancel(false)); - assertFalse(task.runAndReset()); - assertTrue(task.isDone()); - assertTrue(task.isCancelled()); + assertFalse(task.runAndReset()); + assertTrue(task.isDone()); + assertTrue(task.isCancelled()); } @@ -112,9 +112,9 @@ public class FutureTaskTest extends JSR1 public void testCancelBeforeRun() { FutureTask task = new FutureTask(new NoOpCallable()); assertTrue(task.cancel(false)); - task.run(); - assertTrue(task.isDone()); - assertTrue(task.isCancelled()); + task.run(); + assertTrue(task.isDone()); + assertTrue(task.isCancelled()); } /** @@ -123,9 +123,9 @@ public class FutureTaskTest extends JSR1 public void testCancelBeforeRun2() { FutureTask task = new FutureTask(new NoOpCallable()); assertTrue(task.cancel(true)); - task.run(); - assertTrue(task.isDone()); - assertTrue(task.isCancelled()); + task.run(); + assertTrue(task.isDone()); + assertTrue(task.isCancelled()); } /** @@ -133,21 +133,21 @@ public class FutureTaskTest extends JSR1 */ public void testCancelAfterRun() { FutureTask task = new FutureTask(new NoOpCallable()); - task.run(); + task.run(); assertFalse(task.cancel(false)); - assertTrue(task.isDone()); - assertFalse(task.isCancelled()); + assertTrue(task.isDone()); + assertFalse(task.isCancelled()); } /** * cancel(true) interrupts a running task */ public void testCancelInterrupt() throws InterruptedException { - final FutureTask task = + final FutureTask task = new FutureTask(new CheckedInterruptedCallable() { - public Object realCall() throws InterruptedException { + public Object realCall() throws InterruptedException { Thread.sleep(SMALL_DELAY_MS); - return Boolean.TRUE; + return Boolean.TRUE; }}); Thread t = new Thread(task); @@ -164,9 +164,9 @@ public class FutureTaskTest extends JSR1 * cancel(false) does not interrupt a running task */ public void testCancelNoInterrupt() throws InterruptedException { - final FutureTask task = + final FutureTask task = new FutureTask(new CheckedCallable() { - public Object realCall() throws InterruptedException { + public Object realCall() throws InterruptedException { Thread.sleep(MEDIUM_DELAY_MS); return Boolean.TRUE; }}); @@ -184,12 +184,12 @@ public class FutureTaskTest extends JSR1 * set in one thread causes get in another thread to retrieve value */ public void testGet1() throws InterruptedException { - final FutureTask ft = + final FutureTask ft = new FutureTask(new CheckedCallable() { - public Object realCall() throws InterruptedException { + public Object realCall() throws InterruptedException { return Boolean.TRUE; }}); - Thread t = new Thread(new CheckedRunnable() { + Thread t = new Thread(new CheckedRunnable() { public void realRun() throws Exception { assertSame(Boolean.TRUE, ft.get()); }}); @@ -208,12 +208,12 @@ public class FutureTaskTest extends JSR1 * set in one thread causes timed get in another thread to retrieve value */ public void testTimedGet1() throws InterruptedException { - final FutureTask ft = + final FutureTask ft = new FutureTask(new CheckedCallable() { - public Object realCall() throws InterruptedException { + public Object realCall() throws InterruptedException { return Boolean.TRUE; }}); - Thread t = new Thread(new CheckedRunnable() { + Thread t = new Thread(new CheckedRunnable() { public void realRun() throws Exception { assertSame(Boolean.TRUE, ft.get(SMALL_DELAY_MS, MILLISECONDS)); }}); @@ -232,11 +232,11 @@ public class FutureTaskTest extends JSR1 * Cancelling a task causes timed get in another thread to throw CancellationException */ public void testTimedGet_Cancellation() throws InterruptedException { - final FutureTask ft = + final FutureTask ft = new FutureTask(new CheckedInterruptedCallable() { - public Object realCall() throws InterruptedException { + public Object realCall() throws InterruptedException { Thread.sleep(SMALL_DELAY_MS); - return Boolean.TRUE; + return Boolean.TRUE; }}); Thread t1 = new ThreadShouldThrow(CancellationException.class) { @@ -256,11 +256,11 @@ public class FutureTaskTest extends JSR1 * Cancelling a task causes get in another thread to throw CancellationException */ public void testGet_Cancellation() throws InterruptedException { - final FutureTask ft = + final FutureTask ft = new FutureTask(new CheckedInterruptedCallable() { - public Object realCall() throws InterruptedException { + public Object realCall() throws InterruptedException { Thread.sleep(SMALL_DELAY_MS); - return Boolean.TRUE; + return Boolean.TRUE; }}); Thread t1 = new ThreadShouldThrow(CancellationException.class) { public void realRun() throws Exception { @@ -281,16 +281,16 @@ public class FutureTaskTest extends JSR1 * A runtime exception in task causes get to throw ExecutionException */ public void testGet_ExecutionException() throws InterruptedException { - final FutureTask ft = new FutureTask(new Callable() { - public Object call() { + final FutureTask ft = new FutureTask(new Callable() { + public Object call() { return 5/0; }}); ft.run(); try { - ft.get(); - shouldThrow("ExecutionException"); - } catch (ExecutionException success) { + ft.get(); + shouldThrow("ExecutionException"); + } catch (ExecutionException success) { assertTrue(success.getCause() instanceof ArithmeticException); } } @@ -299,16 +299,16 @@ public class FutureTaskTest extends JSR1 * A runtime exception in task causes timed get to throw ExecutionException */ public void testTimedGet_ExecutionException2() throws Exception { - final FutureTask ft = new FutureTask(new Callable() { - public Object call() { + final FutureTask ft = new FutureTask(new Callable() { + public Object call() { return 5/0; }}); ft.run(); - try { - ft.get(SHORT_DELAY_MS, MILLISECONDS); - shouldThrow("ExecutionException"); - } catch (ExecutionException success) { + try { + ft.get(SHORT_DELAY_MS, MILLISECONDS); + shouldThrow("ExecutionException"); + } catch (ExecutionException success) { assertTrue(success.getCause() instanceof ArithmeticException); } } @@ -318,8 +318,8 @@ public class FutureTaskTest extends JSR1 * Interrupting a waiting get causes it to throw InterruptedException */ public void testGet_InterruptedException() throws InterruptedException { - final FutureTask ft = new FutureTask(new NoOpCallable()); - Thread t = new Thread(new CheckedInterruptedRunnable() { + final FutureTask ft = new FutureTask(new NoOpCallable()); + Thread t = new Thread(new CheckedInterruptedRunnable() { public void realRun() throws Exception { ft.get(); }}); @@ -334,8 +334,8 @@ public class FutureTaskTest extends JSR1 * Interrupting a waiting timed get causes it to throw InterruptedException */ public void testTimedGet_InterruptedException2() throws InterruptedException { - final FutureTask ft = new FutureTask(new NoOpCallable()); - Thread t = new Thread(new CheckedInterruptedRunnable() { + final FutureTask ft = new FutureTask(new NoOpCallable()); + Thread t = new Thread(new CheckedInterruptedRunnable() { public void realRun() throws Exception { ft.get(LONG_DELAY_MS,MILLISECONDS); }}); @@ -350,11 +350,11 @@ public class FutureTaskTest extends JSR1 * A timed out timed get throws TimeoutException */ public void testGet_TimeoutException() throws Exception { - try { + try { FutureTask ft = new FutureTask(new NoOpCallable()); - ft.get(1,MILLISECONDS); - shouldThrow("TimeoutException"); - } catch (TimeoutException success) {} + ft.get(1,MILLISECONDS); + shouldThrow("TimeoutException"); + } catch (TimeoutException success) {} } }