JMeter – Until Controller – A Custom Controller

Problem Statement:

I have been using JMeter for years & I always found that difficult when there is no easy way to exit from the loop in case of error. I was looking for something like break statement in Java inside a while / for loop.

JMeter has If Controller which will let you execute the Samplers based on the condition. So, We can actually exit from the loop by designing the Test Plan with standard controllers available with JMeter.

For Example,

while001

As part of my project requirement, I had to execute above transactions in the given order. I do the Login first. Then I keep doing all the transactions inside the While Controller again and again. For this requirement, above setup should work well!

But the problem arises, when there is some failure occurs in any of the transactions.

Say, I search for a product. If the product is not available, there is no point in executing other transactions like – Ordering product, entering payment details, viewing product etc!! They are going to fail for sure!!

So, To make the test as I want with standard controllers, I have to design as given below.

uc-pu-001

Yes, above test plan should work well. But, in this case, I have only few transactions. What if I have 100 transactions? Should I have to add 99 If controllers after the first one!!? Does it not make my test plan very difficult to maintain? Yes, It actually does :(.

 

Until Controller:

So, I wanted to have my own controller which keeps executing all the samplers inside & but checks for the status of the previous sampler/transaction before proceeding. If the previous request passes, send the next request; If any of the sampler/transaction fails, exit from the loop/controller. [Thank God – JMeter is open source & lets us extend it with custom plugins!!]

Why is it called Until Controller? – It keeps executing all the samplers until some failure occurs.

 

How It Works:

Lets see this example. I have a test plan as given below. (1 thread – runs forever)

uc001

 

When i run the test, I see the output as given below just like I had expected. (Just execute all the samplers inside the until controller again and again).

 

uc001a

 

When some samplers fail, just stop the controller’s execution & exit from the loop. Go to the next sampler after the ‘Until Controller’.

uc001b

 

 

This was exactly as I wanted. So, I can remove all the If Controllers, Create my test plan as given below.

uc-pu-001   becomes like this using ‘Until Controller’ uc010

 

Performance of Until Controller:

The behavior is almost same like While Controller, I just wanted to compare the performance of Until Controller (logic of the controller should not affect the test’s performance) with while controller.

I had some samplers inside both controllers & ran it for sometime with no timers. They take sametime in both Pass & Fail cases..

uc-perf-pass

uc-perf-fail

Download:

If you would like to try, Please download it from here & place the jar under JMETER_HOME/lib/ext


	UntilController.zip	(9320 downloads)



Note: It will work only with JMeter version 2.13 or above.

Share This:

3 thoughts on “JMeter – Until Controller – A Custom Controller

  1. For these kind of scenarios, better use regular expression based Java or Groovy requests(JSR) , you can apply condition more specifically because new component might not a suitable way to deploy externally. BTW.. nice article, easy for any to start plugin development.

    1. Thanks for your comment. Not sure if you read the post fully that I have more than 100 HTTP requests to be sent inside a ‘while controller’. To avoid multiple if controllers/to make the script more readable, I was in need of a separate controller to satisfy my requirement. However I do agree that it is not only the approach.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.