same session used for all virtual users?!

Hi all,

I have created this scenario (below code), which work fine with 1 user. But when I “rampUsers” to more then one user, all users get the same “Metadata.metadataMap” which is a var metadataMap = Map( "..." -> "...", ...) loaded from a scala object. What am I doing wrong? I did think that the session got set uniquely for each user? Thereby the var metadataMap.. should be called each time a new user is started?


import io.gatling.core.Predef._

import io.gatling.core.structure.ScenarioBuilder
import io.gatling.http.protocol.HttpProtocolBuilder
import io.gatling.http.Predef._

import com.typesafe.config.{Config, ConfigFactory}
import scala.concurrent.duration._

class LoadSimulation extends Simulation {

val config: Config = ConfigFactory.load()

val httpConf: HttpProtocolBuilder = http.baseURL(config.getString("baseUrl"))

val fileBufferFeeder: Seq[Array[Byte]] = LoadFile.iteratorOfFileByteArrays.toSeq
val runNum: Int = fileBufferFeeder.length - 1

val scn: ScenarioBuilder = scenario("Load Test Simulation")
.exec(session => session.set("START_MAP_METADATA", Metadata.metadataMap).set("CALL_ACTIVE", "True")).exec(session => {session.set("START_METADATA", JsonUtil.toJson(session("START_MAP_METADATA").as[Map[String, Any]]))})
.foreach(fileBufferFeeder, "feedElement", "counter")
{
doIfOrElse(_("counter").as[Int] < runNum) {
exec(
http("Call wav upload ${counter}")
.post(config.getString("baseUrl"))
.bodyPart(ByteArrayBodyPart("file", _("feedElement").as[Array[Byte]]).fileName("file.wav").contentType("application/octet-stream")).asMultipartForm
.bodyPart(StringBodyPart("call", _("START_METADATA").as[String]).fileName("call.json").contentType("application/json")).asMultipartForm
.queryParam("callactive", _("CALL_ACTIVE").as[String])
.header("Content-Type", "multipart/form-data")
.check(status.is(204))
).pause(1 second)} {
exec(session => session.set("STOP_METADATA", JsonUtil.toJson(session("START_MAP_METADATA").as[Map[String, Any]].updated("stop", System.currentTimeMillis()))).set("CALL_ACTIVE", "False"))
.exec(
http("Call wav upload ${counter}")
.post(config.getString("baseUrl"))
.bodyPart(ByteArrayBodyPart("file", _("feedElement").as[Array[Byte]]).fileName("file.wav").contentType("application/octet-stream")).asMultipartForm
.bodyPart(StringBodyPart("call", _("STOP_METADATA").as[String]).fileName("call.json").contentType("application/json")).asMultipartForm
.queryParam("callactive", _("CALL_ACTIVE").as[String])
.header("Content-Type", "multipart/form-data")
.check(status.is(204))
).pause(1 second)}
}

/* Here we ramp up the users */
setUp(
scn.inject(rampUsers(10).over(30 second))
).protocols(httpConf)
}

Thanks for your help.

Ok all sessions are unique… I guess it was just me not thinking right… The

metadataMap = Map( “…” → “…”, …)loaded from a scalaobject`.

was acting like a val event though it was set as var.
But I have now changed it to


def metadataMap(): Map[String, Any]= {
+ Map( ...

And now everything works like a charm… Thanks gatling for such a great tool.