Here is what I NEED to do:
.feed(\"users.csv\") // includes username, password, groupid
// login...
.duration(x) {
feed( csv(\"${groupid}.csv\")
Feeders are instanciated at the same time as the Simulation. You can't defer it to the Simulation runtime, unless you hack with the underlying tools.
How many of those "groupid" files do you have? If you have just a few of them, you can use either doSwitch from Gatling 2 current snapshot, or embedded doIf blocks if you run with Gatling <= 2M3a.
.doSwitch("${groupid}") (
"foo" -> feed(csv("foo.csv").random),
"bar" -> feed(csv("bar.csv").random)
)
This can be generalized:
def groupIdFeed(groupId: String) = groupId -> feed(csv(groupId + ".csv").random)
.doSwitch("${groupid}") (
groupIdFeed("foo"),
groupIdFeed("bar")
)
Thanks to Stephane for the information, on which the final solution was built.
Here is what I did that works for 1.5.5:
object Data {
var groupList : List[Int] = List( ... ) // long list of IDs
def branchByGroup ( path: String ) : ChainBuilder = {
var c = bootstrap
groupList.foreach( x => {
c = c.doIf( "${groupId}", x.toString() ) {
feed( csv( path + "/" + x.toString() + ".csv" ).random )
}
})
return c
}
def searchCriteria () : ChainBuilder = branchByGroup( "search" )
def other() : ChainBuilder = branchByGroup( "other" )
}
Then, inside my scenario, I call it, like so:
def scn = scenario("My Scenario")
.feed( credentialSource )
.exec( Login.steps )
.during( loopTime ) {
Data.searchCriteria()
.exec( Search.steps )
The call to Data.searchCriteria
is injecting the .doIf() calls into the chain. If it was not the first thing in the block, I would have had to wrap it in .exec()
of course.
As a side-note, there was a gotcha that I had to figure out. Notice the part that says c = c.doIf
- the function needs to return the END of the chain, as opposed to the beginning. You can't build a chain by attaching everything to the first link in the chain! Simulating what the DSL does requires this call-and-assign approach.
Hope this helps someone other than just me. :)