Apama Helper Classes for PySys

So that you can easily create tests for your Apama applications, Apama distributes a copy of the open-source “PySys” system testing framework.

We also provide some additional classes that use the functionality provided by PySys to make it easy to work with Apama correlators, IAF adapters, Ant builds, Apama project directories and (Linux-only) Docker containers.

Getting Started

When creating a PySys test project for use with Apama, use the apama project template which will includes support for the self.apama.XXX helper methods, and (optional) EPL code coverage reporting:

mkdir tests
cd tests
pysys makeproject --template=apama

Now create your first testcase:

pysys make MyApplication_001

This will create a MyApplication_001 subdirectory with a pysystest.py file holding both the test descriptor (including its title), and a PySysTest class where you can add the logic to execute your test, and to validate that the results are as expected.

Edit the generated pysystest.py and use methods on the apama.testplugin.ApamaPlugin class (whose members are available using self.apama.XXX) to start a correlator and inject your application into it, for example:

correlator = self.apama.startCorrelator()
correlator.injectEPL([self.appHome+'/monitors/foo.mon'])

For validation, you will want to make use of standard PySys methods such as waitForGrep, assertGrep and assertThatGrep to validate the expected the correlator log messages, and apama.testplugin.ApamaPlugin.extractEventLoggerOutput() if you need to check the events sent by your application. You can read more about the available PySys methods in the pysys.basetest documentation.

A set of sample PySys testcases for Apama can be found in the samples/pysys directory of your Apama installation.

To run your first test, use pysys run:

pysys run 1

When using the apama.coverage.EPLCoverageWriter you can automatically generate an HTML code coverage report for your EPL application like this:

pysys run -XcodeCoverage

Reference