2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
|
* http://creativecommons.org/licenses/publicdomain |
5 |
< |
* Other contributors include Andrew Wright, Jeffrey Hayes, |
6 |
< |
* Pat Fisher, Mike Judd. |
5 |
> |
* Other contributors include Andrew Wright, Jeffrey Hayes, |
6 |
> |
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
|
|
10 |
|
import junit.framework.*; |
11 |
|
import java.util.*; |
12 |
|
import java.util.concurrent.*; |
13 |
+ |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
14 |
|
import java.math.BigInteger; |
15 |
|
import java.security.*; |
16 |
|
|
17 |
< |
public class AbstractExecutorServiceTest extends JSR166TestCase{ |
17 |
> |
public class AbstractExecutorServiceTest extends JSR166TestCase { |
18 |
|
public static void main(String[] args) { |
19 |
< |
junit.textui.TestRunner.run (suite()); |
19 |
> |
junit.textui.TestRunner.run(suite()); |
20 |
|
} |
21 |
|
public static Test suite() { |
22 |
|
return new TestSuite(AbstractExecutorServiceTest.class); |
23 |
|
} |
24 |
|
|
25 |
< |
/** |
25 |
> |
/** |
26 |
|
* A no-frills implementation of AbstractExecutorService, designed |
27 |
|
* to test the submit methods only. |
28 |
|
*/ |
37 |
|
} |
38 |
|
|
39 |
|
/** |
40 |
< |
* execute of runnable runs it to completion |
40 |
> |
* execute(runnable) runs it to completion |
41 |
|
*/ |
42 |
< |
public void testExecuteRunnable() { |
43 |
< |
try { |
44 |
< |
ExecutorService e = new DirectExecutorService(); |
45 |
< |
TrackedShortRunnable task = new TrackedShortRunnable(); |
46 |
< |
assertFalse(task.done); |
47 |
< |
Future<?> future = e.submit(task); |
48 |
< |
future.get(); |
48 |
< |
assertTrue(task.done); |
49 |
< |
} |
50 |
< |
catch (ExecutionException ex) { |
51 |
< |
unexpectedException(); |
52 |
< |
} |
53 |
< |
catch (InterruptedException ex) { |
54 |
< |
unexpectedException(); |
55 |
< |
} |
42 |
> |
public void testExecuteRunnable() throws Exception { |
43 |
> |
ExecutorService e = new DirectExecutorService(); |
44 |
> |
TrackedShortRunnable task = new TrackedShortRunnable(); |
45 |
> |
assertFalse(task.done); |
46 |
> |
Future<?> future = e.submit(task); |
47 |
> |
future.get(); |
48 |
> |
assertTrue(task.done); |
49 |
|
} |
50 |
|
|
51 |
|
|
52 |
|
/** |
53 |
< |
* completed submit of callable returns result |
53 |
> |
* Completed submit(callable) returns result |
54 |
|
*/ |
55 |
< |
public void testSubmitCallable() { |
56 |
< |
try { |
57 |
< |
ExecutorService e = new DirectExecutorService(); |
58 |
< |
Future<String> future = e.submit(new StringTask()); |
59 |
< |
String result = future.get(); |
67 |
< |
assertSame(TEST_STRING, result); |
68 |
< |
} |
69 |
< |
catch (ExecutionException ex) { |
70 |
< |
unexpectedException(); |
71 |
< |
} |
72 |
< |
catch (InterruptedException ex) { |
73 |
< |
unexpectedException(); |
74 |
< |
} |
55 |
> |
public void testSubmitCallable() throws Exception { |
56 |
> |
ExecutorService e = new DirectExecutorService(); |
57 |
> |
Future<String> future = e.submit(new StringTask()); |
58 |
> |
String result = future.get(); |
59 |
> |
assertSame(TEST_STRING, result); |
60 |
|
} |
61 |
|
|
62 |
|
/** |
63 |
< |
* completed submit of runnable returns successfully |
63 |
> |
* Completed submit(runnable) returns successfully |
64 |
|
*/ |
65 |
< |
public void testSubmitRunnable() { |
66 |
< |
try { |
67 |
< |
ExecutorService e = new DirectExecutorService(); |
68 |
< |
Future<?> future = e.submit(new NoOpRunnable()); |
69 |
< |
future.get(); |
85 |
< |
assertTrue(future.isDone()); |
86 |
< |
} |
87 |
< |
catch (ExecutionException ex) { |
88 |
< |
unexpectedException(); |
89 |
< |
} |
90 |
< |
catch (InterruptedException ex) { |
91 |
< |
unexpectedException(); |
92 |
< |
} |
65 |
> |
public void testSubmitRunnable() throws Exception { |
66 |
> |
ExecutorService e = new DirectExecutorService(); |
67 |
> |
Future<?> future = e.submit(new NoOpRunnable()); |
68 |
> |
future.get(); |
69 |
> |
assertTrue(future.isDone()); |
70 |
|
} |
71 |
|
|
72 |
|
/** |
73 |
< |
* completed submit of (runnable, result) returns result |
73 |
> |
* Completed submit(runnable, result) returns result |
74 |
|
*/ |
75 |
< |
public void testSubmitRunnable2() { |
76 |
< |
try { |
77 |
< |
ExecutorService e = new DirectExecutorService(); |
78 |
< |
Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING); |
79 |
< |
String result = future.get(); |
103 |
< |
assertSame(TEST_STRING, result); |
104 |
< |
} |
105 |
< |
catch (ExecutionException ex) { |
106 |
< |
unexpectedException(); |
107 |
< |
} |
108 |
< |
catch (InterruptedException ex) { |
109 |
< |
unexpectedException(); |
110 |
< |
} |
75 |
> |
public void testSubmitRunnable2() throws Exception { |
76 |
> |
ExecutorService e = new DirectExecutorService(); |
77 |
> |
Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING); |
78 |
> |
String result = future.get(); |
79 |
> |
assertSame(TEST_STRING, result); |
80 |
|
} |
81 |
|
|
82 |
|
|
83 |
|
/** |
84 |
< |
* submit of a privileged action runs it to completion |
84 |
> |
* A submitted privileged action runs to completion |
85 |
|
*/ |
86 |
< |
public void testSubmitPrivilegedAction() { |
87 |
< |
Policy savedPolicy = Policy.getPolicy(); |
88 |
< |
AdjustablePolicy policy = new AdjustablePolicy(); |
89 |
< |
policy.addPermission(new RuntimePermission("getContextClassLoader")); |
90 |
< |
policy.addPermission(new RuntimePermission("setContextClassLoader")); |
122 |
< |
Policy.setPolicy(policy); |
123 |
< |
try { |
124 |
< |
ExecutorService e = new DirectExecutorService(); |
125 |
< |
Future future = e.submit(Executors.callable(new PrivilegedAction() { |
86 |
> |
public void testSubmitPrivilegedAction() throws Exception { |
87 |
> |
Runnable r = new CheckedRunnable() { |
88 |
> |
public void realRun() throws Exception { |
89 |
> |
ExecutorService e = new DirectExecutorService(); |
90 |
> |
Future future = e.submit(Executors.callable(new PrivilegedAction() { |
91 |
|
public Object run() { |
92 |
|
return TEST_STRING; |
93 |
|
}})); |
94 |
|
|
95 |
< |
Object result = future.get(); |
96 |
< |
assertSame(TEST_STRING, result); |
97 |
< |
} |
98 |
< |
catch (ExecutionException ex) { |
99 |
< |
unexpectedException(); |
100 |
< |
} |
101 |
< |
catch (InterruptedException ex) { |
137 |
< |
unexpectedException(); |
138 |
< |
} |
139 |
< |
finally { |
140 |
< |
Policy.setPolicy(savedPolicy); |
141 |
< |
} |
95 |
> |
assertSame(TEST_STRING, future.get()); |
96 |
> |
}}; |
97 |
> |
|
98 |
> |
runWithPermissions(r, |
99 |
> |
new RuntimePermission("getClassLoader"), |
100 |
> |
new RuntimePermission("setContextClassLoader"), |
101 |
> |
new RuntimePermission("modifyThread")); |
102 |
|
} |
103 |
|
|
104 |
|
/** |
105 |
< |
* submit of a privileged exception action runs it to completion |
105 |
> |
* A submitted privileged exception action runs to completion |
106 |
|
*/ |
107 |
< |
public void testSubmitPrivilegedExceptionAction() { |
108 |
< |
Policy savedPolicy = Policy.getPolicy(); |
109 |
< |
AdjustablePolicy policy = new AdjustablePolicy(); |
110 |
< |
policy.addPermission(new RuntimePermission("getContextClassLoader")); |
111 |
< |
policy.addPermission(new RuntimePermission("setContextClassLoader")); |
152 |
< |
Policy.setPolicy(policy); |
153 |
< |
try { |
154 |
< |
ExecutorService e = new DirectExecutorService(); |
155 |
< |
Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() { |
107 |
> |
public void testSubmitPrivilegedExceptionAction() throws Exception { |
108 |
> |
Runnable r = new CheckedRunnable() { |
109 |
> |
public void realRun() throws Exception { |
110 |
> |
ExecutorService e = new DirectExecutorService(); |
111 |
> |
Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() { |
112 |
|
public Object run() { |
113 |
|
return TEST_STRING; |
114 |
|
}})); |
115 |
|
|
116 |
< |
Object result = future.get(); |
117 |
< |
assertSame(TEST_STRING, result); |
118 |
< |
} |
119 |
< |
catch (ExecutionException ex) { |
164 |
< |
unexpectedException(); |
165 |
< |
} |
166 |
< |
catch (InterruptedException ex) { |
167 |
< |
unexpectedException(); |
168 |
< |
} |
169 |
< |
finally { |
170 |
< |
Policy.setPolicy(savedPolicy); |
171 |
< |
} |
116 |
> |
assertSame(TEST_STRING, future.get()); |
117 |
> |
}}; |
118 |
> |
|
119 |
> |
runWithPermissions(r); |
120 |
|
} |
121 |
|
|
122 |
|
/** |
123 |
< |
* submit of a failed privileged exception action reports exception |
123 |
> |
* A submitted failed privileged exception action reports exception |
124 |
|
*/ |
125 |
< |
public void testSubmitFailedPrivilegedExceptionAction() { |
126 |
< |
Policy savedPolicy = Policy.getPolicy(); |
127 |
< |
AdjustablePolicy policy = new AdjustablePolicy(); |
128 |
< |
policy.addPermission(new RuntimePermission("getContextClassLoader")); |
129 |
< |
policy.addPermission(new RuntimePermission("setContextClassLoader")); |
182 |
< |
Policy.setPolicy(policy); |
183 |
< |
try { |
184 |
< |
ExecutorService e = new DirectExecutorService(); |
185 |
< |
Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() { |
125 |
> |
public void testSubmitFailedPrivilegedExceptionAction() throws Exception { |
126 |
> |
Runnable r = new CheckedRunnable() { |
127 |
> |
public void realRun() throws Exception { |
128 |
> |
ExecutorService e = new DirectExecutorService(); |
129 |
> |
Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() { |
130 |
|
public Object run() throws Exception { |
131 |
|
throw new IndexOutOfBoundsException(); |
132 |
|
}})); |
133 |
|
|
134 |
< |
Object result = future.get(); |
135 |
< |
shouldThrow(); |
136 |
< |
} |
137 |
< |
catch (ExecutionException success) { |
138 |
< |
} |
139 |
< |
catch (InterruptedException ex) { |
140 |
< |
unexpectedException(); |
141 |
< |
} |
198 |
< |
finally { |
199 |
< |
Policy.setPolicy(savedPolicy); |
200 |
< |
} |
134 |
> |
try { |
135 |
> |
future.get(); |
136 |
> |
shouldThrow(); |
137 |
> |
} catch (ExecutionException success) { |
138 |
> |
assertTrue(success.getCause() instanceof IndexOutOfBoundsException); |
139 |
> |
}}}; |
140 |
> |
|
141 |
> |
runWithPermissions(r); |
142 |
|
} |
143 |
|
|
144 |
|
/** |
145 |
< |
* execute with a null runnable throws NPE |
145 |
> |
* execute(null runnable) throws NPE |
146 |
|
*/ |
147 |
|
public void testExecuteNullRunnable() { |
148 |
|
try { |
149 |
|
ExecutorService e = new DirectExecutorService(); |
150 |
< |
TrackedShortRunnable task = null; |
210 |
< |
Future<?> future = e.submit(task); |
150 |
> |
e.submit((Runnable) null); |
151 |
|
shouldThrow(); |
152 |
< |
} |
213 |
< |
catch (NullPointerException success) { |
214 |
< |
} |
215 |
< |
catch (Exception ex) { |
216 |
< |
unexpectedException(); |
217 |
< |
} |
152 |
> |
} catch (NullPointerException success) {} |
153 |
|
} |
154 |
|
|
155 |
|
|
156 |
|
/** |
157 |
< |
* submit of a null callable throws NPE |
157 |
> |
* submit(null callable) throws NPE |
158 |
|
*/ |
159 |
|
public void testSubmitNullCallable() { |
160 |
|
try { |
161 |
|
ExecutorService e = new DirectExecutorService(); |
162 |
< |
StringTask t = null; |
228 |
< |
Future<String> future = e.submit(t); |
162 |
> |
e.submit((Callable) null); |
163 |
|
shouldThrow(); |
164 |
< |
} |
231 |
< |
catch (NullPointerException success) { |
232 |
< |
} |
233 |
< |
catch (Exception ex) { |
234 |
< |
unexpectedException(); |
235 |
< |
} |
164 |
> |
} catch (NullPointerException success) {} |
165 |
|
} |
166 |
|
|
167 |
|
/** |
168 |
< |
* submit of Runnable throws RejectedExecutionException if |
169 |
< |
* saturated. |
168 |
> |
* submit(runnable) throws RejectedExecutionException if |
169 |
> |
* executor is saturated. |
170 |
|
*/ |
171 |
|
public void testExecute1() { |
172 |
< |
ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1)); |
172 |
> |
ThreadPoolExecutor p = |
173 |
> |
new ThreadPoolExecutor(1, 1, |
174 |
> |
60, TimeUnit.SECONDS, |
175 |
> |
new ArrayBlockingQueue<Runnable>(1)); |
176 |
|
try { |
177 |
< |
|
246 |
< |
for(int i = 0; i < 5; ++i){ |
177 |
> |
for (int i = 0; i < 2; ++i) |
178 |
|
p.submit(new MediumRunnable()); |
179 |
+ |
for (int i = 0; i < 2; ++i) { |
180 |
+ |
try { |
181 |
+ |
p.submit(new MediumRunnable()); |
182 |
+ |
shouldThrow(); |
183 |
+ |
} catch (RejectedExecutionException success) {} |
184 |
|
} |
185 |
< |
shouldThrow(); |
186 |
< |
} catch(RejectedExecutionException success){} |
187 |
< |
joinPool(p); |
185 |
> |
} finally { |
186 |
> |
joinPool(p); |
187 |
> |
} |
188 |
|
} |
189 |
|
|
190 |
|
/** |
191 |
< |
* Completed submit of Callable throws RejectedExecutionException |
192 |
< |
* if saturated. |
191 |
> |
* submit(callable) throws RejectedExecutionException |
192 |
> |
* if executor is saturated. |
193 |
|
*/ |
194 |
|
public void testExecute2() { |
195 |
< |
ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1)); |
195 |
> |
ThreadPoolExecutor p = |
196 |
> |
new ThreadPoolExecutor(1, 1, |
197 |
> |
60, TimeUnit.SECONDS, |
198 |
> |
new ArrayBlockingQueue<Runnable>(1)); |
199 |
|
try { |
200 |
< |
for(int i = 0; i < 5; ++i) { |
201 |
< |
p.submit(new SmallCallable()); |
200 |
> |
for (int i = 0; i < 2; ++i) |
201 |
> |
p.submit(new MediumRunnable()); |
202 |
> |
for (int i = 0; i < 2; ++i) { |
203 |
> |
try { |
204 |
> |
p.submit(new SmallCallable()); |
205 |
> |
shouldThrow(); |
206 |
> |
} catch (RejectedExecutionException success) {} |
207 |
|
} |
208 |
< |
shouldThrow(); |
209 |
< |
} catch(RejectedExecutionException e){} |
210 |
< |
joinPool(p); |
208 |
> |
} finally { |
209 |
> |
joinPool(p); |
210 |
> |
} |
211 |
|
} |
212 |
|
|
213 |
|
|
214 |
|
/** |
215 |
< |
* blocking on submit of Callable throws InterruptedException if |
215 |
> |
* Blocking on submit(callable) throws InterruptedException if |
216 |
|
* caller interrupted. |
217 |
|
*/ |
218 |
< |
public void testInterruptedSubmit() { |
219 |
< |
final ThreadPoolExecutor p = new ThreadPoolExecutor(1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
220 |
< |
Thread t = new Thread(new Runnable() { |
221 |
< |
public void run() { |
222 |
< |
try { |
223 |
< |
p.submit(new Callable<Object>() { |
224 |
< |
public Object call() { |
225 |
< |
try { |
226 |
< |
Thread.sleep(MEDIUM_DELAY_MS); |
227 |
< |
shouldThrow(); |
228 |
< |
} catch(InterruptedException e){ |
229 |
< |
} |
230 |
< |
return null; |
231 |
< |
} |
232 |
< |
}).get(); |
289 |
< |
} catch(InterruptedException success){ |
290 |
< |
} catch(Exception e) { |
291 |
< |
unexpectedException(); |
292 |
< |
} |
293 |
< |
|
294 |
< |
} |
295 |
< |
}); |
296 |
< |
try { |
297 |
< |
t.start(); |
298 |
< |
Thread.sleep(SHORT_DELAY_MS); |
299 |
< |
t.interrupt(); |
300 |
< |
} catch(Exception e){ |
301 |
< |
unexpectedException(); |
302 |
< |
} |
218 |
> |
public void testInterruptedSubmit() throws InterruptedException { |
219 |
> |
final ThreadPoolExecutor p = new ThreadPoolExecutor(1,1,60, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10)); |
220 |
> |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
221 |
> |
public void realRun() throws Exception { |
222 |
> |
p.submit(new CheckedCallable<Object>() { |
223 |
> |
public Object realCall() |
224 |
> |
throws InterruptedException { |
225 |
> |
Thread.sleep(SMALL_DELAY_MS); |
226 |
> |
return null; |
227 |
> |
}}).get(); |
228 |
> |
}}); |
229 |
> |
|
230 |
> |
t.start(); |
231 |
> |
Thread.sleep(SHORT_DELAY_MS); |
232 |
> |
t.interrupt(); |
233 |
|
joinPool(p); |
234 |
|
} |
235 |
|
|
236 |
|
/** |
237 |
< |
* get of submit of Callable throws Exception if callable |
237 |
> |
* get of submitted callable throws InterruptedException if callable |
238 |
|
* interrupted |
239 |
|
*/ |
240 |
< |
public void testSubmitIE() { |
241 |
< |
final ThreadPoolExecutor p = new ThreadPoolExecutor(1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
242 |
< |
|
243 |
< |
final Callable c = new Callable() { |
244 |
< |
public Object call() { |
245 |
< |
try { |
246 |
< |
p.submit(new SmallCallable()).get(); |
247 |
< |
shouldThrow(); |
248 |
< |
} catch(InterruptedException e){} |
249 |
< |
catch(RejectedExecutionException e2){} |
250 |
< |
catch(ExecutionException e3){} |
251 |
< |
return Boolean.TRUE; |
252 |
< |
} |
253 |
< |
}; |
254 |
< |
|
325 |
< |
|
326 |
< |
|
327 |
< |
Thread t = new Thread(new Runnable() { |
328 |
< |
public void run() { |
329 |
< |
try { |
330 |
< |
c.call(); |
331 |
< |
} catch(Exception e){} |
332 |
< |
} |
333 |
< |
}); |
334 |
< |
try { |
335 |
< |
t.start(); |
336 |
< |
Thread.sleep(SHORT_DELAY_MS); |
337 |
< |
t.interrupt(); |
338 |
< |
t.join(); |
339 |
< |
} catch(InterruptedException e){ |
340 |
< |
unexpectedException(); |
341 |
< |
} |
342 |
< |
|
240 |
> |
public void testSubmitIE() throws InterruptedException { |
241 |
> |
final ThreadPoolExecutor p = |
242 |
> |
new ThreadPoolExecutor(1, 1, |
243 |
> |
60, TimeUnit.SECONDS, |
244 |
> |
new ArrayBlockingQueue<Runnable>(10)); |
245 |
> |
|
246 |
> |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
247 |
> |
public void realRun() throws Exception { |
248 |
> |
p.submit(new SmallCallable()).get(); |
249 |
> |
}}); |
250 |
> |
|
251 |
> |
t.start(); |
252 |
> |
Thread.sleep(SHORT_DELAY_MS); |
253 |
> |
t.interrupt(); |
254 |
> |
t.join(); |
255 |
|
joinPool(p); |
256 |
|
} |
257 |
|
|
258 |
|
/** |
259 |
< |
* completed submit of Callable throws ExecutionException if |
260 |
< |
* callable throws exception |
259 |
> |
* get of submit(callable) throws ExecutionException if callable |
260 |
> |
* throws exception |
261 |
|
*/ |
262 |
< |
public void testSubmitEE() { |
263 |
< |
ThreadPoolExecutor p = new ThreadPoolExecutor(1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
264 |
< |
|
265 |
< |
try { |
266 |
< |
Callable c = new Callable() { |
355 |
< |
public Object call() { |
356 |
< |
int i = 5/0; |
357 |
< |
return Boolean.TRUE; |
358 |
< |
} |
359 |
< |
}; |
262 |
> |
public void testSubmitEE() throws InterruptedException { |
263 |
> |
ThreadPoolExecutor p = |
264 |
> |
new ThreadPoolExecutor(1, 1, |
265 |
> |
60, TimeUnit.SECONDS, |
266 |
> |
new ArrayBlockingQueue<Runnable>(10)); |
267 |
|
|
268 |
< |
for(int i =0; i < 5; i++){ |
269 |
< |
p.submit(c).get(); |
363 |
< |
} |
268 |
> |
Callable c = new Callable() { |
269 |
> |
public Object call() { return 5/0; }}; |
270 |
|
|
271 |
+ |
try { |
272 |
+ |
p.submit(c).get(); |
273 |
|
shouldThrow(); |
274 |
< |
} |
275 |
< |
catch(ExecutionException success){ |
368 |
< |
} catch(Exception e) { |
369 |
< |
unexpectedException(); |
274 |
> |
} catch (ExecutionException success) { |
275 |
> |
assertTrue(success.getCause() instanceof ArithmeticException); |
276 |
|
} |
277 |
|
joinPool(p); |
278 |
|
} |
280 |
|
/** |
281 |
|
* invokeAny(null) throws NPE |
282 |
|
*/ |
283 |
< |
public void testInvokeAny1() { |
283 |
> |
public void testInvokeAny1() |
284 |
> |
throws InterruptedException, ExecutionException { |
285 |
|
ExecutorService e = new DirectExecutorService(); |
286 |
|
try { |
287 |
|
e.invokeAny(null); |
288 |
+ |
shouldThrow(); |
289 |
|
} catch (NullPointerException success) { |
382 |
– |
} catch(Exception ex) { |
383 |
– |
unexpectedException(); |
290 |
|
} finally { |
291 |
|
joinPool(e); |
292 |
|
} |
295 |
|
/** |
296 |
|
* invokeAny(empty collection) throws IAE |
297 |
|
*/ |
298 |
< |
public void testInvokeAny2() { |
298 |
> |
public void testInvokeAny2() |
299 |
> |
throws InterruptedException, ExecutionException { |
300 |
|
ExecutorService e = new DirectExecutorService(); |
301 |
|
try { |
302 |
|
e.invokeAny(new ArrayList<Callable<String>>()); |
303 |
+ |
shouldThrow(); |
304 |
|
} catch (IllegalArgumentException success) { |
397 |
– |
} catch(Exception ex) { |
398 |
– |
unexpectedException(); |
305 |
|
} finally { |
306 |
|
joinPool(e); |
307 |
|
} |
310 |
|
/** |
311 |
|
* invokeAny(c) throws NPE if c has null elements |
312 |
|
*/ |
313 |
< |
public void testInvokeAny3() { |
313 |
> |
public void testInvokeAny3() throws Exception { |
314 |
|
ExecutorService e = new DirectExecutorService(); |
315 |
+ |
List<Callable<Integer>> l = new ArrayList<Callable<Integer>>(); |
316 |
+ |
l.add(new Callable<Integer>() { |
317 |
+ |
public Integer call() { return 5/0; }}); |
318 |
+ |
l.add(null); |
319 |
|
try { |
410 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
411 |
– |
l.add(new StringTask()); |
412 |
– |
l.add(null); |
320 |
|
e.invokeAny(l); |
321 |
+ |
shouldThrow(); |
322 |
|
} catch (NullPointerException success) { |
415 |
– |
} catch(Exception ex) { |
416 |
– |
ex.printStackTrace(); |
417 |
– |
unexpectedException(); |
323 |
|
} finally { |
324 |
|
joinPool(e); |
325 |
|
} |
326 |
|
} |
327 |
|
|
328 |
|
/** |
329 |
< |
* invokeAny(c) throws ExecutionException if no task completes |
329 |
> |
* invokeAny(c) throws ExecutionException if no task in c completes |
330 |
|
*/ |
331 |
< |
public void testInvokeAny4() { |
331 |
> |
public void testInvokeAny4() throws InterruptedException { |
332 |
|
ExecutorService e = new DirectExecutorService(); |
333 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
334 |
+ |
l.add(new NPETask()); |
335 |
|
try { |
429 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
430 |
– |
l.add(new NPETask()); |
336 |
|
e.invokeAny(l); |
337 |
< |
} catch(ExecutionException success) { |
338 |
< |
} catch(Exception ex) { |
339 |
< |
unexpectedException(); |
337 |
> |
shouldThrow(); |
338 |
> |
} catch (ExecutionException success) { |
339 |
> |
assertTrue(success.getCause() instanceof NullPointerException); |
340 |
|
} finally { |
341 |
|
joinPool(e); |
342 |
|
} |
343 |
|
} |
344 |
|
|
345 |
|
/** |
346 |
< |
* invokeAny(c) returns result of some task |
346 |
> |
* invokeAny(c) returns result of some task in c if at least one completes |
347 |
|
*/ |
348 |
< |
public void testInvokeAny5() { |
348 |
> |
public void testInvokeAny5() throws Exception { |
349 |
|
ExecutorService e = new DirectExecutorService(); |
350 |
|
try { |
351 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
351 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
352 |
|
l.add(new StringTask()); |
353 |
|
l.add(new StringTask()); |
354 |
|
String result = e.invokeAny(l); |
355 |
|
assertSame(TEST_STRING, result); |
451 |
– |
} catch (ExecutionException success) { |
452 |
– |
} catch(Exception ex) { |
453 |
– |
unexpectedException(); |
356 |
|
} finally { |
357 |
|
joinPool(e); |
358 |
|
} |
361 |
|
/** |
362 |
|
* invokeAll(null) throws NPE |
363 |
|
*/ |
364 |
< |
public void testInvokeAll1() { |
364 |
> |
public void testInvokeAll1() throws InterruptedException { |
365 |
|
ExecutorService e = new DirectExecutorService(); |
366 |
|
try { |
367 |
|
e.invokeAll(null); |
368 |
+ |
shouldThrow(); |
369 |
|
} catch (NullPointerException success) { |
467 |
– |
} catch(Exception ex) { |
468 |
– |
unexpectedException(); |
370 |
|
} finally { |
371 |
|
joinPool(e); |
372 |
|
} |
375 |
|
/** |
376 |
|
* invokeAll(empty collection) returns empty collection |
377 |
|
*/ |
378 |
< |
public void testInvokeAll2() { |
378 |
> |
public void testInvokeAll2() throws InterruptedException { |
379 |
|
ExecutorService e = new DirectExecutorService(); |
380 |
|
try { |
381 |
|
List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>()); |
382 |
|
assertTrue(r.isEmpty()); |
482 |
– |
} catch(Exception ex) { |
483 |
– |
unexpectedException(); |
383 |
|
} finally { |
384 |
|
joinPool(e); |
385 |
|
} |
388 |
|
/** |
389 |
|
* invokeAll(c) throws NPE if c has null elements |
390 |
|
*/ |
391 |
< |
public void testInvokeAll3() { |
391 |
> |
public void testInvokeAll3() throws InterruptedException { |
392 |
|
ExecutorService e = new DirectExecutorService(); |
393 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
394 |
+ |
l.add(new StringTask()); |
395 |
+ |
l.add(null); |
396 |
|
try { |
495 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
496 |
– |
l.add(new StringTask()); |
497 |
– |
l.add(null); |
397 |
|
e.invokeAll(l); |
398 |
+ |
shouldThrow(); |
399 |
|
} catch (NullPointerException success) { |
500 |
– |
} catch(Exception ex) { |
501 |
– |
unexpectedException(); |
400 |
|
} finally { |
401 |
|
joinPool(e); |
402 |
|
} |
403 |
|
} |
404 |
|
|
405 |
|
/** |
406 |
< |
* get of element of invokeAll(c) throws exception on failed task |
406 |
> |
* get of returned element of invokeAll(c) throws exception on failed task |
407 |
|
*/ |
408 |
< |
public void testInvokeAll4() { |
408 |
> |
public void testInvokeAll4() throws Exception { |
409 |
|
ExecutorService e = new DirectExecutorService(); |
410 |
|
try { |
411 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
411 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
412 |
|
l.add(new NPETask()); |
413 |
< |
List<Future<String>> result = e.invokeAll(l); |
414 |
< |
assertEquals(1, result.size()); |
415 |
< |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
416 |
< |
it.next().get(); |
417 |
< |
} catch(ExecutionException success) { |
418 |
< |
} catch(Exception ex) { |
419 |
< |
unexpectedException(); |
413 |
> |
List<Future<String>> futures = e.invokeAll(l); |
414 |
> |
assertEquals(1, futures.size()); |
415 |
> |
try { |
416 |
> |
futures.get(0).get(); |
417 |
> |
shouldThrow(); |
418 |
> |
} catch (ExecutionException success) { |
419 |
> |
assertTrue(success.getCause() instanceof NullPointerException); |
420 |
> |
} |
421 |
|
} finally { |
422 |
|
joinPool(e); |
423 |
|
} |
424 |
|
} |
425 |
|
|
426 |
|
/** |
427 |
< |
* invokeAll(c) returns results of all completed tasks |
427 |
> |
* invokeAll(c) returns results of all completed tasks in c |
428 |
|
*/ |
429 |
< |
public void testInvokeAll5() { |
429 |
> |
public void testInvokeAll5() throws Exception { |
430 |
|
ExecutorService e = new DirectExecutorService(); |
431 |
|
try { |
432 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
432 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
433 |
|
l.add(new StringTask()); |
434 |
|
l.add(new StringTask()); |
435 |
< |
List<Future<String>> result = e.invokeAll(l); |
436 |
< |
assertEquals(2, result.size()); |
437 |
< |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
438 |
< |
assertSame(TEST_STRING, it.next().get()); |
540 |
< |
} catch (ExecutionException success) { |
541 |
< |
} catch(Exception ex) { |
542 |
< |
unexpectedException(); |
435 |
> |
List<Future<String>> futures = e.invokeAll(l); |
436 |
> |
assertEquals(2, futures.size()); |
437 |
> |
for (Future<String> future : futures) |
438 |
> |
assertSame(TEST_STRING, future.get()); |
439 |
|
} finally { |
440 |
|
joinPool(e); |
441 |
|
} |
445 |
|
/** |
446 |
|
* timed invokeAny(null) throws NPE |
447 |
|
*/ |
448 |
< |
public void testTimedInvokeAny1() { |
448 |
> |
public void testTimedInvokeAny1() throws Exception { |
449 |
|
ExecutorService e = new DirectExecutorService(); |
450 |
|
try { |
451 |
< |
e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
451 |
> |
e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS); |
452 |
> |
shouldThrow(); |
453 |
|
} catch (NullPointerException success) { |
557 |
– |
} catch(Exception ex) { |
558 |
– |
unexpectedException(); |
454 |
|
} finally { |
455 |
|
joinPool(e); |
456 |
|
} |
457 |
|
} |
458 |
|
|
459 |
|
/** |
460 |
< |
* timed invokeAny(,,null) throws NPE |
460 |
> |
* timed invokeAny(null time unit) throws NPE |
461 |
|
*/ |
462 |
< |
public void testTimedInvokeAnyNullTimeUnit() { |
462 |
> |
public void testTimedInvokeAnyNullTimeUnit() throws Exception { |
463 |
|
ExecutorService e = new DirectExecutorService(); |
464 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
465 |
+ |
l.add(new StringTask()); |
466 |
|
try { |
570 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
571 |
– |
l.add(new StringTask()); |
467 |
|
e.invokeAny(l, MEDIUM_DELAY_MS, null); |
468 |
+ |
shouldThrow(); |
469 |
|
} catch (NullPointerException success) { |
574 |
– |
} catch(Exception ex) { |
575 |
– |
unexpectedException(); |
470 |
|
} finally { |
471 |
|
joinPool(e); |
472 |
|
} |
475 |
|
/** |
476 |
|
* timed invokeAny(empty collection) throws IAE |
477 |
|
*/ |
478 |
< |
public void testTimedInvokeAny2() { |
478 |
> |
public void testTimedInvokeAny2() throws Exception { |
479 |
|
ExecutorService e = new DirectExecutorService(); |
480 |
|
try { |
481 |
< |
e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
481 |
> |
e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS); |
482 |
> |
shouldThrow(); |
483 |
|
} catch (IllegalArgumentException success) { |
589 |
– |
} catch(Exception ex) { |
590 |
– |
unexpectedException(); |
484 |
|
} finally { |
485 |
|
joinPool(e); |
486 |
|
} |
489 |
|
/** |
490 |
|
* timed invokeAny(c) throws NPE if c has null elements |
491 |
|
*/ |
492 |
< |
public void testTimedInvokeAny3() { |
492 |
> |
public void testTimedInvokeAny3() throws Exception { |
493 |
|
ExecutorService e = new DirectExecutorService(); |
494 |
+ |
List<Callable<Integer>> l = new ArrayList<Callable<Integer>>(); |
495 |
+ |
l.add(new Callable<Integer>() { |
496 |
+ |
public Integer call() { return 5/0; }}); |
497 |
+ |
l.add(null); |
498 |
|
try { |
499 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
500 |
< |
l.add(new StringTask()); |
604 |
< |
l.add(null); |
605 |
< |
e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
499 |
> |
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
500 |
> |
shouldThrow(); |
501 |
|
} catch (NullPointerException success) { |
607 |
– |
} catch(Exception ex) { |
608 |
– |
ex.printStackTrace(); |
609 |
– |
unexpectedException(); |
502 |
|
} finally { |
503 |
|
joinPool(e); |
504 |
|
} |
507 |
|
/** |
508 |
|
* timed invokeAny(c) throws ExecutionException if no task completes |
509 |
|
*/ |
510 |
< |
public void testTimedInvokeAny4() { |
510 |
> |
public void testTimedInvokeAny4() throws Exception { |
511 |
|
ExecutorService e = new DirectExecutorService(); |
512 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
513 |
+ |
l.add(new NPETask()); |
514 |
|
try { |
515 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
516 |
< |
l.add(new NPETask()); |
517 |
< |
e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
518 |
< |
} catch(ExecutionException success) { |
625 |
< |
} catch(Exception ex) { |
626 |
< |
unexpectedException(); |
515 |
> |
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
516 |
> |
shouldThrow(); |
517 |
> |
} catch (ExecutionException success) { |
518 |
> |
assertTrue(success.getCause() instanceof NullPointerException); |
519 |
|
} finally { |
520 |
|
joinPool(e); |
521 |
|
} |
522 |
|
} |
523 |
|
|
524 |
|
/** |
525 |
< |
* timed invokeAny(c) returns result of some task |
525 |
> |
* timed invokeAny(c) returns result of some task in c |
526 |
|
*/ |
527 |
< |
public void testTimedInvokeAny5() { |
527 |
> |
public void testTimedInvokeAny5() throws Exception { |
528 |
|
ExecutorService e = new DirectExecutorService(); |
529 |
|
try { |
530 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
530 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
531 |
|
l.add(new StringTask()); |
532 |
|
l.add(new StringTask()); |
533 |
< |
String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
533 |
> |
String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
534 |
|
assertSame(TEST_STRING, result); |
643 |
– |
} catch (ExecutionException success) { |
644 |
– |
} catch(Exception ex) { |
645 |
– |
unexpectedException(); |
535 |
|
} finally { |
536 |
|
joinPool(e); |
537 |
|
} |
540 |
|
/** |
541 |
|
* timed invokeAll(null) throws NPE |
542 |
|
*/ |
543 |
< |
public void testTimedInvokeAll1() { |
543 |
> |
public void testTimedInvokeAll1() throws InterruptedException { |
544 |
|
ExecutorService e = new DirectExecutorService(); |
545 |
|
try { |
546 |
< |
e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
546 |
> |
e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS); |
547 |
> |
shouldThrow(); |
548 |
|
} catch (NullPointerException success) { |
659 |
– |
} catch(Exception ex) { |
660 |
– |
unexpectedException(); |
549 |
|
} finally { |
550 |
|
joinPool(e); |
551 |
|
} |
552 |
|
} |
553 |
|
|
554 |
|
/** |
555 |
< |
* timed invokeAll(,,null) throws NPE |
555 |
> |
* timed invokeAll(null time unit) throws NPE |
556 |
|
*/ |
557 |
< |
public void testTimedInvokeAllNullTimeUnit() { |
557 |
> |
public void testTimedInvokeAllNullTimeUnit() throws InterruptedException { |
558 |
|
ExecutorService e = new DirectExecutorService(); |
559 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
560 |
+ |
l.add(new StringTask()); |
561 |
|
try { |
672 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
673 |
– |
l.add(new StringTask()); |
562 |
|
e.invokeAll(l, MEDIUM_DELAY_MS, null); |
563 |
+ |
shouldThrow(); |
564 |
|
} catch (NullPointerException success) { |
676 |
– |
} catch(Exception ex) { |
677 |
– |
unexpectedException(); |
565 |
|
} finally { |
566 |
|
joinPool(e); |
567 |
|
} |
570 |
|
/** |
571 |
|
* timed invokeAll(empty collection) returns empty collection |
572 |
|
*/ |
573 |
< |
public void testTimedInvokeAll2() { |
573 |
> |
public void testTimedInvokeAll2() throws InterruptedException { |
574 |
|
ExecutorService e = new DirectExecutorService(); |
575 |
|
try { |
576 |
< |
List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
576 |
> |
List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS); |
577 |
|
assertTrue(r.isEmpty()); |
691 |
– |
} catch(Exception ex) { |
692 |
– |
unexpectedException(); |
578 |
|
} finally { |
579 |
|
joinPool(e); |
580 |
|
} |
583 |
|
/** |
584 |
|
* timed invokeAll(c) throws NPE if c has null elements |
585 |
|
*/ |
586 |
< |
public void testTimedInvokeAll3() { |
586 |
> |
public void testTimedInvokeAll3() throws InterruptedException { |
587 |
|
ExecutorService e = new DirectExecutorService(); |
588 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
589 |
+ |
l.add(new StringTask()); |
590 |
+ |
l.add(null); |
591 |
|
try { |
592 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
593 |
< |
l.add(new StringTask()); |
706 |
< |
l.add(null); |
707 |
< |
e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
592 |
> |
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
593 |
> |
shouldThrow(); |
594 |
|
} catch (NullPointerException success) { |
709 |
– |
} catch(Exception ex) { |
710 |
– |
unexpectedException(); |
595 |
|
} finally { |
596 |
|
joinPool(e); |
597 |
|
} |
598 |
|
} |
599 |
|
|
600 |
|
/** |
601 |
< |
* get of element of invokeAll(c) throws exception on failed task |
601 |
> |
* get of returned element of invokeAll(c) throws exception on failed task |
602 |
|
*/ |
603 |
< |
public void testTimedInvokeAll4() { |
603 |
> |
public void testTimedInvokeAll4() throws Exception { |
604 |
|
ExecutorService e = new DirectExecutorService(); |
605 |
|
try { |
606 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
606 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
607 |
|
l.add(new NPETask()); |
608 |
< |
List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
609 |
< |
assertEquals(1, result.size()); |
610 |
< |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
611 |
< |
it.next().get(); |
612 |
< |
} catch(ExecutionException success) { |
613 |
< |
} catch(Exception ex) { |
614 |
< |
unexpectedException(); |
608 |
> |
List<Future<String>> futures = |
609 |
> |
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
610 |
> |
assertEquals(1, futures.size()); |
611 |
> |
try { |
612 |
> |
futures.get(0).get(); |
613 |
> |
shouldThrow(); |
614 |
> |
} catch (ExecutionException success) { |
615 |
> |
assertTrue(success.getCause() instanceof NullPointerException); |
616 |
> |
} |
617 |
|
} finally { |
618 |
|
joinPool(e); |
619 |
|
} |
620 |
|
} |
621 |
|
|
622 |
|
/** |
623 |
< |
* timed invokeAll(c) returns results of all completed tasks |
623 |
> |
* timed invokeAll(c) returns results of all completed tasks in c |
624 |
|
*/ |
625 |
< |
public void testTimedInvokeAll5() { |
625 |
> |
public void testTimedInvokeAll5() throws Exception { |
626 |
|
ExecutorService e = new DirectExecutorService(); |
627 |
|
try { |
628 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
628 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
629 |
|
l.add(new StringTask()); |
630 |
|
l.add(new StringTask()); |
631 |
< |
List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
632 |
< |
assertEquals(2, result.size()); |
633 |
< |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
634 |
< |
assertSame(TEST_STRING, it.next().get()); |
635 |
< |
} catch (ExecutionException success) { |
750 |
< |
} catch(Exception ex) { |
751 |
< |
unexpectedException(); |
631 |
> |
List<Future<String>> futures = |
632 |
> |
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
633 |
> |
assertEquals(2, futures.size()); |
634 |
> |
for (Future<String> future : futures) |
635 |
> |
assertSame(TEST_STRING, future.get()); |
636 |
|
} finally { |
637 |
|
joinPool(e); |
638 |
|
} |
639 |
|
} |
640 |
|
|
641 |
|
/** |
642 |
< |
* timed invokeAll(c) cancels tasks not completed by timeout |
642 |
> |
* timed invokeAll cancels tasks not completed by timeout |
643 |
|
*/ |
644 |
< |
public void testTimedInvokeAll6() { |
644 |
> |
public void testTimedInvokeAll6() throws InterruptedException { |
645 |
|
ExecutorService e = new DirectExecutorService(); |
646 |
|
try { |
647 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
647 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
648 |
|
l.add(new StringTask()); |
649 |
|
l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING)); |
650 |
|
l.add(new StringTask()); |
651 |
< |
List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
652 |
< |
assertEquals(3, result.size()); |
653 |
< |
Iterator<Future<String>> it = result.iterator(); |
651 |
> |
List<Future<String>> futures = |
652 |
> |
e.invokeAll(l, SMALL_DELAY_MS, MILLISECONDS); |
653 |
> |
assertEquals(3, futures.size()); |
654 |
> |
Iterator<Future<String>> it = futures.iterator(); |
655 |
|
Future<String> f1 = it.next(); |
656 |
|
Future<String> f2 = it.next(); |
657 |
|
Future<String> f3 = it.next(); |
660 |
|
assertTrue(f2.isDone()); |
661 |
|
assertTrue(f3.isDone()); |
662 |
|
assertTrue(f3.isCancelled()); |
778 |
– |
} catch(Exception ex) { |
779 |
– |
unexpectedException(); |
663 |
|
} finally { |
664 |
|
joinPool(e); |
665 |
|
} |