2

A number of samples exists together with the Apama installation, however I haven't been able to identify if you can compare only certain parameters from an event, and not the entire Event.

For instance if capturing the following:

com.eventA("abc",1234,true)

and expecting

com.eventA("abc",*,true)

Then I would like to only compare parameter 1 and 3, is that currently possible from the apama/pysys framework?

and further on, is the same feature possible when comparing with the log file?

Saurav Sahu
  • 13,038
  • 6
  • 64
  • 79
StefanE
  • 817
  • 6
  • 20

1 Answers1

2

You're probably best to use an assertOrderedGrep to do this. This validation routine allows you to build up a set of ordered regular expressions which are searched for in the output file and must occur in the order specified. For instance, assertion on the following captured output (lets call it output.log);

com.eventA("abc",1234,true)
com.eventA("def",1234,false)
com.eventA("abc",1234,false)

could be performed using validation of the form;

def validate(self):
    exprList=[]
    exprList.append('com.eventA\("abc",.*,true\)')
    exprList.append('com.eventA\("abc",.*,false\)')
    self.assertOrderedGrep('output.log', exprList=exprList)

The strings used in the exprList are standard regular expressions, so you need to escape special characters, like parenthesis.

If you were going to use an assertDiff using a reference file, you can replace tokens in both the output file being validated, and the reference file, but again this is on a regex basis. For your example you could have a reference file of the form;

com.eventA("abc",1234,true)
com.eventA("def",4567,false)
com.eventA("abc",1234,false)

and then replace all ",.*," occurences with a blank string so it diffs correctly. The validation would then be of the form;

    replace=((',.*,',''),)
    self.assertDiff(file1='output.log', file2='reference.log', replace=replace)

See the pydoc for the assertDiff method for more details. The main point to note is that there is no parser per say in the apama extensions that work on an event basis; you need to use regex's to validate any output logs.

moraygrieve
  • 466
  • 4
  • 11
  • Hi Moray. Thanks for the answer. I can see this approach for simple events, however they can fast become rather troublesome when having events containing dictionary and many dimensional lists. Thanks for the clarification. – StefanE Sep 24 '15 at 10:35
  • @StefanE Hi Stefan - yes understood on that one. There is no event parser in the Apama extensions ... one approach is to connect another correlator to receive the output, write some monitorscipt to listen for the events of interest, extract the fields of interest and emit to another receiver ... it's a workaround but certainly easy to do (use the connect() method on the correlator helper class to connect two correlators together). Note you can emit strings from the correlator, so you can format the extracted fields anyway you want. – moraygrieve Sep 24 '15 at 13:02