|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.qpid.junit.concurrency.ThreadTestCoordinator
public class ThreadTestCoordinator
ThreadTestCoordinator provides an array of binary latches that allows threads to wait for other threads or to send
them a signal that allows them to continue running or to wait for another thread to signal them. The binary latch
array is always a square array, allowing one latch from and to every thread. Upon accepting an allow signal from one
sender the latches for all senders for a are cleared. This class is always used in conjunction with
TestRunnable
for writing concurrent test code that coordinates multi-threaded activity in order to reproduce
concurrency bugs.
Responsibilities | Collaborations |
---|---|
Accept test threads to coordinate. | |
Allow test threads to send 'allow to continue' signals. | |
Allow test threads to wait on this coordinator for 'allow to continue' signals. | |
Report error messages from test threads. | |
Report exceptions from test threads. | |
Provide method to wait until all test threads have completed. |
Constructor Summary | |
---|---|
ThreadTestCoordinator(int numThreads)
Creates a new test thread coordinator. |
|
ThreadTestCoordinator(int numThreads,
ThreadFactory threadFactory)
Creates a new test thread coordinator with a specific thread factory. |
Method Summary | |
---|---|
void |
addTestThread(TestRunnable runnable,
int id)
Adds a thread to this coordinator and assigns an id to it. |
(package private) boolean |
consumeAllowEvent(int[] threads,
boolean otherWaitIsAllow,
int callerId,
TestRunnable caller)
Consumes an 'allow to continue' from one of the specified threads or waits until one is available or in some cases if one of the specified threads is blocked elsewhere to accept that as an 'allow to continue' event. |
Collection<Exception> |
getExceptions()
Reports any accumulated exceptions from the test threads run methods. |
String |
joinAndRetrieveMessages()
Waits until all the test threads have completed and returns any accumulated error messages from them. |
(package private) void |
produceAllowEvents(int[] threads,
int callerId,
TestRunnable caller)
Creates a set of 'allow to continue' events on the event queues of the specified threads. |
void |
run()
Starts all the coordinated threads running. |
void |
setDeadlockTimeout(long millis)
Sets a timeout to break out of potential deadlocks. |
String |
toString()
Pretty prints the state of the thread test coordinator, for debugging purposes. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ThreadTestCoordinator(int numThreads)
numThreads
- The number of threads to run.public ThreadTestCoordinator(int numThreads, ThreadFactory threadFactory)
numThreads
- The number of threads to run.threadFactory
- The factory to use to create the test threads.Method Detail |
---|
public void addTestThread(TestRunnable runnable, int id)
runnable
- The test thread.id
- The explicit id to assign to the test thread.public void run()
public String joinAndRetrieveMessages()
public Collection<Exception> getExceptions()
joinAndRetrieveMessages()
.
public void setDeadlockTimeout(long millis)
millis
- The minimum time to allow to pass before breaking out of any potential deadlocks.void produceAllowEvents(int[] threads, int callerId, TestRunnable caller)
threads
- The set of threads to allow to continue.callerId
- The explicit id of the calling test thread.caller
- The calling test thread.boolean consumeAllowEvent(int[] threads, boolean otherWaitIsAllow, int callerId, TestRunnable caller)
threads
- The set of threads to accept an allow to continue event from.otherWaitIsAllow
- Whether or not to accept threads being blocked elsewhere as permission to continue.callerId
- The explicit id of the calling test thread.caller
- The calling test thread.
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |