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

Comparing jsr166/src/test/tck/AbstractExecutorServiceTest.java (file contents):
Revision 1.10 by dl, Sat Dec 27 19:26:42 2003 UTC vs.
Revision 1.15 by dl, Tue Jan 20 20:20:56 2004 UTC

# Line 36 | Line 36 | public class AbstractExecutorServiceTest
36      }
37  
38      /**
39 <     * execute of runnable runs it to completion
39 >     * execute(runnable) runs it to completion
40       */
41      public void testExecuteRunnable() {
42          try {
# Line 57 | Line 57 | public class AbstractExecutorServiceTest
57  
58  
59      /**
60 <     * completed submit of callable returns result
60 >     * Completed submit(callable) returns result
61       */
62      public void testSubmitCallable() {
63          try {
# Line 75 | Line 75 | public class AbstractExecutorServiceTest
75      }
76  
77      /**
78 <     * completed submit of runnable returns successfully
78 >     * Completed submit(runnable) returns successfully
79       */
80      public void testSubmitRunnable() {
81          try {
# Line 93 | Line 93 | public class AbstractExecutorServiceTest
93      }
94  
95      /**
96 <     * completed submit of (runnable, result) returns result
96 >     * Completed submit(runnable, result) returns result
97       */
98      public void testSubmitRunnable2() {
99          try {
# Line 112 | Line 112 | public class AbstractExecutorServiceTest
112  
113  
114      /**
115 <     * submit of a privileged action runs it to completion
115 >     * A submitted privileged action to completion
116       */
117      public void testSubmitPrivilegedAction() {
118 <        Policy savedPolicy = Policy.getPolicy();
119 <        AdjustablePolicy policy = new AdjustablePolicy();
120 <        policy.addPermission(new RuntimePermission("getContextClassLoader"));
121 <        policy.addPermission(new RuntimePermission("setContextClassLoader"));
122 <        Policy.setPolicy(policy);
118 >        Policy savedPolicy = null;
119 >        try {
120 >            savedPolicy = Policy.getPolicy();
121 >            AdjustablePolicy policy = new AdjustablePolicy();
122 >            policy.addPermission(new RuntimePermission("getContextClassLoader"));
123 >            policy.addPermission(new RuntimePermission("setContextClassLoader"));
124 >            Policy.setPolicy(policy);
125 >        } catch(AccessControlException ok) {
126 >            return;
127 >        }
128          try {
129              ExecutorService e = new DirectExecutorService();
130              Future future = e.submit(Executors.callable(new PrivilegedAction() {
# Line 137 | Line 142 | public class AbstractExecutorServiceTest
142              unexpectedException();
143          }
144          finally {
145 <            Policy.setPolicy(savedPolicy);
145 >            try {
146 >                Policy.setPolicy(savedPolicy);
147 >            } catch(AccessControlException ok) {
148 >                return;
149 >            }
150          }
151      }
152  
153      /**
154 <     * submit of a privileged exception action runs it to completion
154 >     * A submitted a privileged exception action runs to completion
155       */
156      public void testSubmitPrivilegedExceptionAction() {
157 <        Policy savedPolicy = Policy.getPolicy();
158 <        AdjustablePolicy policy = new AdjustablePolicy();
159 <        policy.addPermission(new RuntimePermission("getContextClassLoader"));
160 <        policy.addPermission(new RuntimePermission("setContextClassLoader"));
161 <        Policy.setPolicy(policy);
157 >        Policy savedPolicy = null;
158 >        try {
159 >            savedPolicy = Policy.getPolicy();
160 >            AdjustablePolicy policy = new AdjustablePolicy();
161 >            policy.addPermission(new RuntimePermission("getContextClassLoader"));
162 >            policy.addPermission(new RuntimePermission("setContextClassLoader"));
163 >            Policy.setPolicy(policy);
164 >        } catch(AccessControlException ok) {
165 >            return;
166 >        }
167 >
168          try {
169              ExecutorService e = new DirectExecutorService();
170              Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
# Line 172 | Line 187 | public class AbstractExecutorServiceTest
187      }
188  
189      /**
190 <     * submit of a failed privileged exception action reports exception
190 >     * A submitted failed privileged exception action reports exception
191       */
192      public void testSubmitFailedPrivilegedExceptionAction() {
193 <        Policy savedPolicy = Policy.getPolicy();
194 <        AdjustablePolicy policy = new AdjustablePolicy();
195 <        policy.addPermission(new RuntimePermission("getContextClassLoader"));
196 <        policy.addPermission(new RuntimePermission("setContextClassLoader"));
197 <        Policy.setPolicy(policy);
193 >        Policy savedPolicy = null;
194 >        try {
195 >            savedPolicy = Policy.getPolicy();
196 >            AdjustablePolicy policy = new AdjustablePolicy();
197 >            policy.addPermission(new RuntimePermission("getContextClassLoader"));
198 >            policy.addPermission(new RuntimePermission("setContextClassLoader"));
199 >            Policy.setPolicy(policy);
200 >        } catch(AccessControlException ok) {
201 >            return;
202 >        }
203 >
204 >
205          try {
206              ExecutorService e = new DirectExecutorService();
207              Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
# Line 201 | Line 223 | public class AbstractExecutorServiceTest
223      }
224  
225      /**
226 <     * execute with a null runnable throws NPE
226 >     * execute(null runnable) throws NPE
227       */
228      public void testExecuteNullRunnable() {
229          try {
# Line 219 | Line 241 | public class AbstractExecutorServiceTest
241  
242  
243      /**
244 <     * submit of a null callable throws NPE
244 >     * submit(null callable) throws NPE
245       */
246      public void testSubmitNullCallable() {
247          try {
# Line 236 | Line 258 | public class AbstractExecutorServiceTest
258      }
259  
260      /**
261 <     * submit of Runnable throws RejectedExecutionException if
262 <     * saturated.
261 >     * submit(runnable) throws RejectedExecutionException if
262 >     * executor is saturated.
263       */
264      public void testExecute1() {
265 <        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1));
265 >        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(1));
266          try {
267  
268              for(int i = 0; i < 5; ++i){
# Line 252 | Line 274 | public class AbstractExecutorServiceTest
274      }
275  
276      /**
277 <     * Completed submit of Callable throws RejectedExecutionException
278 <     *  if saturated.
277 >     * submit(callable) throws RejectedExecutionException
278 >     * if executor is saturated.
279       */
280      public void testExecute2() {
281 <         ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1));
281 >         ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(1));
282          try {
283              for(int i = 0; i < 5; ++i) {
284                  p.submit(new SmallCallable());
# Line 268 | Line 290 | public class AbstractExecutorServiceTest
290  
291  
292      /**
293 <     *  blocking on submit of Callable throws InterruptedException if
293 >     *  Blocking on submit(callable) throws InterruptedException if
294       *  caller interrupted.
295       */
296      public void testInterruptedSubmit() {
297 <        final ThreadPoolExecutor p = new ThreadPoolExecutor(1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
297 >        final ThreadPoolExecutor p = new ThreadPoolExecutor(1,1,60, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
298          Thread t = new Thread(new Runnable() {
299                  public void run() {
300                      try {
# Line 304 | Line 326 | public class AbstractExecutorServiceTest
326      }
327  
328      /**
329 <     *  get of submit of Callable throws Exception if callable
329 >     *  get of submitted callable throws Exception if callable
330       *  interrupted
331       */
332      public void testSubmitIE() {
333 <        final ThreadPoolExecutor p = new ThreadPoolExecutor(1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
333 >        final ThreadPoolExecutor p = new ThreadPoolExecutor(1,1,60, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
334  
335          final Callable c = new Callable() {
336                  public Object call() {
# Line 344 | Line 366 | public class AbstractExecutorServiceTest
366      }
367  
368      /**
369 <     *  completed submit of Callable throws ExecutionException if
370 <     *  callable throws exception
369 >     *  get of submit(callable) throws ExecutionException if callable
370 >     *  throws exception
371       */
372      public void testSubmitEE() {
373 <        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
373 >        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1,60, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
374  
375          try {
376              Callable c = new Callable() {
# Line 421 | Line 443 | public class AbstractExecutorServiceTest
443      }
444  
445      /**
446 <     * invokeAny(c) throws ExecutionException if no task completes
446 >     * invokeAny(c) throws ExecutionException if no task in c completes
447       */
448      public void testInvokeAny4() {
449          ExecutorService e = new DirectExecutorService();
# Line 438 | Line 460 | public class AbstractExecutorServiceTest
460      }
461  
462      /**
463 <     * invokeAny(c) returns result of some task
463 >     * invokeAny(c) returns result of some task in c if at least one completes
464       */
465      public void testInvokeAny5() {
466          ExecutorService e = new DirectExecutorService();
# Line 505 | Line 527 | public class AbstractExecutorServiceTest
527      }
528  
529      /**
530 <     * get of element of invokeAll(c) throws exception on failed task
530 >     * get of returned element of invokeAll(c) throws exception on failed task
531       */
532      public void testInvokeAll4() {
533          ExecutorService e = new DirectExecutorService();
# Line 525 | Line 547 | public class AbstractExecutorServiceTest
547      }
548  
549      /**
550 <     * invokeAll(c) returns results of all completed tasks
550 >     * invokeAll(c) returns results of all completed tasks in c
551       */
552      public void testInvokeAll5() {
553          ExecutorService e = new DirectExecutorService();
# Line 562 | Line 584 | public class AbstractExecutorServiceTest
584      }
585  
586      /**
587 <     * timed invokeAny(,,null) throws NPE
587 >     * timed invokeAny(null time unit) throws NPE
588       */
589      public void testTimedInvokeAnyNullTimeUnit() {
590          ExecutorService e = new DirectExecutorService();
# Line 630 | Line 652 | public class AbstractExecutorServiceTest
652      }
653  
654      /**
655 <     * timed invokeAny(c) returns result of some task
655 >     * timed invokeAny(c) returns result of some task in c
656       */
657      public void testTimedInvokeAny5() {
658          ExecutorService e = new DirectExecutorService();
# Line 664 | Line 686 | public class AbstractExecutorServiceTest
686      }
687  
688      /**
689 <     * timed invokeAll(,,null) throws NPE
689 >     * timed invokeAll(null time unit) throws NPE
690       */
691      public void testTimedInvokeAllNullTimeUnit() {
692          ExecutorService e = new DirectExecutorService();
# Line 714 | Line 736 | public class AbstractExecutorServiceTest
736      }
737  
738      /**
739 <     * get of element of invokeAll(c) throws exception on failed task
739 >     * get of returned element of invokeAll(c) throws exception on failed task
740       */
741      public void testTimedInvokeAll4() {
742          ExecutorService e = new DirectExecutorService();
# Line 734 | Line 756 | public class AbstractExecutorServiceTest
756      }
757  
758      /**
759 <     * timed invokeAll(c) returns results of all completed tasks
759 >     * timed invokeAll(c) returns results of all completed tasks in c
760       */
761      public void testTimedInvokeAll5() {
762          ExecutorService e = new DirectExecutorService();
# Line 755 | Line 777 | public class AbstractExecutorServiceTest
777      }
778  
779      /**
780 <     * timed invokeAll(c) cancels tasks not completed by timeout
780 >     * timed invokeAll cancels tasks not completed by timeout
781       */
782      public void testTimedInvokeAll6() {
783          ExecutorService e = new DirectExecutorService();
784          try {
785              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
786              l.add(new StringTask());
787 <            l.add(Executors.callable(new LongPossiblyInterruptedRunnable(), TEST_STRING));
788 <            List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
789 <            assertEquals(2, result.size());
787 >            l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING));
788 >            l.add(new StringTask());
789 >            List<Future<String>> result = e.invokeAll(l, SMALL_DELAY_MS, TimeUnit.MILLISECONDS);
790 >            assertEquals(3, result.size());
791              Iterator<Future<String>> it = result.iterator();
792              Future<String> f1 = it.next();
793              Future<String> f2 = it.next();
794 +            Future<String> f3 = it.next();
795              assertTrue(f1.isDone());
796              assertFalse(f1.isCancelled());
797              assertTrue(f2.isDone());
798 <            //            assertTrue(f2.isCancelled());
798 >            assertTrue(f3.isDone());
799 >            assertTrue(f3.isCancelled());
800          } catch(Exception ex) {
801              unexpectedException();
802          } finally {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines