|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectjava.lang.Thread
net.sourceforge.jthreadunit.TestThread
A thread that runs in an endless loop performing actions. A controlling
thread should call the various methods of this class to control the
actions performed, and finally call kill() when there are no
more actions to be performed. Calling Thread.interrupt() will not
kill the thread, but merely reset it to the state of waiting for a command.
That is, if the thread is blocked, Thread.interrupt() will unblock it
and make it ready to respond to performAction(String).
Each action must be implemented in a subclass by a parameterless method with void return type named by prepending do to the capitalized action name. For example, performAction("foo") results in a call to the method with signature public void doFoo().
| Nested Class Summary |
|---|
| Nested classes inherited from class java.lang.Thread |
|---|
Thread.UncaughtExceptionHandler |
| Field Summary |
|---|
| Fields inherited from class java.lang.Thread |
|---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
| Constructor Summary | |
|---|---|
TestThread(ThreadGroup group,
String name)
|
|
| Method Summary | |
|---|---|
void |
actionShouldBlock(String actionName)
Called to indicate that this thread should initiate the named action but expect to block before completing it. |
void |
assertStillBlocked()
Called to indicate that a previously blocked action should still be blocked. |
static void |
checkpoint(String actionName)
Called from arbitrary code to mark the current action as complete and wait for the next action without returning from the first action method. |
void |
completeBlockedAction()
Called to indicate that this thread should finish a previously blocked action. |
void |
completeBlockedActionWithActions(String... actionNames)
Complete one action and perform several more. |
protected void |
expectAction(String actionName)
Called from within an action method to mark the current action as complete and wait for the next action without returning from the first action method. |
void |
kill()
Kill this thread. |
void |
performAction(String actionName)
Called to indicate that this thread should perform the named action completely without blocking. |
void |
performActions(String... actionNames)
Perform several actions. |
void |
run()
|
void |
start()
|
| Methods inherited from class java.lang.Thread |
|---|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, stop, stop, suspend, toString, yield |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public TestThread(ThreadGroup group,
String name)
| Method Detail |
|---|
public void performAction(String actionName)
throws InterruptedException
AssertionFailedError - If this thread blocks before completing the
action.
InterruptedException
public void performActions(String... actionNames)
throws InterruptedException
performAction(String) once for each of the given actions.
This is convenient when the code being tested contains
checkpoint(String) calls.
InterruptedException
public void actionShouldBlock(String actionName)
throws InterruptedException
AssertionFailedError - If this thread completes the action without
blocking.
InterruptedExceptionpublic void completeBlockedAction()
AssertionFailedError - If this thread is still blocked without
having completed the action.
public void completeBlockedActionWithActions(String... actionNames)
throws InterruptedException
completeBlockedAction() once followed by calling
performAction(String) once for each of the given actions.
This is convenient when the code being tested contains
checkpoint(String) calls.
InterruptedExceptionpublic void assertStillBlocked()
AssertionFailedError - If this thread has completed the action
without blocking.
protected void expectAction(String actionName)
throws InterruptedException
InterruptedException
public static void checkpoint(String actionName)
throws InterruptedException
expectAction(String) directly from an
action method, unless the current thread is not a TestThread,
in which case does nothing.
InterruptedExceptionpublic void kill()
Thread.stop().
public void start()
start in class Threadpublic void run()
run in interface Runnablerun in class Thread
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||