Warm tip: This article is reproduced from serverfault.com, please click

JSR223 Preprocessor generating the same value when the thread runs in loop

发布于 2022-01-28 05:23:13

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

enter image description here

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)

enter image description here

enter image description here

anything I missed

Questioner
Jyoti Prakash Mallick
Viewed
0
Dmitri T 2022-01-28 13:40:17

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: