8/31/2023 0 Comments Java write a multi counter method![]() ![]() In our scenario, the relevant function will be: All threads share the same counter instance.Each thread (virtual user) has its own counter instance.JMeter provides the _counter() function, which returns an incrementing number starting from 1 and increasing by 1 each time. Tick “Track counter independently for each user” box (this is required for to avoid double counting when you have more than one virtual user).Reference name: any variable name i.e.If for some reason the Counter Config Element doesn’t play for you, there are other approaches to get the current iteration number.ĭefine a Counter inside the Thread Group and configure it as follows: When you look at the View Results Tree listener output, you should see that the results are identical as if they were implemented by copy-and-paste. You have the option to modify the sampler label in order to differentiate between different samplers in Listeners and identify a problematic request in case of a failure. Now let’s amend the HTTP Request sampler “name” parameter so it would take the current Counter value and send it to the server. ![]() The Counter configuration should therefore look like: It’s better to make it something self-explanatory, so that others can understand what it is (and when you revisit your test at a later date, you would easily be able to identify and understand it). Here you can define a JMeter Variable name that will be holding the current Counter value. If you put “00” into the field, the values will be prefixed by double zeros like 001, 002, 003, etc. If it is left blank, the values will be “normal” like 1, 2, 3, etc. You can change the output number format using this parameter. So it is fine either to leave it blank or to set it to 5 or above. When it is set and the current counter value exceeds “maximum” value, counter starts over. If it is left blank, the Counter value will increment infinitely. Let’s make it 1 as well as we need to replicate the above behavior. This value will be added to the current Counter value once the Counter is hit. (If you leave it blank, the Counter will start from zero.) b. ![]() This is initial counter value, let’s make it 1. Define the JMeter Counterĭefine a Counter inside the Loop Controller and configure it as follows. ![]() Add a Loop ControllerĪdd a Loop Controller and set the “Loop Count” to 5 2. Now let’s implement the same scenario using a single HTTP Request run via parameterized iterations. The better way is to use a Loop Controller and a Counter. It works and it works fine, but what if you need to do it 100 times? 200 times? What if you need one more parameter to the HTTP Request? Code duplication isn’t a very good idea by itself - it’s better to design reusable components in the form of pluggable modules, use loops and other logic controllers in order to keep your test as short as possible. The bad way to go about this is to copy and paste the relevant request five times so that the Test Plan appears as in the image below: Let’s imagine a scenario in which you need to create five entities in a loop using the HTTP Request sampler and each entity name has to be unique. How to Use the JMeter Counter Config Element
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |