From 980f0e2b2333caeeb0b9880ae24738d5bcfddbd2 Mon Sep 17 00:00:00 2001
From: "Sudha.Jallu" Navigation
Navigation
Navigation
Navigation
Navigation
Navigation
Navigation
Source code for apamax.eplapplications.perf.basetest
Navigation
Navigation
Source code for apamax.eplapplications.platform
Navigation
Navigation
Navigation
Navigation
Navigation
Navigation
Navigation
Navigation
Navigation
Navigation
Navigation
Navigation
Navigation
Navigation
Navigation
Navigation
Navigation
Navigation
Navigation
Navigation
Navigation
Navigation
Navigation
Introductionhttps://www.apamacommunity.com/docs> and <https://cumulocity.com/guides/apama> for further docs.
-See apama-eplapps-tools for the main github respoitory.
See Apama Documentation and Streaming Analytics guide for further docs. +See apama-eplapps-tools for the main github respoitory.
This document demonstrates the common process involved in writing a performance test for your existing EPL apps and smart rules. The performance tests described in the document use the EPL apps SDK based on the PySys test framework. See the PySys documentation for details on the installation, and how the framework can be used and the facilities it contains. Set up the EPL apps SDK by following the steps mentioned in Testing in the Cumulocity IoT cloud.
pysys run -XmyTestDuration=10 -XmeasurementType="MyMeasurement"
See the PySys test options in the PySys documentation for details on configuring and overriding test options.
+See the PySys test options in the PySys documentation for details on configuring and overriding test options.
Performance tests can only be run using a Cumulocity IoT tenant with EPL apps and smart rules enabled. Set up the framework to use a Cumulocity IoT tenant by following the steps mentioned in Setup for testing in the Cumulocity IoT cloud.
+Performance tests can only be run using a Cumulocity IoT tenant with EPL apps and smart rules enabled. Set up the framework to use a Cumulocity IoT tenant by following the steps mentioned in Testing in the Cumulocity IoT cloud.
When running a test, test options can be overridden by using the -X
argument. See Defining the test options for details on defining and providing test options.
For example, to change the test duration of the AlarmOnThreshold
test, run the following:
pysys run -XtestDuration=180 AlarmOnThreshold
At the end of the test, a basic validation of the test run is performed. See PySys helpers in the EPL Apps Tools documentation for details on validations performed.
+At the end of the test, a basic validation of the test run is performed. See PySys helpers in the EPL Apps Tools documentation for details on validations performed.
The apps directory contains multiple sample apps for performance testing. The correctness directory contains basic correctness tests of the sample apps. It is recommended to always test your EPL apps for correctness before testing them for performance. See Using PySys to test your EPL apps for details on testing EPL apps for correctness. The performance directory contains performance tests for each sample app. These tests can be run as explained in Running the performance test.
+The apps directory contains multiple sample apps for performance testing. The correctness directory contains basic correctness tests of the sample apps. It is recommended to always test your EPL apps for correctness before testing them for performance. See Using PySys to test your EPL apps for details on testing EPL apps for correctness. The performance directory contains performance tests for each sample app. These tests can be run as explained in Running the performance test.
See the Testing the performance of your EPL apps and smart rules document for writing performance tests.
All measurements and alarms in Cumulocity IoT must be associated with a source. Devices in Cumulocity IoT are represented by managed objects, each of which has a unique identifier. When sending measurement or alarm events, the source
field of these events must be set to a identifier of a managed object in Cumulocity IoT. Therefore, in order to send measurements from our test EPL app, it must create a ManagedObject
device simulator to be the source of these measurements.
If you are using the PySys framework to run tests in the cloud, any devices created by your tests should be named with prefix “PYSYS_”, and have the c8y_IsDevice
property. These indicators are what the framework uses to identify which devices should be deleted following a test. Note that deleting a device in Cumulocity IoT will also delete any alarms or measurements associated with that device so the cleanup from a test is done when another test is next run.
If you are using the PySys framework to run tests in the cloud, any devices created by your tests should be named with prefix “PYSYS_”, and have the c8y_IsDevice
property. These indicators are what the framework uses to identify which devices should be deleted following a test. Note that deleting a device in Cumulocity IoT will also delete any alarms or measurements associated with that device so the cleanup from a test is done when another test is next run.
To see how this can be done, have a look at the createNewDevice
action below:
action createNewDevice(string name) returns integer
{
@@ -101,7 +101,7 @@ Introduction}
This action initializes a ManagedObject
(using the “PYSYS_” naming prefix and adding the c8y_IsDevice
property), before sending it using a withResponse
action. It then confirms that it has been successfully created using listeners for ObjectCommitted
and ObjectCommitFailed
events. Whenever you are creating or updating an object in Cumulocity IoT and you want to verify that the change has been successful, it is recommended that you use the withResponse
action in conjunction with ObjectCommitted
and ObjectCommitFailed
listeners (for more information, see the information on updating a managed object in the ‘The Cumulocity IoT Transport Connectivity Plug-in’ section of the documentation). Using this approach you can easily relay when the process has completed (which is done by sending an event, DeviceCreated
, in the example above), and in the event of an error you can cause the test to exit quickly.
This action initializes a ManagedObject
(using the “PYSYS_” naming prefix and adding the c8y_IsDevice
property), before sending it using a withResponse
action. It then confirms that it has been successfully created using listeners for ObjectCommitted
and ObjectCommitFailed
events. Whenever you are creating or updating an object in Cumulocity IoT and you want to verify that the change has been successful, it is recommended that you use the withResponse
action in conjunction with ObjectCommitted
and ObjectCommitFailed
listeners (for more information, see the information on updating a managed object in the ‘The Cumulocity IoT Transport Connectivity Plug-in’ section of the documentation). Using this approach you can easily relay when the process has completed (which is done by sending an event, DeviceCreated
, in the example above), and in the event of an error you can cause the test to exit quickly.
An alternative approach to the one demonstrated in the ‘Receiving events from your EPL apps’ section involves querying Cumulocity IoT. With this approach you are able to retrieve historical data. It is possible to query Cumulocity IoT for alarms, events, measurements, operations, and managed objects. More information on querying can be found in ‘The Cumulocity IoT Transport Connectivity Plug-in’ section of the documentation.
+An alternative approach to the one demonstrated in the ‘Receiving events from your EPL apps’ section involves querying Cumulocity IoT. With this approach you are able to retrieve historical data. It is possible to query Cumulocity IoT for alarms, events, measurements, operations, and managed objects. More information on querying can be found in ‘The Cumulocity IoT Transport Connectivity Plug-in’ section of the documentation.
Using an example of a test that checks for an alarm, this would involve subscribing to the FindAlarmResponse.SUBSCRIBE_CHANNEL
and using a FindAlarm
event with FindAlarmResponse
and FindAlarmResponseAck
listeners:
on DeviceCreated(reqId=createNewDevice("DeviceSimulator")) as device
{
@@ -226,7 +226,7 @@ Summary
EPL test samples¶
-A sample EPL app and test can be found in the samples directory of the EPL Apps Tools SDK. Most of the EPL code snippets in this document are from the sample test, AlarmOnMeasurementThresholdTest, which can be found in the Input directory of any of the samples provided. This tests the sample EPL app, AlarmOnMeasurementThreshold, which can be found in the samples/apps directory of the SDK. Information on how to run the sample test can be found in the Using PySys to test your EPL apps document.
+A sample EPL app and test can be found in the samples directory of the EPL Apps Tools SDK. Most of the EPL code snippets in this document are from the sample test, AlarmOnMeasurementThresholdTest, which can be found in the Input directory of any of the samples provided. This tests the sample EPL app, AlarmOnMeasurementThreshold, which can be found in the samples/apps directory of the SDK. Information on how to run the sample test can be found in the Using PySys to test your EPL apps document.
PySys is a testing framework that provides a way to test your applications.
-See PySys Documentation for details on installation and how the framework can be used and the facilities it contains.
+See PySys Documentation for details on installation and how the framework can be used and the facilities it contains.
See Testing the performance of your EPL apps and smart rules for details on creating and running performance tests.
+See Testing the performance of your EPL apps and smart rules for details on creating and running performance tests.
To create a test, you can either copy an existing test (such as one of our samples) and rename it, or by running:
pysys make TestName
If you do this, the default PySys test case comes with a run.py file. For these tests, you should remove that file, it is not needed. If you do want to use it, see the ‘Advanced tests’ section below.
-A PySys test case comprises a directory with a unique name, containing a pysystest.xml and an Input directory containing your test EPL monitors. These should be written according to the Writing tests for EPL apps document, for example, AlarmOnMeasurementThresholdTest.mon in the provided samples. In particular, they must terminate either by all the listeners terminating or with an explicit ‘die’ statement.
+A PySys test case comprises a directory with a unique name, containing a pysystest.xml and an Input directory containing your test EPL monitors. These should be written according to the Writing tests for EPL apps document, for example, AlarmOnMeasurementThresholdTest.mon in the provided samples. In particular, they must terminate either by all the listeners terminating or with an explicit ‘die’ statement.
The test is configured through the pysystest.xml file. This contains the title and purpose, which you should use for a description of what your test does. You must also use it to specify how to run your test. To run a test using Apama EPL Apps in your Cumulocity IoT tenant, you must add the following block:
<data>
<class name="EPLAppsSimpleTest" module="${EPL_TESTING_SDK}/testframework/apamax/eplapplications/basetest"/>
@@ -116,7 +116,7 @@ Running the testTesting the performance of your EPL apps and smart rules for details on running performance tests.
+
See Testing the performance of your EPL apps and smart rules for details on running performance tests.
To run the test using a local correlator requires the APAMA_HOME project property to be set as the path to your installation of Apama. This can be done by simply running the test in an Apama command prompt or by explicitly setting the APAMA_HOME environment variable.
The sample for running with a local correlator is as below:
For anyone who already knows how to use PySys and wants to write Python code for their test running and validation, it is possible to also add a run.py to your test case. We provide samples of tests both running within Apama EPL Apps and with a local correlator in the advanced directory of the samples.
-In order to view documentation on classes for PySys helpers for EPL Apps please see: PySys helpers
-See Testing the performance of your EPL apps and smart rules for details on writing performance tests.
+In order to view documentation on classes for PySys helpers for EPL Apps please see: PySys helpers
+See Testing the performance of your EPL apps and smart rules for details on writing performance tests.
To run in Apama EPL Apps, your run.py should look something like this:
from apamax.eplapplications.basetest import ApamaC8YBaseTest
class PySysTest(ApamaC8YBaseTest):
@@ -240,7 +240,7 @@ Table of Contents