engineer diaries Logo

Logic Controller in Jmeter And Its Types | EngineerDiaries

Jan 31, 2021, 1153 Views, 0

Contents

  • Simple Controller
  • Loop Controller
  • Once Only Controller
  • Interleave Controller
  • Random Controller
  • Random Order Controller
  • Throughput Controller
  • Runtime Controller
  • If Controller
  • While Controller
  • Switch Controller
  • ForEach Controller
  • Module Controller
  • Include Controller
  • Transaction Controller
  • Recording Controller
  • Critical Section Controller
  • Logic controller in Jmeter is among the major components of the JMeter test plan besides sampler, configuration element, and listener. Though logic controller themselves do not send the request to the server. They are majorly used to add repeat value to the sampler as applying if-else, loop in the sampler. They are also used to group samplers in thread group as samplers and attached listeners are placed in the logic controller. Jmeter allows more than 15 types of logic controllers and below we are going to look into the purpose of each. So, let us get started.Logic Controller in Jmeter And Its Types | EngineerDiaries

    1.Simple Controller

    Simple controller does not add any logic behind the sampler but is used to group samplers together to make them more readable and hence be able to control the flow of execution.  Say you have multiple samplers and listeners for authentication and cookie management, so you put them under a simple controller here.
    Logic Controller in Jmeter And Its Types | EngineerDiaries

    2. Loop Controller

    Loop controller will execute the sampler requests to the times specified in the loop logic controller. Say you specify 3 times, and in the thread group, you have already specified it 2 times. Then the sampler request would be sent 3*2 =6 times. Now the difference lies in the fact that thread group is the representation of multiple users, whereas a sampler in loop controller is the request sent by the same user multiple times that too in a short span of time. So, you have handled two types of loads here, one of the multiple users and the other multiple requests by the same user. Cool right! 

    Logic Controller in Jmeter And Its Types | EngineerDiaries

    3. Once Only Controller

    Once only Logic Controller behaves as the name specified that is the controller under the logic would only be executed once per thread.  Even though the main thread group asks to have 10 users so the samplers should be expected to get execute 10 times, but the sampler under once only controller would override that and only execute once than expected 10 times. This makes even more sense for authentication, cookie management, and logic scenarios.

    Logic Controller in Jmeter And Its Types | EngineerDiaries

    4. Interleave Controller

    Interleave Controller is even more fun. So, the controllers under the interleave logic controller would be executed only once leaving the rest behind, and on the next turn, the next one would get executed.  The example below would show the sequence, but where the possibility of this could arise? Say you want to log in first through a sampler then sends the request to website1, then logic through 2 samplers, and then send the request to website 2, and so on. 


    Logic Controller in Jmeter And Its Types | EngineerDiaries

    5. Random Controller

    Random controller is different from interleave controller where there the sub ones get sequentially executed one at a time to anyone getting executed with the possibility of the same one getting executed again than in the order. Look at the example below for more detail. Now, that is a problem that in random order also same could be getting execute again and again, and to overcome this scenario we have random order controller. 

    Logic Controller in Jmeter And Its Types | EngineerDiaries

    6. Random Order Controller

    The major issue with Random Controller was that the sub-controllers could be getting executed, again and again, that would spoil the purpose of having Random in the first place, hence random order controller would let you execute sub-controller at most once. But the order would still remain random than the interleave. 

    Logic Controller in Jmeter And Its Types | EngineerDiaries

    7. Throughput Controller

    So, the throughput term itself signifies how much data could be transferred in a given time. Like once only controller throughput allows resetting the execution of sub-controllers with percentages where percent executions would tell the amount that can get executed whereas total executions restrict to not execute the sub-controllers more than this much. 

    Logic Controller in Jmeter And Its Types | EngineerDiaries

    8.Runtime Controller

    Runtime controller limits the sub-controller execution by the parameter of time. Till the defined time only the sub-controllers would continue the execution. Now this would prevent requests being sent in a particular frame of sessions like OTP has validity for 120 seconds, these logics are implemented in the controller.

    Logic Controller in Jmeter And Its Types | EngineerDiaries

    9. If Controller

    If Controller will select if the samplers in the controller should be executed or not. This is the only controller where you need to write a bit of code. Syntax is :"${myVar}" == "\${myVar}" where the result needs to be evaluated to be true or false and myVar is the variable. 



    Logic Controller in Jmeter And Its Types | EngineerDiaries

    10. While Controller

    While controller allows the samplers to send in the requests till the condition becomes false. Again you have to write the login for the expression as if the response is not 200 then, the execution must stop and likewise.

    Logic Controller in Jmeter And Its Types | EngineerDiaries

    11. Switch Controller

    Switch controller is pretty similar to interleave controller but in interleave controller, the sequence was 1 here, you can set the sequence of the samplers and by default are numbered from 0.

    Logic Controller in Jmeter And Its Types | EngineerDiaries


    12. ForEach Controller

    When you want to repeat the occurrence of the controller and its elements on the basis of condition then forEach logic controller is used as in if the variable value is true then execute it 2 times as such which is how switch case works in our regular coding language.

    Logic Controller in Jmeter And Its Types | EngineerDiaries


    13.  Module Controller

    Now controllers are of 3 types: Samplers which sends in the request, logic controller which controls the logic of sampler and lastly test fragments which are reusable components to fit in the code. Here we are talking about the module controller which allows the use of test fragments that can be added anywhere in the thread group.
    Logic Controller in Jmeter And Its Types | EngineerDiaries


    14. Include Controller

    Include allows using an external JMX file which contains a separate test plan be used in the current test plan, pretty much like how we import libraries in java. This makes it easier and more readable and hence enhance reusability. 
    Logic Controller in Jmeter And Its Types | EngineerDiaries


    15. Transaction Controller

    Transaction controller does not control the time here, rather measure the time taken to perform all the nested samplers sending-receiving request. Also, assertions here could be used as if time is being taken more than the desired then mark it as a failure event. Likewise.


    Logic Controller in Jmeter And Its Types | EngineerDiaries

    16. Recording Controller

    The recording controller writes the samples been sent by the sampler. As listeners record the responses. Hence can be used efficiently in debugging scenarios.


    Logic Controller in Jmeter And Its Types | EngineerDiaries

    17. Critical Section Controller

    Critical section controller takes in lock property where the elements inside the controller would be used by only one controller and its value has been defined by the lock. With this, we have completed the different types of logical controllers in JMeter. 

    Logic Controller in Jmeter And Its Types | EngineerDiaries

    Comments Section: