イベント・シーケンスの作成

イベント・シーケンスでテスト・イベントのセットを定義します。出力するイベントは、イベント・シーケンス・ファイル内に定義されている順序でサーバーに送信されます。

始める前に

イベント・シーケンス・ファイルを作成する前に、テスト・クライアント・プロジェクトを作成する必要があります。

このタスクについて

イベント・シーケンス・ファイルでは、ソリューション BOM プロジェクトで定義されたイベントのインスタンスを作成できます。 イベント・シーケンスの構文は、Intellirule エディターで管理され、ビジネス・ルール言語をベースとします。 イベントのタイム・スタンプの設定、変数の使用、イベントのデータの変更を行うために、固有の言語構成体があります。

イベント・シーケンス・ファイル (.eseq) 内のイベントはすべて、 emit <event> 構成体または emit <event>, time-stamped <date & time> 構成体を使用して定義されなければなりません。 .eseq ファイルでイベントが指定された順序で、その処理順序が決まります。 イベント・タイム・スタンプは、イベントが発生した時間を表します。例えば、.eseq ファイルに以下の 3 つのイベントがあるとします。

  • event1 のタイム・スタンプは 3/24/2015 です。
  • event2 のタイム・スタンプは 3/25/2015 です。
  • event3 のタイム・スタンプは 3/22/2015 です。

処理されるイベントの順序は、タイム・スタンプに関係なく、event1、event2、 event3 です。event3 のタイム・スタンプは event2 と event1 よりも前ですが、 転送中に遅延して順序が誤って到着したイベントとして解釈できます。 テストは、イベント・シーケンスの最初のタイム・スタンプで開始します。これは、絶対時間でなければなりません。 後続のイベントのタイム・スタンプは、最初のタイム・スタンプより前 (過去) であることも、後 (未来) であることも可能です。 ただし、イベント・シーケンスの順序で、イベントは処理されます。 つまり、イベントはすべて、いつ発生したかには関係なく、処理されます。

別の方法として、相対タイム・スタンプを持つイベント・シーケンスを作成する場合は、出力した最初のイベントに続けて、time-stamped by the test scenario 構成体を使用できます。この構成体を最初のイベントに使用すると、以降のすべてのイベントには、シーケンス内で直前にあるイベントからの相対的なタイム・スタンプが付けられます。その後、さまざまなタイム・スタンプで同じシーケンスを出力することにより、イベント・シーケンスをテスト・シナリオで再使用できます。

手順

  1. イベント・シーケンス・ファイルを作成します。
    1. ソリューション・マップで、「イベント・シーケンスの作成」をクリックします。
    2. 「イベント・シーケンス」ウィザードで、ワークスペース内のテスト・クライアント・プロジェクトを選択し、イベント・シーケンス・ファイルの名前を入力します。
    3. 「終了」をクリックします。
    イベント・シーケンス・ファイルが、ソリューションの「イベント・シーケンス」フォルダーに保存されます。 新しい .eseq ファイルが開きます。
  2. .eseq ファイルのテキスト・エディターを開きます。
  3. スペースまたは Ctrl + スペース を押して、使用可能な構成体を表示します。
  4. 構成体をダブルクリックして定義に挿入します。

    例えば、the customer を John として識別する変数を定義するには、 define 'the customer' as the customer identified by "John"; という行を記述します。 その後、この変数を使用して、 emit 構成体で the customer を参照することができます。

  5. オプション: オブジェクトのコレクションに、イベントに関連するオブジェクトを追加します。

    例えば、purchase イベント・タイプには、 price 属性や amount 属性などの一連の項目が含まれます。 以下の行では、エンティティー the customer に関連する新しいイベントとして purchase1 を定義します。 add 構成体により、 price と amount の特定値を持つ新しいオブジェクトを purchase1 イベントに追加します。

    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. オプション: シーケンスに組み込む各イベントの emit 構成体を追加します。 イベントは、変数名、または特定タイプの新しいイベントを参照することができます。 イベントには、それがいつ発生するのかを示すタイム・スタンプが必要であり、最初のイベントには絶対タイム・スタンプが必要です。シーケンスの最初のイベントでは、絶対タイム・スタンプをイベント・シーケンスに組み込むかテスト・シナリオに組み込むかを選択できます。
    • タイム・スタンプをイベント・シーケンスに追加するには、time-stamped <date & time> 節を最初のイベントに追加します。以降のイベントには、シーケンスに必要な数の絶対タイム・スタンプまたは相対タイム・スタンプを組み込めます。

      以下の例では、出力される最初のイベント (purchase1) は絶対タイム・スタンプを持ち、出力される 2 番目と 3 番目のイベント (それぞれ purchase2 と purchase3) は相対タイム・スタンプを持ちます。各イベントは、2:00:00 PM、2:05:00 PM、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 ;

      イベントがタイム・スタンプ属性を持ち、time-stamped 構成体も使用する場合、タイム・スタンプ属性はオーバーライドされ、警告が発生します。次の例で、処理されるタイム・スタンプは、 タイム・スタンプ 1 hour later だけです。 これは、シーケンスで直前のイベントのタイム・スタンプとの相対値です。

      emit a new request event where
         the timestamp is 1/1/2015 ,
         time-stamped 1 hour later ;
    • 相対タイム・スタンプのみを持つシーケンスを記述するには、time-stamped by the test scenario 節を最初のイベントに追加します。この節を追加すると、イベントを送信するたびにテスト・シナリオにタイム・スタンプを指定することができ、イベント・シーケンスの再使用が容易になります。各イベントが、直前のイベントから相対的な間隔で出力されるようにするために、以降の各イベントが相対タイム・スタンプを持つようにします。
      以下の例では、新規の購入イベントがテスト・シナリオのタイム・スタンプを取得します。最初のイベント後、以降のすべてのイベントは相対タイム・スタンプを持ちます。
      emit a new purchase, time-stamped by the test scenario ;
      emit a new purchase ,
         2 hours later ;
      emit a new purchase , 
         30 minutes later ;
      このイベント・シーケンスの例をテスト・シナリオから送信し、そのタイム・スタンプを time-stamped 1/1/2016 10:00:00 AM と指定すると、他の 2 つの新規購入イベントが 1/1/2016 12:00:00 と 1/1/2016 12:30:00にそれぞれ送信されます。
  7. シーケンス内のすべてのイベントに、対応した emit 構成体があることを確認します。
  8. ファイルを保存します。

例

イベント 属性

イベントはイベント属性を持つことができます。イベント属性もタイム・スタンプを持つことができます。 次の例で、request event 属性にはタイム・スタンプがあります。

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 ;

次の例では、new customer registration イベントの address 属性が emit 構成体の中で記述されています。 a new <item> 構成体の中で、where 構成体が使用されています。

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 ;
相対タイム・スタンプを持つイベント・シーケンス
以下の例では、テスト・シナリオで指定された日時に、顧客 Fred によって購入イベントが出力されます。2 番目と 3 番目の購入は、最初の購入イベントから 3 日後と 5 日後に出力されます。
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 ;
別個の概念定義を含むイベント・シーケンス
次の例で、イベント・シーケンスは customer registration イベントと purchase イベントの 2 つのイベントで構成され、 それらは the customer と purchase1 の 2 つの変数に関連します。 これらの変数は、emit ステートメントの外部にある define ステートメントで定義されています。 括弧はオプションです。
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;
インラインの概念定義を含むイベント・シーケンス
次の例で、イベント・シーケンスは customer registration イベントと purchase イベントの 2 つのイベントで構成され、 それらは the customer と purchase1 の 2 つの変数に関連します。 the customer の address 属性の変数は、 customer registration イベントの emit 定義の中で定義されています。 new customer registration イベントには、 識別子以外の、address 概念タイプの属性の値は含まれません。 これは、address インスタンスが関係の確立に使用されているためです。 括弧はオプションです。
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;
2 つのイベントが同じ変数を使用するイベント・シーケンス
次の例で、変数 paddington は各イベントで再使用され、 特定の 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 ;
異なるタイプのタイム・スタンプを使用するイベントを含むイベント・シーケンス
次の例で、最初の purchase イベントのタイム・スタンプは、 customer registration イベントの 10 分後です。 シーケンスで 3 番目のイベントは、直前のイベント (この例では customer registration イベント) の 3 日後に発生します。 これらのイベントは、順序に従わずに処理されるイベントのシーケンスをシミュレートする方法の例を示しています。
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 ;

次のタスク

イベント・シーケンスを定義したら、シーケンスを実行して、ソリューションに対してそれをテストすることができます。