[Gatling2] adding random int as query param

2,501 views
Skip to first unread message

Uladzimir Kazimirchyk

unread,
Nov 5, 2013, 5:34:03 AM11/5/13
to gat...@googlegroups.com
Hi!

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..?

Thanks.

Stéphane Landelle

unread,
Nov 5, 2013, 5:54:49 AM11/5/13
to gat...@googlegroups.com
Hi,

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)

Cheers,

Stéphane



2013/11/5 Uladzimir Kazimirchyk <kazim...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Uladzimir Kazimirchyk

unread,
Nov 5, 2013, 6:12:12 AM11/5/13
to gat...@googlegroups.com
Stéphane,

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")
    .feed(csv("test_data.csv").random)
    .exec(http("srvc_call").get("${url}")
    .queryParam("testParam", getRand(1000))
    .check(status.is(200))
  )

Right?

Stéphane Landelle

unread,
Nov 5, 2013, 6:13:57 AM11/5/13
to gat...@googlegroups.com
Nope, getRand(1000) will still be evaluated once.
_ => getRand(1000)


2013/11/5 Uladzimir Kazimirchyk <kazim...@gmail.com>

Uladzimir Kazimirchyk

unread,
Nov 5, 2013, 6:17:13 AM11/5/13
to gat...@googlegroups.com
and now I get ClassNotFoundException

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)

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

Stéphane Landelle

unread,
Nov 5, 2013, 6:22:47 AM11/5/13
to gat...@googlegroups.com
o_O

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


2013/11/5 Uladzimir Kazimirchyk <kazim...@gmail.com>

Uladzimir Kazimirchyk

unread,
Nov 5, 2013, 6:29:57 AM11/5/13
to gat...@googlegroups.com
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...

Stéphane Landelle

unread,
Nov 5, 2013, 6:35:34 AM11/5/13
to gat...@googlegroups.com
At this point, I can't help you find out what's wrong with getting my hands on your files.
Can you share?


2013/11/5 Uladzimir Kazimirchyk <kazim...@gmail.com>

Uladzimir Kazimirchyk

unread,
Nov 5, 2013, 6:35:55 AM11/5/13
to gat...@googlegroups.com
My bad, sorry. I added .scala extension to class name when running by maven.
So it was looking for scala class :)

Stéphane Landelle

unread,
Nov 5, 2013, 6:37:58 AM11/5/13
to gat...@googlegroups.com
Ahhhhhhh :)


2013/11/5 Uladzimir Kazimirchyk <kazim...@gmail.com>
Reply all
Reply to author
Forward
0 new messages