org.mule.tck.concurrency
Class TestingThread
java.lang.Object
java.lang.Thread
org.mule.tck.concurrency.TestingThread
- All Implemented Interfaces:
- Runnable
public abstract class TestingThread
- extends Thread
- implements Runnable
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.
Method Summary |
void |
await()
Block until the thread completes its doRun() method. |
protected abstract void |
doRun()
|
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, clone, 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 |
AWAIT_TIMEOUT
public static final long AWAIT_TIMEOUT
- See Also:
- Constant Field Values
TestingThread
public TestingThread()
run
public final void run()
- Executes the doRun() method and stores any exception which occurred to be
returned at a later time.
- Specified by:
run
in interface Runnable
- Overrides:
run
in class Thread
doRun
protected abstract void doRun()
throws Throwable
- Throws:
Throwable
await
public void await()
throws InterruptedException
- Block until the thread completes its doRun() method.
- Throws:
InterruptedException
getException
public Throwable getException()
- Returns:
- any exception thrown by the doRun() method, including failed assertions
Copyright © 2003-2014 MuleSoft, Inc.. All Rights Reserved.