Context: Want to generate unique and different value when the thread runs in loop. Currently it is generating the same value.
Script Inside JSR223 Preprocessor,
String subscribeSchemaNamePreProcesser="agent-Perf-${__Random(1,99999,)}"
log.info("Schema Name --------------->"+subscribeSchemaNamePreProcesser)
vars.put("subscribeSchemaNamePreProcesser", subscribeSchemaNamePreProcesser)
When run with number of threads more than 1(i.e. 2 thread 1 loop), it is generating different value
When run with number of loops more than 1 (i.e. 1 thread 2 loop), it is generating the same value (want to fix it)
anything I missed
Don't inline JMeter Functions or Variables into Groovy scripts, they will be cached and only first occurrence will be used for subsequent calls.
You need to change this line:
String subscribeSchemaNamePreProcesser="agent-Perf-${__Random(1,99999,)}"
to this one:
String subscribeSchemaNamePreProcesser = "agent-Perf-" + org.apache.commons.lang3.RandomUtils.nextInt(1, 99999)
More information:
Thanks for letting me know the issue, one more quick question off the topic from this question, I am running another thread with the same configuration where I am using the value which I am creating through this JSR223 preprocessor. Iam seeing the same value for all the request when I am running the next thread group in the same loop. Any clue how to fix it ?