Struggling with proper way to println and get/set session vars inside repeat loop

I have a few questions based on the following code. I’m trying to repeat creating new users multiple times serially and create a 6 digit identity number each time. I’m attempting to pad the repeat index number with this, otherwise once it gets over 9 the creation process fails since it’s adding too many digits. I may not be doing that right, but I think I’m on the right track with that. I’m using gatling 2.0 m4 I believe.

val CreateNewUserScenario = scenario(“Create New Users”)
.repeat(3, “n”) {
exec(session => {
var intN: java.lang.Integer = Integer.parseInt(session(“n”).as[String])
var identSuffix = String.format("%03d", intN)
session.set(“identSuffix”, identSuffix)

println(“session follows”)
println(session)

// return the original session
session
})

exec(http(“CNU_get_ext_home”)
.get("""/external/"""))
.pause(4)
.exec(http(“CNU_get_create_acct”)
.get("""/external/createAccount"""))
.pause(10)
.exec(http(“CNU_save_user”)
.post("""/external/user/saveSelf""")
.formParam(""“user_company_ident”"", “”“123${identSuffix}”"")
.check(regex(""“User Account Created”"").exists))
}

Questions are…

  1. I get the following error with the above “> No attribute named ‘identSuffix’ is defined 3 (100.0%)” How do I set this session var in the repeat loop so it’s available later in my http calls?

  2. I never see the println output despite setting the logback to DEBUG once and INFO another time. How do I use println within a scenario to output the session? I attempted to follow the example from the guide but I’m not seeing anything.

  3. Should I have the execs inside the repeat as two separate exec statements or is there some way to get these to work fluently? I tried adding a . in front of the second exec block but it threw errors.

Thanks!

  • Galen Fisher

Session is immutable!!!
http://gatling.io/docs/2.0.0-RC5/session/session_api.html#setting-attributes

Thanks, my mistake. That just wasn’t getting through my head earlier.

I got it working(I think, it’s not failing anymore) by doing this:

val CreateNewUserScenario = scenario(“Create New Users”)
.repeat(3, “n”) {
exec(session => {
var intN: java.lang.Integer = Integer.parseInt(session(“n”).as[Int].toString())
var identSuffix = String.format("%03d", intN)

// return the original session
session.set(“identSuffix”, identSuffix)
})

.exec(http(“CNU_get_ext_home”)
.get("""/external/"""))
.pause(4)
.exec(http(“CNU_get_create_acct”)
.get("""/external/createAccount"""))
.pause(10)
.exec(http(“CNU_save_user”)
.post("""/external/user/saveSelf""")
.formParam(""“user_company_ident”"", “”“123${identSuffix}”"")
.check(regex(""“User Account Created”"").exists))
}

What would you recommend for checking the values of session for debugging after setting values as best practice? Something like this?

exec(session => {
var intN: java.lang.Integer = Integer.parseInt(session(“n”).as[Int].toString())
var identSuffix = String.format("%03d", intN)

// return the original session
session.set(“identSuffix”, identSuffix)
})

.exec(session => {

println(“session follows”)
println(session)

session
})

Yep, that’s what I usually do.