Dynamically add 5 minutes to TimeShift in Jmeter - performance

I have created a loop in Jmeter and I have a counter within the loop.
vars.put("counter", "5")
I am then incrementing the loop by +5 for every iteration of the loop. What I am trying to do is add that counter to this:
${__timeShift(HH:mm:ss,,PT5M,,)}
So I am trying to dynamically add 5 minutes to the TimeShift each iteration. so something like ${__timeShift(HH:mm:ss,,PT${counter}M,,)}. I know this is wrong but I can't think of a way to do it. Does anyone have any ideas?

This guy: ${__timeShift(HH:mm:ss,,PT${counter}M,,)} should work just fine, most probably the problem is with the way you're incrementing the counter.
Instead of scripting you can consider switching to Counter configuration element:
So you would be able to get something like:
If you want to continue with scripting be aware of vars.putObject() function which allows you storing any arbitrary object into JMeter Variables so you won't have to convert it from String to Integer and vice versa

Related

Jmeter reading input parameters from dynamically appending file

Please tell me, is it possible to read data into Jmeter from a dynamically changing file? I have a file with parameters, which will be appended during the test itself. Is it possible to somehow define a global counter that will allow each thread to read its own line every iteration? User Defined Variables are reset every iteration as i understood.
In theory, I can read a specific line using File.readLines().get(counter) in JSR223 Sampler but problem is how to define correctly this counter.
I believe __counter() function is what you're looking for. If you invoke it like ${__counter(FALSE,)} it will return an incremented value each time it will be called.
Example usage:
More information: How to Use a Counter in a JMeter Test

How to print iteration number in Pepper-Box plain text config?

I want to print iteration number in pepper-box plain text config and i tried Counter config element of jmeter but during execution it is not replacing iteration number. Like if i am using ${counter} so in execution it is printing ${counter}.
I am using counter config element because i need iteration number in some format like 00001,00002,00003 etc.
I also tried to use function like Counter(TRUE,) but it is just replacing first iteration number and not increasing it. Only first iteration number printing in all next iteration.
In Pepper-Box sampler you can only use a limited subset of built-in template functions having different syntax.
You can try doing something like:
{{org.apache.jmeter.threads.JMeterContextService.getContext().getVariables().get("counter")}}
or if you want to share your script with others you can consider implementing a custom function
Check out Apache Kafka - How to Load Test with JMeter article for more information on building a Kakfa test plan using JMeter

Labview events - do a taks in parallel to a running loop

I'm trying to do something very simple:
OK button sums a+b and shows in c
Loop switch button control a infinity loop
Option 1 - Loop outside event
Option 2 - Loop inside event
I just want to be able to keep the loop running and the OK button working at the same time, how can achieve that simple task in Labview "way of life".
Results:
Op 1 - Outside event: One loop occurs after OK click, if loop is running, OK works only at first time
Op 2 - Inside event: Button OK does not work
You can't. You'll need two seperate while loops, one with the count functionality, but don't use the 'loop' variable as the stop condition, make the loop variable control a the count condition.
In the other while loop you'll have your event code.
The only thing you'll have to worry about is stopping the first while loop from the event code.
Here is how you can do it with a Master/Slave configuration. All the user events are handled in the master, the counting is handled in the slave. The loop can be restarted and the stop works for both loops.
To Stop the code you use a different event, in the case the loop conditional is false you don't do anything in the slave loop. Not shown here, but the loop conditional also has it's own event structure to reset the counter if needed.
This master/slave structure is extendable to as many loops as you want.
I see two options:
Similiar to option 2 but do the "loop math" not inside the "Loop Value Canged"-Case but inside the "Timeout"-Case. Then you don't need the while loop, use a if-case (loop = true) instead.
Use two while loops. Inside each of them put a event case. One to handle the "C=A+B"-Event and one for the "Loop Value Changed".
I think the design pattern you are looking for is the Producer/Consumer pattern. This allows you to run parallel loops and if need be share data between them.
A quick google on the term combined with labview will give you enough examples.

how to use jmeter functions in loop controller

My test plan is below
!TestPlan
ThreadGroup
LoopController1
Sampler1
BeanShellPostProcessor
Listener
LoopController2
Sampler2
As part of Beanshellpostprocessor, i am putting count value to a variable
props.put("noOfRecords",vars.get("msg_#"));
Now this value i am placing on 2nd loopcontroller as ${__P(noOfRecords,0)}
This setup is failing for iterations where we don't have any records. So the previous "${__P(noOfRecords,0)}" value is considered while running the Loop2.
Is there any other way we can achieve the dynamic loop counter?
You can use variables or properties in the Loop Controller to change the loop count at run time.
If the Property/Variable is set correctly by the Beanshell postprocessor in your test, It should work. That is, you need to set the value to 0 explicitly when there is no record. Otherwise Properties (which are not destroyed until you close JMeter) might use the previous value.

How to set counter in nested while loop in jMeter?

in my jmeter test I have a loop controller which works on messages got from previous thread group with a while loop inside. In while I'm sending GET as long as it is not successful. I would like to know how many of GETs was send. It looks like this:
-Loop Controller
--While (${__javaScript("${statusCode}"!="200")})
----Counter (on retry variable)
----GET ${retry}
I thought that every while loop will have an individual counter, but it's not. The counter gets incremented in every Loop Controller iteration. Any ideas?
It looks like that you need __counter() function instead of Counter Config Element. It's incremented by one on call, not on iteration.

Resources