7 |
|
*/ |
8 |
|
|
9 |
|
import junit.framework.*; |
10 |
< |
import java.util.*; |
10 |
> |
import java.util.PropertyPermission; |
11 |
|
import java.util.concurrent.*; |
12 |
+ |
import java.util.concurrent.atomic.AtomicReference; |
13 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
14 |
< |
import java.io.*; |
15 |
< |
import java.security.*; |
14 |
> |
import java.security.CodeSource; |
15 |
> |
import java.security.Permission; |
16 |
> |
import java.security.PermissionCollection; |
17 |
> |
import java.security.Permissions; |
18 |
> |
import java.security.Policy; |
19 |
> |
import java.security.ProtectionDomain; |
20 |
> |
import java.security.SecurityPermission; |
21 |
|
|
22 |
|
/** |
23 |
|
* Base class for JSR166 Junit TCK tests. Defines some constants, |
105 |
|
Policy.setPolicy(permissivePolicy()); |
106 |
|
System.setSecurityManager(new SecurityManager()); |
107 |
|
} |
108 |
< |
int iters = 1; |
109 |
< |
if (args.length > 0) |
104 |
< |
iters = Integer.parseInt(args[0]); |
108 |
> |
int iters = (args.length == 0) ? 1 : Integer.parseInt(args[0]); |
109 |
> |
|
110 |
|
Test s = suite(); |
111 |
|
for (int i = 0; i < iters; ++i) { |
112 |
|
junit.textui.TestRunner.run(s); |
122 |
|
public static Test suite() { |
123 |
|
TestSuite suite = new TestSuite("JSR166 Unit Tests"); |
124 |
|
|
125 |
< |
suite.addTest(new TestSuite(ForkJoinPoolTest.class)); |
126 |
< |
suite.addTest(new TestSuite(ForkJoinTaskTest.class)); |
127 |
< |
suite.addTest(new TestSuite(RecursiveActionTest.class)); |
128 |
< |
suite.addTest(new TestSuite(RecursiveTaskTest.class)); |
129 |
< |
suite.addTest(new TestSuite(LinkedTransferQueueTest.class)); |
130 |
< |
suite.addTest(new TestSuite(PhaserTest.class)); |
131 |
< |
suite.addTest(new TestSuite(ThreadLocalRandomTest.class)); |
132 |
< |
suite.addTest(new TestSuite(AbstractExecutorServiceTest.class)); |
133 |
< |
suite.addTest(new TestSuite(AbstractQueueTest.class)); |
134 |
< |
suite.addTest(new TestSuite(AbstractQueuedSynchronizerTest.class)); |
135 |
< |
suite.addTest(new TestSuite(AbstractQueuedLongSynchronizerTest.class)); |
136 |
< |
suite.addTest(new TestSuite(ArrayBlockingQueueTest.class)); |
137 |
< |
suite.addTest(new TestSuite(ArrayDequeTest.class)); |
138 |
< |
suite.addTest(new TestSuite(AtomicBooleanTest.class)); |
139 |
< |
suite.addTest(new TestSuite(AtomicIntegerArrayTest.class)); |
140 |
< |
suite.addTest(new TestSuite(AtomicIntegerFieldUpdaterTest.class)); |
141 |
< |
suite.addTest(new TestSuite(AtomicIntegerTest.class)); |
142 |
< |
suite.addTest(new TestSuite(AtomicLongArrayTest.class)); |
143 |
< |
suite.addTest(new TestSuite(AtomicLongFieldUpdaterTest.class)); |
144 |
< |
suite.addTest(new TestSuite(AtomicLongTest.class)); |
145 |
< |
suite.addTest(new TestSuite(AtomicMarkableReferenceTest.class)); |
146 |
< |
suite.addTest(new TestSuite(AtomicReferenceArrayTest.class)); |
147 |
< |
suite.addTest(new TestSuite(AtomicReferenceFieldUpdaterTest.class)); |
148 |
< |
suite.addTest(new TestSuite(AtomicReferenceTest.class)); |
149 |
< |
suite.addTest(new TestSuite(AtomicStampedReferenceTest.class)); |
150 |
< |
suite.addTest(new TestSuite(ConcurrentHashMapTest.class)); |
151 |
< |
suite.addTest(new TestSuite(ConcurrentLinkedDequeTest.class)); |
152 |
< |
suite.addTest(new TestSuite(ConcurrentLinkedQueueTest.class)); |
153 |
< |
suite.addTest(new TestSuite(ConcurrentSkipListMapTest.class)); |
154 |
< |
suite.addTest(new TestSuite(ConcurrentSkipListSubMapTest.class)); |
155 |
< |
suite.addTest(new TestSuite(ConcurrentSkipListSetTest.class)); |
156 |
< |
suite.addTest(new TestSuite(ConcurrentSkipListSubSetTest.class)); |
157 |
< |
suite.addTest(new TestSuite(CopyOnWriteArrayListTest.class)); |
158 |
< |
suite.addTest(new TestSuite(CopyOnWriteArraySetTest.class)); |
159 |
< |
suite.addTest(new TestSuite(CountDownLatchTest.class)); |
160 |
< |
suite.addTest(new TestSuite(CyclicBarrierTest.class)); |
161 |
< |
suite.addTest(new TestSuite(DelayQueueTest.class)); |
162 |
< |
suite.addTest(new TestSuite(EntryTest.class)); |
163 |
< |
suite.addTest(new TestSuite(ExchangerTest.class)); |
164 |
< |
suite.addTest(new TestSuite(ExecutorsTest.class)); |
165 |
< |
suite.addTest(new TestSuite(ExecutorCompletionServiceTest.class)); |
166 |
< |
suite.addTest(new TestSuite(FutureTaskTest.class)); |
167 |
< |
suite.addTest(new TestSuite(LinkedBlockingDequeTest.class)); |
168 |
< |
suite.addTest(new TestSuite(LinkedBlockingQueueTest.class)); |
169 |
< |
suite.addTest(new TestSuite(LinkedListTest.class)); |
170 |
< |
suite.addTest(new TestSuite(LockSupportTest.class)); |
171 |
< |
suite.addTest(new TestSuite(PriorityBlockingQueueTest.class)); |
172 |
< |
suite.addTest(new TestSuite(PriorityQueueTest.class)); |
173 |
< |
suite.addTest(new TestSuite(ReentrantLockTest.class)); |
174 |
< |
suite.addTest(new TestSuite(ReentrantReadWriteLockTest.class)); |
175 |
< |
suite.addTest(new TestSuite(ScheduledExecutorTest.class)); |
176 |
< |
suite.addTest(new TestSuite(ScheduledExecutorSubclassTest.class)); |
177 |
< |
suite.addTest(new TestSuite(SemaphoreTest.class)); |
178 |
< |
suite.addTest(new TestSuite(SynchronousQueueTest.class)); |
179 |
< |
suite.addTest(new TestSuite(SystemTest.class)); |
180 |
< |
suite.addTest(new TestSuite(ThreadLocalTest.class)); |
181 |
< |
suite.addTest(new TestSuite(ThreadPoolExecutorTest.class)); |
182 |
< |
suite.addTest(new TestSuite(ThreadPoolExecutorSubclassTest.class)); |
183 |
< |
suite.addTest(new TestSuite(ThreadTest.class)); |
184 |
< |
suite.addTest(new TestSuite(TimeUnitTest.class)); |
185 |
< |
suite.addTest(new TestSuite(TreeMapTest.class)); |
186 |
< |
suite.addTest(new TestSuite(TreeSetTest.class)); |
187 |
< |
suite.addTest(new TestSuite(TreeSubMapTest.class)); |
188 |
< |
suite.addTest(new TestSuite(TreeSubSetTest.class)); |
125 |
> |
suite.addTest(ForkJoinPoolTest.suite()); |
126 |
> |
suite.addTest(ForkJoinTaskTest.suite()); |
127 |
> |
suite.addTest(RecursiveActionTest.suite()); |
128 |
> |
suite.addTest(RecursiveTaskTest.suite()); |
129 |
> |
suite.addTest(LinkedTransferQueueTest.suite()); |
130 |
> |
suite.addTest(PhaserTest.suite()); |
131 |
> |
suite.addTest(ThreadLocalRandomTest.suite()); |
132 |
> |
suite.addTest(AbstractExecutorServiceTest.suite()); |
133 |
> |
suite.addTest(AbstractQueueTest.suite()); |
134 |
> |
suite.addTest(AbstractQueuedSynchronizerTest.suite()); |
135 |
> |
suite.addTest(AbstractQueuedLongSynchronizerTest.suite()); |
136 |
> |
suite.addTest(ArrayBlockingQueueTest.suite()); |
137 |
> |
suite.addTest(ArrayDequeTest.suite()); |
138 |
> |
suite.addTest(AtomicBooleanTest.suite()); |
139 |
> |
suite.addTest(AtomicIntegerArrayTest.suite()); |
140 |
> |
suite.addTest(AtomicIntegerFieldUpdaterTest.suite()); |
141 |
> |
suite.addTest(AtomicIntegerTest.suite()); |
142 |
> |
suite.addTest(AtomicLongArrayTest.suite()); |
143 |
> |
suite.addTest(AtomicLongFieldUpdaterTest.suite()); |
144 |
> |
suite.addTest(AtomicLongTest.suite()); |
145 |
> |
suite.addTest(AtomicMarkableReferenceTest.suite()); |
146 |
> |
suite.addTest(AtomicReferenceArrayTest.suite()); |
147 |
> |
suite.addTest(AtomicReferenceFieldUpdaterTest.suite()); |
148 |
> |
suite.addTest(AtomicReferenceTest.suite()); |
149 |
> |
suite.addTest(AtomicStampedReferenceTest.suite()); |
150 |
> |
suite.addTest(ConcurrentHashMapTest.suite()); |
151 |
> |
suite.addTest(ConcurrentLinkedDequeTest.suite()); |
152 |
> |
suite.addTest(ConcurrentLinkedQueueTest.suite()); |
153 |
> |
suite.addTest(ConcurrentSkipListMapTest.suite()); |
154 |
> |
suite.addTest(ConcurrentSkipListSubMapTest.suite()); |
155 |
> |
suite.addTest(ConcurrentSkipListSetTest.suite()); |
156 |
> |
suite.addTest(ConcurrentSkipListSubSetTest.suite()); |
157 |
> |
suite.addTest(CopyOnWriteArrayListTest.suite()); |
158 |
> |
suite.addTest(CopyOnWriteArraySetTest.suite()); |
159 |
> |
suite.addTest(CountDownLatchTest.suite()); |
160 |
> |
suite.addTest(CyclicBarrierTest.suite()); |
161 |
> |
suite.addTest(DelayQueueTest.suite()); |
162 |
> |
suite.addTest(EntryTest.suite()); |
163 |
> |
suite.addTest(ExchangerTest.suite()); |
164 |
> |
suite.addTest(ExecutorsTest.suite()); |
165 |
> |
suite.addTest(ExecutorCompletionServiceTest.suite()); |
166 |
> |
suite.addTest(FutureTaskTest.suite()); |
167 |
> |
suite.addTest(LinkedBlockingDequeTest.suite()); |
168 |
> |
suite.addTest(LinkedBlockingQueueTest.suite()); |
169 |
> |
suite.addTest(LinkedListTest.suite()); |
170 |
> |
suite.addTest(LockSupportTest.suite()); |
171 |
> |
suite.addTest(PriorityBlockingQueueTest.suite()); |
172 |
> |
suite.addTest(PriorityQueueTest.suite()); |
173 |
> |
suite.addTest(ReentrantLockTest.suite()); |
174 |
> |
suite.addTest(ReentrantReadWriteLockTest.suite()); |
175 |
> |
suite.addTest(ScheduledExecutorTest.suite()); |
176 |
> |
suite.addTest(ScheduledExecutorSubclassTest.suite()); |
177 |
> |
suite.addTest(SemaphoreTest.suite()); |
178 |
> |
suite.addTest(SynchronousQueueTest.suite()); |
179 |
> |
suite.addTest(SystemTest.suite()); |
180 |
> |
suite.addTest(ThreadLocalTest.suite()); |
181 |
> |
suite.addTest(ThreadPoolExecutorTest.suite()); |
182 |
> |
suite.addTest(ThreadPoolExecutorSubclassTest.suite()); |
183 |
> |
suite.addTest(ThreadTest.suite()); |
184 |
> |
suite.addTest(TimeUnitTest.suite()); |
185 |
> |
suite.addTest(TreeMapTest.suite()); |
186 |
> |
suite.addTest(TreeSetTest.suite()); |
187 |
> |
suite.addTest(TreeSubMapTest.suite()); |
188 |
> |
suite.addTest(TreeSubSetTest.suite()); |
189 |
|
|
190 |
|
return suite; |
191 |
|
} |
211 |
|
*/ |
212 |
|
protected void setDelays() { |
213 |
|
SHORT_DELAY_MS = getShortDelay(); |
214 |
< |
SMALL_DELAY_MS = SHORT_DELAY_MS * 5; |
214 |
> |
SMALL_DELAY_MS = SHORT_DELAY_MS * 5; |
215 |
|
MEDIUM_DELAY_MS = SHORT_DELAY_MS * 10; |
216 |
< |
LONG_DELAY_MS = SHORT_DELAY_MS * 50; |
216 |
> |
LONG_DELAY_MS = SHORT_DELAY_MS * 50; |
217 |
|
} |
218 |
|
|
219 |
|
/** |
220 |
< |
* Flag set true if any threadAssert methods fail |
220 |
> |
* The first exception encountered if any threadAssertXXX method fails. |
221 |
|
*/ |
222 |
< |
volatile boolean threadFailed; |
222 |
> |
private final AtomicReference<Throwable> threadFailure |
223 |
> |
= new AtomicReference<Throwable>(null); |
224 |
|
|
225 |
|
/** |
226 |
< |
* Initializes test to indicate that no thread assertions have failed |
226 |
> |
* Records an exception so that it can be rethrown later in the test |
227 |
> |
* harness thread, triggering a test case failure. Only the first |
228 |
> |
* failure is recorded; subsequent calls to this method from within |
229 |
> |
* the same test have no effect. |
230 |
|
*/ |
231 |
+ |
public void threadRecordFailure(Throwable t) { |
232 |
+ |
threadFailure.compareAndSet(null, t); |
233 |
+ |
} |
234 |
+ |
|
235 |
|
public void setUp() { |
236 |
|
setDelays(); |
224 |
– |
threadFailed = false; |
237 |
|
} |
238 |
|
|
239 |
|
/** |
240 |
< |
* Triggers test case failure if any thread assertions have failed |
241 |
< |
*/ |
242 |
< |
public void tearDown() { |
243 |
< |
assertFalse(threadFailed); |
240 |
> |
* Triggers test case failure if any thread assertions have failed, |
241 |
> |
* by rethrowing, in the test harness thread, any exception recorded |
242 |
> |
* earlier by threadRecordFailure. |
243 |
> |
*/ |
244 |
> |
public void tearDown() throws Exception { |
245 |
> |
Throwable t = threadFailure.get(); |
246 |
> |
if (t != null) { |
247 |
> |
if (t instanceof Error) |
248 |
> |
throw (Error) t; |
249 |
> |
else if (t instanceof RuntimeException) |
250 |
> |
throw (RuntimeException) t; |
251 |
> |
else if (t instanceof Exception) |
252 |
> |
throw (Exception) t; |
253 |
> |
else { |
254 |
> |
AssertionFailedError afe = |
255 |
> |
new AssertionFailedError(t.toString()); |
256 |
> |
afe.initCause(t); |
257 |
> |
throw afe; |
258 |
> |
} |
259 |
> |
} |
260 |
|
} |
261 |
|
|
262 |
|
/** |
263 |
< |
* Fail, also setting status to indicate current testcase should fail |
263 |
> |
* Just like fail(reason), but additionally recording (using |
264 |
> |
* threadRecordFailure) any AssertionFailedError thrown, so that |
265 |
> |
* the current testcase will fail. |
266 |
|
*/ |
267 |
|
public void threadFail(String reason) { |
268 |
< |
threadFailed = true; |
269 |
< |
fail(reason); |
268 |
> |
try { |
269 |
> |
fail(reason); |
270 |
> |
} catch (AssertionFailedError t) { |
271 |
> |
threadRecordFailure(t); |
272 |
> |
fail(reason); |
273 |
> |
} |
274 |
|
} |
275 |
|
|
276 |
|
/** |
277 |
< |
* If expression not true, set status to indicate current testcase |
278 |
< |
* should fail |
277 |
> |
* Just like assertTrue(b), but additionally recording (using |
278 |
> |
* threadRecordFailure) any AssertionFailedError thrown, so that |
279 |
> |
* the current testcase will fail. |
280 |
|
*/ |
281 |
|
public void threadAssertTrue(boolean b) { |
282 |
< |
if (!b) { |
248 |
< |
threadFailed = true; |
282 |
> |
try { |
283 |
|
assertTrue(b); |
284 |
+ |
} catch (AssertionFailedError t) { |
285 |
+ |
threadRecordFailure(t); |
286 |
+ |
throw t; |
287 |
|
} |
288 |
|
} |
289 |
|
|
290 |
|
/** |
291 |
< |
* If expression not false, set status to indicate current testcase |
292 |
< |
* should fail |
291 |
> |
* Just like assertFalse(b), but additionally recording (using |
292 |
> |
* threadRecordFailure) any AssertionFailedError thrown, so that |
293 |
> |
* the current testcase will fail. |
294 |
|
*/ |
295 |
|
public void threadAssertFalse(boolean b) { |
296 |
< |
if (b) { |
259 |
< |
threadFailed = true; |
296 |
> |
try { |
297 |
|
assertFalse(b); |
298 |
+ |
} catch (AssertionFailedError t) { |
299 |
+ |
threadRecordFailure(t); |
300 |
+ |
throw t; |
301 |
|
} |
302 |
|
} |
303 |
|
|
304 |
|
/** |
305 |
< |
* If argument not null, set status to indicate current testcase |
306 |
< |
* should fail |
305 |
> |
* Just like assertNull(x), but additionally recording (using |
306 |
> |
* threadRecordFailure) any AssertionFailedError thrown, so that |
307 |
> |
* the current testcase will fail. |
308 |
|
*/ |
309 |
|
public void threadAssertNull(Object x) { |
310 |
< |
if (x != null) { |
270 |
< |
threadFailed = true; |
310 |
> |
try { |
311 |
|
assertNull(x); |
312 |
+ |
} catch (AssertionFailedError t) { |
313 |
+ |
threadRecordFailure(t); |
314 |
+ |
throw t; |
315 |
|
} |
316 |
|
} |
317 |
|
|
318 |
|
/** |
319 |
< |
* If arguments not equal, set status to indicate current testcase |
320 |
< |
* should fail |
319 |
> |
* Just like assertEquals(x, y), but additionally recording (using |
320 |
> |
* threadRecordFailure) any AssertionFailedError thrown, so that |
321 |
> |
* the current testcase will fail. |
322 |
|
*/ |
323 |
|
public void threadAssertEquals(long x, long y) { |
324 |
< |
if (x != y) { |
281 |
< |
threadFailed = true; |
324 |
> |
try { |
325 |
|
assertEquals(x, y); |
326 |
+ |
} catch (AssertionFailedError t) { |
327 |
+ |
threadRecordFailure(t); |
328 |
+ |
throw t; |
329 |
|
} |
330 |
|
} |
331 |
|
|
332 |
|
/** |
333 |
< |
* If arguments not equal, set status to indicate current testcase |
334 |
< |
* should fail |
333 |
> |
* Just like assertEquals(x, y), but additionally recording (using |
334 |
> |
* threadRecordFailure) any AssertionFailedError thrown, so that |
335 |
> |
* the current testcase will fail. |
336 |
|
*/ |
337 |
|
public void threadAssertEquals(Object x, Object y) { |
338 |
< |
if (x != y && (x == null || !x.equals(y))) { |
292 |
< |
threadFailed = true; |
338 |
> |
try { |
339 |
|
assertEquals(x, y); |
340 |
+ |
} catch (AssertionFailedError t) { |
341 |
+ |
threadRecordFailure(t); |
342 |
+ |
throw t; |
343 |
+ |
} catch (Throwable t) { |
344 |
+ |
threadUnexpectedException(t); |
345 |
|
} |
346 |
|
} |
347 |
|
|
348 |
|
/** |
349 |
< |
* threadFail with message "should throw exception" |
349 |
> |
* Just like assertSame(x, y), but additionally recording (using |
350 |
> |
* threadRecordFailure) any AssertionFailedError thrown, so that |
351 |
> |
* the current testcase will fail. |
352 |
|
*/ |
353 |
< |
public void threadShouldThrow() { |
354 |
< |
threadFailed = true; |
355 |
< |
fail("should throw exception"); |
353 |
> |
public void threadAssertSame(Object x, Object y) { |
354 |
> |
try { |
355 |
> |
assertSame(x, y); |
356 |
> |
} catch (AssertionFailedError t) { |
357 |
> |
threadRecordFailure(t); |
358 |
> |
throw t; |
359 |
> |
} |
360 |
|
} |
361 |
|
|
362 |
|
/** |
363 |
< |
* threadFail with message "should throw" + exceptionName |
363 |
> |
* Calls threadFail with message "should throw exception". |
364 |
|
*/ |
365 |
< |
public void threadShouldThrow(String exceptionName) { |
366 |
< |
threadFailed = true; |
310 |
< |
fail("should throw " + exceptionName); |
365 |
> |
public void threadShouldThrow() { |
366 |
> |
threadFail("should throw exception"); |
367 |
|
} |
368 |
|
|
369 |
|
/** |
370 |
< |
* threadFail with message "Unexpected exception" |
370 |
> |
* Calls threadFail with message "should throw" + exceptionName. |
371 |
|
*/ |
372 |
< |
public void threadUnexpectedException() { |
373 |
< |
threadFailed = true; |
318 |
< |
fail("Unexpected exception"); |
372 |
> |
public void threadShouldThrow(String exceptionName) { |
373 |
> |
threadFail("should throw " + exceptionName); |
374 |
|
} |
375 |
|
|
376 |
|
/** |
377 |
< |
* threadFail with message "Unexpected exception", with argument |
377 |
> |
* Records the given exception using {@link #threadRecordFailure}, |
378 |
> |
* then rethrows the exception, wrapping it in an |
379 |
> |
* AssertionFailedError if necessary. |
380 |
|
*/ |
381 |
< |
public void threadUnexpectedException(Throwable ex) { |
382 |
< |
threadFailed = true; |
383 |
< |
ex.printStackTrace(); |
384 |
< |
fail("Unexpected exception: " + ex); |
381 |
> |
public void threadUnexpectedException(Throwable t) { |
382 |
> |
threadRecordFailure(t); |
383 |
> |
t.printStackTrace(); |
384 |
> |
if (t instanceof RuntimeException) |
385 |
> |
throw (RuntimeException) t; |
386 |
> |
else if (t instanceof Error) |
387 |
> |
throw (Error) t; |
388 |
> |
else { |
389 |
> |
AssertionFailedError afe = |
390 |
> |
new AssertionFailedError("unexpected exception: " + t); |
391 |
> |
t.initCause(t); |
392 |
> |
throw afe; |
393 |
> |
} |
394 |
|
} |
395 |
|
|
396 |
|
/** |
397 |
< |
* Wait out termination of a thread pool or fail doing so |
397 |
> |
* Waits out termination of a thread pool or fails doing so. |
398 |
|
*/ |
399 |
|
public void joinPool(ExecutorService exec) { |
400 |
|
try { |
401 |
|
exec.shutdown(); |
402 |
< |
assertTrue(exec.awaitTermination(LONG_DELAY_MS, MILLISECONDS)); |
402 |
> |
assertTrue("ExecutorService did not terminate in a timely manner", |
403 |
> |
exec.awaitTermination(LONG_DELAY_MS, MILLISECONDS)); |
404 |
|
} catch (SecurityException ok) { |
405 |
|
// Allowed in case test doesn't have privs |
406 |
|
} catch (InterruptedException ie) { |
410 |
|
|
411 |
|
|
412 |
|
/** |
413 |
< |
* fail with message "should throw exception" |
413 |
> |
* Fails with message "should throw exception". |
414 |
|
*/ |
415 |
|
public void shouldThrow() { |
416 |
|
fail("Should throw exception"); |
417 |
|
} |
418 |
|
|
419 |
|
/** |
420 |
< |
* fail with message "should throw " + exceptionName |
420 |
> |
* Fails with message "should throw " + exceptionName. |
421 |
|
*/ |
422 |
|
public void shouldThrow(String exceptionName) { |
423 |
|
fail("Should throw " + exceptionName); |
424 |
|
} |
425 |
|
|
426 |
|
/** |
360 |
– |
* fail with message "Unexpected exception" |
361 |
– |
*/ |
362 |
– |
public void unexpectedException() { |
363 |
– |
fail("Unexpected exception"); |
364 |
– |
} |
365 |
– |
|
366 |
– |
/** |
367 |
– |
* fail with message "Unexpected exception", with argument |
368 |
– |
*/ |
369 |
– |
public void unexpectedException(Throwable ex) { |
370 |
– |
ex.printStackTrace(); |
371 |
– |
fail("Unexpected exception: " + ex); |
372 |
– |
} |
373 |
– |
|
374 |
– |
|
375 |
– |
/** |
427 |
|
* The number of elements to place in collections, arrays, etc. |
428 |
|
*/ |
429 |
|
public static final int SIZE = 20; |
544 |
|
} |
545 |
|
|
546 |
|
/** |
547 |
< |
* Returns a new started Thread running the given runnable. |
547 |
> |
* Returns a new started daemon Thread running the given runnable. |
548 |
|
*/ |
549 |
|
Thread newStartedThread(Runnable runnable) { |
550 |
|
Thread t = new Thread(runnable); |
551 |
+ |
t.setDaemon(true); |
552 |
|
t.start(); |
553 |
|
return t; |
554 |
|
} |
629 |
|
return realCall(); |
630 |
|
} catch (Throwable t) { |
631 |
|
threadUnexpectedException(t); |
632 |
+ |
return null; |
633 |
|
} |
581 |
– |
return null; |
634 |
|
} |
635 |
|
} |
636 |
|
|
637 |
< |
public abstract class CheckedInterruptedCallable<T> implements Callable<T> { |
637 |
> |
public abstract class CheckedInterruptedCallable<T> |
638 |
> |
implements Callable<T> { |
639 |
|
protected abstract T realCall() throws Throwable; |
640 |
|
|
641 |
|
public final T call() { |
716 |
|
} |
717 |
|
} |
718 |
|
|
666 |
– |
public class SmallInterruptedRunnable extends CheckedInterruptedRunnable { |
667 |
– |
protected void realRun() throws InterruptedException { |
668 |
– |
Thread.sleep(SMALL_DELAY_MS); |
669 |
– |
} |
670 |
– |
} |
671 |
– |
|
719 |
|
public class MediumRunnable extends CheckedRunnable { |
720 |
|
protected void realRun() throws Throwable { |
721 |
|
Thread.sleep(MEDIUM_DELAY_MS); |
801 |
|
} |
802 |
|
} |
803 |
|
|
804 |
+ |
/** |
805 |
+ |
* Analog of CheckedRunnable for RecursiveAction |
806 |
+ |
*/ |
807 |
+ |
public abstract class CheckedRecursiveAction extends RecursiveAction { |
808 |
+ |
protected abstract void realCompute() throws Throwable; |
809 |
+ |
|
810 |
+ |
public final void compute() { |
811 |
+ |
try { |
812 |
+ |
realCompute(); |
813 |
+ |
} catch (Throwable t) { |
814 |
+ |
threadUnexpectedException(t); |
815 |
+ |
} |
816 |
+ |
} |
817 |
+ |
} |
818 |
+ |
|
819 |
+ |
/** |
820 |
+ |
* Analog of CheckedCallable for RecursiveTask |
821 |
+ |
*/ |
822 |
+ |
public abstract class CheckedRecursiveTask<T> extends RecursiveTask<T> { |
823 |
+ |
protected abstract T realCompute() throws Throwable; |
824 |
+ |
|
825 |
+ |
public final T compute() { |
826 |
+ |
try { |
827 |
+ |
return realCompute(); |
828 |
+ |
} catch (Throwable t) { |
829 |
+ |
threadUnexpectedException(t); |
830 |
+ |
return null; |
831 |
+ |
} |
832 |
+ |
} |
833 |
+ |
} |
834 |
|
|
835 |
|
/** |
836 |
|
* For use as RejectedExecutionHandler in constructors |