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.17 by jsr166, Sun May 29 06:54: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.*;
12   import static java.util.concurrent.TimeUnit.MILLISECONDS;
13   import java.util.concurrent.atomic.*;
15 import java.math.BigInteger;
14   import java.security.*;
15  
16   public class ExecutorCompletionServiceTest extends JSR166TestCase {
# Line 23 | Line 21 | public class ExecutorCompletionServiceTe
21          return new TestSuite(ExecutorCompletionServiceTest.class);
22      }
23  
26
24      /**
25       * Creating a new ECS with null Executor throw NPE
26       */
# Line 112 | Line 109 | public class ExecutorCompletionServiceTe
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 <            Thread.sleep(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          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines