9 |
|
import java.util.*; |
10 |
|
import java.util.concurrent.*; |
11 |
|
import java.io.*; |
12 |
< |
|
12 |
> |
import java.security.*; |
13 |
|
|
14 |
|
/** |
15 |
|
* Base class for JSR166 Junit TCK tests. Defines some constants, |
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(AbstractExecutorServiceTest.class)); |
102 |
+ |
suite.addTest(new TestSuite(ArrayBlockingQueueTest.class)); |
103 |
+ |
suite.addTest(new TestSuite(AtomicBooleanTest.class)); |
104 |
+ |
suite.addTest(new TestSuite(AtomicIntegerArrayTest.class)); |
105 |
+ |
suite.addTest(new TestSuite(AtomicIntegerFieldUpdaterTest.class)); |
106 |
+ |
suite.addTest(new TestSuite(AtomicIntegerTest.class)); |
107 |
+ |
suite.addTest(new TestSuite(AtomicLongArrayTest.class)); |
108 |
+ |
suite.addTest(new TestSuite(AtomicLongFieldUpdaterTest.class)); |
109 |
+ |
suite.addTest(new TestSuite(AtomicLongTest.class)); |
110 |
+ |
suite.addTest(new TestSuite(AtomicMarkableReferenceTest.class)); |
111 |
+ |
suite.addTest(new TestSuite(AtomicReferenceArrayTest.class)); |
112 |
+ |
suite.addTest(new TestSuite(AtomicReferenceFieldUpdaterTest.class)); |
113 |
+ |
suite.addTest(new TestSuite(AtomicReferenceTest.class)); |
114 |
+ |
suite.addTest(new TestSuite(AtomicStampedReferenceTest.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(FutureTaskTest.class)); |
125 |
+ |
suite.addTest(new TestSuite(LinkedBlockingQueueTest.class)); |
126 |
+ |
suite.addTest(new TestSuite(LinkedListTest.class)); |
127 |
+ |
suite.addTest(new TestSuite(LockSupportTest.class)); |
128 |
+ |
suite.addTest(new TestSuite(PriorityBlockingQueueTest.class)); |
129 |
+ |
suite.addTest(new TestSuite(PriorityQueueTest.class)); |
130 |
+ |
suite.addTest(new TestSuite(ReentrantLockTest.class)); |
131 |
+ |
suite.addTest(new TestSuite(ReentrantReadWriteLockTest.class)); |
132 |
+ |
suite.addTest(new TestSuite(ScheduledExecutorTest.class)); |
133 |
+ |
suite.addTest(new TestSuite(SemaphoreTest.class)); |
134 |
+ |
suite.addTest(new TestSuite(SynchronousQueueTest.class)); |
135 |
+ |
suite.addTest(new TestSuite(SystemTest.class)); |
136 |
+ |
suite.addTest(new TestSuite(ThreadLocalTest.class)); |
137 |
+ |
suite.addTest(new TestSuite(ThreadPoolExecutorTest.class)); |
138 |
+ |
suite.addTest(new TestSuite(ThreadTest.class)); |
139 |
+ |
suite.addTest(new TestSuite(TimeUnitTest.class)); |
140 |
+ |
|
141 |
+ |
return suite; |
142 |
+ |
} |
143 |
+ |
|
144 |
|
|
145 |
|
public static long SHORT_DELAY_MS; |
146 |
|
public static long SMALL_DELAY_MS; |
320 |
|
static final Integer m10 = new Integer(-10); |
321 |
|
|
322 |
|
|
323 |
+ |
/** |
324 |
+ |
* A security policy where new permissions can be dynamically added |
325 |
+ |
* or all cleared. |
326 |
+ |
*/ |
327 |
+ |
static class AdjustablePolicy extends java.security.Policy { |
328 |
+ |
Permissions perms = new Permissions(); |
329 |
+ |
AdjustablePolicy() { } |
330 |
+ |
void addPermission(Permission perm) { perms.add(perm); } |
331 |
+ |
void clearPermissions() { perms = new Permissions(); } |
332 |
+ |
public PermissionCollection getPermissions(CodeSource cs) { |
333 |
+ |
return perms; |
334 |
+ |
} |
335 |
+ |
public PermissionCollection getPermissions(ProtectionDomain pd) { |
336 |
+ |
return perms; |
337 |
+ |
} |
338 |
+ |
public boolean implies(ProtectionDomain pd, Permission p) { |
339 |
+ |
return perms.implies(p); |
340 |
+ |
} |
341 |
+ |
public void refresh() {} |
342 |
+ |
} |
343 |
+ |
|
344 |
+ |
|
345 |
|
// Some convenient Runnable classes |
346 |
|
|
347 |
|
static class NoOpRunnable implements Runnable { |
352 |
|
public Object call() { return Boolean.TRUE; } |
353 |
|
} |
354 |
|
|
355 |
+ |
static final String TEST_STRING = "a test string"; |
356 |
+ |
|
357 |
+ |
static class StringTask implements Callable<String> { |
358 |
+ |
public String call() { return TEST_STRING; } |
359 |
+ |
} |
360 |
+ |
|
361 |
+ |
static class NPETask implements Callable<String> { |
362 |
+ |
public String call() { throw new NullPointerException(); } |
363 |
+ |
} |
364 |
+ |
|
365 |
+ |
static class CallableOne implements Callable<Integer> { |
366 |
+ |
public Integer call() { return one; } |
367 |
+ |
} |
368 |
+ |
|
369 |
|
class ShortRunnable implements Runnable { |
370 |
|
public void run() { |
371 |
|
try { |
399 |
|
} |
400 |
|
} |
401 |
|
|
402 |
+ |
class SmallPossiblyInterruptedRunnable implements Runnable { |
403 |
+ |
public void run() { |
404 |
+ |
try { |
405 |
+ |
Thread.sleep(SMALL_DELAY_MS); |
406 |
+ |
} |
407 |
+ |
catch(Exception e) { |
408 |
+ |
} |
409 |
+ |
} |
410 |
+ |
} |
411 |
+ |
|
412 |
|
class SmallCallable implements Callable { |
413 |
|
public Object call() { |
414 |
|
try { |
474 |
|
} |
475 |
|
} |
476 |
|
|
477 |
< |
static class TrackedRunnable implements Runnable { |
477 |
> |
static class TrackedShortRunnable implements Runnable { |
478 |
|
volatile boolean done = false; |
479 |
|
public void run() { |
480 |
|
try { |
485 |
|
} |
486 |
|
} |
487 |
|
|
488 |
+ |
static class TrackedMediumRunnable implements Runnable { |
489 |
+ |
volatile boolean done = false; |
490 |
+ |
public void run() { |
491 |
+ |
try { |
492 |
+ |
Thread.sleep(MEDIUM_DELAY_MS); |
493 |
+ |
done = true; |
494 |
+ |
} catch(Exception e){ |
495 |
+ |
} |
496 |
+ |
} |
497 |
+ |
} |
498 |
+ |
|
499 |
+ |
static class TrackedLongRunnable implements Runnable { |
500 |
+ |
volatile boolean done = false; |
501 |
+ |
public void run() { |
502 |
+ |
try { |
503 |
+ |
Thread.sleep(LONG_DELAY_MS); |
504 |
+ |
done = true; |
505 |
+ |
} catch(Exception e){ |
506 |
+ |
} |
507 |
+ |
} |
508 |
+ |
} |
509 |
+ |
|
510 |
+ |
static class TrackedNoOpRunnable implements Runnable { |
511 |
+ |
volatile boolean done = false; |
512 |
+ |
public void run() { |
513 |
+ |
done = true; |
514 |
+ |
} |
515 |
+ |
} |
516 |
+ |
|
517 |
|
static class TrackedCallable implements Callable { |
518 |
|
volatile boolean done = false; |
519 |
|
public Object call() { |