ptolemy.actor.lib
Class TestExceptionHandler

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.InstantiableNamedObj
          extended by ptolemy.kernel.Entity
              extended by ptolemy.kernel.ComponentEntity
                  extended by ptolemy.actor.AtomicActor
                      extended by ptolemy.actor.TypedAtomicActor
                          extended by ptolemy.actor.lib.TestExceptionHandler
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TypedActor, Changeable, Debuggable, DebugListener, Derivable, ExceptionHandler, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

public class TestExceptionHandler
extends TypedAtomicActor
implements ExceptionHandler

This actor tests for exceptions that are expected to occur when running a test model. When an exception is thrown by the model, this actor is invoked. It has two working modes, training mode and non-training mode. If in training mode, this actor handles an exception by recording the exception message. If not in training mode, this actor first compares the previously stored (assumed correct) message to the exception message and then throws an exception if the two messages are not the same. Also, if a test runs to completion without throwing an exception, this actor throws an exception in its wrapup() method. An exception is expected.

Since:
Ptolemy II 5.2
Version:
$Id: TestExceptionHandler.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Haiyang Zheng
See Also:
Serialized Form
Accepted Rating:
Yellow (hyzheng)
Proposed Rating:
Yellow (hyzheng)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
 
Field Summary
private  boolean _invoked
           
 StringParameter correctExceptionMessage
          The correct exception message to be compared against.
static java.lang.String TRAINING_MODE_ERROR_MESSAGE
          Exception message that is used if we are running under the nightly build and the trainingMode parameter is true.
 SharedParameter trainingMode
          If true, then collect the exception message and set the correctExceptionMessage parameter with the content of the exception.
 
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
TestExceptionHandler(CompositeEntity container, java.lang.String name)
          Create a new actor in the specified container with the specified name.
 
Method Summary
 boolean handleException(NamedObj context, java.lang.Throwable exception)
          Handle an exception thrown in a test.
static boolean isRunningNightlyBuild()
          If the trainingMode parameter is true and the model is being run as part of the test suite, then return true.
 void wrapup()
          Call the super.wrapup() method.
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, _fireAt, _fireAt, attributeTypeChanged, clone, newPort, typeConstraintList, typeConstraints
 
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, addActorFiringListener, addInitializable, clone, connectionsChanged, createReceivers, declareDelayDependency, fire, getCausalityInterface, getDirector, getExecutiveDirector, getManager, initialize, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, postfire, prefire, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
fire, isFireFunctional, isStrict, iterate, postfire, prefire, stop, stopFire, terminate
 
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, initialize, preinitialize, removeInitializable
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 

Field Detail

trainingMode

public SharedParameter trainingMode
If true, then collect the exception message and set the correctExceptionMessage parameter with the content of the exception. This parameter is a boolean, and it defaults to false. It is a shared parameter, meaning that changing it for any one instance in a model will change it for all instances in the model.


correctExceptionMessage

public StringParameter correctExceptionMessage
The correct exception message to be compared against.


TRAINING_MODE_ERROR_MESSAGE

public static final java.lang.String TRAINING_MODE_ERROR_MESSAGE
Exception message that is used if we are running under the nightly build and the trainingMode parameter is true.

See Also:
Constant Field Values

_invoked

private boolean _invoked
Constructor Detail

TestExceptionHandler

public TestExceptionHandler(CompositeEntity container,
                            java.lang.String name)
                     throws NameDuplicationException,
                            IllegalActionException
Create a new actor in the specified container with the specified name. The name must be unique within the container or an exception is thrown. The container argument must not be null, or a NullPointerException will be thrown.

Parameters:
container - The container.
name - The name of this actor within the container.
Throws:
IllegalActionException - If this actor cannot be contained by the proposed container (see the setContainer() method).
NameDuplicationException - If the name coincides with an entity already in the container.
Method Detail

handleException

public boolean handleException(NamedObj context,
                               java.lang.Throwable exception)
                        throws IllegalActionException
Handle an exception thrown in a test. If in training mode, simply record the exception message. If not in training mode, first compare the stored good message against the exception message. If they are the same, do nothing. Otherwise, throw the exception again.

Specified by:
handleException in interface ExceptionHandler
Parameters:
context - The object in which the error occurred.
exception - The exception to be handled.
Returns:
True if the exception message is the same as the saved message.
Throws:
IllegalActionException - If cannot get a valid token from the traningMode parameter or the exception message is not the same as the stored message.

isRunningNightlyBuild

public static boolean isRunningNightlyBuild()
If the trainingMode parameter is true and the model is being run as part of the test suite, then return true. This method merely checks to see if "ptolemy.ptII.isRunningNightlyBuild" property exists and is not empty. To run the test suite in the Nightly Build mode, use
  make nightly
  

Returns:
True if the nightly build is running.

wrapup

public void wrapup()
            throws IllegalActionException
Call the super.wrapup() method. Check whether this actor has been invoked to handle exceptions. If not, throw an exception. Otherwise, do nothing.

Specified by:
wrapup in interface Initializable
Overrides:
wrapup in class AtomicActor
Throws:
IllegalActionException - If this actor has not been invoked to handle exceptions.