90 |
|
/** |
91 |
|
* Runs all JSR166 unit tests using junit.textui.TestRunner |
92 |
|
*/ |
93 |
< |
public static void main (String[] args) { |
93 |
> |
public static void main(String[] args) { |
94 |
|
int iters = 1; |
95 |
|
if (args.length > 0) |
96 |
|
iters = Integer.parseInt(args[0]); |
97 |
|
Test s = suite(); |
98 |
|
for (int i = 0; i < iters; ++i) { |
99 |
< |
junit.textui.TestRunner.run (s); |
99 |
> |
junit.textui.TestRunner.run(s); |
100 |
|
System.gc(); |
101 |
|
System.runFinalization(); |
102 |
|
} |
106 |
|
/** |
107 |
|
* Collects all JSR166 unit tests as one suite |
108 |
|
*/ |
109 |
< |
public static Test suite ( ) { |
109 |
> |
public static Test suite() { |
110 |
|
TestSuite suite = new TestSuite("JSR166 Unit Tests"); |
111 |
|
|
112 |
|
suite.addTest(new TestSuite(ForkJoinPoolTest.class)); |
195 |
|
/** |
196 |
|
* Sets delays as multiples of SHORT_DELAY. |
197 |
|
*/ |
198 |
< |
protected void setDelays() { |
198 |
> |
protected void setDelays() { |
199 |
|
SHORT_DELAY_MS = getShortDelay(); |
200 |
|
SMALL_DELAY_MS = SHORT_DELAY_MS * 5; |
201 |
|
MEDIUM_DELAY_MS = SHORT_DELAY_MS * 10; |
294 |
|
} |
295 |
|
|
296 |
|
/** |
297 |
+ |
* 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 |
|
* threadFail with message "Unexpected exception" |
306 |
|
*/ |
307 |
|
public void threadUnexpectedException() { |
341 |
|
} |
342 |
|
|
343 |
|
/** |
344 |
+ |
* fail with message "should throw " + exceptionName |
345 |
+ |
*/ |
346 |
+ |
public void shouldThrow(String exceptionName) { |
347 |
+ |
fail("Should throw " + exceptionName); |
348 |
+ |
} |
349 |
+ |
|
350 |
+ |
/** |
351 |
|
* fail with message "Unexpected exception" |
352 |
|
*/ |
353 |
|
public void unexpectedException() { |
398 |
|
AdjustablePolicy() { } |
399 |
|
void addPermission(Permission perm) { perms.add(perm); } |
400 |
|
void clearPermissions() { perms = new Permissions(); } |
401 |
< |
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() {} |
401 |
> |
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 |
|
} |
412 |
|
|
413 |
|
/** |
444 |
|
} |
445 |
|
} |
446 |
|
|
447 |
+ |
abstract class RunnableShouldThrow implements Runnable { |
448 |
+ |
abstract void realRun() throws Throwable; |
449 |
+ |
|
450 |
+ |
final Class<?> exceptionClass; |
451 |
+ |
|
452 |
+ |
<T extends Throwable> RunnableShouldThrow(Class<T> exceptionClass) { |
453 |
+ |
this.exceptionClass = exceptionClass; |
454 |
+ |
} |
455 |
+ |
|
456 |
+ |
public final void run() { |
457 |
+ |
try { |
458 |
+ |
realRun(); |
459 |
+ |
threadShouldThrow(exceptionClass.getSimpleName()); |
460 |
+ |
} catch (InterruptedException success) { |
461 |
+ |
} catch (Throwable t) { |
462 |
+ |
if (! exceptionClass.isInstance(t)) |
463 |
+ |
threadUnexpectedException(t); |
464 |
+ |
} |
465 |
+ |
} |
466 |
+ |
} |
467 |
+ |
|
468 |
+ |
abstract class ThreadShouldThrow extends Thread { |
469 |
+ |
abstract void realRun() throws Throwable; |
470 |
+ |
|
471 |
+ |
final Class<?> exceptionClass; |
472 |
+ |
|
473 |
+ |
<T extends Throwable> ThreadShouldThrow(Class<T> exceptionClass) { |
474 |
+ |
this.exceptionClass = exceptionClass; |
475 |
+ |
} |
476 |
+ |
|
477 |
+ |
public final void run() { |
478 |
+ |
try { |
479 |
+ |
realRun(); |
480 |
+ |
threadShouldThrow(exceptionClass.getSimpleName()); |
481 |
+ |
} catch (InterruptedException success) { |
482 |
+ |
} catch (Throwable t) { |
483 |
+ |
if (! exceptionClass.isInstance(t)) |
484 |
+ |
threadUnexpectedException(t); |
485 |
+ |
} |
486 |
+ |
} |
487 |
+ |
} |
488 |
+ |
|
489 |
|
abstract class CheckedInterruptedRunnable implements Runnable { |
490 |
|
abstract void realRun() throws Throwable; |
491 |
|
|
492 |
|
public final void run() { |
493 |
|
try { |
494 |
|
realRun(); |
495 |
< |
threadShouldThrow(); |
495 |
> |
threadShouldThrow("InterruptedException"); |
496 |
|
} catch (InterruptedException success) { |
497 |
|
} catch (Throwable t) { |
498 |
|
threadUnexpectedException(t); |
508 |
|
return realCall(); |
509 |
|
} catch (Throwable t) { |
510 |
|
threadUnexpectedException(t); |
454 |
– |
return null; |
511 |
|
} |
512 |
+ |
return null; |
513 |
+ |
} |
514 |
+ |
} |
515 |
+ |
|
516 |
+ |
abstract class CheckedInterruptedCallable<T> implements Callable<T> { |
517 |
+ |
abstract T realCall() throws Throwable; |
518 |
+ |
|
519 |
+ |
public final T call() { |
520 |
+ |
try { |
521 |
+ |
T result = realCall(); |
522 |
+ |
threadShouldThrow("InterruptedException"); |
523 |
+ |
return result; |
524 |
+ |
} catch (InterruptedException success) { |
525 |
+ |
} catch (Throwable t) { |
526 |
+ |
threadUnexpectedException(t); |
527 |
+ |
} |
528 |
+ |
return null; |
529 |
|
} |
530 |
|
} |
531 |
|
|