4
votes

I have Jmeter test with following scenario:

Thread (5 in number)
  -> counter X (X value 0, increment by 1 till 10)
  -> req1 uses X
  -> req2 uses X

Now what I want to achieve is that, for each user and each request the value of X should increment without overlapping/repeating i.e If I run it for 5 user * 2 runs = 10 request, than value of X for each request should very from 1 to 10 without repetition.

But above approach does not work as the each user the counter start from 0 so I get duplicate X in request made, something like

user1 -> req1 X = 0, 
user1 -> req2 X = 1
user2 -> req1 X = 0
user2 -> req2 X = 1

I tried to use user defined variable with : bean shell pre-process still the same issue. even the ${__intSum(${X},1,X)} does not solve the issue. even tried ${__counter(TRUE,X)} does not solve the issue.

2

2 Answers

8
votes

JMeter Counter by default does not give duplicate value - gets incremented automatically for each user & for each iteration.

Uncheck 'Track counter independently for each user' check box.

enter image description here

EDIT:

If your requirement is to increase the counter for each request inside a thread-group, It is not possible with counter. You can use JMeter properties to do that.

Check here - http://jmeter.apache.org/usermanual/best-practices.html - Sharing Variables.

0
votes

Solution for this is to use BeanShell preprocessor. I used the bean shell with below value and use the variable "transactionId" in all my request and I get different value for each call by each thread(user).

import java.util.Random;

long x = 1000000L;
long y = 9999999L;
Random r = new Random();
long number = x+((long)(r.nextDouble()*(y-x)));

vars.put("transactionId",number );

log.info(" transactionId : " +  number );

Note : You can use any logic to generate the value as per your requirement.