Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## 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.

Nested Class Summary

Nested classes/interfaces inherited from class java.lang.Thread
`Thread.State, 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()`
`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

### AWAIT_TIMEOUT

    public static final long AWAIT_TIMEOUT

See Also:
  Constant Field Values

Constructor Detail

### TestingThread

    public TestingThread()

Method Detail

### 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

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2003-2010 MuleSoft, Inc.. All Rights Reserved.