Creating event sequences

You define a set of test events in an event sequence. The events that you emit are sent to the server in the order in which they are defined in the event sequence file.

Before you begin

Before you create event sequence files, you must create a Test Client project.

About this task

In an event sequence file, you can create an instance of an event that is defined in the solution BOM project. The event sequence syntax is controlled by the Intellirule editor, and is based on the business rules language. Specific language constructs are available to set the timestamp of the event, to use variables, and to modify the data of an event.

All the events in an event sequence file (.eseq) must be defined by using the emit <event> construct or emit <event>, time-stamped <date & time> construct. The order in which the events are specified in the .eseq file determines the order in which they are processed. The event timestamp represents the time when an event occurs. For example, if there are three events in the .eseq file:

  • event1 has a timestamp of 3/24/2015
  • event2 has a timestamp of 3/25/2015
  • event3 has a timestamp of 3/22/2015

The sequence of events that is processed is event1, event2, and then event3, regardless of their timestamps. event3 has a timestamp that is earlier than event2 and event1, and can be interpreted as an event that is delayed in transit, and arrived out of order. A test commences at the first timestamp of the event sequence, which must be an absolute time. Subsequent events can have timestamps that are earlier (in the past) or later (in the future) relative to the first timestamp. However, the order in which the events are processed is the order of the event sequence. In other words, all of the events are processed regardless of when they occurred.

Alternatively, if you want to create an event sequence with relative timestamps, you can use the time-stamped by the test scenario construct following the first event you emit. When you use this construct on the first event, all of the subsequent events are timestamped relative to the event immediately preceding them in the sequence. You can then reuse event sequences in a test scenario by emitting the same sequence with various timestamps.

Procedure

  1. Create an event sequence file:
    1. In the solution map, click Create event sequence.
    2. In the Event Sequence wizard, select a test client project in your workspace and enter a name for your event sequence file.
    3. Click Finish.
    The event sequence file is saved in the Event Sequences folder in the solution. The new .eseq file opens.
  2. Open the Text editor of the .eseq file.
  3. Press Space or Ctrl+Space to view the available constructs.
  4. Double-click a construct to insert it in the definition.

    For example, to define a variable that identifies the customer as John, write the following line: define 'the customer' as the customer identified by "John";. You can then use this variable to refer to the customer in the emit construct.

  5. Optional: Add objects to a collection of objects that are related to an event.

    For example, the purchase event type has a list of items that include price and amount attributes. The following lines define purchase1 as a new event, which is related to the entity the customer. The add construct adds a new object with specific values for price and amount in the purchase1 event.

    define 'purchase1' as a new purchase where 
       the customer is 'the customer' ;
    add ( a new item where
       the price is 10 ,
       the amount is 1 )
       to the items of purchase1 ;
  6. Optional: Add an emit construct for each event that you want to include in your sequence. The event can refer to a variable name or a new event of a specific type. Events require timestamps to indicate when they occur, and the first event requires an absolute timestamp. For the first event in a sequence, you can choose to include an absolute timestamp in the event sequence or in a test scenario.
    • To add timestamps to your event sequence, append the time-stamped <date & time> clause to your first event. Subsequent events can include as many absolute or relative timestamps as your sequence requires.

      In the following example, the first event emitted (purchase1) has an absolute timestamp; the second and third events (purchase2 and purchase3, in this order) emitted have relative timestamps. The events are emitted at 2:00:00 PM, 2:05:00 PM, and then 2:15:00 PM:

      emit purchase1 , time-stamped 3/20/2016 2:00:00 PM ;
      emit purchase2 , time-stamped 5 minutes later ;
      emit purchase3 , time-stamped 10 minutes later ;

      If an event has a timestamp attribute and also uses the time-stamped construct, the timestamp attribute is overridden, and a warning is raised. In the following example, the only timestamp that is processed is the timestamp 1 hour later, which is relative to the timestamp of the previous event in the sequence.

      emit a new request event where
         the timestamp is 1/1/2015 ,
         time-stamped 1 hour later ;
    • To write a sequence that has only relative timestamps, append the time-stamped by the test scenario clause to the first event. When you add this clause, you can specify a timestamp in the test scenario each time you submit the events, which makes it easier for you to reuse event sequences. Ensure that each subsequent event has a relative timestamp so that each event is emitted relative to the event that immediately precedes it.
      In the following example, a new purchase event gets a timestamp in the test scenario. After the first event, all of the following events have relative timestamps:
      emit a new purchase, time-stamped by the test scenario ;
      emit a new purchase ,
         2 hours later ;
      emit a new purchase , 
         30 minutes later ;
      If you submit this example event sequence from a test scenario, and specify that it is time-stamped 1/1/2016 10:00:00 AM, then the two other new purchase events are submitted at 1/1/2016 12:00:00 and 1/1/2016 12:30:00, respectively.
  7. Check that all of the events in your sequence have a corresponding emit construct.
  8. Save the file.

Examples

Event attributes

Events can have event attributes, which can also have timestamps. In the following example, the request event attribute has a timestamp.

emit a new response event where
   the in response to is ( a new request event where the timestamp is 1/1/2015 ) ,
   time-stamped 1/2/2015 ;

In the following example, the address attribute of the new customer registration event is written inside the emit construct. The where construct is used in the a new <item> constructs.

emit a new customer registration where
   the address is ( a new address where
      the street is "221B Baker Street" ,
      the city is "London" ,
      the country is "UK" ) ,
      time-stamped 3/25/2015 ;
Event sequence with a relative timestamp
In the following example, a purchase event is emitted by the customer Fred at a time specified in the test scenario. A second and third purchase are emitted 3 days and 5 days after the first purchase event.
emit a new purchase where  
the customer is the customer
   "Fred",  
   the amount is 100.0, 
   time-stamped by the test scenario ;

emit a new purchase where  
   the customer is the customer
   "Fred",  the amount is 50, 
   time-stamped 3 days later ;

emit a new purchase where  
   the customer is the customer 
   "Fred",  
   the amount is 250, 
   time-stamped 2 days later ;
Event sequence with separate concept definitions
In the following example, the event sequence is composed of two events, a customer registration event and a purchase event, which are related to two variables, the customer and purchase1. These variables are defined in define statements, outside of the emit statement. The parentheses are optional.
define 'the customer' as the customer identified by "John";

emit ( a new customer registration where
   the customer is 'the customer' ,
   the first name is "John" ,
   the last name is "Watson" ) ,
   time-stamped 3/25/2015 ;

define 'purchase1' as a new purchase where 
   the customer is 'the customer';

emit purchase1 ,
   time-stamped 5 minutes later;
Event sequence with inline concept definitions
In the following example, the event sequence is composed of two events, a customer registration event and a purchase event, which are related to two variables, the customer and purchase1. The variable for the address attribute of the customer is defined inside of the emit definition for the customer registration event. The new customer registration event does not contain the values of the attributes of the address concept type that are not identifiers, because the address instance is used to establish the relationship. The parentheses are optional.
define 'the customer' as the customer identified by "John";

emit a new customer registration where
   the customer is 'the customer' ,
   the first name is "John" ,
   the last name is "Watson" ,
   the address is ( a new address where
      the address id is "123"
      the street is "221B Baker Street" ,
      the city is "London" ,
      the country is "UK" ) ,
   time-stamped 3/25/2015 ;

define 'purchase1' as a new purchase where 
   the customer is 'the customer';

emit purchase1 ,
   time-stamped 5 minutes later;
Event sequence where two events use the same variable
In the following example, the variable paddington is reused in each event to refer to a specific customer.
define 'paddington' as the customer identified by "paddington@example.com"

emit a new customer registration where
   the customer is paddington ,
   time-stamped 4/07/2015 ;

emit a new purchase where
   the customer is paddington ,
   the price is 25 ,
   time-stamped 10 minutes later ;

emit a new purchase where
   the customer is paddington ,
   the price is 62 ,
   time-stamped 3 days later ;
Event sequence with events that use different types of timestamps
In the following example, the first purchase event has a timestamp that is 10 minutes after the customer registration event. The third event in the sequence occurs 3 days after the previous event, which in this example is the customer registration event. These events show an example of how to simulate a sequence of events that are processed out of order.
define 'paddington' as the customer identified by "paddington@example.com"

emit a new purchase where
   the customer is paddington ,
   the price is 25 ,
   time-stamped 4/07/2015 ;

emit a new customer registration where
   the customer is paddington ,
   time-stamped 10 minutes earlier ;

emit a new purchase where
   the customer is paddington ,
   the price is 62 ,
   time-stamped 3 days later ;

What to do next

After you define the event sequence, you can run the sequence to test it against your solution.