[cvs] / jsr166 / src / test / tck / JSR166TestCase.java Repository:
ViewVC logotype

Annotation of /jsr166/src/test/tck/JSR166TestCase.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.44 - (view) (download)

1 : dl 1.1 /*
2 : dl 1.13 * 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 : jsr166 1.27 * Other contributors include Andrew Wright, Jeffrey Hayes,
6 :     * Pat Fisher, Mike Judd.
7 : dl 1.1 */
8 :    
9 :     import junit.framework.*;
10 :     import java.util.*;
11 :     import java.util.concurrent.*;
12 : jsr166 1.36 import static java.util.concurrent.TimeUnit.MILLISECONDS;
13 : dl 1.1 import java.io.*;
14 : dl 1.7 import java.security.*;
15 : dl 1.1
16 :     /**
17 : dl 1.5 * Base class for JSR166 Junit TCK tests. Defines some constants,
18 :     * utility methods and classes, as well as a simple framework for
19 :     * helping to make sure that assertions failing in generated threads
20 :     * cause the associated test that generated them to itself fail (which
21 : jsr166 1.27 * JUnit does not otherwise arrange). The rules for creating such
22 : dl 1.5 * tests are:
23 : dl 1.1 *
24 :     * <ol>
25 :     *
26 :     * <li> All assertions in code running in generated threads must use
27 : jsr166 1.27 * the forms {@link #threadFail}, {@link #threadAssertTrue}, {@link
28 : dl 1.18 * #threadAssertEquals}, or {@link #threadAssertNull}, (not
29 : dl 1.1 * <tt>fail</tt>, <tt>assertTrue</tt>, etc.) It is OK (but not
30 :     * particularly recommended) for other code to use these forms too.
31 :     * Only the most typically used JUnit assertion methods are defined
32 :     * this way, but enough to live with.</li>
33 :     *
34 : dl 1.18 * <li> If you override {@link #setUp} or {@link #tearDown}, make sure
35 : dl 1.1 * to invoke <tt>super.setUp</tt> and <tt>super.tearDown</tt> within
36 :     * them. These methods are used to clear and check for thread
37 :     * assertion failures.</li>
38 :     *
39 : dl 1.6 * <li>All delays and timeouts must use one of the constants <tt>
40 :     * SHORT_DELAY_MS</tt>, <tt> SMALL_DELAY_MS</tt>, <tt> MEDIUM_DELAY_MS</tt>,
41 :     * <tt> LONG_DELAY_MS</tt>. The idea here is that a SHORT is always
42 : dl 1.5 * discriminable from zero time, and always allows enough time for the
43 :     * small amounts of computation (creating a thread, calling a few
44 : dl 1.1 * methods, etc) needed to reach a timeout point. Similarly, a SMALL
45 :     * is always discriminable as larger than SHORT and smaller than
46 :     * MEDIUM. And so on. These constants are set to conservative values,
47 : dl 1.2 * but even so, if there is ever any doubt, they can all be increased
48 : jsr166 1.27 * in one spot to rerun tests on slower platforms.</li>
49 : dl 1.1 *
50 :     * <li> All threads generated must be joined inside each test case
51 :     * method (or <tt>fail</tt> to do so) before returning from the
52 : dl 1.6 * method. The <tt> joinPool</tt> method can be used to do this when
53 : dl 1.1 * using Executors.</li>
54 :     *
55 :     * </ol>
56 : dl 1.6 *
57 :     * <p> <b>Other notes</b>
58 :     * <ul>
59 :     *
60 :     * <li> Usually, there is one testcase method per JSR166 method
61 :     * covering "normal" operation, and then as many exception-testing
62 :     * methods as there are exceptions the method can throw. Sometimes
63 :     * there are multiple tests per JSR166 method when the different
64 :     * "normal" behaviors differ significantly. And sometimes testcases
65 :     * cover multiple methods when they cannot be tested in
66 :     * isolation.</li>
67 : jsr166 1.27 *
68 : dl 1.6 * <li> The documentation style for testcases is to provide as javadoc
69 :     * a simple sentence or two describing the property that the testcase
70 :     * method purports to test. The javadocs do not say anything about how
71 :     * the property is tested. To find out, read the code.</li>
72 :     *
73 :     * <li> These tests are "conformance tests", and do not attempt to
74 :     * test throughput, latency, scalability or other performance factors
75 :     * (see the separate "jtreg" tests for a set intended to check these
76 :     * for the most central aspects of functionality.) So, most tests use
77 :     * the smallest sensible numbers of threads, collection sizes, etc
78 :     * needed to check basic conformance.</li>
79 :     *
80 :     * <li>The test classes currently do not declare inclusion in
81 :     * any particular package to simplify things for people integrating
82 :     * them in TCK test suites.</li>
83 :     *
84 :     * <li> As a convenience, the <tt>main</tt> of this class (JSR166TestCase)
85 :     * runs all JSR166 unit tests.</li>
86 :     *
87 :     * </ul>
88 : dl 1.1 */
89 :     public class JSR166TestCase extends TestCase {
90 : dl 1.6 /**
91 :     * Runs all JSR166 unit tests using junit.textui.TestRunner
92 : jsr166 1.27 */
93 : jsr166 1.41 public static void main(String[] args) {
94 : dl 1.16 int iters = 1;
95 : jsr166 1.27 if (args.length > 0)
96 : dl 1.16 iters = Integer.parseInt(args[0]);
97 :     Test s = suite();
98 : dl 1.22 for (int i = 0; i < iters; ++i) {
99 : jsr166 1.41 junit.textui.TestRunner.run(s);
100 : dl 1.22 System.gc();
101 :     System.runFinalization();
102 :     }
103 :     System.exit(0);
104 : dl 1.6 }
105 :    
106 :     /**
107 :     * Collects all JSR166 unit tests as one suite
108 : jsr166 1.27 */
109 : jsr166 1.41 public static Test suite() {
110 : dl 1.6 TestSuite suite = new TestSuite("JSR166 Unit Tests");
111 : jsr166 1.27
112 : dl 1.32 suite.addTest(new TestSuite(ForkJoinPoolTest.class));
113 :     suite.addTest(new TestSuite(ForkJoinTaskTest.class));
114 :     suite.addTest(new TestSuite(RecursiveActionTest.class));
115 :     suite.addTest(new TestSuite(RecursiveTaskTest.class));
116 :     suite.addTest(new TestSuite(LinkedTransferQueueTest.class));
117 :     suite.addTest(new TestSuite(PhaserTest.class));
118 :     suite.addTest(new TestSuite(ThreadLocalRandomTest.class));
119 : dl 1.10 suite.addTest(new TestSuite(AbstractExecutorServiceTest.class));
120 : dl 1.19 suite.addTest(new TestSuite(AbstractQueueTest.class));
121 : dl 1.14 suite.addTest(new TestSuite(AbstractQueuedSynchronizerTest.class));
122 : dl 1.25 suite.addTest(new TestSuite(AbstractQueuedLongSynchronizerTest.class));
123 : dl 1.6 suite.addTest(new TestSuite(ArrayBlockingQueueTest.class));
124 : dl 1.23 suite.addTest(new TestSuite(ArrayDequeTest.class));
125 : jsr166 1.27 suite.addTest(new TestSuite(AtomicBooleanTest.class));
126 :     suite.addTest(new TestSuite(AtomicIntegerArrayTest.class));
127 :     suite.addTest(new TestSuite(AtomicIntegerFieldUpdaterTest.class));
128 :     suite.addTest(new TestSuite(AtomicIntegerTest.class));
129 :     suite.addTest(new TestSuite(AtomicLongArrayTest.class));
130 :     suite.addTest(new TestSuite(AtomicLongFieldUpdaterTest.class));
131 :     suite.addTest(new TestSuite(AtomicLongTest.class));
132 :     suite.addTest(new TestSuite(AtomicMarkableReferenceTest.class));
133 :     suite.addTest(new TestSuite(AtomicReferenceArrayTest.class));
134 :     suite.addTest(new TestSuite(AtomicReferenceFieldUpdaterTest.class));
135 :     suite.addTest(new TestSuite(AtomicReferenceTest.class));
136 :     suite.addTest(new TestSuite(AtomicStampedReferenceTest.class));
137 : dl 1.6 suite.addTest(new TestSuite(ConcurrentHashMapTest.class));
138 :     suite.addTest(new TestSuite(ConcurrentLinkedQueueTest.class));
139 : dl 1.23 suite.addTest(new TestSuite(ConcurrentSkipListMapTest.class));
140 :     suite.addTest(new TestSuite(ConcurrentSkipListSubMapTest.class));
141 :     suite.addTest(new TestSuite(ConcurrentSkipListSetTest.class));
142 :     suite.addTest(new TestSuite(ConcurrentSkipListSubSetTest.class));
143 : dl 1.6 suite.addTest(new TestSuite(CopyOnWriteArrayListTest.class));
144 :     suite.addTest(new TestSuite(CopyOnWriteArraySetTest.class));
145 :     suite.addTest(new TestSuite(CountDownLatchTest.class));
146 :     suite.addTest(new TestSuite(CyclicBarrierTest.class));
147 :     suite.addTest(new TestSuite(DelayQueueTest.class));
148 : dl 1.29 suite.addTest(new TestSuite(EntryTest.class));
149 : dl 1.6 suite.addTest(new TestSuite(ExchangerTest.class));
150 :     suite.addTest(new TestSuite(ExecutorsTest.class));
151 : dl 1.11 suite.addTest(new TestSuite(ExecutorCompletionServiceTest.class));
152 : dl 1.6 suite.addTest(new TestSuite(FutureTaskTest.class));
153 : dl 1.23 suite.addTest(new TestSuite(LinkedBlockingDequeTest.class));
154 : dl 1.6 suite.addTest(new TestSuite(LinkedBlockingQueueTest.class));
155 :     suite.addTest(new TestSuite(LinkedListTest.class));
156 :     suite.addTest(new TestSuite(LockSupportTest.class));
157 :     suite.addTest(new TestSuite(PriorityBlockingQueueTest.class));
158 :     suite.addTest(new TestSuite(PriorityQueueTest.class));
159 :     suite.addTest(new TestSuite(ReentrantLockTest.class));
160 :     suite.addTest(new TestSuite(ReentrantReadWriteLockTest.class));
161 :     suite.addTest(new TestSuite(ScheduledExecutorTest.class));
162 : dl 1.28 suite.addTest(new TestSuite(ScheduledExecutorSubclassTest.class));
163 : dl 1.6 suite.addTest(new TestSuite(SemaphoreTest.class));
164 :     suite.addTest(new TestSuite(SynchronousQueueTest.class));
165 :     suite.addTest(new TestSuite(SystemTest.class));
166 :     suite.addTest(new TestSuite(ThreadLocalTest.class));
167 :     suite.addTest(new TestSuite(ThreadPoolExecutorTest.class));
168 : dl 1.28 suite.addTest(new TestSuite(ThreadPoolExecutorSubclassTest.class));
169 : dl 1.6 suite.addTest(new TestSuite(ThreadTest.class));
170 : dl 1.24 suite.addTest(new TestSuite(TimeUnitTest.class));
171 : dl 1.23 suite.addTest(new TestSuite(TreeMapTest.class));
172 :     suite.addTest(new TestSuite(TreeSetTest.class));
173 : dl 1.26 suite.addTest(new TestSuite(TreeSubMapTest.class));
174 :     suite.addTest(new TestSuite(TreeSubSetTest.class));
175 : jsr166 1.27
176 : dl 1.6 return suite;
177 :     }
178 :    
179 : dl 1.1
180 : dl 1.2 public static long SHORT_DELAY_MS;
181 :     public static long SMALL_DELAY_MS;
182 :     public static long MEDIUM_DELAY_MS;
183 :     public static long LONG_DELAY_MS;
184 :    
185 :    
186 :     /**
187 : jsr166 1.27 * Returns the shortest timed delay. This could
188 : dl 1.15 * be reimplemented to use for example a Property.
189 : jsr166 1.27 */
190 : dl 1.2 protected long getShortDelay() {
191 : dl 1.21 return 50;
192 : dl 1.2 }
193 :    
194 :    
195 :     /**
196 : jsr166 1.27 * Sets delays as multiples of SHORT_DELAY.
197 : dl 1.2 */
198 : jsr166 1.43 protected void setDelays() {
199 : dl 1.2 SHORT_DELAY_MS = getShortDelay();
200 :     SMALL_DELAY_MS = SHORT_DELAY_MS * 5;
201 :     MEDIUM_DELAY_MS = SHORT_DELAY_MS * 10;
202 :     LONG_DELAY_MS = SHORT_DELAY_MS * 50;
203 :     }
204 :    
205 : dl 1.1 /**
206 :     * Flag set true if any threadAssert methods fail
207 :     */
208 : dl 1.5 volatile boolean threadFailed;
209 : dl 1.1
210 :     /**
211 : jsr166 1.27 * Initializes test to indicate that no thread assertions have failed
212 : dl 1.1 */
213 : jsr166 1.27 public void setUp() {
214 : dl 1.2 setDelays();
215 : jsr166 1.27 threadFailed = false;
216 : dl 1.1 }
217 :    
218 :     /**
219 : jsr166 1.27 * Triggers test case failure if any thread assertions have failed
220 : dl 1.1 */
221 : jsr166 1.27 public void tearDown() {
222 :     assertFalse(threadFailed);
223 : dl 1.1 }
224 :    
225 : dl 1.5 /**
226 :     * Fail, also setting status to indicate current testcase should fail
227 : jsr166 1.27 */
228 : dl 1.1 public void threadFail(String reason) {
229 :     threadFailed = true;
230 :     fail(reason);
231 :     }
232 :    
233 : dl 1.5 /**
234 :     * If expression not true, set status to indicate current testcase
235 :     * should fail
236 : jsr166 1.27 */
237 : dl 1.1 public void threadAssertTrue(boolean b) {
238 :     if (!b) {
239 :     threadFailed = true;
240 :     assertTrue(b);
241 :     }
242 :     }
243 : dl 1.5
244 :     /**
245 :     * If expression not false, set status to indicate current testcase
246 :     * should fail
247 : jsr166 1.27 */
248 : dl 1.1 public void threadAssertFalse(boolean b) {
249 :     if (b) {
250 :     threadFailed = true;
251 :     assertFalse(b);
252 :     }
253 :     }
254 : dl 1.5
255 :     /**
256 :     * If argument not null, set status to indicate current testcase
257 :     * should fail
258 : jsr166 1.27 */
259 : dl 1.1 public void threadAssertNull(Object x) {
260 :     if (x != null) {
261 :     threadFailed = true;
262 :     assertNull(x);
263 :     }
264 :     }
265 : dl 1.5
266 :     /**
267 :     * If arguments not equal, set status to indicate current testcase
268 :     * should fail
269 : jsr166 1.27 */
270 : dl 1.1 public void threadAssertEquals(long x, long y) {
271 :     if (x != y) {
272 :     threadFailed = true;
273 :     assertEquals(x, y);
274 :     }
275 :     }
276 : dl 1.5
277 :     /**
278 :     * If arguments not equal, set status to indicate current testcase
279 :     * should fail
280 : jsr166 1.27 */
281 : dl 1.1 public void threadAssertEquals(Object x, Object y) {
282 :     if (x != y && (x == null || !x.equals(y))) {
283 :     threadFailed = true;
284 :     assertEquals(x, y);
285 :     }
286 :     }
287 :    
288 : dl 1.5 /**
289 :     * threadFail with message "should throw exception"
290 : jsr166 1.33 */
291 : dl 1.3 public void threadShouldThrow() {
292 : dl 1.37 threadFailed = true;
293 :     fail("should throw exception");
294 : dl 1.3 }
295 :    
296 : dl 1.5 /**
297 : jsr166 1.40 * threadFail with message "should throw" + exceptionName
298 :     */
299 :     public void threadShouldThrow(String exceptionName) {
300 :     threadFailed = true;
301 :     fail("should throw " + exceptionName);
302 :     }
303 :    
304 :     /**
305 : dl 1.5 * threadFail with message "Unexpected exception"
306 :     */
307 : dl 1.3 public void threadUnexpectedException() {
308 :     threadFailed = true;
309 :     fail("Unexpected exception");
310 :     }
311 :    
312 : dl 1.31 /**
313 :     * threadFail with message "Unexpected exception", with argument
314 :     */
315 :     public void threadUnexpectedException(Throwable ex) {
316 :     threadFailed = true;
317 :     ex.printStackTrace();
318 :     fail("Unexpected exception: " + ex);
319 :     }
320 : dl 1.3
321 : dl 1.1 /**
322 :     * Wait out termination of a thread pool or fail doing so
323 :     */
324 :     public void joinPool(ExecutorService exec) {
325 :     try {
326 :     exec.shutdown();
327 : jsr166 1.36 assertTrue(exec.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
328 : jsr166 1.33 } catch (SecurityException ok) {
329 : dl 1.22 // Allowed in case test doesn't have privs
330 : jsr166 1.33 } catch (InterruptedException ie) {
331 : jsr166 1.44 fail("Unexpected InterruptedException");
332 : dl 1.1 }
333 :     }
334 :    
335 : dl 1.5
336 :     /**
337 :     * fail with message "should throw exception"
338 : jsr166 1.27 */
339 : dl 1.3 public void shouldThrow() {
340 :     fail("Should throw exception");
341 :     }
342 :    
343 : dl 1.5 /**
344 : jsr166 1.40 * fail with message "should throw " + exceptionName
345 :     */
346 :     public void shouldThrow(String exceptionName) {
347 :     fail("Should throw " + exceptionName);
348 :     }
349 :    
350 :     /**
351 : dl 1.5 * fail with message "Unexpected exception"
352 :     */
353 : dl 1.3 public void unexpectedException() {
354 :     fail("Unexpected exception");
355 :     }
356 : dl 1.1
357 : jsr166 1.36 /**
358 :     * fail with message "Unexpected exception", with argument
359 :     */
360 :     public void unexpectedException(Throwable ex) {
361 :     ex.printStackTrace();
362 :     fail("Unexpected exception: " + ex);
363 :     }
364 :    
365 : dl 1.1
366 :     /**
367 :     * The number of elements to place in collections, arrays, etc.
368 :     */
369 : dl 1.5 static final int SIZE = 20;
370 : dl 1.1
371 :     // Some convenient Integer constants
372 :    
373 : dl 1.5 static final Integer zero = new Integer(0);
374 :     static final Integer one = new Integer(1);
375 :     static final Integer two = new Integer(2);
376 :     static final Integer three = new Integer(3);
377 :     static final Integer four = new Integer(4);
378 :     static final Integer five = new Integer(5);
379 :     static final Integer six = new Integer(6);
380 :     static final Integer seven = new Integer(7);
381 :     static final Integer eight = new Integer(8);
382 :     static final Integer nine = new Integer(9);
383 :     static final Integer m1 = new Integer(-1);
384 :     static final Integer m2 = new Integer(-2);
385 :     static final Integer m3 = new Integer(-3);
386 :     static final Integer m4 = new Integer(-4);
387 :     static final Integer m5 = new Integer(-5);
388 : dl 1.30 static final Integer m6 = new Integer(-6);
389 : dl 1.5 static final Integer m10 = new Integer(-10);
390 : dl 1.7
391 :    
392 :     /**
393 :     * A security policy where new permissions can be dynamically added
394 :     * or all cleared.
395 :     */
396 :     static class AdjustablePolicy extends java.security.Policy {
397 :     Permissions perms = new Permissions();
398 :     AdjustablePolicy() { }
399 :     void addPermission(Permission perm) { perms.add(perm); }
400 :     void clearPermissions() { perms = new Permissions(); }
401 : jsr166 1.42 public PermissionCollection getPermissions(CodeSource cs) {
402 :     return perms;
403 :     }
404 :     public PermissionCollection getPermissions(ProtectionDomain pd) {
405 :     return perms;
406 :     }
407 :     public boolean implies(ProtectionDomain pd, Permission p) {
408 :     return perms.implies(p);
409 :     }
410 :     public void refresh() {}
411 : dl 1.7 }
412 : dl 1.1
413 : jsr166 1.38 /**
414 :     * Sleep until the timeout has elapsed, or interrupted.
415 :     * Does <em>NOT</em> throw InterruptedException.
416 :     */
417 :     void sleepTillInterrupted(long timeoutMillis) {
418 :     try {
419 :     Thread.sleep(timeoutMillis);
420 : jsr166 1.44 } catch (InterruptedException wakeup) {}
421 : jsr166 1.38 }
422 :    
423 :     /**
424 :     * Returns a new started Thread running the given runnable.
425 :     */
426 :     Thread newStartedThread(Runnable runnable) {
427 :     Thread t = new Thread(runnable);
428 :     t.start();
429 :     return t;
430 :     }
431 : dl 1.1
432 :     // Some convenient Runnable classes
433 :    
434 : jsr166 1.35 abstract class CheckedRunnable implements Runnable {
435 :     abstract void realRun() throws Throwable;
436 :    
437 :     public final void run() {
438 :     try {
439 :     realRun();
440 :     } catch (Throwable t) {
441 :     threadUnexpectedException(t);
442 :     }
443 :     }
444 :     }
445 :    
446 : jsr166 1.40 abstract class RunnableShouldThrow implements Runnable {
447 :     abstract void realRun() throws Throwable;
448 :    
449 :     final Class<?> exceptionClass;
450 :    
451 :     <T extends Throwable> RunnableShouldThrow(Class<T> exceptionClass) {
452 :     this.exceptionClass = exceptionClass;
453 :     }
454 :    
455 :     public final void run() {
456 :     try {
457 :     realRun();
458 :     threadShouldThrow(exceptionClass.getSimpleName());
459 :     } catch (InterruptedException success) {
460 :     } catch (Throwable t) {
461 :     if (! exceptionClass.isInstance(t))
462 :     threadUnexpectedException(t);
463 :     }
464 :     }
465 :     }
466 :    
467 :     abstract class ThreadShouldThrow extends Thread {
468 :     abstract void realRun() throws Throwable;
469 :    
470 :     final Class<?> exceptionClass;
471 :    
472 :     <T extends Throwable> ThreadShouldThrow(Class<T> exceptionClass) {
473 :     this.exceptionClass = exceptionClass;
474 :     }
475 :    
476 :     public final void run() {
477 :     try {
478 :     realRun();
479 :     threadShouldThrow(exceptionClass.getSimpleName());
480 :     } catch (InterruptedException success) {
481 :     } catch (Throwable t) {
482 :     if (! exceptionClass.isInstance(t))
483 :     threadUnexpectedException(t);
484 :     }
485 :     }
486 :     }
487 :    
488 : jsr166 1.35 abstract class CheckedInterruptedRunnable implements Runnable {
489 :     abstract void realRun() throws Throwable;
490 :    
491 :     public final void run() {
492 :     try {
493 :     realRun();
494 : jsr166 1.40 threadShouldThrow("InterruptedException");
495 : jsr166 1.35 } catch (InterruptedException success) {
496 :     } catch (Throwable t) {
497 :     threadUnexpectedException(t);
498 :     }
499 :     }
500 :     }
501 :    
502 :     abstract class CheckedCallable<T> implements Callable<T> {
503 :     abstract T realCall() throws Throwable;
504 :    
505 :     public final T call() {
506 :     try {
507 :     return realCall();
508 :     } catch (Throwable t) {
509 :     threadUnexpectedException(t);
510 :     }
511 : jsr166 1.40 return null;
512 :     }
513 :     }
514 :    
515 :     abstract class CheckedInterruptedCallable<T> implements Callable<T> {
516 :     abstract T realCall() throws Throwable;
517 :    
518 :     public final T call() {
519 :     try {
520 :     T result = realCall();
521 :     threadShouldThrow("InterruptedException");
522 :     return result;
523 :     } catch (InterruptedException success) {
524 :     } catch (Throwable t) {
525 :     threadUnexpectedException(t);
526 :     }
527 :     return null;
528 : jsr166 1.35 }
529 :     }
530 :    
531 : dl 1.5 static class NoOpRunnable implements Runnable {
532 : dl 1.1 public void run() {}
533 :     }
534 :    
535 : dl 1.5 static class NoOpCallable implements Callable {
536 : dl 1.1 public Object call() { return Boolean.TRUE; }
537 : dl 1.10 }
538 :    
539 :     static final String TEST_STRING = "a test string";
540 :    
541 :     static class StringTask implements Callable<String> {
542 :     public String call() { return TEST_STRING; }
543 :     }
544 :    
545 :     static class NPETask implements Callable<String> {
546 :     public String call() { throw new NullPointerException(); }
547 :     }
548 :    
549 :     static class CallableOne implements Callable<Integer> {
550 :     public Integer call() { return one; }
551 : dl 1.1 }
552 :    
553 : jsr166 1.35 class ShortRunnable extends CheckedRunnable {
554 :     void realRun() throws Throwable {
555 :     Thread.sleep(SHORT_DELAY_MS);
556 : dl 1.1 }
557 :     }
558 :    
559 : jsr166 1.35 class ShortInterruptedRunnable extends CheckedInterruptedRunnable {
560 :     void realRun() throws InterruptedException {
561 :     Thread.sleep(SHORT_DELAY_MS);
562 : dl 1.1 }
563 :     }
564 :    
565 : jsr166 1.35 class SmallRunnable extends CheckedRunnable {
566 :     void realRun() throws Throwable {
567 :     Thread.sleep(SMALL_DELAY_MS);
568 : dl 1.1 }
569 :     }
570 :    
571 : jsr166 1.35 class SmallPossiblyInterruptedRunnable extends CheckedRunnable {
572 :     void realRun() {
573 : dl 1.6 try {
574 :     Thread.sleep(SMALL_DELAY_MS);
575 : jsr166 1.44 } catch (InterruptedException ok) {}
576 : dl 1.6 }
577 :     }
578 :    
579 : jsr166 1.35 class SmallCallable extends CheckedCallable {
580 : jsr166 1.44 Object realCall() throws InterruptedException {
581 : jsr166 1.35 Thread.sleep(SMALL_DELAY_MS);
582 : dl 1.1 return Boolean.TRUE;
583 :     }
584 :     }
585 :    
586 : jsr166 1.35 class SmallInterruptedRunnable extends CheckedInterruptedRunnable {
587 :     void realRun() throws InterruptedException {
588 :     Thread.sleep(SMALL_DELAY_MS);
589 : dl 1.1 }
590 :     }
591 :    
592 : jsr166 1.35 class MediumRunnable extends CheckedRunnable {
593 :     void realRun() throws Throwable {
594 :     Thread.sleep(MEDIUM_DELAY_MS);
595 : dl 1.1 }
596 :     }
597 :    
598 : jsr166 1.35 class MediumInterruptedRunnable extends CheckedInterruptedRunnable {
599 :     void realRun() throws InterruptedException {
600 :     Thread.sleep(MEDIUM_DELAY_MS);
601 : dl 1.1 }
602 :     }
603 :    
604 : jsr166 1.35 class MediumPossiblyInterruptedRunnable extends CheckedRunnable {
605 :     void realRun() {
606 : dl 1.1 try {
607 :     Thread.sleep(MEDIUM_DELAY_MS);
608 : jsr166 1.44 } catch (InterruptedException ok) {}
609 : dl 1.1 }
610 :     }
611 : dl 1.5
612 : jsr166 1.35 class LongPossiblyInterruptedRunnable extends CheckedRunnable {
613 :     void realRun() {
614 : dl 1.12 try {
615 :     Thread.sleep(LONG_DELAY_MS);
616 : jsr166 1.44 } catch (InterruptedException ok) {}
617 : dl 1.12 }
618 :     }
619 :    
620 : dl 1.5 /**
621 :     * For use as ThreadFactory in constructors
622 :     */
623 : jsr166 1.33 static class SimpleThreadFactory implements ThreadFactory {
624 :     public Thread newThread(Runnable r) {
625 : dl 1.5 return new Thread(r);
626 : jsr166 1.27 }
627 : dl 1.5 }
628 :    
629 : dl 1.6 static class TrackedShortRunnable implements Runnable {
630 : dl 1.5 volatile boolean done = false;
631 :     public void run() {
632 :     try {
633 :     Thread.sleep(SMALL_DELAY_MS);
634 :     done = true;
635 : jsr166 1.44 } catch (InterruptedException ok) {}
636 : dl 1.6 }
637 :     }
638 :    
639 :     static class TrackedMediumRunnable implements Runnable {
640 :     volatile boolean done = false;
641 :     public void run() {
642 :     try {
643 :     Thread.sleep(MEDIUM_DELAY_MS);
644 :     done = true;
645 : jsr166 1.44 } catch (InterruptedException ok) {}
646 : dl 1.6 }
647 :     }
648 :    
649 :     static class TrackedLongRunnable implements Runnable {
650 :     volatile boolean done = false;
651 :     public void run() {
652 :     try {
653 :     Thread.sleep(LONG_DELAY_MS);
654 :     done = true;
655 : jsr166 1.44 } catch (InterruptedException ok) {}
656 : dl 1.6 }
657 :     }
658 :    
659 :     static class TrackedNoOpRunnable implements Runnable {
660 :     volatile boolean done = false;
661 :     public void run() {
662 :     done = true;
663 : dl 1.5 }
664 :     }
665 :    
666 :     static class TrackedCallable implements Callable {
667 :     volatile boolean done = false;
668 :     public Object call() {
669 :     try {
670 :     Thread.sleep(SMALL_DELAY_MS);
671 :     done = true;
672 : jsr166 1.44 } catch (InterruptedException ok) {}
673 : dl 1.5 return Boolean.TRUE;
674 :     }
675 :     }
676 : dl 1.14
677 : dl 1.5
678 :     /**
679 :     * For use as RejectedExecutionHandler in constructors
680 :     */
681 : jsr166 1.33 static class NoOpREHandler implements RejectedExecutionHandler {
682 : jsr166 1.35 public void rejectedExecution(Runnable r,
683 :     ThreadPoolExecutor executor) {}
684 : dl 1.5 }
685 : jsr166 1.27
686 : dl 1.1 }

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8