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 { |
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 |
|
} |