edu.rice.cs.cunit.concJUnit
Class TestThreadGroup

java.lang.Object
  extended by java.lang.ThreadGroup
      extended by edu.rice.cs.cunit.concJUnit.TestThreadGroup
All Implemented Interfaces:
Thread.UncaughtExceptionHandler

public class TestThreadGroup
extends ThreadGroup

Test thread group.


Nested Class Summary
static class TestThreadGroup.AwtHandler
          "sun.awt.exception.handler" handler.
static class TestThreadGroup.DummyHandler
          "sun.awt.exception.handler" dummy handler.
static class TestThreadGroup.LuckyWarningsDisabledException
          Exception indicating that "lucky" warnings can't be used.
 
Constructor Summary
TestThreadGroup()
          Create a new test thread group.
 
Method Summary
static Thread[] checkThreadsAlive(ThreadGroup tg, Thread t)
          Check if there are still some threads alive, i.e.
static HashSet<Thread> collectThreads(Thread t, String fieldName)
           
static void dumpThreads(String fieldName)
          Print thread set with the specified name.
static void extendStackTrace(Throwable t, Thread thread)
          Extend the stack trace in the throwable by the start stack trace of the thread.
static TestThreadGroup getCurrentThreadGroup()
          Get the current thread group so the AWT handler can use it.
 Object getEvent()
          Get the event that gets notified when the test is done.
static String getThreadStartStackTrace(Thread t)
          Return the start stack trace for the specified thread.
 Throwable getUncaughtException()
          Get the uncaught exception, or null if none.
 Thread getUncaughtThread()
          Get the thread that threw the uncaught exception, or null if none.
 boolean hasBeenNotified()
          Returns true if the event has already been notified.
static boolean isCheckJoinEnabled()
           
static boolean isCheckLuckyEnabled()
           
static boolean isCheckThreadsEnabled()
           
 void notifyEvent()
          Signal that the event has occurred.
static void setCurrentThreadGroup(TestThreadGroup tg)
          Set the current thread group so the AWT handler can use it.
 void setNotified()
          Sets the notified flag to true.
static boolean shouldIgnoreThread(Thread at)
          Return true if the specified thread should be ignored because it is a system thread or a daemon.
 void uncaughtException(Thread t, Throwable e)
          Catch and register an uncaught exception.
 void waitForEvent()
          Wait for the event to occur, if it hasn't already occurred.
 
Methods inherited from class java.lang.ThreadGroup
activeCount, activeGroupCount, allowThreadSuspension, checkAccess, destroy, enumerate, enumerate, enumerate, enumerate, getMaxPriority, getName, getParent, interrupt, isDaemon, isDestroyed, list, parentOf, resume, setDaemon, setMaxPriority, stop, suspend, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TestThreadGroup

public TestThreadGroup()
Create a new test thread group.

Method Detail

uncaughtException

public void uncaughtException(Thread t,
                              Throwable e)
Catch and register an uncaught exception. Also notify the event that the test is done.

Specified by:
uncaughtException in interface Thread.UncaughtExceptionHandler
Overrides:
uncaughtException in class ThreadGroup
Parameters:
t - thread
e - exception

getUncaughtException

public Throwable getUncaughtException()
Get the uncaught exception, or null if none.

Returns:
uncaught exception, or null if none

getUncaughtThread

public Thread getUncaughtThread()
Get the thread that threw the uncaught exception, or null if none.

Returns:
thread that threw uncaught exception, or null if none

getEvent

public Object getEvent()
Get the event that gets notified when the test is done.

Returns:
event that gets notified

hasBeenNotified

public boolean hasBeenNotified()
Returns true if the event has already been notified.

Returns:
true if notified

setNotified

public void setNotified()
Sets the notified flag to true.


waitForEvent

public void waitForEvent()
                  throws InterruptedException
Wait for the event to occur, if it hasn't already occurred.

Throws:
InterruptedException

notifyEvent

public void notifyEvent()
Signal that the event has occurred.


checkThreadsAlive

public static Thread[] checkThreadsAlive(ThreadGroup tg,
                                         Thread t)
Check if there are still some threads alive, i.e. ones that have not been joined yet.

Parameters:
tg - thread group the threads are in
t - main test thread, i.e. the thread that may have spawned others
Returns:
list of living threads

shouldIgnoreThread

public static boolean shouldIgnoreThread(Thread at)
Return true if the specified thread should be ignored because it is a system thread or a daemon.

Parameters:
at - thread
Returns:
true if thread should be ignored

collectThreads

public static HashSet<Thread> collectThreads(Thread t,
                                             String fieldName)
                                      throws TestThreadGroup.LuckyWarningsDisabledException
Throws:
TestThreadGroup.LuckyWarningsDisabledException

dumpThreads

public static void dumpThreads(String fieldName)
Print thread set with the specified name.

Parameters:
fieldName - name of the thread set

getThreadStartStackTrace

public static String getThreadStartStackTrace(Thread t)
                                       throws TestThreadGroup.LuckyWarningsDisabledException
Return the start stack trace for the specified thread.

Parameters:
t - thread
Returns:
start stack trace
Throws:
TestThreadGroup.LuckyWarningsDisabledException

extendStackTrace

public static void extendStackTrace(Throwable t,
                                    Thread thread)
                             throws TestThreadGroup.LuckyWarningsDisabledException
Extend the stack trace in the throwable by the start stack trace of the thread.

Parameters:
t - throwable whose stack trace should be extended
thread - thread whose start stack trace should be appended to the throwable's stack trace
Throws:
TestThreadGroup.LuckyWarningsDisabledException

setCurrentThreadGroup

public static void setCurrentThreadGroup(TestThreadGroup tg)
Set the current thread group so the AWT handler can use it.

Parameters:
tg - thread group

getCurrentThreadGroup

public static TestThreadGroup getCurrentThreadGroup()
Get the current thread group so the AWT handler can use it.

Returns:
current thread group

isCheckThreadsEnabled

public static boolean isCheckThreadsEnabled()
Returns:
false if check threads is disabled per Java property.

isCheckJoinEnabled

public static boolean isCheckJoinEnabled()
Returns:
false if check join is disabled per Java property.

isCheckLuckyEnabled

public static boolean isCheckLuckyEnabled()
Returns:
false if check lucky is disabled per Java property.