ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/FutureTaskTest.java
(Generate patch)

Comparing jsr166/src/test/tck/FutureTaskTest.java (file contents):
Revision 1.53 by jsr166, Sun Jul 22 22:13:55 2018 UTC vs.
Revision 1.58 by jsr166, Wed Jan 27 01:57:24 2021 UTC

# Line 90 | Line 90 | public class FutureTaskTest extends JSR1
90      void checkIsRunning(Future<?> f) {
91          checkNotDone(f);
92          if (f instanceof FutureTask) {
93 <            FutureTask ft = (FutureTask<?>) f;
93 >            FutureTask<?> ft = (FutureTask<?>) f;
94              // Check that run methods do nothing
95              ft.run();
96              if (f instanceof PublicFutureTask) {
# Line 164 | Line 164 | public class FutureTaskTest extends JSR1
164      /**
165       * Subclass to expose protected methods
166       */
167 <    static class PublicFutureTask extends FutureTask {
167 >    static class PublicFutureTask extends FutureTask<Object> {
168          private final AtomicInteger runCount;
169          private final AtomicInteger doneCount = new AtomicInteger(0);
170          private final AtomicInteger runAndResetCount = new AtomicInteger(0);
# Line 191 | Line 191 | public class FutureTaskTest extends JSR1
191                  }}, result);
192              this.runCount = runCount;
193          }
194 <        PublicFutureTask(Callable callable) {
194 >        PublicFutureTask(Callable<?> callable) {
195              this(callable, new AtomicInteger(0));
196          }
197 <        private PublicFutureTask(final Callable callable,
197 >        private PublicFutureTask(final Callable<?> callable,
198                                   final AtomicInteger runCount) {
199 <            super(new Callable() {
199 >            super(new Callable<Object>() {
200                  public Object call() throws Exception {
201                      runCount.getAndIncrement();
202                      return callable.call();
# Line 235 | Line 235 | public class FutureTaskTest extends JSR1
235       */
236      public void testConstructor() {
237          try {
238 <            new FutureTask(null);
238 >            new FutureTask<Void>(null);
239              shouldThrow();
240          } catch (NullPointerException success) {}
241      }
# Line 245 | Line 245 | public class FutureTaskTest extends JSR1
245       */
246      public void testConstructor2() {
247          try {
248 <            new FutureTask(null, Boolean.TRUE);
248 >            new FutureTask<Boolean>(null, Boolean.TRUE);
249              shouldThrow();
250          } catch (NullPointerException success) {}
251      }
# Line 629 | Line 629 | public class FutureTaskTest extends JSR1
629      public void testTimedGet_Cancellation(final boolean mayInterruptIfRunning) {
630          final CountDownLatch pleaseCancel = new CountDownLatch(3);
631          final CountDownLatch cancelled = new CountDownLatch(1);
632 <        final Callable<Object> callable =
633 <            new CheckedCallable<Object>() {
632 >        final Callable<Object> callable = new CheckedCallable<>() {
633              public Object realCall() throws InterruptedException {
634                  pleaseCancel.countDown();
635                  if (mayInterruptIfRunning) {
# Line 677 | Line 676 | public class FutureTaskTest extends JSR1
676       */
677      public void testGet_ExecutionException() throws InterruptedException {
678          final ArithmeticException e = new ArithmeticException();
679 <        final PublicFutureTask task = new PublicFutureTask(new Callable() {
679 >        final PublicFutureTask task = new PublicFutureTask(new Callable<Object>() {
680              public Object call() {
681                  throw e;
682              }});
# Line 701 | Line 700 | public class FutureTaskTest extends JSR1
700       */
701      public void testTimedGet_ExecutionException2() throws Exception {
702          final ArithmeticException e = new ArithmeticException();
703 <        final PublicFutureTask task = new PublicFutureTask(new Callable() {
703 >        final PublicFutureTask task = new PublicFutureTask(new Callable<Object>() {
704              public Object call() {
705                  throw e;
706              }});
# Line 720 | Line 719 | public class FutureTaskTest extends JSR1
719      /**
720       * get is interruptible
721       */
722 <    public void testGet_interruptible() {
722 >    public void testGet_Interruptible() {
723          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
724 <        final FutureTask task = new FutureTask(new NoOpCallable());
724 >        final FutureTask<Object> task = new FutureTask<>(new NoOpCallable());
725          Thread t = newStartedThread(new CheckedRunnable() {
726              public void realRun() throws Exception {
727                  Thread.currentThread().interrupt();
# Line 749 | Line 748 | public class FutureTaskTest extends JSR1
748      /**
749       * timed get is interruptible
750       */
751 <    public void testTimedGet_interruptible() {
751 >    public void testTimedGet_Interruptible() {
752          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
753 <        final FutureTask task = new FutureTask(new NoOpCallable());
753 >        final FutureTask<Object> task = new FutureTask<>(new NoOpCallable());
754          Thread t = newStartedThread(new CheckedRunnable() {
755              public void realRun() throws Exception {
756                  Thread.currentThread().interrupt();
757                  try {
758 <                    task.get(2*LONG_DELAY_MS, MILLISECONDS);
758 >                    task.get(randomTimeout(), randomTimeUnit());
759                      shouldThrow();
760                  } catch (InterruptedException success) {}
761                  assertFalse(Thread.interrupted());
762  
763                  pleaseInterrupt.countDown();
764                  try {
765 <                    task.get(2*LONG_DELAY_MS, MILLISECONDS);
765 >                    task.get(LONGER_DELAY_MS, MILLISECONDS);
766                      shouldThrow();
767                  } catch (InterruptedException success) {}
768                  assertFalse(Thread.interrupted());
769              }});
770  
771          await(pleaseInterrupt);
772 +        if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
773          t.interrupt();
774          awaitTermination(t);
775          checkNotDone(task);
# Line 779 | Line 779 | public class FutureTaskTest extends JSR1
779       * A timed out timed get throws TimeoutException
780       */
781      public void testGet_TimeoutException() throws Exception {
782 <        FutureTask task = new FutureTask(new NoOpCallable());
782 >        FutureTask<Object> task = new FutureTask<>(new NoOpCallable());
783          long startTime = System.nanoTime();
784          try {
785              task.get(timeoutMillis(), MILLISECONDS);
# Line 793 | Line 793 | public class FutureTaskTest extends JSR1
793       * timed get with null TimeUnit throws NullPointerException
794       */
795      public void testGet_NullTimeUnit() throws Exception {
796 <        FutureTask task = new FutureTask(new NoOpCallable());
796 >        FutureTask<Object> task = new FutureTask<>(new NoOpCallable());
797          long[] timeouts = { Long.MIN_VALUE, 0L, Long.MAX_VALUE };
798  
799          for (long timeout : timeouts) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines