ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ExecutorCompletionServiceTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ExecutorCompletionServiceTest.java (file contents):
Revision 1.13 by jsr166, Tue Mar 15 19:47:06 2011 UTC vs.
Revision 1.18 by jsr166, Tue May 31 16:16:23 2011 UTC

# Line 6 | Line 6
6   * Pat Fisher, Mike Judd.
7   */
8  
9
9   import junit.framework.*;
10   import java.util.*;
11 < import java.util.concurrent.*;
11 > import java.util.concurrent.ArrayBlockingQueue;
12 > import java.util.concurrent.Callable;
13 > import java.util.concurrent.ExecutorCompletionService;
14 > import java.util.concurrent.ExecutorService;
15 > import java.util.concurrent.Executors;
16 > import java.util.concurrent.Future;
17 > import java.util.concurrent.FutureTask;
18 > import java.util.concurrent.RunnableFuture;
19 > import java.util.concurrent.ThreadPoolExecutor;
20 > import java.util.concurrent.TimeUnit;
21   import static java.util.concurrent.TimeUnit.MILLISECONDS;
22 < import java.util.concurrent.atomic.*;
15 < import java.math.BigInteger;
22 > import java.util.concurrent.atomic.AtomicBoolean;
23   import java.security.*;
24  
25   public class ExecutorCompletionServiceTest extends JSR166TestCase {
# Line 23 | Line 30 | public class ExecutorCompletionServiceTe
30          return new TestSuite(ExecutorCompletionServiceTest.class);
31      }
32  
26
33      /**
34       * Creating a new ECS with null Executor throw NPE
35       */
# Line 112 | Line 118 | public class ExecutorCompletionServiceTe
118      /**
119       * If poll returns non-null, the returned task is completed
120       */
121 <    public void testPoll1() throws InterruptedException {
121 >    public void testPoll1() throws Exception {
122          ExecutorService e = Executors.newCachedThreadPool();
123          ExecutorCompletionService ecs = new ExecutorCompletionService(e);
124          try {
125              assertNull(ecs.poll());
126              Callable c = new StringTask();
127              ecs.submit(c);
128 <            Thread.sleep(SHORT_DELAY_MS);
129 <            for (;;) {
130 <                Future f = ecs.poll();
131 <                if (f != null) {
132 <                    assertTrue(f.isDone());
133 <                    break;
134 <                }
128 >
129 >            long startTime = System.nanoTime();
130 >            Future f;
131 >            while ((f = ecs.poll()) == null) {
132 >                if (millisElapsedSince(startTime) > LONG_DELAY_MS)
133 >                    fail("timed out");
134 >                Thread.yield();
135              }
136 +            assertTrue(f.isDone());
137 +            assertSame(TEST_STRING, f.get());
138          } finally {
139              joinPool(e);
140          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines