11 |
|
import java.util.concurrent.*; |
12 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
13 |
|
import java.util.concurrent.atomic.*; |
14 |
– |
import java.math.BigInteger; |
14 |
|
import java.security.*; |
15 |
|
|
16 |
|
public class ExecutorCompletionServiceTest extends JSR166TestCase { |
109 |
|
/** |
110 |
|
* If poll returns non-null, the returned task is completed |
111 |
|
*/ |
112 |
< |
public void testPoll1() throws InterruptedException { |
112 |
> |
public void testPoll1() throws Exception { |
113 |
|
ExecutorService e = Executors.newCachedThreadPool(); |
114 |
|
ExecutorCompletionService ecs = new ExecutorCompletionService(e); |
115 |
|
try { |
116 |
|
assertNull(ecs.poll()); |
117 |
|
Callable c = new StringTask(); |
118 |
|
ecs.submit(c); |
119 |
< |
delay(SHORT_DELAY_MS); |
120 |
< |
for (;;) { |
121 |
< |
Future f = ecs.poll(); |
122 |
< |
if (f != null) { |
123 |
< |
assertTrue(f.isDone()); |
124 |
< |
break; |
125 |
< |
} |
119 |
> |
|
120 |
> |
long startTime = System.nanoTime(); |
121 |
> |
Future f; |
122 |
> |
while ((f = ecs.poll()) == null) { |
123 |
> |
if (millisElapsedSince(startTime) > LONG_DELAY_MS) |
124 |
> |
fail("timed out"); |
125 |
> |
Thread.yield(); |
126 |
|
} |
127 |
+ |
assertTrue(f.isDone()); |
128 |
+ |
assertSame(TEST_STRING, f.get()); |
129 |
|
} finally { |
130 |
|
joinPool(e); |
131 |
|
} |