Passing parameter in Gatling2

Hi everybody,
I have a problem, when I try to pass external parameters in gatling 2 I receive an error. I used the example for gatling 1

val nbUsers = java.lang.Integer.getInteger(“users”, 1)
val myRamp = java.lang.Long.getLong(“ramp”, 0L)

and I applied in the new API of gatling 2, but I’m not an expert of Scala:

setUp(scn.inject(atOnce(nbUsers users), ramp(10 users) over (myRamp seconds))).protocols(httpProtocol)

During the compilation I have this error:

value users is not a member of Integer
[main][ERROR][ZincCompiler.scala:98] i.g.a.ZincCompiler$ - setUp(scn.inject(atOnce(nbUsers users), ramp(10 users) over (myRamp seconds))).protocols(httpProtocol)

Could you help me?

Thanks,
Andrea

We’ve just introduced a way to have this kind of things work as is in master/next 2M4.
Until then, you have to convert your java.lang.Integer into scala.Int: java.lang.Integer.getInteger(“users”, 1).toInt

val nbUsers:Int = java.lang.Integer.getInteger(“users”, 1)
val myRamp:Long = java.lang.Long.getLong(“ramp”, 0L)

It only works with Scala Int/Long. So, with the typing I added, there is an automatic conversion.

It works.
Thanks!

Hi,
now everything works well, but when I try to pass those parameters from the maven gatling plugin the compiled class doesn’t receive the parameter and it always uses the default values.

This is what I declared in the pom file:

100

1

io.gatling gatling-maven-plugin ${gatling.version} test execute false true src/test/resources src/test/scala src/test/resources/data target/gatling/results **/*.scala -Dusers=${numberOfThreads} -Dramp=${rumpUpPeriod}

How the variable are retrieved in the scala (like you suggested):

val nbUsers = java.lang.Integer.getInteger(“users”, 1).toInt
val myRamp = java.lang.Long.getLong(“ramp”, 1).toLong

setUp(scn.inject(atOnce(nbUsers users), ramp(10 users) over (myRamp seconds))).protocols(httpProtocol)

What is wrong?

Thanks,
Andrea

Try pulling the configuration block out of the executions block:

100

1

io.gatling gatling-maven-plugin ${gatling.version} test execute false true src/test/resources src/test/scala src/test/resources/data target/gatling/results **/*.scala -Dusers=${numberOfThreads} -Dramp=${rumpUpPeriod}

This is a bug that’s been fixed in master but is still there in 2M3a.

I’m having a similar problem, but casting to Int is not working.

val numUsers:Int = Integer.getInteger(“users”, 1)

val ramp:Long = java.lang.Long.getLong(“ramp”, 0L)

setUp(scn.inject(ramp(numUsers users) over (ramp seconds)).protocols(httpConf))

gives me

value users is not a member of Int

Is there a new and improved way to do this? The 2.0.3 wiki still mentions the old 1.5.6 syntax.
Thanks!

...
  setUp(scn.inject(ramp(numUsers users) over (ramp
seconds)).protocols(httpConf))

Proper syntax is rampUsers(numUsers)

Is there a new and improved way to do this? The 2.0.3 wiki still mentions

the old 1.5.6 syntax.

Really? Could you show where, please?

This page: http://gatling.io/docs/2.0.3/cookbook/passing_parameters.html

says:

val nbUsers = Integer.getInteger("users", 1)
val myRamp  = java.lang.Long.getLong("ramp", 0L)
setUp(scn.inject(ramp(nbUsers users) over (ramp seconds))

There’s no mention of casting to Int or the rampUsers technique you just mentioned.

Thanks!

That new syntax you gave me works, though, so thank you very much!

setUp(scn.inject(rampUsers(numUsers) over (myRamp seconds)).protocols(httpConf))

compiled just fine.

Oh, right!
https://github.com/gatling/gatling/issues/2412

Thanks for reporting!

Related question to passing parameters.

How can I pass the parameters when using the SBT plugin?

I tried the following but it doesn’t work:

$ sbt -DnrUsers=10 'testOnly *HomePage*'

Thanks
Carlos

The only way I’m able to pass parameters is through javaOptions in the build.sbt file.

Like follows:

javaOptions += "-DnrUsers=10"

But I actually want to be able to pass parameters from the command line, since this would require that I change the build.sbt file every time I want to change a property.

Hi,

Unfortunately, SBT doesn’t pass system properties to its subprocessses (e.g. tests, main classes ran from SBT…).
The only other option I can think about is using environment variables, which you would then access in your simulation using :

sys.env("nrUsers").toInt

Cheers,

Pierre