|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Thread
org.mule.tck.concurrency.TestingThread
public abstract class TestingThread
This class is very useful for test cases which need to make assertions
concurrently in different threads. Usage is as follows:
public void testConcurrency()
{
TestingThread thread = new TestingThread()
{
protected void doRun() throws Throwable
{
// Wait a few seconds for somethingElse to begin
Thread.sleep(3000);
assertTrue(somethingElse.isRunning());
assertEquals(3, somethingElse.counter);
}
};
thread.start();
// This will block the main test thread
runSomething("big long task");
assertEquals("peachy", something.getResult());
assertFalse(something.isOutOfControl());
// Verify that no exceptions occurred meanwhile in the TestingThread
thread.await();
if (thread.getException() != null)
{
fail(thread.getException().getMessage());
}
}
Both the TestingThread and the main thread will run in parallel,
therefore assertions can be made on "somethingElse" while the call
to runSomething() is blocking the main thread of the TestCase.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.lang.Thread |
---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
Field Summary | |
---|---|
static long |
AWAIT_TIMEOUT
|
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
---|---|
TestingThread()
|
Method Summary | |
---|---|
void |
await()
Block until the thread completes its doRun() method. |
protected abstract void |
doRun()
|
java.lang.Throwable |
getException()
|
void |
run()
Executes the doRun() method and stores any exception which occurred to be returned at a later time. |
Methods inherited from class java.lang.Thread |
---|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final long AWAIT_TIMEOUT
Constructor Detail |
---|
public TestingThread()
Method Detail |
---|
public final void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
protected abstract void doRun() throws java.lang.Throwable
java.lang.Throwable
public void await() throws java.lang.InterruptedException
java.lang.InterruptedException
public java.lang.Throwable getException()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |