def getrandomNo(): String = {
return ((rnd.nextDouble() * (1000000.0)).toLong).toString
}
scenario("scn getart).during(test_duration minutes) {
exec(actionBuilder = http("req getart")
.post(apiurl)
.header("txn-id", getrandomNo()+"_getart")
.body(apibody)
}
In the above code sample trying to generate unique txn-id for each request. However, observed that it is reusing the same number causing duplicates. Also I tried using the following to generate based on current time still it is causing duplicate when more than 1 requests are fired within 1second.
def getTxnId(): String = {
"PerfTest_" + System.currentTimeMillis().toString+ getrandomNo()
}
Any alternate solutions to generate unique ids for each requests irrespective of concurrency?
Thanks in advance.
This doesn't work because your getrandomNo
is only called once when building the Simulation. If you don't want to pass a value, but some piece of code you want to get executed on each execution, you have to pass a function:
.header("txn-id", session => getrandomNo()+"_getart")