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

Comparing jsr166/src/test/tck/ThreadPoolExecutorTest.java (file contents):
Revision 1.14 by dl, Thu Dec 25 19:48:57 2003 UTC vs.
Revision 1.17 by dl, Tue Jan 20 20:20:56 2004 UTC

# Line 1 | Line 1
1   /*
2 < * Written by members of JCP JSR-166 Expert Group and released to the
3 < * public domain. Use, modify, and redistribute this code in any way
4 < * without acknowledgement. Other contributors include Andrew Wright,
5 < * Jeffrey Hayes, Pat Fischer, Mike Judd.
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.
7   */
8  
9   import java.util.concurrent.*;
# Line 116 | Line 117 | public class ThreadPoolExecutorTest exte
117              unexpectedException();
118          }
119          assertEquals(1, p2.getCompletedTaskCount());
120 <        p2.shutdown();
120 >        try { p2.shutdown(); } catch(SecurityException ok) { return; }
121          joinPool(p2);
122      }
123      
# Line 146 | Line 147 | public class ThreadPoolExecutorTest exte
147          ThreadFactory tf = new SimpleThreadFactory();
148          ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10), tf, new NoOpREHandler());
149          assertSame(tf, p.getThreadFactory());
149        p.shutdown();
150          joinPool(p);
151      }
152  
# Line 158 | Line 158 | public class ThreadPoolExecutorTest exte
158          ThreadFactory tf = new SimpleThreadFactory();
159          p.setThreadFactory(tf);
160          assertSame(tf, p.getThreadFactory());
161        p.shutdown();
161          joinPool(p);
162      }
163  
# Line 184 | Line 183 | public class ThreadPoolExecutorTest exte
183          RejectedExecutionHandler h = new NoOpREHandler();
184          ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10), h);
185          assertSame(h, p.getRejectedExecutionHandler());
187        p.shutdown();
186          joinPool(p);
187      }
188  
# Line 197 | Line 195 | public class ThreadPoolExecutorTest exte
195          RejectedExecutionHandler h = new NoOpREHandler();
196          p.setRejectedExecutionHandler(h);
197          assertSame(h, p.getRejectedExecutionHandler());
200        p.shutdown();
198          joinPool(p);
199      }
200  
# Line 280 | Line 277 | public class ThreadPoolExecutorTest exte
277          
278          ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
279          assertFalse(p1.isShutdown());
280 <        p1.shutdown();
280 >        try { p1.shutdown(); } catch(SecurityException ok) { return; }
281          assertTrue(p1.isShutdown());
282          joinPool(p1);
283      }
# Line 295 | Line 292 | public class ThreadPoolExecutorTest exte
292          try {
293              p1.execute(new MediumRunnable());
294          } finally {
295 <            p1.shutdown();
295 >            try { p1.shutdown(); } catch(SecurityException ok) { return; }
296          }
297          try {
298              assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
# Line 315 | Line 312 | public class ThreadPoolExecutorTest exte
312              p1.execute(new SmallRunnable());
313              assertFalse(p1.isTerminating());
314          } finally {
315 <            p1.shutdown();
315 >            try { p1.shutdown(); } catch(SecurityException ok) { return; }
316          }
317          try {
318              assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
# Line 343 | Line 340 | public class ThreadPoolExecutorTest exte
340              assertSame(q, wq);
341              assertFalse(wq.contains(tasks[0]));
342              assertTrue(wq.contains(tasks[4]));
346            p1.shutdownNow();
343          } catch(Exception e) {
344              unexpectedException();
345          } finally {
# Line 373 | Line 369 | public class ThreadPoolExecutorTest exte
369              assertTrue(q.contains(tasks[3]));
370              assertTrue(p1.remove(tasks[3]));
371              assertFalse(q.contains(tasks[3]));
376            p1.shutdownNow();
372          } catch(Exception e) {
373              unexpectedException();
374          } finally {
# Line 396 | Line 391 | public class ThreadPoolExecutorTest exte
391          p1.purge();
392          long count = p1.getTaskCount();
393          assertTrue(count >= 2 && count < 5);
399        p1.shutdownNow();
394          joinPool(p1);
395      }
396  
# Line 411 | Line 405 | public class ThreadPoolExecutorTest exte
405                  p1.execute(new MediumPossiblyInterruptedRunnable());
406          }
407          finally {
408 <            l = p1.shutdownNow();
408 >            try {
409 >                l = p1.shutdownNow();
410 >            } catch (SecurityException ok) { return; }
411 >            
412          }
413          assertTrue(p1.isShutdown());
414          assertTrue(l.size() <= 4);
# Line 772 | Line 769 | public class ThreadPoolExecutorTest exte
769              for(int i = 1; i < 5; ++i) {
770                  assertTrue(tasks[i].done);
771              }
775            p.shutdownNow();
772          } catch(RejectedExecutionException ex){
773              unexpectedException();
774          } finally {
# Line 799 | Line 795 | public class ThreadPoolExecutorTest exte
795              for(int i = 0; i < 5; ++i){
796                  assertFalse(tasks[i].done);
797              }
802            p.shutdownNow();
798          } catch(RejectedExecutionException ex){
799              unexpectedException();
800          } finally {
# Line 822 | Line 817 | public class ThreadPoolExecutorTest exte
817              p.execute(r3);
818              assertFalse(p.getQueue().contains(r2));
819              assertTrue(p.getQueue().contains(r3));
825            p.shutdownNow();
820          } catch(RejectedExecutionException ex){
821              unexpectedException();
822          } finally {
# Line 836 | Line 830 | public class ThreadPoolExecutorTest exte
830      public void testRejectedExecutionExceptionOnShutdown() {
831          ThreadPoolExecutor tpe =
832              new ThreadPoolExecutor(1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(1));
833 <        tpe.shutdown();
833 >        try { tpe.shutdown(); } catch(SecurityException ok) { return; }
834          try {
835              tpe.execute(new NoOpRunnable());
836              shouldThrow();
# Line 852 | Line 846 | public class ThreadPoolExecutorTest exte
846          RejectedExecutionHandler h = new ThreadPoolExecutor.CallerRunsPolicy();
847          ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
848  
849 <        p.shutdown();
849 >        try { p.shutdown(); } catch(SecurityException ok) { return; }
850          try {
851              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
852              p.execute(r);
# Line 871 | Line 865 | public class ThreadPoolExecutorTest exte
865          RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardPolicy();
866          ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
867  
868 <        p.shutdown();
868 >        try { p.shutdown(); } catch(SecurityException ok) { return; }
869          try {
870              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
871              p.execute(r);
# Line 891 | Line 885 | public class ThreadPoolExecutorTest exte
885          RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardOldestPolicy();
886          ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
887  
888 <        p.shutdown();
888 >        try { p.shutdown(); } catch(SecurityException ok) { return; }
889          try {
890              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
891              p.execute(r);
# Line 931 | Line 925 | public class ThreadPoolExecutorTest exte
925              shouldThrow();
926          } catch(IllegalArgumentException success){
927          } finally {
928 <            tpe.shutdown();
928 >            try { tpe.shutdown(); } catch(SecurityException ok) { return; }
929          }
930          joinPool(tpe);
931      }  
# Line 950 | Line 944 | public class ThreadPoolExecutorTest exte
944              shouldThrow();
945          } catch(IllegalArgumentException success){
946          } finally {
947 <            tpe.shutdown();
947 >            try { tpe.shutdown(); } catch(SecurityException ok) { return; }
948          }
949          joinPool(tpe);
950      }
# Line 969 | Line 963 | public class ThreadPoolExecutorTest exte
963              shouldThrow();
964          } catch(IllegalArgumentException success){
965          } finally {
966 <            tpe.shutdown();
966 >            try { tpe.shutdown(); } catch(SecurityException ok) { return; }
967          }
968          joinPool(tpe);
969      }
# Line 990 | Line 984 | public class ThreadPoolExecutorTest exte
984              shouldThrow();
985          } catch(IllegalArgumentException success){
986          } finally {
987 <            tpe.shutdown();
987 >            try { tpe.shutdown(); } catch(SecurityException ok) { return; }
988          }
989          joinPool(tpe);
990      }
# Line 1000 | Line 994 | public class ThreadPoolExecutorTest exte
994       */
995      public void testTerminated() {
996          ExtendedTPE tpe = new ExtendedTPE();
997 <        tpe.shutdown();
997 >        try { tpe.shutdown(); } catch(SecurityException ok) { return; }
998          assertTrue(tpe.terminatedCalled);
999          joinPool(tpe);
1000      }
# Line 1017 | Line 1011 | public class ThreadPoolExecutorTest exte
1011              assertTrue(r.done);
1012              assertTrue(tpe.beforeCalled);
1013              assertTrue(tpe.afterCalled);
1014 <            tpe.shutdown();
1014 >            try { tpe.shutdown(); } catch(SecurityException ok) { return; }
1015          }
1016          catch(Exception ex) {
1017              unexpectedException();
# Line 1482 | Line 1476 | public class ThreadPoolExecutorTest exte
1476              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1477              l.add(new StringTask());
1478              l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING));
1479 +            l.add(new StringTask());
1480              List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
1481 <            assertEquals(2, result.size());
1481 >            assertEquals(3, result.size());
1482              Iterator<Future<String>> it = result.iterator();
1483              Future<String> f1 = it.next();
1484              Future<String> f2 = it.next();
1485 +            Future<String> f3 = it.next();
1486              assertTrue(f1.isDone());
1491            assertFalse(f1.isCancelled());
1487              assertTrue(f2.isDone());
1488 +            assertTrue(f3.isDone());
1489 +            assertFalse(f1.isCancelled());
1490              assertTrue(f2.isCancelled());
1491          } catch(Exception ex) {
1492              unexpectedException();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines