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 |
|
|
16 |
|
|
17 |
|
public class ExecutorCompletionServiceTest 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(ExecutorCompletionServiceTest.class); |
25 |
|
|
26 |
|
/** |
27 |
|
* Creating a new ECS with null Executor throw NPE |
28 |
< |
*/ |
28 |
> |
*/ |
29 |
|
public void testConstructorNPE() { |
30 |
|
try { |
31 |
|
ExecutorCompletionService ecs = new ExecutorCompletionService(null); |
36 |
|
|
37 |
|
/** |
38 |
|
* Creating a new ECS with null queue throw NPE |
39 |
< |
*/ |
39 |
> |
*/ |
40 |
|
public void testConstructorNPE2() { |
41 |
|
try { |
42 |
|
ExecutorService e = Executors.newCachedThreadPool(); |
48 |
|
|
49 |
|
/** |
50 |
|
* Submitting a null callable throws NPE |
51 |
< |
*/ |
51 |
> |
*/ |
52 |
|
public void testSubmitNPE() { |
53 |
|
ExecutorService e = Executors.newCachedThreadPool(); |
54 |
|
ExecutorCompletionService ecs = new ExecutorCompletionService(e); |
64 |
|
|
65 |
|
/** |
66 |
|
* Submitting a null runnable throws NPE |
67 |
< |
*/ |
67 |
> |
*/ |
68 |
|
public void testSubmitNPE2() { |
69 |
|
ExecutorService e = Executors.newCachedThreadPool(); |
70 |
|
ExecutorCompletionService ecs = new ExecutorCompletionService(e); |
80 |
|
|
81 |
|
/** |
82 |
|
* A taken submitted task is completed |
83 |
< |
*/ |
83 |
> |
*/ |
84 |
|
public void testTake() { |
85 |
|
ExecutorService e = Executors.newCachedThreadPool(); |
86 |
|
ExecutorCompletionService ecs = new ExecutorCompletionService(e); |
98 |
|
|
99 |
|
/** |
100 |
|
* Take returns the same future object returned by submit |
101 |
< |
*/ |
101 |
> |
*/ |
102 |
|
public void testTake2() { |
103 |
|
ExecutorService e = Executors.newCachedThreadPool(); |
104 |
|
ExecutorCompletionService ecs = new ExecutorCompletionService(e); |
116 |
|
|
117 |
|
/** |
118 |
|
* If poll returns non-null, the returned task is completed |
119 |
< |
*/ |
119 |
> |
*/ |
120 |
|
public void testPoll1() { |
121 |
|
ExecutorService e = Executors.newCachedThreadPool(); |
122 |
|
ExecutorCompletionService ecs = new ExecutorCompletionService(e); |
141 |
|
|
142 |
|
/** |
143 |
|
* If timed poll returns non-null, the returned task is completed |
144 |
< |
*/ |
144 |
> |
*/ |
145 |
|
public void testPoll2() { |
146 |
|
ExecutorService e = Executors.newCachedThreadPool(); |
147 |
|
ExecutorCompletionService ecs = new ExecutorCompletionService(e); |
150 |
|
Callable c = new StringTask(); |
151 |
|
ecs.submit(c); |
152 |
|
Future f = ecs.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
153 |
< |
if (f != null) |
153 |
> |
if (f != null) |
154 |
|
assertTrue(f.isDone()); |
155 |
|
} catch (Exception ex) { |
156 |
|
unexpectedException(); |