Gatling 2.0.0-RC5 Custom feeder by a SCALA noob

Hello,
I could use some help with a custom feeder. I have a scenario using one feeder to provide user, and project. I have the user log in, then I load their project page.

Later in the scenario I want to use the ‘project’ from the first feeder as a ‘lookup’ in a second feeder.

I have an almost working solution for the second feeder, but I can’t seem to get at the session variable.

This one works, but ‘project’ is hardcoded (i.e ‘aProject’):

`
feed(csv(“projectsAndIssues.csv”).records.filter( (i: Map[String, String]) => i.get(“projectKey”).get == “aProject” ).random )

`

I tried first using Gatling Expression Language:

`
feed(csv(“projectsAndIssues.csv”).records.filter( (i: Map[String, String]) => i.get(“pkey”).get == “${project}” ).random )

`

That doesn’t work (after reading some other posts here I understand why).

So I tried using ‘project’ from the session. I am a total SCALA noob so be gentle.

I tried to add a closure to get at the session (not sure this is really a closure, but I thought it was):

`
feed(csv(“projectAndIssue.csv”).records.filter( (i: Map[String, String]) => i.get(“pkey”).get == {(session: Session) => session(“project”).as[String] } ).random )

`

Woohoo, that compiles, but my feeder is empty. I have confirmed that ‘project’ is in fact set on the session.

I feel like I have really messed this up. Could someone suggest what I could try next?

I have two data files, userProjects.csv and projectIssues.csv. I would like to take the project name from the first feed and restrict (filter) the second feed to only projects matching the current project.

userProject.csv

user, project
bob, aProject
sue, bProject

projectIssue.csv

Hi George,

It looks like you’re shooting in the dark here :wink:

First of all, as the doc states: Feeder is an alias for Iterator[Map[String, T]]. Iterator’s main method, next, doesn’t have an input parameter, it just blindly provide the next record and is completely unaware of the context, so you can’t expect to work with the Session.

Moreover, all Gatling built-in feeders process everything upfront (reading from file, parsing, converting, etc) so it only works in memory once the simulation starts and doesn’t hurt IO and CPU. It’s a tradeoff in favor of running the Simulation. Then, working in memory is also the only way to have the “random” strategy working efficiently.

So, you’ll have to manually feeder the data into the session.
I already answered this same question on this ML and provided a solution, but you’d have to dig pretty deep into the archives.
I guess I’ll have to add this into the cookbook.

Basically, you have to turn projectIssue.csv into a Map, and manually inject data into the session in a exec(function).
I’ll add the detailed cookbook entry later today.

Cheers,

Stéphane

https://github.com/gatling/gatling/issues/2259

Haha, well I often shoot in the dark when I run out of other choices. Thanks for the Gatling 2 documentation by the way, I love it! I do spend a lot of time in the docs and I read the section on custom feeders and the fact that feeder was an iterator made sense. I think where I lost my way was not realizing the feeder was loaded into memory up front. That makes sense now, thanks for the clarification. That explains why my feeder worked when I provided the project as a parameter.

Thanks for the cookbook, I will go give that a try.

I had a similar issue in the past, but I did not try to solve it using a single feeder. I created a separate file for each subset that I wanted. Then I jumped through some hoops because I could not specify an EL string as a filename in gatling 1.5, but apparently you can in 2.0. So you might create something like this:

users.csv
user,project
bob,aProject
sue,bProject

aProject_details.csv with just the parts relevant to aProject
bProject_details.csv for bProject

Then do .feed( “${project}_details.csv” ) and see how that works out.

That would work as well. Unfortunately, I have hundreds of ‘projects’. I would need a file for each project.

I was able to use the cookbook to create a custom feeder and it’s working great.