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.
Related
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
Example:
Thread: 50,
Ramp-Period: 0,
Loop: 1.
I have to send different value with each thread. Is it possible to do it without changing the loop count?.
If you need to add something to an existing variable it may be done via __intSum() function
__counter() function generates incremented number each time it's being called either per-thread or global
Another candidate is __threadNum() function which is basically the number of current thread.
See How to Use JMeter Functions posts series for advanced information on above and other useful functions.
Your question looks like this - jmeter unique id per thread for http request
You can also use Beanshell to create an unique ID for every thread.
You can achieve this by adding a counter under the thread group.
In the counter it's possible to set the start, increase and maximum number you want to reach.
Then add reference name in counter, which will be used in your request as ${reference_name}
I am new to JMeter and it maybe a stupid question but I still find it hard to understand the concept here.
I have a simple test.
Thread Group with a Single thread with loop count of 2
PreProcessor that place two
variables on the vars map
A loop that execute a request twice based
on the PreProcessor parameters
I expected that the preprocessor will initialize the parameter and it will use the same values twice in the request.
It looks like it’s executing the PreProcessor once pair call.
When I switch the PreProcessor with similar User Defined Variables it reuses the same value on every call.
Can anyone explain the logic here?
I am using JMeter 2.11
A PreProcessor is executed each time the HTTP Request is executed so if you have a total of 2 iterations, you should see log twice, you have it 4 times so maybe number of iteration is different than what your write or you have 2 threads.
When you use User Defined Variables, the value is computed once and then reused. Value will be different per thread.
After reading the documentations and with #UBIK LOAD PACK help I used User Variables and it worked
User Variables - are specific to individual threads.
Pre-Processor is attached to a Sampler element (e.g. http request in our case), then it will execute just prior to that sampler element running
So 4 request for different parameters because it runs before every request
User Defined Variables - It is processed at the start of a test, no matter where it is placed. For simplicity, it is suggested that the element is placed only at the start of a Thread Group. This is why I get the same value all the time
I have a test that loops as suggested here:
Is it possible to loop a test in JMeter?
I have a Thread Group with 100 users and a loop count of 5.
A Runtime Controller to run for 30 seconds.
Now when the Runtime Controller finishes I would like to increment a variable that I can read inside my BeanShell sampler in my test. At the end of the test this variable should be equal to the loop count.
Ok figured it out!
I used a Counter element and set it to "Track counter independently for each user".
The variable increments only after each loop.
Also very important the Counter has to be under Thread Group but not inside the Runtime Controller.
Since you use Beanshell you can access current loop number as simple as
vars.getIteration();
See JMeterVariables class JavaDoc to see what else could be done using it, How to use BeanShell: JMeter's favorite built-in component guide for advanced information on Beanshell scripting in Apache JMeter and remember that the method will work only on Thread Group level, the value won't increment inside Loop Controller
In JMeter, I have a test plan with a thread group. The thread group has number of threads and a loop count which can be set in the gui.
Is there anyway I can figure out dynamically what they have being set so I can pass them to variable?
Thanks.
Use BeanShell PostProcessor with following code:
vars.put("threads", Integer.toString(prev.getAllThreads()));
Or maybe you just looking for this: http://code.google.com/p/jmeter-plugins/wiki/ActiveThreadsOverTime
You can parametrize the thread count defining a property like
${__P(users, 1)}
and if you run the test plan from command line, you can specify its value as -Jusers=XX. If, instead, you run the test from JMeter gui, to verify the text plan for example, the users property assume the default value of 1.
Don't forget to reference the property in the thread count, with ${users}.
You should parameterize your thread count at TestPlan level settings, then use that parameter (variable) both in ThreadGroup and Listener.
If the value varies and you want to pass it from command line use __P() function instead of variable.