Example: Adding a repeating timer behavior to a stub
In this example, you add a repeating timer event to a stub that starts after zero seconds and then repeats every 10 seconds.
About this task
To use repeating timers, you must add a Lifecycle and Timer to the stub behavior before you add lifecycle and timer events to the Events. The Lifecycle is used to initialize the timer when the stub starts and the Timer is used to trigger an action and retrigger it. For more information about stub behavior, see The Behavior tab.
Procedure
- Create an empty stub from an operation that has no transport that is configured. Right-click the operation in Rational® Integration Tester Test Factory perspective and click .
- Next, add the stub behaviors. From the Stub Editor, click the Behavior tab and then click Add to open the Add Behavioral Entity dialog.
- Now, set a Lifecycle behavior instance so you can schedule
a repeating timer event to trigger after 10 seconds and a Timer behavior
instance so you can define a message to be sent when the timer event
is triggered.
- Next, set the events for the behavior types by clicking
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.
Tip: Thetimer.onTimerEvent
event has an Input tab that you can use to filter different timer events. In this example, since you have only one timer event, you do not need to configure a filter. - Go to the Test Lab perspective and run the stub.
In the Test Lab, you can see that the
timer
event repeats every 10 seconds, at which time the output messageCallback triggered!!!
was sent.