21 |
|
private static long MEDIUM_DELAY_MS = 1000; |
22 |
|
private static long LONG_DELAY_MS = 10000; |
23 |
|
|
24 |
+ |
public void testConstructor(){ |
25 |
+ |
try { |
26 |
+ |
FutureTask task = new FutureTask(null); |
27 |
+ |
fail("should throw"); |
28 |
+ |
} |
29 |
+ |
catch(NullPointerException success) { |
30 |
+ |
} |
31 |
+ |
} |
32 |
+ |
|
33 |
+ |
public void testConstructor2(){ |
34 |
+ |
try { |
35 |
+ |
FutureTask task = new FutureTask(null, Boolean.TRUE); |
36 |
+ |
fail("should throw"); |
37 |
+ |
} |
38 |
+ |
catch(NullPointerException success) { |
39 |
+ |
} |
40 |
+ |
} |
41 |
+ |
|
42 |
|
public void testIsDone(){ |
43 |
|
FutureTask task = new FutureTask( new Callable() { |
44 |
|
public Object call() { return Boolean.TRUE; } }); |
129 |
|
public Object call(){ |
130 |
|
try{ |
131 |
|
Thread.sleep(MEDIUM_DELAY_MS); |
132 |
< |
}catch(InterruptedException e){ |
132 |
> |
} catch(InterruptedException e){ |
133 |
|
fail("unexpected exception"); |
134 |
|
} |
135 |
|
return Boolean.TRUE; |
139 |
|
public void run(){ |
140 |
|
try{ |
141 |
|
ft.get(); |
142 |
< |
}catch(Exception e){ |
142 |
> |
} catch(Exception e){ |
143 |
|
fail("unexpected exception"); |
144 |
|
} |
145 |
|
} |
164 |
|
public Object call(){ |
165 |
|
try{ |
166 |
|
Thread.sleep(MEDIUM_DELAY_MS); |
167 |
< |
}catch(InterruptedException e){ |
167 |
> |
} catch(InterruptedException e){ |
168 |
|
fail("unexpected exception"); |
169 |
|
} |
170 |
|
return Boolean.TRUE; |
200 |
|
public Object call(){ |
201 |
|
try{ |
202 |
|
Thread.sleep(MEDIUM_DELAY_MS); |
203 |
< |
}catch(InterruptedException e){ |
203 |
> |
} catch(InterruptedException e){ |
204 |
|
fail("unexpected exception"); |
205 |
|
} |
206 |
|
return Boolean.TRUE; |
213 |
|
try{ |
214 |
|
ft.get(); |
215 |
|
fail("should throw"); |
216 |
< |
}catch(CancellationException success){ |
216 |
> |
} catch(CancellationException success){ |
217 |
|
} |
218 |
|
catch(Exception e){ |
219 |
|
fail("unexpected exception"); |
223 |
|
t.start(); |
224 |
|
ft.cancel(true); |
225 |
|
t.join(); |
226 |
< |
}catch(InterruptedException sucess){ |
226 |
> |
} catch(InterruptedException success){ |
227 |
|
fail("unexpected exception"); |
228 |
|
} |
229 |
|
} |
246 |
|
try{ |
247 |
|
ft.get(3 * SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
248 |
|
fail("should throw"); |
249 |
< |
}catch(CancellationException success) {} |
249 |
> |
} catch(CancellationException success) {} |
250 |
|
catch(Exception e){ |
251 |
|
fail("unexpected exception"); |
252 |
|
} |
257 |
|
ft.cancel(true); |
258 |
|
Thread.sleep(SHORT_DELAY_MS); |
259 |
|
t.join(); |
260 |
< |
}catch(InterruptedException ie){ |
260 |
> |
} catch(InterruptedException ie){ |
261 |
|
fail("unexpected exception"); |
262 |
|
} |
263 |
|
} |
273 |
|
ft.run(); |
274 |
|
ft.get(); |
275 |
|
fail("should throw"); |
276 |
< |
}catch(ExecutionException success){ |
276 |
> |
} catch(ExecutionException success){ |
277 |
|
} |
278 |
|
catch(Exception e){ |
279 |
|
fail("unexpected exception"); |
291 |
|
ft.run(); |
292 |
|
ft.get(SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
293 |
|
fail("should throw"); |
294 |
< |
}catch(ExecutionException success) { |
295 |
< |
}catch(TimeoutException success) { } // unlikely but OK |
294 |
> |
} catch(ExecutionException success) { |
295 |
> |
} catch(TimeoutException success) { } // unlikely but OK |
296 |
|
catch(Exception e){ |
297 |
|
fail("unexpected exception"); |
298 |
|
} |
337 |
|
try{ |
338 |
|
ft.get(100,TimeUnit.SECONDS); |
339 |
|
fail("should throw"); |
340 |
< |
}catch(InterruptedException success){} |
340 |
> |
} catch(InterruptedException success){} |
341 |
|
catch(Exception e){ |
342 |
|
fail("unexpected exception"); |
343 |
|
} |
362 |
|
try{ |
363 |
|
ft.get(1,TimeUnit.MILLISECONDS); |
364 |
|
fail("should throw"); |
365 |
< |
}catch(TimeoutException success){} |
366 |
< |
catch(Exception sucess){ |
365 |
> |
} catch(TimeoutException success){} |
366 |
> |
catch(Exception success){ |
367 |
|
fail("unexpected exception"); |
368 |
|
} |
369 |
|
|