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 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 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.util.List<java.lang.Thread> |
getThreadsInGroup(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
@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
Statement
Throwable
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.util.List<java.lang.Thread> getThreadsInGroup(java.lang.ThreadGroup group)
group
- The thread group.private long cpuTime(java.lang.Thread thr)
thr
- The thread to query.thr
, or 0 if it cannot be determined.