34 |
|
* them. These methods are used to clear and check for thread |
35 |
|
* assertion failures.</li> |
36 |
|
* |
37 |
< |
* <li>All delays and timeouts must use one of the constants {@link |
38 |
< |
* SHORT_DELAY_MS}, {@link SMALL_DELAY_MS}, {@link MEDIUM_DELAY_MS}, |
39 |
< |
* {@link LONG_DELAY_MS}. The idea here is that a SHORT is always |
37 |
> |
* <li>All delays and timeouts must use one of the constants <tt> |
38 |
> |
* SHORT_DELAY_MS</tt>, <tt> SMALL_DELAY_MS</tt>, <tt> MEDIUM_DELAY_MS</tt>, |
39 |
> |
* <tt> LONG_DELAY_MS</tt>. The idea here is that a SHORT is always |
40 |
|
* discriminable from zero time, and always allows enough time for the |
41 |
|
* small amounts of computation (creating a thread, calling a few |
42 |
|
* methods, etc) needed to reach a timeout point. Similarly, a SMALL |
47 |
|
* |
48 |
|
* <li> All threads generated must be joined inside each test case |
49 |
|
* method (or <tt>fail</tt> to do so) before returning from the |
50 |
< |
* method. The {@link joinPool} method can be used to do this when |
50 |
> |
* method. The <tt> joinPool</tt> method can be used to do this when |
51 |
|
* using Executors.</li> |
52 |
|
* |
53 |
|
* </ol> |
54 |
+ |
* |
55 |
+ |
* <p> <b>Other notes</b> |
56 |
+ |
* <ul> |
57 |
+ |
* |
58 |
+ |
* <li> Usually, there is one testcase method per JSR166 method |
59 |
+ |
* covering "normal" operation, and then as many exception-testing |
60 |
+ |
* methods as there are exceptions the method can throw. Sometimes |
61 |
+ |
* there are multiple tests per JSR166 method when the different |
62 |
+ |
* "normal" behaviors differ significantly. And sometimes testcases |
63 |
+ |
* cover multiple methods when they cannot be tested in |
64 |
+ |
* isolation.</li> |
65 |
+ |
* |
66 |
+ |
* <li> The documentation style for testcases is to provide as javadoc |
67 |
+ |
* a simple sentence or two describing the property that the testcase |
68 |
+ |
* method purports to test. The javadocs do not say anything about how |
69 |
+ |
* the property is tested. To find out, read the code.</li> |
70 |
+ |
* |
71 |
+ |
* <li> These tests are "conformance tests", and do not attempt to |
72 |
+ |
* test throughput, latency, scalability or other performance factors |
73 |
+ |
* (see the separate "jtreg" tests for a set intended to check these |
74 |
+ |
* for the most central aspects of functionality.) So, most tests use |
75 |
+ |
* the smallest sensible numbers of threads, collection sizes, etc |
76 |
+ |
* needed to check basic conformance.</li> |
77 |
+ |
* |
78 |
+ |
* <li>The test classes currently do not declare inclusion in |
79 |
+ |
* any particular package to simplify things for people integrating |
80 |
+ |
* them in TCK test suites.</li> |
81 |
+ |
* |
82 |
+ |
* <li> As a convenience, the <tt>main</tt> of this class (JSR166TestCase) |
83 |
+ |
* runs all JSR166 unit tests.</li> |
84 |
+ |
* |
85 |
+ |
* </ul> |
86 |
|
*/ |
87 |
|
public class JSR166TestCase extends TestCase { |
88 |
+ |
/** |
89 |
+ |
* Runs all JSR166 unit tests using junit.textui.TestRunner |
90 |
+ |
*/ |
91 |
+ |
public static void main (String[] args) { |
92 |
+ |
junit.textui.TestRunner.run (suite()); |
93 |
+ |
} |
94 |
+ |
|
95 |
+ |
/** |
96 |
+ |
* Collects all JSR166 unit tests as one suite |
97 |
+ |
*/ |
98 |
+ |
public static Test suite ( ) { |
99 |
+ |
TestSuite suite = new TestSuite("JSR166 Unit Tests"); |
100 |
+ |
|
101 |
+ |
suite.addTest(new TestSuite(ArrayBlockingQueueTest.class)); |
102 |
+ |
suite.addTest(new TestSuite(AtomicBooleanTest.class)); |
103 |
+ |
suite.addTest(new TestSuite(AtomicIntegerArrayTest.class)); |
104 |
+ |
suite.addTest(new TestSuite(AtomicIntegerFieldUpdaterTest.class)); |
105 |
+ |
suite.addTest(new TestSuite(AtomicIntegerTest.class)); |
106 |
+ |
suite.addTest(new TestSuite(AtomicLongArrayTest.class)); |
107 |
+ |
suite.addTest(new TestSuite(AtomicLongFieldUpdaterTest.class)); |
108 |
+ |
suite.addTest(new TestSuite(AtomicLongTest.class)); |
109 |
+ |
suite.addTest(new TestSuite(AtomicMarkableReferenceTest.class)); |
110 |
+ |
suite.addTest(new TestSuite(AtomicReferenceArrayTest.class)); |
111 |
+ |
suite.addTest(new TestSuite(AtomicReferenceFieldUpdaterTest.class)); |
112 |
+ |
suite.addTest(new TestSuite(AtomicReferenceTest.class)); |
113 |
+ |
suite.addTest(new TestSuite(AtomicStampedReferenceTest.class)); |
114 |
+ |
suite.addTest(new TestSuite(CancellableTaskTest.class)); |
115 |
+ |
suite.addTest(new TestSuite(ConcurrentHashMapTest.class)); |
116 |
+ |
suite.addTest(new TestSuite(ConcurrentLinkedQueueTest.class)); |
117 |
+ |
suite.addTest(new TestSuite(CopyOnWriteArrayListTest.class)); |
118 |
+ |
suite.addTest(new TestSuite(CopyOnWriteArraySetTest.class)); |
119 |
+ |
suite.addTest(new TestSuite(CountDownLatchTest.class)); |
120 |
+ |
suite.addTest(new TestSuite(CyclicBarrierTest.class)); |
121 |
+ |
suite.addTest(new TestSuite(DelayQueueTest.class)); |
122 |
+ |
suite.addTest(new TestSuite(ExchangerTest.class)); |
123 |
+ |
suite.addTest(new TestSuite(ExecutorsTest.class)); |
124 |
+ |
suite.addTest(new TestSuite(FairSemaphoreTest.class)); |
125 |
+ |
suite.addTest(new TestSuite(FutureTaskTest.class)); |
126 |
+ |
suite.addTest(new TestSuite(LinkedBlockingQueueTest.class)); |
127 |
+ |
suite.addTest(new TestSuite(LinkedListTest.class)); |
128 |
+ |
suite.addTest(new TestSuite(LockSupportTest.class)); |
129 |
+ |
suite.addTest(new TestSuite(PriorityBlockingQueueTest.class)); |
130 |
+ |
suite.addTest(new TestSuite(PriorityQueueTest.class)); |
131 |
+ |
suite.addTest(new TestSuite(ReentrantLockTest.class)); |
132 |
+ |
suite.addTest(new TestSuite(ReentrantReadWriteLockTest.class)); |
133 |
+ |
suite.addTest(new TestSuite(ScheduledExecutorTest.class)); |
134 |
+ |
suite.addTest(new TestSuite(SemaphoreTest.class)); |
135 |
+ |
suite.addTest(new TestSuite(SynchronousQueueTest.class)); |
136 |
+ |
suite.addTest(new TestSuite(SystemTest.class)); |
137 |
+ |
suite.addTest(new TestSuite(ThreadLocalTest.class)); |
138 |
+ |
suite.addTest(new TestSuite(ThreadPoolExecutorTest.class)); |
139 |
+ |
suite.addTest(new TestSuite(ThreadTest.class)); |
140 |
+ |
suite.addTest(new TestSuite(TimeUnitTest.class)); |
141 |
+ |
|
142 |
+ |
return suite; |
143 |
+ |
} |
144 |
+ |
|
145 |
|
|
146 |
|
public static long SHORT_DELAY_MS; |
147 |
|
public static long SMALL_DELAY_MS; |
364 |
|
} |
365 |
|
} |
366 |
|
|
367 |
+ |
class SmallPossiblyInterruptedRunnable implements Runnable { |
368 |
+ |
public void run() { |
369 |
+ |
try { |
370 |
+ |
Thread.sleep(SMALL_DELAY_MS); |
371 |
+ |
} |
372 |
+ |
catch(Exception e) { |
373 |
+ |
} |
374 |
+ |
} |
375 |
+ |
} |
376 |
+ |
|
377 |
|
class SmallCallable implements Callable { |
378 |
|
public Object call() { |
379 |
|
try { |
439 |
|
} |
440 |
|
} |
441 |
|
|
442 |
< |
static class TrackedRunnable implements Runnable { |
442 |
> |
static class TrackedShortRunnable implements Runnable { |
443 |
|
volatile boolean done = false; |
444 |
|
public void run() { |
445 |
|
try { |
450 |
|
} |
451 |
|
} |
452 |
|
|
453 |
+ |
static class TrackedMediumRunnable implements Runnable { |
454 |
+ |
volatile boolean done = false; |
455 |
+ |
public void run() { |
456 |
+ |
try { |
457 |
+ |
Thread.sleep(MEDIUM_DELAY_MS); |
458 |
+ |
done = true; |
459 |
+ |
} catch(Exception e){ |
460 |
+ |
} |
461 |
+ |
} |
462 |
+ |
} |
463 |
+ |
|
464 |
+ |
static class TrackedLongRunnable implements Runnable { |
465 |
+ |
volatile boolean done = false; |
466 |
+ |
public void run() { |
467 |
+ |
try { |
468 |
+ |
Thread.sleep(LONG_DELAY_MS); |
469 |
+ |
done = true; |
470 |
+ |
} catch(Exception e){ |
471 |
+ |
} |
472 |
+ |
} |
473 |
+ |
} |
474 |
+ |
|
475 |
+ |
static class TrackedNoOpRunnable implements Runnable { |
476 |
+ |
volatile boolean done = false; |
477 |
+ |
public void run() { |
478 |
+ |
done = true; |
479 |
+ |
} |
480 |
+ |
} |
481 |
+ |
|
482 |
|
static class TrackedCallable implements Callable { |
483 |
|
volatile boolean done = false; |
484 |
|
public Object call() { |