loop variable not set in repeat

Hi there,
with gatling 2.0.0M3a the loop variable is not present in the session object:

repeat(3, “subsIdx”){

println("session in repeat: "+session)

val i = session(“subsIdx”).as [Int]

exec(addSubscription(subsList(i)))

}

results in

[ERROR] [04/08/2014 14:04:09.029] [GatlingSystem-akka.actor.default-dispatcher-9] [akka://GatlingSystem/user/$d] key not found: subsIdx

Thanks in advance

–Ulrich

You trimmed too much, the code you pasted here doesn’t even compile (where does this session come from?).

Could you share a gist, please?

object AddProfileScenario {

val headers= Map(

“Content-Type” → “application/json; charset=utf-8”)

val getChannels = http(“getChannels”)

.get("/channels")

.headers(headers)

.check(status.saveAs(“status”), status.is(200))

val updateChannel = http(“updateChannel”)

.put("/channels/${deviceId}")

.body(StringBody("""{ “token” : “${handle}” }""")).asJSON

.headers(headers)

.check(status.saveAs(“status”), status.is(204))

val addProfile = http(“addProfile”)

.post("/profile")

.body(ELFileBody(“michael/addProfile.ssp”)).asJSON

.headers(headers)

.check(status.saveAs(“status”))

def addSubscription(json:String) = http(“addSubscription”)

.post("/subscription")

.body(StringBody(json)).asJSON

.headers(headers_wind)

.check(status.saveAs(“status”), status.is(200))

session})

val addSubscriptions = exec(session =>{println(“addSubscriptions”)

val subsList = new SubscriptionExtractor(session(“subs”).as [String]).getSubs()

val nSubs = subsList.size

repeat(nSubs, “subsIdx”){

println("session in repeat: "+session)

val i = session(“subsIdx”).as [Int]

exec(addSubscription(subsList(i)))

}

session})

val scn = scenario(“add profile”)

.feed(ssv(“michael/devices.ssv”))

.exec(

http(“getProfile”)

.get("/profile")

.headers(headers)

.check(status.saveAs(“status”), status.in(Seq(200,404))))

.doIf("${status}", “404”)(exec(addProfile)

.doIf("${status}",“201”)(exec(getChannels)

.doIf("${status}",“200”)(exec(updateChannel)

.doIf("${status}",“204”)(exec(addSubscriptions)))))

}

Sorry, still not compiling, I suspect gmail filters things.
Please use a gist: https://gist.github.com

Sorry, it’s a larger test suite. I’ll try to construct a compilable example in a single file and send it.

val addSubscriptions = exec(session =>{println(“addSubscriptions”)

val subsList = new SubscriptionExtractor(session(“subs”).as [String]).getSubs()

val nSubs = subsList.size

repeat(nSubs, “subsIdx”){

println("session in repeat: "+session)

val i = session(“subsIdx”).as [Int]

exec(addSubscription(subsList(i)))

}

session})

Well, that will obviously not work.The Gatling DSL elements won’t be executed in a simple Scala closure.

Problem is solved:

  1. I forgot that session is immutable
  2. Instead repeat foreach is more adequate for my use case

Thanks to all for the hints