public class FailOnTimeout extends Statement
| Modifier and Type | Class and Description |
|---|---|
static class |
FailOnTimeout.Builder
Builder for
FailOnTimeout. |
private class |
FailOnTimeout.CallableStatement |
| Modifier and Type | Field and Description |
|---|---|
private boolean |
lookForStuckThread |
private Statement |
originalStatement |
private java.lang.ThreadGroup |
threadGroup |
private long |
timeout |
private java.util.concurrent.TimeUnit |
timeUnit |
| Modifier | Constructor and Description |
|---|---|
private |
FailOnTimeout(FailOnTimeout.Builder builder,
Statement statement) |
|
FailOnTimeout(Statement statement,
long timeoutMillis)
Deprecated.
use
builder() instead. |
| Modifier and Type | Method and Description |
|---|---|
static FailOnTimeout.Builder |
builder()
Returns a new builder for building an instance.
|
private java.lang.Thread[] |
copyThreads(java.lang.Thread[] threads,
int count)
Returns an array of the first
count Threads in threads. |
private long |
cpuTime(java.lang.Thread thr)
Returns the CPU time used by a thread, if possible.
|
private java.lang.Exception |
createTimeoutException(java.lang.Thread thread) |
void |
evaluate()
Run the action, throwing a
Throwable if anything goes wrong. |
private java.lang.Throwable |
getResult(java.util.concurrent.FutureTask<java.lang.Throwable> task,
java.lang.Thread thread)
Wait for the test task, returning the exception thrown by the test if the
test failed, an exception indicating a timeout if the test timed out, or
null if the test passed. |
private java.lang.StackTraceElement[] |
getStackTrace(java.lang.Thread thread)
Retrieves the stack trace for a given thread.
|
private java.lang.Thread |
getStuckThread(java.lang.Thread mainThread)
Determines whether the test appears to be stuck in some thread other than
the "main thread" (the one created to run the test).
|
private java.lang.Thread[] |
getThreadArray(java.lang.ThreadGroup group)
Returns all active threads belonging to a thread group.
|
private final Statement originalStatement
private final java.util.concurrent.TimeUnit timeUnit
private final long timeout
private final boolean lookForStuckThread
private volatile java.lang.ThreadGroup threadGroup
@Deprecated public FailOnTimeout(Statement statement, long timeoutMillis)
builder() instead.statement - the statement to wraptimeoutMillis - the timeout in millisecondsprivate FailOnTimeout(FailOnTimeout.Builder builder, Statement statement)
public static FailOnTimeout.Builder builder()
public void evaluate()
throws java.lang.Throwable
StatementThrowable if anything goes wrong.private java.lang.Throwable getResult(java.util.concurrent.FutureTask<java.lang.Throwable> task,
java.lang.Thread thread)
null if the test passed.private java.lang.Exception createTimeoutException(java.lang.Thread thread)
private java.lang.StackTraceElement[] getStackTrace(java.lang.Thread thread)
thread - The thread whose stack is to be retrieved.private java.lang.Thread getStuckThread(java.lang.Thread mainThread)
mainThread - The main thread created by evaluate()mainThread, or null if the main thread appears to be the
problem or if the thread cannot be determined. The return value is never equal
to mainThread.private java.lang.Thread[] getThreadArray(java.lang.ThreadGroup group)
group - The thread group.null
if this cannot be determined, e.g. because new threads are being created at an
extremely fast rate.private java.lang.Thread[] copyThreads(java.lang.Thread[] threads,
int count)
count Threads in threads.
(Use instead of Arrays.copyOf to maintain compatibility with Java 1.5.)threads - The source array.count - The maximum length of the result array.threads.private long cpuTime(java.lang.Thread thr)
thr - The thread to query.thr, or 0 if it cannot be determined.