Test Script Services Reference

prevnext

Measurement Class


Use the measurement methods to set timers and environment variables and to get the value of internal variables. Timers allow you to gauge how much time is required to complete specific activities under varying load conditions. Environment variables allow for the setting and passing of information to virtual testers during script playback. Internal variables store information used by the TestManager to initialize and reset virtual tester parameters during script playback.


Applicability

Commonly used with TestManager.


Summary

The following table lists the measurement methods. They are static methods of class TSSMeasure.

Method Description
commandEnd() Logs an end-command event.
commandStart() Logs a start-command event.
environmentOp() Sets an environment variable.
getTime() Gets the elapsed time of a run.
internalVarGet() Gets the value of an internal variable.
think() Sets a think-time delay.
timerStart() Marks the start of a block of actions to be timed.
timerStop() Marks the end of a block of timed actions.


TSSMeasure.commandEnd()

Marks the end of a timed command.


Syntax

void commandEnd(short result, String description, int 
starttime, int endtime, String logdata, TSSNamedValue [] 
property)
void commandEnd(short result)

Element Description
result Specifies the notification preference regarding the result of the call. Can be one of the following:
  • TSS_LOG_RESULT_NONE (default: no notification)

  • TSS_LOG_RESULT_PASS

  • TSS_LOG_RESULT_FAIL

  • TSS_LOG_RESULT_WARN

  • TSS_LOG_RESULT_STOPPED

  • TSS_LOG_RESULT_INFO

  • TSS_LOG_RESULT_COMPLETED

  • TSS_LOG_RESULT_UNEVALUATED.

0 specifies the default.
description Contains the string to be displayed in the event of failure.
starttime An integer indicating a time stamp to override the time stamp set by commandStart(). To use the time stamp set by commandStart(), specify as 0.
endtime An integer indicating a time stamp to override the current time. To use the current time, specify as 0.
logdata Text to be logged describing the ended command.
property An array containing property name/value pairs, where property[n].name is the property name and property[n].value is its value. See TSSNamedValue for the implementation of this argument's data type.


Exceptions

These methods may throw an exception with one of the following values:

If you handle one of these exceptions and do not log it, TestManager is not aware of the exception and does not log a Fail result for it. The script continues to run, and TestManager could log a Pass result for the script.


Comments

The command name and label entered with commandStart() are logged, and the run state is restored to the value that existed before the commandStart() call.

An event and any data associated with it are logged only if the specified result preference matches associated settings in the EVAR_LogData_control or EVAR_LogEvent_control environment variables. (See Arguments of TSSMeasure.environmentOp().) Alternatively, the logging preference can be set with the EVAR_Log_level and EVAR_Record_level environment variables. The TSS_LOG_RESULT_STOPPED, TSS_LOG_RESULT_COMPLETED, and TSS_LOG_RESULT_UNEVALUATED preferences are intended for internal use.


Example

This example marks the end of the timed activity specified by the previous commandStart() call.

TSSMeasure.commandEnd(TSS_LOG_RESULT_PASS,"Command timer failed", 0, 
0, "Login command completed", null);

See Also

commandStart(), TSSAdvanced.logCommand()


TSSMeasure.commandStart()

Starts a timed command.


Syntax

void commandStart(String label, String name, int state)

Element Description
label The name of the timer to be started and logged, or NULL for an unlabeled timer.
name The name of the command to time.
state The run state to log with the timed command. See the run state table. You can enter 0 (MST_UNDEF) if you're uninterested in the run state.


Exceptions

This method may throw an exception with one of the following values:

If you handle one of these exceptions and do not log it, TestManager is not aware of the exception and does not log a Fail result for it. The script continues to run, and TestManager could log a Pass result for the script.


Comments

A command is a user-defined name appearing in the log of a test run. By placing commandStart() and commandEnd() calls around a block of lines in a script, you can log the time required to complete the actions in the block.

During script playback, TestManager displays progress for different virtual testers. What is displayed for a group of actions associated by commandStart() depends on the run state argument. Run states are listed in the run state table.

commandStart() increments IV_cmdcnt, sets the name, label, and run state for TestManager, and sets the beginning time stamp for the log entry. commandEnd() restores the TestManager run state to the run state that was in effect immediately before commandStart().


Example

This example starts timing the period associated with the string Login.

TSSMeasure.commandStart("initTimer", "Login", MST_WAITRESP);

See Also

commandEnd(), TSSAdvanced.logCommand()


TSSMeasure.environmentOp()

Sets a virtual tester environment variable.


Syntax

void environmentOp(int envVar, int envOp)
void environmentOpGetIntValue(int envVar, int envOp, TSSInteger 
envInt)
void environmentOpGetStringValue(int envVar, StringBuffer 
envString)
void environmentOpSetIntValue(int envVar, int envOp, int 
envVal)
void environmentOpSetStringValue(int envVar, int envOp, 
StringBuffer envString)

Element Description
envVar The environment variable to operate on. See Arguments of TSSMeasure.environmentOp()for a list and description of environment variable constants.
envOp The operation to perform. See Arguments of TSSMeasure.environmentOp() for a list and description of the operation constants..
envInt The new value for an integer environment variable. See TSSInteger for the implementation of this argument's data type.
envString The new value for a string environment variable.
envVal The array index of the value to set the variable to.


Exceptions

These methods may throw an exception with one of the following values:

If you handle one of these exceptions and do not log it, TestManager is not aware of the exception and does not log a Fail result for it. The script continues to run, and TestManager could log a Pass result for the script.


Comments

Environment variables define and control the environment of virtual testers. Using environment variables allows you to test different assumptions or runtime scenarios without re-writing your test scripts. For example, you can use environment variables to specify:

Use environmentOp() for operations (such as EVOP_pop) that require no integer or string values.

See Arguments of TSSMeasure.environmentOp() for a list and description of the values that can be used for argument envVar.

Environment control options allow a script to control a virtual tester's environment by operating on the environment variables. Every environment variable has, instead of a single value, a group of values: a default value, a saved value, and a current value.

See Arguments of environmentOP() for the values that can be used for argument envOp.


Example

This example gets the current value of EVAR_Think_dist. For a more extensive illustration of environment variable manipulation, see Example: Manipulating Environment Variables.

StringBuffer cur_dist = new StringBuffer();
TSSMeasure.environmentOpGetStringValue(EVAL_Think_dist, EVOP_eval, 
cur_dist);

TSSMeasure.getTime()

Gets the elapsed time since the beginning of a suite run.


Syntax

int getTime()

Return Value

On success, this method returns the number of milliseconds elapsed in a suite run.


Exceptions

This method may throw an exception with one of the following values:

If you handle one of these exceptions and do not log it, TestManager is not aware of the exception and does not log a Fail result for it. The script continues to run, and TestManager could log a Pass result for the script.


Comments

For execution within TestManager, this call retrieves the time elapsed since the start time shared by all virtual testers in all test scripts in a suite.

For a test script executed outside TestManager, the time returned is the milliseconds elapsed since the call to TSSSession.connect(), or since the value of CTXT_timeZero set by TSSSession.context().


Example

This example stores the elapsed time in etime.

int etime = TSSMeasure.getTime();

TSSMeasure.internalVarGet()

Gets the value of an internal variable.


Syntax

void internalVarGetInt(int internVar, TSSInteger iVal)
void internalVarGetString(int internVar, StringBuffer sVal)

Element Description
internVar The internal variable to operate on. See Arguments of TSSMeasure.internalVarGet() for a list and description of the internal variable constants..
iVal OUTPUT. The returned value of the specified integer internal variable. For the implementation of this argument's data type, see TSSInteger.
sVal OUTPUT. The returned value of the specified string internal variable.


Exceptions

These methods may throw an exception with one of the following values:

If you handle one of these exceptions and do not log it, TestManager is not aware of the exception and does not log a Fail result for it. The script continues to run, and TestManager could log a Pass result for the script.


Comments

Internal variables contain detailed information that is logged during script playback and used for performance analysis reporting. This function allows you to customize logging and reporting detail.


Example

This example stores the current value of the IV_error internal variable in IVVal.

TSSMeasure.internalVarGet(IV_error,IVVal);

TSSMeasure.think()

Puts a time delay in a script that emulates a pause for thinking.


Syntax

void think(int thinkAverage)
void think()

Element Description
thinkAverage If specified as 0 or omitted, the number of milliseconds stored in the EVAR_Think_avg environment variable is used as the basis of the calculation. Otherwise, the calculation is based on the value specified.


Exceptions

These methods may throw an exception with one of the following values:

If you handle one of these exceptions and do not log it, TestManager is not aware of the exception and does not log a Fail result for it. The script continues to run, and TestManager could log a Pass result for the script.


Comments

A think-time delay is a pause inserted in a performance test script in order to emulate the behavior of actual application users.

For a description of environment variables, see environmentOp() on page53.


Example

This example calculates a pause based on the value stored in the environment variable EVAR_Think_avg and inserts the pause into the script.

TSSMeasure.think();

See Also

TSSAdvanced.thinkTime()


TSSMeasure.timerStart()

Marks the start of a block of actions to be timed.


Syntax

void timerStart(String label, int timeStamp)
void timerStart(String label)
void timerStart()

Element Description
label The name of the timer to be inserted into the log. If specified as null or not specified, an unlabeled timer is created. Only one unlabeled timer is supported at a time.
timeStamp An integer specifying a time stamp to override the current time. If specified as 0 or not specified, the current time is logged.


Exceptions

These methods may throw an exception with one of the following values:

If you handle one of these exceptions and do not log it, TestManager is not aware of the exception and does not log a Fail result for it. The script continues to run, and TestManager could log a Pass result for the script.


Comments

This call associates a starting time stamp with label for later reference by timerStop(). The TestManager reporting system uses captured timing information for performance analysis reports.

Starting an unlabeled timer sets a start time for an event that you want to subdivide into timed intervals. See the example for timerStop(). You can get a similar result using named timers, but there will be a slight difference in the timing calculation due to the overhead of starting a timer.


Example

This example times actions designated event1, logging the current time.

TSSMeasure.timerStart ("event1");
// action to be timed //
TSSMeasure.timerStop("event1");

See Also

timerStop()


TSSMeasure.timerStop()

Marks the end of a block of timed actions.


Syntax

void timerStop(String label, int timeStamp, boolean rmFlag)
void timerStop(String label)

Element Description
label The name to be logged.
timeStamp An integer indicating the time stamp to log. If not specified or specified as 0, the current time is used.
rmFlag Specify as false or omit to stop the timer without removing it; otherwise, specify as true. A timer that is not removed can be stopped multiple times in order to measure intervals of this timed event.


Exceptions

These methods may throw an exception with one of the following values:

If you handle one of these exceptions and do not log it, TestManager is not aware of the exception and does not log a Fail result for it. The script continues to run, and TestManager could log a Pass result for the script.


Comments

Normally, this call associates an ending time stamp with a label specified with timerStart(). If the specifiedlabel was not set by a previous timerStart() but an unlabeled timer exists, this call logs an event using the specified label and the start time specified for the unlabeled timer with timerStart(). If rmFlag is specified as 0, multiple invocations of timerStop() are allowed against a single timerStart(). This usage (see the example) allows you to subdivide a timed event into separate timed intervals.


Example

This example stops an unlabeled timer without removing it. In the log, event1 and event2 will record the time elapsed since the timerStart() call.

TSSMeasure.timerStart();
// action to be timed //
TSSMeasure.timerStop("event1");
// another action to be timed //
TSSMeasure.timerStop("event2");

See Also

timerStart()

prevnext


Rational Test Script Services for Java Rational Software Corporation
Copyright (c) 2003, Rational Software Corporation http://www.rational.com
support@rational.com
info@rational.com