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

Comparing jsr166/src/test/tck/ExecutorsTest.java (file contents):
Revision 1.22 by jsr166, Mon Nov 16 05:30:07 2009 UTC vs.
Revision 1.23 by jsr166, Thu Nov 19 03:55:29 2009 UTC

# Line 90 | Line 90 | public class ExecutorsTest extends JSR16
90          try {
91              ExecutorService e = Executors.newCachedThreadPool(null);
92              shouldThrow();
93 <        }
94 <        catch (NullPointerException success) {
95 <        }
93 >        } catch (NullPointerException success) {}
94      }
95  
96  
# Line 125 | Line 123 | public class ExecutorsTest extends JSR16
123          try {
124              ExecutorService e = Executors.newSingleThreadExecutor(null);
125              shouldThrow();
126 <        }
129 <        catch (NullPointerException success) {
130 <        }
126 >        } catch (NullPointerException success) {}
127      }
128  
129      /**
# Line 137 | Line 133 | public class ExecutorsTest extends JSR16
133          ExecutorService e = Executors.newSingleThreadExecutor();
134          try {
135              ThreadPoolExecutor tpe = (ThreadPoolExecutor)e;
136 +            shouldThrow();
137          } catch (ClassCastException success) {
138          } finally {
139              joinPool(e);
# Line 173 | Line 170 | public class ExecutorsTest extends JSR16
170          try {
171              ExecutorService e = Executors.newFixedThreadPool(2, null);
172              shouldThrow();
173 <        }
177 <        catch (NullPointerException success) {
178 <        }
173 >        } catch (NullPointerException success) {}
174      }
175  
176      /**
# Line 185 | Line 180 | public class ExecutorsTest extends JSR16
180          try {
181              ExecutorService e = Executors.newFixedThreadPool(0);
182              shouldThrow();
183 <        }
189 <        catch (IllegalArgumentException success) {
190 <        }
183 >        } catch (IllegalArgumentException success) {}
184      }
185  
186  
# Line 208 | Line 201 | public class ExecutorsTest extends JSR16
201      public void testunconfigurableExecutorServiceNPE() {
202          try {
203              ExecutorService e = Executors.unconfigurableExecutorService(null);
204 <        }
205 <        catch (NullPointerException success) {
213 <        }
204 >            shouldThrow();
205 >        } catch (NullPointerException success) {}
206      }
207  
208      /**
# Line 219 | Line 211 | public class ExecutorsTest extends JSR16
211      public void testunconfigurableScheduledExecutorServiceNPE() {
212          try {
213              ExecutorService e = Executors.unconfigurableScheduledExecutorService(null);
214 <        }
215 <        catch (NullPointerException success) {
224 <        }
214 >            shouldThrow();
215 >        } catch (NullPointerException success) {}
216      }
217  
218  
219      /**
220       * a newSingleThreadScheduledExecutor successfully runs delayed task
221       */
222 <    public void testNewSingleThreadScheduledExecutor() {
222 >    public void testNewSingleThreadScheduledExecutor() throws Exception {
223          try {
224              TrackedCallable callable = new TrackedCallable();
225              ScheduledExecutorService p1 = Executors.newSingleThreadScheduledExecutor();
# Line 239 | Line 230 | public class ExecutorsTest extends JSR16
230              assertEquals(Boolean.TRUE, f.get());
231              joinPool(p1);
232          } catch (RejectedExecutionException e) {}
242        catch (Exception e) {
243            e.printStackTrace();
244            unexpectedException();
245        }
233      }
234  
235      /**
236       * a newScheduledThreadPool successfully runs delayed task
237       */
238 <    public void testnewScheduledThreadPool() {
238 >    public void testnewScheduledThreadPool() throws Exception {
239          try {
240              TrackedCallable callable = new TrackedCallable();
241              ScheduledExecutorService p1 = Executors.newScheduledThreadPool(2);
# Line 259 | Line 246 | public class ExecutorsTest extends JSR16
246              assertEquals(Boolean.TRUE, f.get());
247              joinPool(p1);
248          } catch (RejectedExecutionException e) {}
262        catch (Exception e) {
263            e.printStackTrace();
264            unexpectedException();
265        }
249      }
250  
251      /**
252       * an unconfigurable  newScheduledThreadPool successfully runs delayed task
253       */
254 <    public void testunconfigurableScheduledExecutorService() {
254 >    public void testunconfigurableScheduledExecutorService() throws Exception {
255          try {
256              TrackedCallable callable = new TrackedCallable();
257              ScheduledExecutorService p1 = Executors.unconfigurableScheduledExecutorService(Executors.newScheduledThreadPool(2));
# Line 279 | Line 262 | public class ExecutorsTest extends JSR16
262              assertEquals(Boolean.TRUE, f.get());
263              joinPool(p1);
264          } catch (RejectedExecutionException e) {}
282        catch (Exception e) {
283            e.printStackTrace();
284            unexpectedException();
285        }
265      }
266  
267      /**
268       *  timeouts from execute will time out if they compute too long.
269       */
270 <    public void testTimedCallable() {
270 >    public void testTimedCallable() throws Exception {
271          int N = 10000;
272          ExecutorService executor = Executors.newSingleThreadExecutor();
273          List<Callable<BigInteger>> tasks = new ArrayList<Callable<BigInteger>>(N);
# Line 312 | Line 291 | public class ExecutorsTest extends JSR16
291                      assertTrue(iters > 0);
292                      return;
293                  }
315                catch (Exception e) {
316                    unexpectedException();
317                }
294              }
295              // if by chance we didn't ever time out, total time must be small
296              long elapsed = System.currentTimeMillis() - startTime;
# Line 330 | Line 306 | public class ExecutorsTest extends JSR16
306       * ThreadPoolExecutor using defaultThreadFactory has
307       * specified group, priority, daemon status, and name
308       */
309 <    public void testDefaultThreadFactory() {
309 >    public void testDefaultThreadFactory() throws Exception {
310          final ThreadGroup egroup = Thread.currentThread().getThreadGroup();
311          Runnable r = new Runnable() {
312                  public void run() {
# Line 361 | Line 337 | public class ExecutorsTest extends JSR16
337  
338          try {
339              Thread.sleep(SHORT_DELAY_MS);
364        } catch (Exception eX) {
365            unexpectedException();
340          } finally {
341              joinPool(e);
342          }
# Line 373 | Line 347 | public class ExecutorsTest extends JSR16
347       * specified group, priority, daemon status, name,
348       * access control context and context class loader
349       */
350 <    public void testPrivilegedThreadFactory() {
350 >    public void testPrivilegedThreadFactory() throws Exception {
351          Policy savedPolicy = null;
352          try {
353              savedPolicy = Policy.getPolicy();
# Line 418 | Line 392 | public class ExecutorsTest extends JSR16
392          }
393          try {
394              Thread.sleep(SHORT_DELAY_MS);
421        } catch (Exception ex) {
422            unexpectedException();
395          } finally {
396              joinPool(e);
397          }
# Line 469 | Line 441 | public class ExecutorsTest extends JSR16
441              Callable task = Executors.privilegedCallableUsingCurrentClassLoader(new NoOpCallable());
442              shouldThrow();
443          } catch (AccessControlException success) {
444 <        } catch (Exception ex) {
473 <            unexpectedException();
474 <        }
475 <        finally {
444 >        } finally {
445              Policy.setPolicy(savedPolicy);
446          }
447      }
# Line 481 | Line 450 | public class ExecutorsTest extends JSR16
450       * With class loader permissions, calling
451       * privilegedCallableUsingCurrentClassLoader does not throw ACE
452       */
453 <    public void testprivilegedCallableUsingCCLWithPrivs() {
453 >    public void testprivilegedCallableUsingCCLWithPrivs() throws Exception {
454          Policy savedPolicy = null;
455          try {
456              savedPolicy = Policy.getPolicy();
# Line 496 | Line 465 | public class ExecutorsTest extends JSR16
465          try {
466              Callable task = Executors.privilegedCallableUsingCurrentClassLoader(new NoOpCallable());
467              task.call();
499        } catch (Exception ex) {
500            unexpectedException();
468          }
469          finally {
470              Policy.setPolicy(savedPolicy);
# Line 507 | Line 474 | public class ExecutorsTest extends JSR16
474      /**
475       * Without permissions, calling privilegedCallable throws ACE
476       */
477 <    public void testprivilegedCallableWithNoPrivs() {
477 >    public void testprivilegedCallableWithNoPrivs() throws Exception {
478          Callable task;
479          Policy savedPolicy = null;
480          AdjustablePolicy policy = null;
# Line 538 | Line 505 | public class ExecutorsTest extends JSR16
505          try {
506              task.call();
507              shouldThrow();
508 <        } catch (AccessControlException success) {
542 <        } catch (Exception ex) {
543 <            unexpectedException();
544 <        }
508 >        } catch (AccessControlException success) {}
509      }
510  
511      /**
512       * With permissions, calling privilegedCallable succeeds
513       */
514 <    public void testprivilegedCallableWithPrivs() {
514 >    public void testprivilegedCallableWithPrivs() throws Exception {
515          Policy savedPolicy = null;
516          try {
517              savedPolicy = Policy.getPolicy();
# Line 562 | Line 526 | public class ExecutorsTest extends JSR16
526          Callable task = Executors.privilegedCallable(new CheckCCL());
527          try {
528              task.call();
565        } catch (Exception ex) {
566            unexpectedException();
529          } finally {
530              Policy.setPolicy(savedPolicy);
531          }
# Line 572 | Line 534 | public class ExecutorsTest extends JSR16
534      /**
535       * callable(Runnable) returns null when called
536       */
537 <    public void testCallable1() {
538 <        try {
539 <            Callable c = Executors.callable(new NoOpRunnable());
578 <            assertNull(c.call());
579 <        } catch (Exception ex) {
580 <            unexpectedException();
581 <        }
582 <
537 >    public void testCallable1() throws Exception {
538 >        Callable c = Executors.callable(new NoOpRunnable());
539 >        assertNull(c.call());
540      }
541  
542      /**
543       * callable(Runnable, result) returns result when called
544       */
545 <    public void testCallable2() {
546 <        try {
547 <            Callable c = Executors.callable(new NoOpRunnable(), one);
591 <            assertEquals(one, c.call());
592 <        } catch (Exception ex) {
593 <            unexpectedException();
594 <        }
545 >    public void testCallable2() throws Exception {
546 >        Callable c = Executors.callable(new NoOpRunnable(), one);
547 >        assertEquals(one, c.call());
548      }
549  
550      /**
551       * callable(PrivilegedAction) returns its result when called
552       */
553 <    public void testCallable3() {
554 <        try {
555 <            Callable c = Executors.callable(new PrivilegedAction() {
603 <                    public Object run() { return one; }});
553 >    public void testCallable3() throws Exception {
554 >        Callable c = Executors.callable(new PrivilegedAction() {
555 >                public Object run() { return one; }});
556          assertEquals(one, c.call());
605        } catch (Exception ex) {
606            unexpectedException();
607        }
557      }
558  
559      /**
560       * callable(PrivilegedExceptionAction) returns its result when called
561       */
562 <    public void testCallable4() {
563 <        try {
564 <            Callable c = Executors.callable(new PrivilegedExceptionAction() {
565 <                    public Object run() { return one; }});
617 <            assertEquals(one, c.call());
618 <        } catch (Exception ex) {
619 <            unexpectedException();
620 <        }
562 >    public void testCallable4() throws Exception {
563 >        Callable c = Executors.callable(new PrivilegedExceptionAction() {
564 >                public Object run() { return one; }});
565 >        assertEquals(one, c.call());
566      }
567  
568  
# Line 626 | Line 571 | public class ExecutorsTest extends JSR16
571       */
572      public void testCallableNPE1() {
573          try {
574 <            Runnable r = null;
575 <            Callable c = Executors.callable(r);
576 <        } catch (NullPointerException success) {
632 <        }
574 >            Callable c = Executors.callable((Runnable) null);
575 >            shouldThrow();
576 >        } catch (NullPointerException success) {}
577      }
578  
579      /**
# Line 637 | Line 581 | public class ExecutorsTest extends JSR16
581       */
582      public void testCallableNPE2() {
583          try {
584 <            Runnable r = null;
585 <            Callable c = Executors.callable(r, one);
586 <        } catch (NullPointerException success) {
643 <        }
584 >            Callable c = Executors.callable((Runnable) null, one);
585 >            shouldThrow();
586 >        } catch (NullPointerException success) {}
587      }
588  
589      /**
# Line 648 | Line 591 | public class ExecutorsTest extends JSR16
591       */
592      public void testCallableNPE3() {
593          try {
594 <            PrivilegedAction r = null;
595 <            Callable c = Executors.callable(r);
596 <        } catch (NullPointerException success) {
654 <        }
594 >            Callable c = Executors.callable((PrivilegedAction) null);
595 >            shouldThrow();
596 >        } catch (NullPointerException success) {}
597      }
598  
599      /**
# Line 659 | Line 601 | public class ExecutorsTest extends JSR16
601       */
602      public void testCallableNPE4() {
603          try {
604 <            PrivilegedExceptionAction r = null;
605 <            Callable c = Executors.callable(r);
606 <        } catch (NullPointerException success) {
665 <        }
604 >            Callable c = Executors.callable((PrivilegedExceptionAction) null);
605 >            shouldThrow();
606 >        } catch (NullPointerException success) {}
607      }
608  
609  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines