Trigger scenario over csv records (like in a loop)

Gatling version: 3.6.1
Gatling flavor: scala
Gatling build tool: maven

Hello all,

I’d like to ask you about a possibility of triggering each scenario by record taken from a csv file, like:
example csv:
101,
102,
103

There is used setUp() method which doesn’t allow me to use any for loop. Inside this method is called Scenario.scnProcessEvent(params) method.

What I would like to achieve is adding a param alias which is taken each time from csv file and passed to the method:

def scnProcessEvent(url: String, param1: Type, alias: String) =
    scenario(s"ProcessEvent_${param1.consId}")
      .feed(Iterator.continually(Map("Alias" -> alias)))
      ... // other feeders here
      .exec(Xyz.postXml("ProcessEvent", s"$url/${param1.consId}", "ProcessEvent",
        RequestsXML.processEventWithBody(param1))).exitHereIfFailed
      .exec { session => ..., session)   session }

Can you give me a hint how it could be solved to iterate over all records from CSV file and call for each records a new scenario ?

That’s not possible using feeders.
Feeders store data in the virtual users Session while the scenario names are static and loaded once prior to starting generating load.
If you want to build a list of scenarios from a CSV file, that’s something you’ll have to code yourself, and parse the CSV file with your library of choice.

thank you slandelle for the explanation

I understand a bit better now. I just started using whole stack related to Gatling, Scala and Redis DB for addition, all is new completely to me, since I work for longer time with Java mainly.
I try to understand how to assemble these stuff together from existing code.

Regarding what you said: ‘build a list of scenarios from a CSV file’ I’d would say rather that I want to loop over csv file to get numbers and pass each of them to the scenario. Otherwise I consider putting all numbers to the Redis DB and if it’s possible to do the same but taking numbers directly from Redis DB. Not sure which solution will be better and what is possible.
Let’s imagine I decided for coding it myself to use CSV file to loop over it (still I need to pass it to the method and later to the XML file to replace placeholder existing there with real number taken from CSV). Can you say something more about it. Or if you think putting data from CSV directly to Redis will be better then can you explain it more ?

Hi there,

Just a quick note. If you’re comfortable in Java, you should use Gatling’s Java DSL. It can do anything our Scala DSL can and compiles faster. You can see examples of everything in Java in our documentation.

All the best,
Pete

whole stack related to Gatling, Scala and Redis DB for addition, all is new completely to me, since I work for longer time with Java mainly.

Gatling has been providing a Java SDK for 3 years now. I really recommend against using Scala unless you’re a trained Scala developper.

Sorry but this CSV vs Redis discussion is not about Gatling usage but about building an in-house framework/platform. This is not something we can help with without a consulting contract.

The only thing I can say is that , whatever the format, you need to construct the list of scenarios once, when passing it to setUp, as the scenario names are static and can’t use users’ Sessions.

Thanks for replying. If I could change Scala to Java only :slight_smile:

And your version is support old too :man_shrugging:

I see :slight_smile: anyway, Redis DB is now fed with data without coding, so no issue anymore (at least for now)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.