Getting feeder values from a session function

Hi -
Can I get the current feeder values from a session function like the one below (getData)? (I’m using the 2.x snapshot from July 1, 2014). The getData function is for putting together a JSON post body including values from the csv file defined by the feeder and used by potentially different paths.

val getData = exec((session) => {
count = count + 1
the_username = session.getTypedAttribute(“username”) // wanting to get ‘username’ from the csv feeder here, but how? this does not compile (getTypedAttribute is not a method of Session and seems to be deprecated anyway)
the_password = session.getTypedAttribute(“password”) // wanting to get ‘password’ from the csv feeder here, but how?
val data: String = “”"{ “user”: “”" + the_username + “”",“password”:""" + the_password + “”"}"""
session.set(“message”, data)
}
)

val scn = scenario(“Feeder Test”)
.feed(userCredentials)
.repeat(1) {
exec(getData)
.doIfOrElse((session:Session) => count % 10 == 0) {
chain1
} {
randomSwitch (
percentage1 → chain2,
percentage2 → chain3
)
}
.pause(1000 milliseconds)
}

Thanks in advance
Tom

Hi,

Did you check out this page? https://github.com/excilys/gatling/wiki/Gatling%202

If the data comes from a feeder, it’s safe to assume it’s indeed here (not depending on a check that might have failed) and use “as”:
session(“username”).as[String]

Then, you probably don’t define the variables properly (count, the_username, the_password).
If I get it properly:

  • the_username and the_password are only used inside the function, so they should be defined as local val.

  • count is a global counter, so it should be an AtomicInteger or you’ll experience race conditions/visibility issues as the function will be executed by multiple concurrent threads.

Cheers,

Stéphane

Thanks, Stephane. I see that in the Wiki now.