Getting a circular feeder from user dependent data

Hi,

I’m trying to implement a variation of the user dependent feeder from the documentation (http://gatling.io/docs/2.2.3/session/feeder.html#user-dependent-data), but instead of getting a random issue I want it to work like a circular feeder where it iterates through the relevant issues.

I have tried the code below, but I always get the first matching issue - any suggestions on how to get this working with Gatling 2.2.3?

`
import io.gatling.commons.util.RoundRobin

// index records by project
val recordsByProject: Map[String, IndexedSeq[Record[String]]] = csv(“projectIssue.csv”).records.groupBy{ record => record(“project”) }

// convert the Map values to get only the issues instead of the full records
val issuesByProject: Map[String, Iterator[Record[String]]] = recordsByProject.mapValues{ records => RoundRobin.apply(records) }

// inject project

feed(csv(“userProject.csv”))

.exec { session =>
// fetch project from session
session(“project”).validate[String].map { project =>
// fetch project’s issues
val issues = issuesByProject(project)

val selectedIssue = issues.next()

// inject the issue in the session
session.set(“issue”, selectedIssue)
}
}
`

Regards,
Martin

I managed to find the problem and learned something new about Scala today :slight_smile:

The problem is in my use of mapValues. The function is applied every time a value is retrieved from the map and not just once as I thought, see http://blog.bruchez.name/2013/02/mapmap-vs-mapmapvalues.html

Here is the working code:

val issuesByProject: Map[String, Iterator[Record[String]]] = recordsByProject.map { case (k,v) => k → (RoundRobin.apply(records)) }

Martin