Choosing random customer from sequence of customers

Hello,

I’m using Gatling 2, and I have something like the following:

.exec(http(“Customer_information”)
.get("/customers")
.check(jsonPath("$…customerNumber").findAll.saveAs(“customers”)))

.exec(session => session.set(“customer”, session(“customers”).random))

That last line does not work. I’ve also tried something like ${customers.random}, which works in for instance in a get query, but I need to store the chosen customer number in the session.

What is the correct way of doing this?

-Andreas

Would be something like this:

import scala.concurrent.forkjoin.ThreadLocalRandom // just a backport of JDK7 ThreadLocalRandom

.exec(session => {
for {
customers ← session(“customers”).validate[Seq[String]]
val customer = customers(ThreadLocalRandom.current.nextInt(customers.size))
} yield session.set(“customer”, customer)
})

A follow up to this, how can I make sure that the first exec has finished and that I actually have “customers” in my session, before executing the next exec that tries to use the “customers” session?

-Andreas

exec are sequential