Class FailOnTimeout
java.lang.Object
org.junit.runners.model.Statement
org.junit.internal.runners.statements.FailOnTimeout
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
FailOnTimeout
(FailOnTimeout.Builder builder, Statement statement) FailOnTimeout
(Statement statement, long timeoutMillis) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionstatic FailOnTimeout.Builder
builder()
Returns a new builder for building an instance.private long
Returns the CPU time used by a thread, if possible.private Exception
createTimeoutException
(Thread thread) void
evaluate()
Run the action, throwing aThrowable
if anything goes wrong.private Throwable
getResult
(FutureTask<Throwable> task, 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, ornull
if the test passed.private StackTraceElement[]
getStackTrace
(Thread thread) Retrieves the stack trace for a given thread.private Thread
getStuckThread
(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).getThreadsInGroup
(ThreadGroup group) Returns all active threads belonging to a thread group.private ThreadGroup
-
Field Details
-
originalStatement
-
timeUnit
-
timeout
private final long timeout -
lookForStuckThread
private final boolean lookForStuckThread
-
-
Constructor Details
-
FailOnTimeout
Deprecated.usebuilder()
instead.Creates an instance wrapping the given statement with the given timeout in milliseconds.- Parameters:
statement
- the statement to wraptimeoutMillis
- the timeout in milliseconds
-
FailOnTimeout
-
-
Method Details
-
builder
Returns a new builder for building an instance.- Since:
- 4.12
-
evaluate
Description copied from class:Statement
Run the action, throwing aThrowable
if anything goes wrong. -
threadGroupForNewThread
-
getResult
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, ornull
if the test passed. -
createTimeoutException
-
getStackTrace
Retrieves the stack trace for a given thread.- Parameters:
thread
- The thread whose stack is to be retrieved.- Returns:
- The stack trace; returns a zero-length array if the thread has terminated or the stack cannot be retrieved for some other reason.
-
getStuckThread
Determines whether the test appears to be stuck in some thread other than the "main thread" (the one created to run the test). This feature is experimental. Behavior may change after the 4.12 release in response to feedback.- Parameters:
mainThread
- The main thread created byevaluate()
- Returns:
- The thread which appears to be causing the problem, if different from
mainThread
, ornull
if the main thread appears to be the problem or if the thread cannot be determined. The return value is never equal tomainThread
.
-
getThreadsInGroup
Returns all active threads belonging to a thread group.- Parameters:
group
- The thread group.- Returns:
- The active threads in the thread group. The result should be a complete list of the active threads at some point in time. Returns an empty list if this cannot be determined, e.g. because new threads are being created at an extremely fast rate.
-
cpuTime
Returns the CPU time used by a thread, if possible.- Parameters:
thr
- The thread to query.- Returns:
- The CPU time used by
thr
, or 0 if it cannot be determined.
-
builder()
instead.