# Feeder that create scenarios

**URL:** <https://community.gatling.io/t/feeder-that-create-scenarios/825>\
**Category:** Gatling (Open-Source)\
**Created:** [February 19, 2014, 4:57pm UTC](https://community.gatling.io/t/feeder-that-create-scenarios/825 "2014-02-19T16:57:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joerg\_Weingarten](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@Joerg\_Weingarten](https://community.gatling.io/u/Joerg_Weingarten)\
**Post date:** [February 19, 2014, 4:57pm UTC](https://community.gatling.io/t/feeder-that-create-scenarios/825/1 "2014-02-19T16:57:40Z")

</div>

Hi,

my question comes based on what I think I understood from the documentation and testing Gatling out. I hope the following is correct:

1. Multiple exec’s in the same scenario are executed after each other and not in parallel.
2. Feeders can only be used inside a scenario.
3. To have 2 http request run in parallel i’d have to create 2 scenarios where each scenario has 1 exec with the http request.

I am testing a web service post api that takes different json data as input. I wanted to store each test, which would be a different json blog, in a different file in the same directory. Also I want to execute each request (each json file) in parallel and not sequential, which would mean for each request (each json file) a new scenario.

So what would be nice is if I could write a Feeder that reads in all files from my directory and create’s an array of scenarios from it that I can launch using “setUp(arrayScenarios.inject(atOnce(10 users)))”. The feeder itself would create the scenario with the appropriate “.check(…)” in place.

Is that doable or just a dumb idea 🙂

Thx  
—Joerg—

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [February 19, 2014, 5:18pm UTC](https://community.gatling.io/t/feeder-that-create-scenarios/825/2 "2014-02-19T17:18:07Z")

</div>

> Hi,
> 
> my question comes based on what I think I understood from the  
> documentation and testing Gatling out. I hope the following is correct:
> 
> 1. Multiple exec's in the same scenario are executed after each other and  
> not in parallel.

true

> 2. Feeders can only be used inside a scenario.

or a chain  
but it has to be passed to feed()

I don't see your point here.

> 3. To have 2 http request run in parallel i'd have to create 2 scenarios  
> where each scenario has 1 exec with the http request.

It depends on if you want those to be executed by the same virtual user or  
not.

If no:  
you can also have several users run the same scenario

if yes:  
In Gatling 2 master/snapshot/upcoming 2M4, you can attach resources to a  
HTTP request and those will be fetched in parallel (simulates page  
resources fetching or ajax calls).  
But at the moment it has to be attached to a root request, not top level  
like what you want.

> I am testing a web service post api that takes different json data as  
> input. I wanted to store each test, which would be a different json blog,  
> in a different file in the same directory. Also I want to execute each  
> request (each json file) in parallel and not sequential, which would mean  
> for each request (each json file) a new scenario.
> 
> So what would be nice is if I could write a Feeder that reads in all files  
> from my directory and create's an array of scenarios from it that I can  
> launch using "setUp(arrayScenarios.inject(atOnce(10 users)))". The feeder  
> itself would create the scenario with the appropriate ".check(..)" in  
> place.
> 
> Is that doable or just a dumb idea 🙂

First, I advise you stick to Gatling defaults and place your body templates  
into expected folder:

> **[GitHub - gatling/gatling: Modern Load Testing as Code](https://github.com/gatling/gatling#wiki-request-body)**
>
> Modern Load Testing as Code. Contribute to gatling/gatling development by creating an account on GitHub.

However, you can change it with -bf:

> **[GitHub - gatling/gatling: Modern Load Testing as Code](https://github.com/gatling/gatling#wiki-cli-options)**
>
> Modern Load Testing as Code. Contribute to gatling/gatling development by creating an account on GitHub.

Then, Feeder is not suited for your needs (at least, as long as we don't  
have top level parallel requests, as mentioned above, but I'd like to be  
convinced by your use case).

Create a method that takes a body template location and returns a scenario.  
Then list all the files in your template, and for each, call setup with the  
above method result.

Get it?

Cheers,

Stéphane

---

<div class="post-metadata">

**Author:** ![Joerg\_Weingarten](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@Joerg\_Weingarten](https://community.gatling.io/u/Joerg_Weingarten)\
**Post date:** [February 19, 2014, 5:37pm UTC](https://community.gatling.io/t/feeder-that-create-scenarios/825/3 "2014-02-19T17:37:53Z")

</div>

> > Hi,
> > 
> > my question comes based on what I think I understood from the documentation and testing Gatling out. I hope the following is correct:
> > 
> > 1. Multiple exec’s in the same scenario are executed after each other and not in parallel.
> 
> true
> 
> > 1. Feeders can only be used inside a scenario.
> 
> or a chain  
> but it has to be passed to feed()
> 
> I don’t see your point here.

No point. Just stating what I thought I understood 🙂

> > 1. To have 2 http request run in parallel i’d have to create 2 scenarios where each scenario has 1 exec with the http request.
> 
> It depends on if you want those to be executed by the same virtual user or not.
> 
> If no:  
> you can also have several users run the same scenario
> 
> if yes:  
> In Gatling 2 master/snapshot/upcoming 2M4, you can attach resources to a HTTP request and those will be fetched in parallel (simulates page resources fetching or ajax calls).  
> But at the moment it has to be attached to a root request, not top level like what you want.

Got it.

> > I am testing a web service post api that takes different json data as input. I wanted to store each test, which would be a different json blog, in a different file in the same directory. Also I want to execute each request (each json file) in parallel and not sequential, which would mean for each request (each json file) a new scenario.
> 
> > So what would be nice is if I could write a Feeder that reads in all files from my directory and create’s an array of scenarios from it that I can launch using “setUp(arrayScenarios.inject(atOnce(10 users)))”. The feeder itself would create the scenario with the appropriate “.check(…)” in place.
> > 
> > Is that doable or just a dumb idea 🙂
> 
> First, I advise you stick to Gatling defaults and place your body templates into expected folder: [https://github.com/excilys/gatling/wiki/HTTP#wiki-request-body](https://github.com/excilys/gatling/wiki/HTTP#wiki-request-body)  
> However, you can change it with -bf: [https://github.com/excilys/gatling/wiki/Configuration#wiki-cli-options](https://github.com/excilys/gatling/wiki/Configuration#wiki-cli-options)
> 
> Then, Feeder is not suited for your needs (at least, as long as we don’t have top level parallel requests, as mentioned above, but I’d like to be convinced by your use case).

The use case would be to simply create new test runs by having anybody on a team create a bunch of files in a specific directory and run a test pointing to that directory. This is not a UI test cases. This is basically for plain web service test cases. I don’t want to create/change a script every time I add a new file, delete a file. But from what you describe below that is possible without using a feeder. So “no use case” anymore 🙂

> Create a method that takes a body template location and returns a scenario.  
> Then list all the files in your template, and for each, call setup with the above method result.
> 
> Get it?

Kind off until you said “…for each, call setup…”. Wouldn’t that imply they are executed serial and not in parallel?

Thx  
—Joerg—

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [February 19, 2014, 5:43pm UTC](https://community.gatling.io/t/feeder-that-create-scenarios/825/4 "2014-02-19T17:43:36Z")

</div>

In the end, a Simulation is just a plain old Scala class.  
What I suggest is to scan your directory and have a many scenarios as you have files when the class is instanciated (not when it’s executed).

I have to go, but I can help later if you’re stuck.

---

<div class="post-metadata">

**Author:** ![Joerg\_Weingarten](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@Joerg\_Weingarten](https://community.gatling.io/u/Joerg_Weingarten)\
**Post date:** [February 19, 2014, 7:28pm UTC](https://community.gatling.io/t/feeder-that-create-scenarios/825/5 "2014-02-19T19:28:52Z")

</div>

The only thing I am stuck with is the setUp call.  
If I have a List or Seq of scenarios, how to I pass them into the setUp call, which I think takes a Seq of PopulatedScenarioBuilder?

Thx  
—Joerg—

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [February 19, 2014, 7:46pm UTC](https://community.gatling.io/t/feeder-that-create-scenarios/825/6 "2014-02-19T19:46:35Z")

</div>

Arghhhh

If you’re using 2M3a, Simulation.setUp signature was stupid back then:  
[https://github.com/excilys/gatling/blob/2.0.0-M3X/gatling-core/src/main/scala/io/gatling/core/scenario/Simulation.scala#L36-L39](https://github.com/excilys/gatling/blob/2.0.0-M3X/gatling-core/src/main/scala/io/gatling/core/scenario/Simulation.scala#L36-L39)

The idea was to enforce users to pass at least one scenario, but that just made things horrible for users trying to do exactly like you.

If you’re using snapshot, the signature is more convenient.  
[https://github.com/excilys/gatling/blob/master/gatling-core/src/main/scala/io/gatling/core/scenario/Simulation.scala#L57](https://github.com/excilys/gatling/blob/master/gatling-core/src/main/scala/io/gatling/core/scenario/Simulation.scala#L57)

So, assuming you have a List[ScenarioBuilder]:

with 2M3a:

val scns: List[ScenarioBuilder] = ???  
val profiledScenarios = scns.map(\_.inject(atOnce(1)))  
setUp(profiledScenarios.head, profiledScenarios.tail: \_\*)

with snapshot:

val scns: List[ScenarioBuilder] = ???  
val profiledScenarios = scns.map(\_.inject(atOnceUsers(1)))  
setUp(profiledScenarios: \_\*)

casting to \_\* is how you deal with passing a sequence to a vararg/array in Scala

I’ll also change snapshot so that you can pile up setUps, so you can write:

val scns: List[ScenarioBuilder] = ???  
val profiledScenarios = scns.map(\_.inject(atOnceUsers(1)))  
profiledScenarios.forEach(setUp)

Cheers,

Stéphane

---

<div class="post-metadata">

**Author:** ![Joerg\_Weingarten](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@Joerg\_Weingarten](https://community.gatling.io/u/Joerg_Weingarten)\
**Post date:** [February 19, 2014, 7:55pm UTC](https://community.gatling.io/t/feeder-that-create-scenarios/825/7 "2014-02-19T19:55:18Z")

</div>

Very nice. Thank you!

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [February 19, 2014, 8:01pm UTC](https://community.gatling.io/t/feeder-that-create-scenarios/825/8 "2014-02-19T20:01:01Z")

</div>

You’re welcome!
