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.5 by dl, Mon Aug 1 19:54:04 2005 UTC vs.
Revision 1.9 by jsr166, Sat Nov 21 02:33:20 2009 UTC

# Line 2 | Line 2
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  
10   import junit.framework.*;
11   import java.util.*;
12   import java.util.concurrent.*;
13 + import static java.util.concurrent.TimeUnit.MILLISECONDS;
14   import java.util.concurrent.atomic.*;
15   import java.math.BigInteger;
16   import java.security.*;
17  
18 < public class ExecutorCompletionServiceTest extends JSR166TestCase{
18 > public class ExecutorCompletionServiceTest extends JSR166TestCase {
19      public static void main(String[] args) {
20 <        junit.textui.TestRunner.run (suite());  
20 >        junit.textui.TestRunner.run (suite());
21      }
22      public static Test suite() {
23          return new TestSuite(ExecutorCompletionServiceTest.class);
# Line 25 | Line 26 | public class ExecutorCompletionServiceTe
26  
27      /**
28       * Creating a new ECS with null Executor throw NPE
29 <     */
29 >     */
30      public void testConstructorNPE() {
31          try {
32              ExecutorCompletionService ecs = new ExecutorCompletionService(null);
# Line 36 | Line 37 | public class ExecutorCompletionServiceTe
37  
38      /**
39       * Creating a new ECS with null queue throw NPE
40 <     */
40 >     */
41      public void testConstructorNPE2() {
42          try {
43              ExecutorService e = Executors.newCachedThreadPool();
# Line 48 | Line 49 | public class ExecutorCompletionServiceTe
49  
50      /**
51       * Submitting a null callable throws NPE
52 <     */
52 >     */
53      public void testSubmitNPE() {
54          ExecutorService e = Executors.newCachedThreadPool();
55          ExecutorCompletionService ecs = new ExecutorCompletionService(e);
# Line 64 | Line 65 | public class ExecutorCompletionServiceTe
65  
66      /**
67       * Submitting a null runnable throws NPE
68 <     */
68 >     */
69      public void testSubmitNPE2() {
70          ExecutorService e = Executors.newCachedThreadPool();
71          ExecutorCompletionService ecs = new ExecutorCompletionService(e);
# Line 80 | Line 81 | public class ExecutorCompletionServiceTe
81  
82      /**
83       * A taken submitted task is completed
84 <     */
84 >     */
85      public void testTake() {
86          ExecutorService e = Executors.newCachedThreadPool();
87          ExecutorCompletionService ecs = new ExecutorCompletionService(e);
# Line 98 | Line 99 | public class ExecutorCompletionServiceTe
99  
100      /**
101       * Take returns the same future object returned by submit
102 <     */
102 >     */
103      public void testTake2() {
104          ExecutorService e = Executors.newCachedThreadPool();
105          ExecutorCompletionService ecs = new ExecutorCompletionService(e);
# Line 116 | Line 117 | public class ExecutorCompletionServiceTe
117  
118      /**
119       * If poll returns non-null, the returned task is completed
120 <     */
120 >     */
121      public void testPoll1() {
122          ExecutorService e = Executors.newCachedThreadPool();
123          ExecutorCompletionService ecs = new ExecutorCompletionService(e);
# Line 141 | Line 142 | public class ExecutorCompletionServiceTe
142  
143      /**
144       * If timed poll returns non-null, the returned task is completed
145 <     */
145 >     */
146      public void testPoll2() {
147          ExecutorService e = Executors.newCachedThreadPool();
148          ExecutorCompletionService ecs = new ExecutorCompletionService(e);
# Line 149 | Line 150 | public class ExecutorCompletionServiceTe
150              assertNull(ecs.poll());
151              Callable c = new StringTask();
152              ecs.submit(c);
153 <            Future f = ecs.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
154 <            if (f != null)
153 >            Future f = ecs.poll(SHORT_DELAY_MS, MILLISECONDS);
154 >            if (f != null)
155                  assertTrue(f.isDone());
156          } catch (Exception ex) {
157              unexpectedException();
# Line 214 | Line 215 | public class ExecutorCompletionServiceTe
215               new ExecutorCompletionService<String>(e);
216           try {
217               assertNull(ecs.poll());
218 <             Callable<String> c = new StringTask();
219 <             Future f1 = ecs.submit(c);
218 >             Runnable r = new NoOpRunnable();
219 >             Future f1 = ecs.submit(r, null);
220               assertTrue("submit must return MyRunnableFuture",
221                          f1 instanceof MyRunnableFuture);
222               Future f2 = ecs.take();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines