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)
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)
java.lang.reflect.InvocationTargetException
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)
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…