Pysys with Apama - How to validate only on certain parameters when comparing events with reference?

234 views Asked by At

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?

1

There are 1 answers

2
moraygrieve On BEST ANSWER

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.