Adding a timer behavior to a stub
You can use a timer behavior to set a timer event in a stub. After a set time period, the timer event is triggered, the stub receives the event, which it can then respond to. For example, you might have a stub to manage user sessions and you want to add a timer behavior that automatically logs out a user after 30 seconds of inactivity.
Before you begin
You must have a stub before you can add a timer behavior to it. For information about stubs and what you can do with them, see Stubs: Overview and tasks.
About this task
You want to schedule a timer event to trigger after 30 seconds of elapsed time.
To add a timer behavior to a stub:
Procedure
- In
Rational® Integration
Tester Test Factory perspective,
double-click the stub that you want to add a timer behavior to.
The Stub Editor opens.
Next, you want to add stub behaviors. You do that from the Behavior page.
- Click the Behavior tab and then
click Add to open the Add Behavioral Entity
dialog box.
You can see the behavior-types that are provided with Rational® Integration Tester. You can also see a description of the Lifecycle behavior.
Tip: To see the Timer behavior description, select it from the list. For more information about the behavior types, see The Behavior tab.Now, you want a Lifecycle behavior instance so you can schedule a timer event to trigger after 30 seconds. You also want a Timer behavior instance so you can define a message to be sent when the timer event runs.
- Set behavior types for the stub:
- Click the Events tab.
- To start a timer, you must add code to the lifecycle.onStart event.
- To add an action to run when the timer is triggered, you
can add business logic or a send message to the
timer.onTimerEvent
event.- Go to the Activity tab of this event and add a log action by right-clicking in the Activity pane and selecting .
- Type an output message and click OK to close the Log action.
- Go to the Test Lab perspective and run the stub.
In the Test Lab, you can see that the
timer
event was triggered after 30 seconds, at which time the output messageCallback triggered!!!
was sent.Tip: You can use filtering to act on a stub only when a specific timer is triggered. In this example, the timer event is only triggered for the timer namedmyTimer
. You can also tag the parameter object and reuse it in further actions.