6 |
|
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
– |
import junit.framework.*; |
10 |
– |
import java.util.*; |
11 |
– |
import java.util.concurrent.*; |
12 |
– |
import java.util.concurrent.atomic.AtomicBoolean; |
9 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
10 |
< |
import java.security.*; |
10 |
> |
|
11 |
> |
import java.security.PrivilegedAction; |
12 |
> |
import java.security.PrivilegedExceptionAction; |
13 |
> |
import java.util.ArrayList; |
14 |
> |
import java.util.Collections; |
15 |
> |
import java.util.List; |
16 |
> |
import java.util.concurrent.AbstractExecutorService; |
17 |
> |
import java.util.concurrent.ArrayBlockingQueue; |
18 |
> |
import java.util.concurrent.Callable; |
19 |
> |
import java.util.concurrent.CountDownLatch; |
20 |
> |
import java.util.concurrent.ExecutionException; |
21 |
> |
import java.util.concurrent.Executors; |
22 |
> |
import java.util.concurrent.ExecutorService; |
23 |
> |
import java.util.concurrent.Future; |
24 |
> |
import java.util.concurrent.ThreadPoolExecutor; |
25 |
> |
import java.util.concurrent.TimeUnit; |
26 |
> |
import java.util.concurrent.atomic.AtomicBoolean; |
27 |
> |
|
28 |
> |
import junit.framework.Test; |
29 |
> |
import junit.framework.TestSuite; |
30 |
|
|
31 |
|
public class AbstractExecutorServiceTest extends JSR166TestCase { |
32 |
|
public static void main(String[] args) { |
61 |
|
public void testExecuteRunnable() throws Exception { |
62 |
|
ExecutorService e = new DirectExecutorService(); |
63 |
|
final AtomicBoolean done = new AtomicBoolean(false); |
64 |
< |
CheckedRunnable task = new CheckedRunnable() { |
64 |
> |
Future<?> future = e.submit(new CheckedRunnable() { |
65 |
|
public void realRun() { |
66 |
|
done.set(true); |
67 |
< |
}}; |
53 |
< |
Future<?> future = e.submit(task); |
67 |
> |
}}); |
68 |
|
assertNull(future.get()); |
69 |
|
assertNull(future.get(0, MILLISECONDS)); |
70 |
|
assertTrue(done.get()); |
227 |
|
new ArrayBlockingQueue<Runnable>(10)); |
228 |
|
|
229 |
|
Callable c = new Callable() { |
230 |
< |
public Object call() { return 5/0; }}; |
230 |
> |
public Object call() { throw new ArithmeticException(); }}; |
231 |
|
|
232 |
|
try { |
233 |
|
p.submit(c).get(); |
271 |
|
*/ |
272 |
|
public void testInvokeAny3() throws Exception { |
273 |
|
ExecutorService e = new DirectExecutorService(); |
274 |
< |
List<Callable<Integer>> l = new ArrayList<Callable<Integer>>(); |
275 |
< |
l.add(new Callable<Integer>() { |
276 |
< |
public Integer call() { return 5/0; }}); |
274 |
> |
List<Callable<Long>> l = new ArrayList<Callable<Long>>(); |
275 |
> |
l.add(new Callable<Long>() { |
276 |
> |
public Long call() { throw new ArithmeticException(); }}); |
277 |
|
l.add(null); |
278 |
|
try { |
279 |
|
e.invokeAny(l); |
449 |
|
*/ |
450 |
|
public void testTimedInvokeAny3() throws Exception { |
451 |
|
ExecutorService e = new DirectExecutorService(); |
452 |
< |
List<Callable<Integer>> l = new ArrayList<Callable<Integer>>(); |
453 |
< |
l.add(new Callable<Integer>() { |
454 |
< |
public Integer call() { return 5/0; }}); |
452 |
> |
List<Callable<Long>> l = new ArrayList<Callable<Long>>(); |
453 |
> |
l.add(new Callable<Long>() { |
454 |
> |
public Long call() { throw new ArithmeticException(); }}); |
455 |
|
l.add(null); |
456 |
|
try { |
457 |
|
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |