57 |
|
* ecs.submit(null) throws NullPointerException |
58 |
|
*/ |
59 |
|
public void testSubmitNullCallable() { |
60 |
< |
CompletionService<Item> cs = new ExecutorCompletionService<Item>(cachedThreadPool); |
60 |
> |
CompletionService<Item> cs = new ExecutorCompletionService<>(cachedThreadPool); |
61 |
|
try { |
62 |
|
cs.submit((Callable<Item>) null); |
63 |
|
shouldThrow(); |
68 |
|
* ecs.submit(null, val) throws NullPointerException |
69 |
|
*/ |
70 |
|
public void testSubmitNullRunnable() { |
71 |
< |
CompletionService<Boolean> cs = new ExecutorCompletionService<Boolean>(cachedThreadPool); |
71 |
> |
CompletionService<Boolean> cs = new ExecutorCompletionService<>(cachedThreadPool); |
72 |
|
try { |
73 |
|
cs.submit((Runnable) null, Boolean.TRUE); |
74 |
|
shouldThrow(); |
79 |
|
* A taken submitted task is completed |
80 |
|
*/ |
81 |
|
public void testTake() throws Exception { |
82 |
< |
CompletionService<String> cs = new ExecutorCompletionService<String>(cachedThreadPool); |
82 |
> |
CompletionService<String> cs = new ExecutorCompletionService<>(cachedThreadPool); |
83 |
|
cs.submit(new StringTask()); |
84 |
|
Future<?> f = cs.take(); |
85 |
|
assertTrue(f.isDone()); |
90 |
|
* Take returns the same future object returned by submit |
91 |
|
*/ |
92 |
|
public void testTake2() throws InterruptedException { |
93 |
< |
CompletionService<String> cs = new ExecutorCompletionService<String>(cachedThreadPool); |
93 |
> |
CompletionService<String> cs = new ExecutorCompletionService<>(cachedThreadPool); |
94 |
|
Future<?> f1 = cs.submit(new StringTask()); |
95 |
|
Future<?> f2 = cs.take(); |
96 |
|
assertSame(f1, f2); |
100 |
|
* poll returns non-null when the returned task is completed |
101 |
|
*/ |
102 |
|
public void testPoll1() throws Exception { |
103 |
< |
CompletionService<String> cs = new ExecutorCompletionService<String>(cachedThreadPool); |
103 |
> |
CompletionService<String> cs = new ExecutorCompletionService<>(cachedThreadPool); |
104 |
|
assertNull(cs.poll()); |
105 |
|
cs.submit(new StringTask()); |
106 |
|
|
119 |
|
* timed poll returns non-null when the returned task is completed |
120 |
|
*/ |
121 |
|
public void testPoll2() throws Exception { |
122 |
< |
CompletionService<String> cs = new ExecutorCompletionService<String>(cachedThreadPool); |
122 |
> |
CompletionService<String> cs = new ExecutorCompletionService<>(cachedThreadPool); |
123 |
|
assertNull(cs.poll()); |
124 |
|
cs.submit(new StringTask()); |
125 |
|
|
139 |
|
* poll returns null before the returned task is completed |
140 |
|
*/ |
141 |
|
public void testPollReturnsNullBeforeCompletion() throws Exception { |
142 |
< |
CompletionService<String> cs = new ExecutorCompletionService<String>(cachedThreadPool); |
142 |
> |
CompletionService<String> cs = new ExecutorCompletionService<>(cachedThreadPool); |
143 |
|
final CountDownLatch proceed = new CountDownLatch(1); |
144 |
|
cs.submit(new Callable<String>() { public String call() throws Exception { |
145 |
|
await(proceed); |
159 |
|
* successful and failed tasks are both returned |
160 |
|
*/ |
161 |
|
public void testTaskAssortment() throws Exception { |
162 |
< |
CompletionService<String> cs = new ExecutorCompletionService<String>(cachedThreadPool); |
162 |
> |
CompletionService<String> cs = new ExecutorCompletionService<>(cachedThreadPool); |
163 |
|
ArithmeticException ex = new ArithmeticException(); |
164 |
|
final int rounds = 2; |
165 |
|
for (int i = rounds; i--> 0; ) { |