[Gatling2] adding random int as query param


I need to avoid server request caching so i decided to add a random int as query param to urls.
I’m trying to add additional parameter via .queryParam(“param”, “value”) and use

ThreadLocalRandom.current.nextInt(1000) as a random number generator. The problem is –

when I add .toString and pass this value to .queryParam I get an error:

type mismatch;
found : () => String
required: io.gatling.core.session.Session => io.gatling.core.validation.Validation[String]
13:25:58.444 [ERROR] i.g.a.ZincCompiler$ - .queryParam(“testParam”, ThreadLocalRandom.current.nextInt(1000).toString)

What am I doing wrong…?



This indeed fails to compile with 2M3a but compiles fine with master, not sure why…

Anyway, this won’t work as you expect because you’re passing a value, not a function, ie it will be only evaluated once, when the scenario is built, not every time a request is built and sent.

long form: .queryParam(“testParam”, (session: Session) =>ThreadLocalRandom.current.nextInt(1000).toString)
can omit session type as the compiler can infer it: .queryParam(“testParam”, session =>ThreadLocalRandom.current.nextInt(1000).toString)
session is not used here anyway: .queryParam(“testParam”, _ =>ThreadLocalRandom.current.nextInt(1000).toString)




so I need something like this:

val httpProtocol = http.baseURL(“http://some.url.com”)

def getRand(i: Int) : String = ThreadLocalRandom.current.nextInt(i).toString

val scn = scenario(“Load test”)
.queryParam(“testParam”, getRand(1000))


Nope, getRand(1000) will still be evaluated once.
_ => getRand(1000)

and now I get ClassNotFoundException

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at scala_maven_executions.MainHelper.runMain(MainHelper.java:164)
at scala_maven_executions.MainWithArgsInFile.main(MainWithArgsInFile.java:26)
Caused by: java.lang.ClassNotFoundException: performance.img_srvc.Img_perftest.scala
at scala.tools.nsc.interpreter.AbstractFileClassLoader.findClass(AbstractFileClassLoader.scala:69)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at io.gatling.app.SimulationClassLoader$$anonfun$simulationClasses$1.apply(SimulationClassLoader.scala:56)
at io.gatling.app.SimulationClassLoader$$anonfun$simulationClasses$1.apply(SimulationClassLoader.scala:55)
at scala.Option.map(Option.scala:145)
at io.gatling.app.SimulationClassLoader.simulationClasses(SimulationClassLoader.scala:55)
at io.gatling.app.Gatling.start(Gatling.scala:174)
at io.gatling.app.Gatling$.fromMap(Gatling.scala:59)
at io.gatling.app.Gatling$.runGatling(Gatling.scala:80)
at io.gatling.app.Gatling$.main(Gatling.scala:54)
at io.gatling.app.Gatling.main(Gatling.scala)

That drives me crazy :slight_smile:
What could be the reason?


Is performance.img_srvc the expected package name and Img_perftest the expected Simulation class name?
Is performance/img_srvc a valid folder hierarchy?

Yes. I guess if it was wrong then I should get the same error earlier(instead of Type Mismatch one).
But when I corrected the error with types in .queryParam - I got this one. That’s strange…

At this point, I can’t help you find out what’s wrong with getting my hands on your files.
Can you share?

My bad, sorry. I added .scala extension to class name when running by maven.
So it was looking for scala class :slight_smile:

Ahhhhhhh :slight_smile: