JTR 4.0 API Documentation

jtr.runners
Class AbstractRunnerAncestor

java.lang.Object
  extended by jtr.runners.AbstractRunnerAncestor
All Implemented Interfaces:
java.lang.Runnable, IRunner, IRunnerClean, IRunnerParameterized, IRunnerPooled
Direct Known Subclasses:
AbstractJMSRunner, AbstractRunner, AbstractWsRunner

public abstract class AbstractRunnerAncestor
extends java.lang.Object
implements IRunner

This base abstract class is the ancestor common to every JTR abstract runner. It is not meant to be available to test-suite developers.

Since:
1.1
Version:
4.0
Author:
Francesco Russo (frusso@dev.java.net)

Field Summary
protected  int epoch
           
protected  org.apache.log4j.Logger logger
           
protected  IParamsAssigner paramsAssigner
           
protected  RunnerPool pool
           
 
Constructor Summary
AbstractRunnerAncestor()
           
 
Method Summary
 IRunnerClean clean()
          This method cleans all the configurations/parameters assigned to the current IRunner.
protected  void doRunTest()
          This method is in charge of actually starting the test by calling the user defined test() method over the user-defined runner instances.
 void enrichOutcome(IOutcome outcome)
          This abstract method must be used either when the user needs to enrich the given outcome with a JTR UserObject or in case the default IOutcomeFactory has been replaced with a custom one.
 java.lang.String getDefaultName()
          Get the default name provided by this.getClass().getName()
 EnterpriseConfig getEnterprise()
          Return the enterprise configuration assigned to the current IRunner
 int getEpoch()
          Return the current epoch assigned to the IRunner
 int getFailures()
          Get the number of failures
 int getInstanceCount()
          Get the number of instances that must be active, according to the jtr.xml, during the test-suite.
 java.lang.String getName()
          Return the name of the IRunner
 IOutcomeFactory getOutcomeFactory()
          Get the current IOutcomeTable
 ParametersMap getParameters()
          Return the set of runtime parameters configured for the IRunner
 IParamsAssigner getParamsAssigner()
          Get the IParamsAssigner in charge of assigning parameters to the current IRunner
 RunnerPool getPool()
          Get the pool this IRunner belongs to
 int getRuns()
          Return the number of runs assigned to the IRunner
 long getSleepTime()
          Get the sleep runDuration assigned to this IRunner
 int getSuccesses()
          Get the number of successes.
 TestOutcomeTable getTestOutcomeTable()
          Return the current TestOutcomeTable
protected  void handleFailure(int run, java.lang.Throwable t)
          Whenever an exception is caught during the execution of the test() method of the IRunner interface, the AbstractRunner takes care of instantiating a new IOutcome and of adding it to the current TestOutcomeTable.
Once this steps have been performed, the receiveFailureNotification(Throwable,String)" of the IRunner interface is called.
protected  void initializeTimers()
          Thie method is required to prevent that errors happening before the doRunTest() method is invoked have negative impacts on the computation of the time spent during tests.
 void setEnterprise(EnterpriseConfig enterprise)
          Assign the given enterprise configuration to the current IRunner
 void setEpoch(int epoch)
          Assign the current epoch to the IRunner
 void setInstanceCount(int i)
          Set the number of instances that must be active, according to the jtr.xml, during the test-suite.
 void setName(java.lang.String name)
          Set the name of the IRunner.
 void setOutcomeFactory(IOutcomeFactory outcomeFactory)
          Set the current IOutcomeTable
 void setParameters(ParametersMap params)
          Provides the IRunner with its runtime parameters.
 void setParamsAssigner(IParamsAssigner paramsAssigner)
          Set the IParamsAssigner in charge of assigning parameters to the current IRunner
 IRunnerPooled setPool(RunnerPool pool)
          Set the pool this IRunner will belong to
 void setRuns(int runs)
          Set the number of runs assigned to the IRunner
 void setSleepTime(long sleepTime)
          Get the sleep runDuration assigned to this IRunner
 void setTestCompletionListener(ITestCompletionListener testComplLsnr)
          This method assigns an ITestCompletionListener instance to a runner in CLEAN state.
 void setTestOutcomeTable(TestOutcomeTable testOutcomeTable)
          Set the current TestOutcomeTable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface jtr.runners.IRunner
getCurrentRun, receiveFailureNotification, test
 
Methods inherited from interface jtr.runners.IRunnerPooled
cleanupResources, run
 

Field Detail

epoch

protected int epoch

paramsAssigner

protected IParamsAssigner paramsAssigner

pool

protected RunnerPool pool

logger

protected org.apache.log4j.Logger logger
Constructor Detail

AbstractRunnerAncestor

public AbstractRunnerAncestor()
Method Detail

clean

public IRunnerClean clean()
This method cleans all the configurations/parameters assigned to the current IRunner. It should be overridden by an application-level runner using the delegation pattern for adding the clean up of resources. This method is invoked every time an IRunner implementation completes one of its runs. It is used for reinitializing a runner between two consecutive runs if this is required by the associated assignment policy (i.e. cyclic).
This method is not intended for finalizing "expensive resources": you might want to avoid the reinitialization of a JDBC or JMS connection every time a run completes, maybe because you think it would be too much expensive obtaining it every time.
In such a case you should avoid putting such clean up activity in this method: you should think about using the IRunnerPooled.cleanupResources() method instead.

Returns:
IRunnerClean The same runner in the CLEAN state.
See Also:
IRunnerPooled.cleanupResources()

setEpoch

public void setEpoch(int epoch)
Assign the current epoch to the IRunner

Specified by:
setEpoch in interface IRunnerPooled
Parameters:
epoch - The current epoch

getEpoch

public int getEpoch()
Return the current epoch assigned to the IRunner

Specified by:
getEpoch in interface IRunnerPooled
Returns:
int The current epoch

setName

public void setName(java.lang.String name)
Set the name of the IRunner. This is by default its FQN followed by an increasing integer stating that this is the i-th IRunner of that class.

Specified by:
setName in interface IRunnerClean
Parameters:
name - The name

getName

public java.lang.String getName()
Return the name of the IRunner

Specified by:
getName in interface IRunnerClean
Returns:
String

getDefaultName

public java.lang.String getDefaultName()
Get the default name provided by this.getClass().getName()

Specified by:
getDefaultName in interface IRunnerClean
Returns:
String The default name.

getEnterprise

public EnterpriseConfig getEnterprise()
Return the enterprise configuration assigned to the current IRunner

Specified by:
getEnterprise in interface IRunnerClean
Returns:
EnterpriseConfig The enterprise configuration

setEnterprise

public void setEnterprise(EnterpriseConfig enterprise)
Assign the given enterprise configuration to the current IRunner

Specified by:
setEnterprise in interface IRunnerClean
Parameters:
enterprise - The enterprise configuration

setInstanceCount

public void setInstanceCount(int i)
Set the number of instances that must be active, according to the jtr.xml, during the test-suite.

Specified by:
setInstanceCount in interface IRunnerClean
Parameters:
i - The number of instances

getInstanceCount

public int getInstanceCount()
Get the number of instances that must be active, according to the jtr.xml, during the test-suite.

Specified by:
getInstanceCount in interface IRunnerClean
Returns:
int The number of instances

getRuns

public int getRuns()
Return the number of runs assigned to the IRunner

Specified by:
getRuns in interface IRunnerClean
Returns:
int The number of runs

setRuns

public void setRuns(int runs)
Set the number of runs assigned to the IRunner

Specified by:
setRuns in interface IRunnerClean
Parameters:
runs - The number of runs

getSleepTime

public long getSleepTime()
Get the sleep runDuration assigned to this IRunner

Specified by:
getSleepTime in interface IRunnerClean
Returns:
long The sleep runDuration

setSleepTime

public void setSleepTime(long sleepTime)
Get the sleep runDuration assigned to this IRunner

Specified by:
setSleepTime in interface IRunnerClean
Parameters:
sleepTime - The sleep runDuration

setParameters

public void setParameters(ParametersMap params)
Provides the IRunner with its runtime parameters.

Specified by:
setParameters in interface IRunnerClean
Parameters:
params - The parameters

getParameters

public ParametersMap getParameters()
Return the set of runtime parameters configured for the IRunner

Specified by:
getParameters in interface IRunnerClean
Returns:
ParametersMap

setPool

public IRunnerPooled setPool(RunnerPool pool)
Set the pool this IRunner will belong to

Specified by:
setPool in interface IRunnerParameterized
Parameters:
pool - The pool
Returns:
IRunnerPooled The same runner in its POOLED state

getPool

public RunnerPool getPool()
Get the pool this IRunner belongs to

Specified by:
getPool in interface IRunnerPooled
Returns:
RunnerPool The pool

getParamsAssigner

public IParamsAssigner getParamsAssigner()
Get the IParamsAssigner in charge of assigning parameters to the current IRunner

Specified by:
getParamsAssigner in interface IRunnerClean
Returns:
IParamsAssigner The assigner

setParamsAssigner

public void setParamsAssigner(IParamsAssigner paramsAssigner)
Set the IParamsAssigner in charge of assigning parameters to the current IRunner

Specified by:
setParamsAssigner in interface IRunnerClean
Parameters:
paramsAssigner - IParamsAssigner

getFailures

public int getFailures()
Get the number of failures

Specified by:
getFailures in interface IRunner
Returns:
int The failures

getSuccesses

public int getSuccesses()
Get the number of successes.

Specified by:
getSuccesses in interface IRunner
Returns:
int The successes

getTestOutcomeTable

public TestOutcomeTable getTestOutcomeTable()
Return the current TestOutcomeTable

Specified by:
getTestOutcomeTable in interface IRunnerClean
Returns:
TestOutcomeTable

setTestOutcomeTable

public void setTestOutcomeTable(TestOutcomeTable testOutcomeTable)
Set the current TestOutcomeTable

Specified by:
setTestOutcomeTable in interface IRunnerClean
Parameters:
testOutcomeTable - TestOutcomeTable

getOutcomeFactory

public IOutcomeFactory getOutcomeFactory()
Get the current IOutcomeTable

Specified by:
getOutcomeFactory in interface IRunnerClean
Returns:
IOutcomeFactory

setOutcomeFactory

public void setOutcomeFactory(IOutcomeFactory outcomeFactory)
Set the current IOutcomeTable

Specified by:
setOutcomeFactory in interface IRunnerClean
Parameters:
outcomeFactory - IOutcomeFactory

setTestCompletionListener

public void setTestCompletionListener(ITestCompletionListener testComplLsnr)
This method assigns an ITestCompletionListener instance to a runner in CLEAN state. This assignment can be performed for just one time in a JTR test-session for each runner instance.
Note: it is legal for this instance to be always null for runner instances started on JTR passive-nodes.

Specified by:
setTestCompletionListener in interface IRunnerClean
Parameters:
testComplLsnr - The listener instance

doRunTest

protected final void doRunTest()
                        throws java.lang.Throwable
This method is in charge of actually starting the test by calling the user defined test() method over the user-defined runner instances. Doing this, runDuration information is collected and at the end of the run, a new IOutcome instance is obtained from the configured IOutcomeFactory. Thus the outcome is passed to the enrichOutcome() method.
Should a user-defined outcome be in use, the developer is required to override the enrichOutcome() method.

Nota: the enrichOutcome() method can alse be used to set a user-message into each run's outcome.

Throws:
java.lang.Throwable

initializeTimers

protected final void initializeTimers()
Thie method is required to prevent that errors happening before the doRunTest() method is invoked have negative impacts on the computation of the time spent during tests.


handleFailure

protected final void handleFailure(int run,
                                   java.lang.Throwable t)
Whenever an exception is caught during the execution of the test() method of the IRunner interface, the AbstractRunner takes care of instantiating a new IOutcome and of adding it to the current TestOutcomeTable.
Once this steps have been performed, the receiveFailureNotification(Throwable,String)" of the IRunner interface is called. At this point your custom IRunner gets notified of the exception and can decide what to do with it.

Parameters:
run - The run of the exception
t - The exceptioin

enrichOutcome

public void enrichOutcome(IOutcome outcome)
This abstract method must be used either when the user needs to enrich the given outcome with a JTR UserObject or in case the default IOutcomeFactory has been replaced with a custom one. Responsability of this method is filling in the provided IOutcome instance. That instance will then be put into the TestOutcomeTable by the JTR runtime.

Parameters:
outcome - The empty outcome of a single run

The JTR Project is licensed under GPL version 2