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.38 by jsr166, Wed Jun 19 05:54:45 2013 UTC vs.
Revision 1.39 by jsr166, Fri Aug 22 03:30:56 2014 UTC

# Line 10 | Line 10 | import junit.framework.*;
10   import java.util.concurrent.Callable;
11   import java.util.concurrent.CancellationException;
12   import java.util.concurrent.CountDownLatch;
13 + import java.util.concurrent.ExecutorService;
14 + import java.util.concurrent.Executors;
15   import java.util.concurrent.ExecutionException;
16   import java.util.concurrent.Future;
17   import java.util.concurrent.FutureTask;
18   import java.util.concurrent.TimeoutException;
19   import java.util.concurrent.atomic.AtomicInteger;
20 < import static java.util.concurrent.TimeUnit.MILLISECONDS;
19 < import static java.util.concurrent.TimeUnit.SECONDS;
20 > import static java.util.concurrent.TimeUnit.*;
21   import java.util.*;
22  
23   public class FutureTaskTest extends JSR166TestCase {
# Line 801 | Line 802 | public class FutureTaskTest extends JSR1
802          }
803      }
804  
805 +    /**
806 +     * timed get with most negative timeout works correctly (i.e. no
807 +     * underflow bug)
808 +     */
809 +    public void testGet_NegativeInfinityTimeout() throws Exception {
810 +        final ExecutorService pool = Executors.newFixedThreadPool(10);
811 +        final Runnable nop = new Runnable() { public void run() {}};
812 +        final FutureTask<Void> task = new FutureTask<>(nop, null);
813 +        final List<Future<?>> futures = new ArrayList<>();
814 +        Runnable r = new Runnable() { public void run() {
815 +            for (long timeout : new long[] { 0L, -1L, Long.MIN_VALUE }) {
816 +                try {
817 +                    task.get(timeout, NANOSECONDS);
818 +                    shouldThrow();
819 +                } catch (TimeoutException success) {
820 +                } catch (Throwable fail) {threadUnexpectedException(fail);}}}};
821 +        for (int i = 0; i < 10; i++)
822 +            futures.add(pool.submit(r));
823 +        try {
824 +            joinPool(pool);
825 +            for (Future<?> future : futures)
826 +                checkCompletedNormally(future, null);
827 +        } finally {
828 +            task.run();         // last resort to help terminate
829 +        }
830 +    }
831 +
832   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines