60 |
|
} |
61 |
|
} |
62 |
|
|
63 |
– |
/** |
64 |
– |
* invoke of a runnable runs it to completion |
65 |
– |
*/ |
66 |
– |
public void testInvokeRunnable() { |
67 |
– |
try { |
68 |
– |
ExecutorService e = new DirectExecutorService(); |
69 |
– |
TrackedShortRunnable task = new TrackedShortRunnable(); |
70 |
– |
assertFalse(task.done); |
71 |
– |
e.invoke(task); |
72 |
– |
assertTrue(task.done); |
73 |
– |
} |
74 |
– |
catch (ExecutionException ex) { |
75 |
– |
unexpectedException(); |
76 |
– |
} |
77 |
– |
catch (InterruptedException ex) { |
78 |
– |
unexpectedException(); |
79 |
– |
} |
80 |
– |
} |
63 |
|
|
64 |
|
/** |
65 |
|
* execute of a callable runs it to completion |
170 |
|
} |
171 |
|
|
172 |
|
/** |
173 |
< |
* invoke of a collable runs it to completion |
173 |
> |
* invoke of a callable runs it to completion |
174 |
|
*/ |
175 |
|
public void testInvokeCallable() { |
176 |
|
try { |
204 |
|
} |
205 |
|
} |
206 |
|
|
225 |
– |
/** |
226 |
– |
* invoke of a null runnable throws NPE |
227 |
– |
*/ |
228 |
– |
public void testInvokeNullRunnable() { |
229 |
– |
try { |
230 |
– |
ExecutorService e = new DirectExecutorService(); |
231 |
– |
TrackedShortRunnable task = null; |
232 |
– |
e.invoke(task); |
233 |
– |
shouldThrow(); |
234 |
– |
} |
235 |
– |
catch (NullPointerException success) { |
236 |
– |
} |
237 |
– |
catch (Exception ex) { |
238 |
– |
unexpectedException(); |
239 |
– |
} |
240 |
– |
} |
207 |
|
|
208 |
|
/** |
209 |
|
* execute of a null callable throws NPE |
272 |
|
|
273 |
|
|
274 |
|
/** |
275 |
< |
* invoke(Executor, Runnable) throws InterruptedException if |
275 |
> |
* invoke(Executor, Callable) throws InterruptedException if |
276 |
|
* caller interrupted. |
277 |
|
*/ |
278 |
|
public void testInterruptedInvoke() { |
280 |
|
Thread t = new Thread(new Runnable() { |
281 |
|
public void run() { |
282 |
|
try { |
283 |
< |
p.invoke(new Runnable() { |
284 |
< |
public void run() { |
283 |
> |
p.invoke(new Callable<Object>() { |
284 |
> |
public Object call() { |
285 |
|
try { |
286 |
|
Thread.sleep(MEDIUM_DELAY_MS); |
287 |
|
shouldThrow(); |
288 |
|
} catch(InterruptedException e){ |
289 |
|
} |
290 |
+ |
return null; |
291 |
|
} |
292 |
|
}); |
293 |
|
} catch(InterruptedException success){ |
308 |
|
} |
309 |
|
|
310 |
|
/** |
344 |
– |
* invoke(Executor, Runnable) throws ExecutionException if |
345 |
– |
* runnable throws exception. |
346 |
– |
*/ |
347 |
– |
public void testInvoke3() { |
348 |
– |
ThreadPoolExecutor p = new ThreadPoolExecutor(1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
349 |
– |
try { |
350 |
– |
Runnable r = new Runnable() { |
351 |
– |
public void run() { |
352 |
– |
int i = 5/0; |
353 |
– |
} |
354 |
– |
}; |
355 |
– |
|
356 |
– |
for(int i =0; i < 5; i++){ |
357 |
– |
p.invoke(r); |
358 |
– |
} |
359 |
– |
|
360 |
– |
shouldThrow(); |
361 |
– |
} catch(ExecutionException success){ |
362 |
– |
} catch(Exception e){ |
363 |
– |
unexpectedException(); |
364 |
– |
} |
365 |
– |
joinPool(p); |
366 |
– |
} |
367 |
– |
|
368 |
– |
|
369 |
– |
|
370 |
– |
/** |
311 |
|
* invoke(Executor, Callable) throws InterruptedException if |
312 |
|
* callable throws exception |
313 |
|
*/ |
375 |
|
joinPool(p); |
376 |
|
} |
377 |
|
|
378 |
< |
} |
378 |
> |
} |