Testing a Siddhi Application
WSO2 Stream Processor Studio allows the following tasks to be carried out to ensure that the Siddhi applications you create and deploy are validated before they are run in an actual production environment.
- Validate Siddhi applications that are written in the Stream Processor Studio.
- Run Siddhi applications that were written in the Stream Processor Studio in either Run or Debug mode.
- Simulate events to test the Siddhi applications and analyze events that are received and sent. This allows you to analyze the status of each query within a Siddhi application at different execution points.
Validating a Siddhi application
To validate a Siddhi application, follow the procedure below:
- Start and access the Stream Processor Studio. For detailed instructions, see Starting Stream Processor Studio.
- In this example, let's use an existing sample as an example. Click on the ReceiveAndCount sample to open it.
Sample opens in a new tab. This sample does not have errors, and therefore, no errors are displayed in the editor. To create an error for demonstration purposes, change the
count()
function in thequery1
querytocountNew()
as shown below.@info(name='query1') from SweetProductionStream select countNew() as totalCount insert into TotalCountStream;
Now, the editor indicates that there is a syntax error. If you move the cursor over the error icon, it indicates that
countNew
is an invalid function name as shown below.
Running or debugging a Siddhi application
You can run or debug a siddhi application to verify whether the logic you have written is correct. To start a Siddhi application in the run/debug mode, follow the procedure below:
- Start and access the Stream Processor Studio. For detailed instructions, see Starting Stream Processor Studio.
- For this example, click the existing sample ReceiveAndCount. It opens in a new untitled tab.
- Save the Siddhi file sothat you can run it in the Run or Debug mode. To save it, click File => Save. Once the file is saved, you can see the Run and Debug menu options enables as shown below.
- Go to File and click Save. (Default saved in default workspace folder). Once saved you can see the above options are now enabled.
- To start the application in Run mode, click Run => Run. This logs the following output in the console.
- Start the application in the Debug mode, click Run =>Debug. As a result, the following mesage is logged in the console. You can also note that another console tab is opened with debug options.
- To start the application in Run mode, click Run => Run. This logs the following output in the console.
- To create an error for demonstration purposes, change the
count()
function in thequery1
query tocountNew()
, and save. Then click Run => Run. As a result, the following output is logged in the console.
Simulating events
This section demonstrates how to test a Siddhi application via event simulation. There are multiple methods to simulate events. In this example, you can use single simulation. For more information about all available methods, see Simulating Events.
To simulate a single event in order to check the status of your Siddhi queries, follow the procedure below:
Before you simulate events for a Siddhi application, you need to run or debug it. Therefore, before you try this section, see Run or debug a Siddhi application.
Run the
ReceiveAndCount
Siddhi application.- Click the following icon for event simulation.
It opens the left panel for event simulation as follows.
- In the Siddhi App Name field, select the name of the application for which you want to simulate events. For this example, select ReceiveAndCount.
- In the Stream Name field, select the stream defined in the Siddhi application for which you want to simulate events. For this example, select SweetProductionStream.
- Enter values for the attributes of the selected stream that appear in the pane, and click Send.
- In this Siddhi application, you have a sink of the log type connected to the
TotalCountStream
output stream. Therefore, once the events are received at the input stream, a log ise printed in the output console as shown below.