jsr166testcase.java
来自「SRI international 发布的OAA框架软件」· Java 代码 · 共 583 行 · 第 1/2 页
JAVA
583 行
/**
* threadFail with message "Unexpected exception"
*/
public void threadUnexpectedException() {
threadFailed = true;
fail("Unexpected exception");
}
/**
* Wait out termination of a thread pool or fail doing so
*/
public void joinPool(ExecutorService exec) {
try {
exec.shutdown();
assertTrue(exec.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
} catch(SecurityException ok) {
// Allowed in case test doesn't have privs
} catch(InterruptedException ie) {
fail("Unexpected exception");
}
}
/**
* fail with message "should throw exception"
*/
public void shouldThrow() {
fail("Should throw exception");
}
/**
* fail with message "Unexpected exception"
*/
public void unexpectedException() {
fail("Unexpected exception");
}
/**
* The number of elements to place in collections, arrays, etc.
*/
static final int SIZE = 20;
// Some convenient Integer constants
static final Integer zero = new Integer(0);
static final Integer one = new Integer(1);
static final Integer two = new Integer(2);
static final Integer three = new Integer(3);
static final Integer four = new Integer(4);
static final Integer five = new Integer(5);
static final Integer six = new Integer(6);
static final Integer seven = new Integer(7);
static final Integer eight = new Integer(8);
static final Integer nine = new Integer(9);
static final Integer m1 = new Integer(-1);
static final Integer m2 = new Integer(-2);
static final Integer m3 = new Integer(-3);
static final Integer m4 = new Integer(-4);
static final Integer m5 = new Integer(-5);
static final Integer m10 = new Integer(-10);
/**
* A security policy where new permissions can be dynamically added
* or all cleared.
*/
static class AdjustablePolicy extends java.security.Policy {
Permissions perms = new Permissions();
AdjustablePolicy() { }
void addPermission(Permission perm) { perms.add(perm); }
void clearPermissions() { perms = new Permissions(); }
public PermissionCollection getPermissions(CodeSource cs) {
return perms;
}
public PermissionCollection getPermissions(ProtectionDomain pd) {
return perms;
}
public boolean implies(ProtectionDomain pd, Permission p) {
return perms.implies(p);
}
public void refresh() {}
}
// Some convenient Runnable classes
static class NoOpRunnable implements Runnable {
public void run() {}
}
static class NoOpCallable implements Callable {
public Object call() { return Boolean.TRUE; }
}
static final String TEST_STRING = "a test string";
static class StringTask implements Callable {
public Object call() { return TEST_STRING; }
}
static class NPETask implements Callable {
public Object call() { throw new NullPointerException(); }
}
static class CallableOne implements Callable {
public Object call() { return one; }
}
class ShortRunnable implements Runnable {
public void run() {
try {
Thread.sleep(SHORT_DELAY_MS);
}
catch(Exception e) {
threadUnexpectedException();
}
}
}
class ShortInterruptedRunnable implements Runnable {
public void run() {
try {
Thread.sleep(SHORT_DELAY_MS);
threadShouldThrow();
}
catch(InterruptedException success) {
}
}
}
class SmallRunnable implements Runnable {
public void run() {
try {
Thread.sleep(SMALL_DELAY_MS);
}
catch(Exception e) {
threadUnexpectedException();
}
}
}
class SmallPossiblyInterruptedRunnable implements Runnable {
public void run() {
try {
Thread.sleep(SMALL_DELAY_MS);
}
catch(Exception e) {
}
}
}
class SmallCallable implements Callable {
public Object call() {
try {
Thread.sleep(SMALL_DELAY_MS);
}
catch(Exception e) {
threadUnexpectedException();
}
return Boolean.TRUE;
}
}
class SmallInterruptedRunnable implements Runnable {
public void run() {
try {
Thread.sleep(SMALL_DELAY_MS);
threadShouldThrow();
}
catch(InterruptedException success) {
}
}
}
class MediumRunnable implements Runnable {
public void run() {
try {
Thread.sleep(MEDIUM_DELAY_MS);
}
catch(Exception e) {
threadUnexpectedException();
}
}
}
class MediumInterruptedRunnable implements Runnable {
public void run() {
try {
Thread.sleep(MEDIUM_DELAY_MS);
threadShouldThrow();
}
catch(InterruptedException success) {
}
}
}
class MediumPossiblyInterruptedRunnable implements Runnable {
public void run() {
try {
Thread.sleep(MEDIUM_DELAY_MS);
}
catch(InterruptedException success) {
}
}
}
class LongPossiblyInterruptedRunnable implements Runnable {
public void run() {
try {
Thread.sleep(LONG_DELAY_MS);
}
catch(InterruptedException success) {
}
}
}
/**
* For use as ThreadFactory in constructors
*/
static class SimpleThreadFactory implements ThreadFactory{
public Thread newThread(Runnable r){
return new Thread(r);
}
}
static class TrackedShortRunnable implements Runnable {
volatile boolean done = false;
public void run() {
try {
Thread.sleep(SMALL_DELAY_MS);
done = true;
} catch(Exception e){
}
}
}
static class TrackedMediumRunnable implements Runnable {
volatile boolean done = false;
public void run() {
try {
Thread.sleep(MEDIUM_DELAY_MS);
done = true;
} catch(Exception e){
}
}
}
static class TrackedLongRunnable implements Runnable {
volatile boolean done = false;
public void run() {
try {
Thread.sleep(LONG_DELAY_MS);
done = true;
} catch(Exception e){
}
}
}
static class TrackedNoOpRunnable implements Runnable {
volatile boolean done = false;
public void run() {
done = true;
}
}
static class TrackedCallable implements Callable {
volatile boolean done = false;
public Object call() {
try {
Thread.sleep(SMALL_DELAY_MS);
done = true;
} catch(Exception e){
}
return Boolean.TRUE;
}
}
/**
* For use as RejectedExecutionHandler in constructors
*/
static class NoOpREHandler implements RejectedExecutionHandler{
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor){}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?