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.39 by dl, Fri May 6 11:22:07 2011 UTC vs.
Revision 1.40 by jsr166, Fri May 27 19:28:38 2011 UTC

# Line 6 | Line 6
6   * Pat Fisher, Mike Judd.
7   */
8  
9
9   import junit.framework.*;
10   import java.util.*;
11   import java.util.concurrent.*;
# Line 54 | Line 53 | public class ExecutorsTest extends JSR16
53          } catch (NullPointerException success) {}
54      }
55  
57
56      /**
57       * A new SingleThreadExecutor can execute runnables
58       */
# Line 101 | Line 99 | public class ExecutorsTest extends JSR16
99          }
100      }
101  
104
102      /**
103       * A new newFixedThreadPool can execute runnables
104       */
# Line 144 | Line 141 | public class ExecutorsTest extends JSR16
141          } catch (IllegalArgumentException success) {}
142      }
143  
147
144      /**
145       * An unconfigurable newFixedThreadPool can execute runnables
146       */
# Line 176 | Line 172 | public class ExecutorsTest extends JSR16
172          } catch (NullPointerException success) {}
173      }
174  
179
175      /**
176       * a newSingleThreadScheduledExecutor successfully runs delayed task
177       */
# Line 252 | Line 247 | public class ExecutorsTest extends JSR16
247       * Future.get on submitted tasks will time out if they compute too long.
248       */
249      public void testTimedCallable() throws Exception {
250 +        final ExecutorService[] executors = {
251 +            Executors.newSingleThreadExecutor(),
252 +            Executors.newCachedThreadPool(),
253 +            Executors.newFixedThreadPool(2),
254 +            Executors.newScheduledThreadPool(2),
255 +        };
256 +
257          final Runnable sleeper = new CheckedInterruptedRunnable() {
258              public void realRun() throws InterruptedException {
259                  delay(LONG_DELAY_MS);
260              }};
261 <        for (ExecutorService executor :
262 <                 new ExecutorService[] {
263 <                     Executors.newSingleThreadExecutor(),
264 <                     Executors.newCachedThreadPool(),
265 <                     Executors.newFixedThreadPool(2),
266 <                     Executors.newScheduledThreadPool(2),
267 <                 }) {
268 <            try {
269 <                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 <            }
261 >
262 >        List<Thread> threads = new ArrayList<Thread>();
263 >        for (final ExecutorService executor : executors) {
264 >            threads.add(newStartedThread(new CheckedRunnable() {
265 >                public void realRun() {
266 >                    long startTime = System.nanoTime();
267 >                    Future future = executor.submit(sleeper);
268 >                    assertFutureTimesOut(future);
269 >                }}));
270          }
271 +        for (Thread thread : threads)
272 +            awaitTermination(thread);
273 +        for (ExecutorService executor : executors)
274 +            joinPool(executor);
275      }
276  
282
277      /**
278       * ThreadPoolExecutor using defaultThreadFactory has
279       * specified group, priority, daemon status, and name
# Line 387 | Line 381 | public class ExecutorsTest extends JSR16
381          }
382      }
383  
390
384      /**
385       * Without class loader permissions, creating
386       * privilegedCallableUsingCurrentClassLoader throws ACE
# Line 543 | Line 536 | public class ExecutorsTest extends JSR16
536          assertSame(one, c.call());
537      }
538  
546
539      /**
540       * callable(null Runnable) throws NPE
541       */
# Line 584 | Line 576 | public class ExecutorsTest extends JSR16
576          } catch (NullPointerException success) {}
577      }
578  
587
579   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines