While Controller and Why is it needed?
In today`s Microservices architecture, when calling services, we do not expect an instant answer from them. It is quite possible that they are using a messaging service e.g.: Rabbit or one service keeps pooling, expecting an answer from the other till the time out happens or a desired response is attained.
We will talk about the case of using messaging service like a RABBIT MQ in a different post.
Normally there is a flag which defines that is it still waiting for the response or is happy or not happy with the response or has it timed out.
This is a classic example of using a While Condition in our Java or Javascript codes.
For someone who is a fan of coding or scripting he/she would be using a bean shell and storing the value of the flag in a variable and then checking for the expected values to move forward or stop the execution.
But to avoid that there is a simpler solution which is by using a While Controller.
Below is how it looks like.
Description of the various fields.
Name: Name to be seen in the script.
Comments: Further description of what and why it does what it is supposed to do.
Condition (function or variable): This is where we write a small line of script which is the WHILE Condition.
Below is how to fill the fields.
Explanation of the Condition field:
Jmeter uses the javascript and here we are simply using the condition that, till the flag (status) is not equal to the value of “FINISHED” keep calling the end point.
But this is just in case we are waiting for one flag what if the outcome is based on multiple flags.
Then like we do in coding:
1) And condition
2) OR condition
Syntax is as follows
1) And Condition
${__javaScript ("${status}" != "FINISHED" && ${Results} >= 0,) }
2) OR Condition
${__javaScript ("${status}" != "FINISHED" || ${Results} >= 0,) }