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.36 by jsr166, Tue Nov 9 15:29:11 2010 UTC vs.
Revision 1.41 by jsr166, Sun May 29 06:54:23 2011 UTC

# Line 1 | Line 1
1   /*
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
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   * Other contributors include Andrew Wright, Jeffrey Hayes,
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;
14 import java.math.BigInteger;
13   import java.security.*;
14  
15   public class ExecutorsTest extends JSR166TestCase {
# Line 54 | Line 52 | public class ExecutorsTest extends JSR16
52          } catch (NullPointerException success) {}
53      }
54  
57
55      /**
56       * A new SingleThreadExecutor can execute runnables
57       */
# Line 101 | Line 98 | public class ExecutorsTest extends JSR16
98          }
99      }
100  
104
101      /**
102       * A new newFixedThreadPool can execute runnables
103       */
# Line 144 | Line 140 | public class ExecutorsTest extends JSR16
140          } catch (IllegalArgumentException success) {}
141      }
142  
147
143      /**
144       * An unconfigurable newFixedThreadPool can execute runnables
145       */
# Line 176 | Line 171 | public class ExecutorsTest extends JSR16
171          } catch (NullPointerException success) {}
172      }
173  
179
174      /**
175       * a newSingleThreadScheduledExecutor successfully runs delayed task
176       */
# Line 252 | Line 246 | public class ExecutorsTest extends JSR16
246       * Future.get on submitted tasks will time out if they compute too long.
247       */
248      public void testTimedCallable() throws Exception {
249 +        final ExecutorService[] executors = {
250 +            Executors.newSingleThreadExecutor(),
251 +            Executors.newCachedThreadPool(),
252 +            Executors.newFixedThreadPool(2),
253 +            Executors.newScheduledThreadPool(2),
254 +        };
255 +
256          final Runnable sleeper = new CheckedInterruptedRunnable() {
257              public void realRun() throws InterruptedException {
258 <                Thread.sleep(LONG_DELAY_MS);
258 >                delay(LONG_DELAY_MS);
259              }};
260 <        for (ExecutorService executor :
261 <                 new ExecutorService[] {
262 <                     Executors.newSingleThreadExecutor(),
263 <                     Executors.newCachedThreadPool(),
264 <                     Executors.newFixedThreadPool(2),
265 <                     Executors.newScheduledThreadPool(2),
266 <                 }) {
267 <            try {
268 <                Future future = executor.submit(sleeper);
268 <                try {
269 <                    future.get(SHORT_DELAY_MS, MILLISECONDS);
270 <                    shouldThrow();
271 <                } catch (TimeoutException success) {
272 <                } finally {
273 <                    future.cancel(true);
274 <                }
275 <            }
276 <            finally {
277 <                joinPool(executor);
278 <            }
260 >
261 >        List<Thread> threads = new ArrayList<Thread>();
262 >        for (final ExecutorService executor : executors) {
263 >            threads.add(newStartedThread(new CheckedRunnable() {
264 >                public void realRun() {
265 >                    long startTime = System.nanoTime();
266 >                    Future future = executor.submit(sleeper);
267 >                    assertFutureTimesOut(future);
268 >                }}));
269          }
270 +        for (Thread thread : threads)
271 +            awaitTermination(thread);
272 +        for (ExecutorService executor : executors)
273 +            joinPool(executor);
274      }
275  
282
276      /**
277       * ThreadPoolExecutor using defaultThreadFactory has
278       * specified group, priority, daemon status, and name
# Line 313 | Line 306 | public class ExecutorsTest extends JSR16
306          }
307  
308          try {
309 <            Thread.sleep(SHORT_DELAY_MS);
309 >            delay(SHORT_DELAY_MS);
310          } finally {
311              joinPool(e);
312          }
# Line 349 | Line 342 | public class ExecutorsTest extends JSR16
342                  ExecutorService e = Executors.newSingleThreadExecutor(Executors.privilegedThreadFactory());
343                  e.execute(r);
344                  e.shutdown();
345 <                Thread.sleep(SHORT_DELAY_MS);
345 >                delay(SHORT_DELAY_MS);
346                  joinPool(e);
347              }};
348  
# Line 387 | Line 380 | public class ExecutorsTest extends JSR16
380          }
381      }
382  
390
383      /**
384       * Without class loader permissions, creating
385       * privilegedCallableUsingCurrentClassLoader throws ACE
# Line 504 | Line 496 | public class ExecutorsTest extends JSR16
496                  Executors.privilegedCallable(new CheckCCL()).call();
497              }};
498  
499 <         runWithPermissions(r,
499 >        runWithPermissions(r,
500                             new RuntimePermission("getClassLoader"),
501                             new RuntimePermission("setContextClassLoader"));
502      }
# Line 543 | Line 535 | public class ExecutorsTest extends JSR16
535          assertSame(one, c.call());
536      }
537  
546
538      /**
539       * callable(null Runnable) throws NPE
540       */
# Line 584 | Line 575 | public class ExecutorsTest extends JSR16
575          } catch (NullPointerException success) {}
576      }
577  
587
578   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines