# feeders

**URL:** <https://community.gatling.io/t/feeders/577>\
**Category:** Gatling (Open-Source)\
**Created:** [September 9, 2013, 5:17pm UTC](https://community.gatling.io/t/feeders/577 "2013-09-09T17:17:54Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hassen\_KHAIL](https://avatars.discourse-cdn.com/v4/letter/h/7ea924/32.png) [@Hassen\_KHAIL](https://community.gatling.io/u/Hassen_KHAIL)\
**Post date:** [September 9, 2013, 5:17pm UTC](https://community.gatling.io/t/feeders/577/1 "2013-09-09T17:17:54Z")

</div>

Hello,

J’ai deux fichiers : un fichier A (contient ID1) et un fichier B (contient ID2)

J’ai une URL de ce type :

http://…/…/{ID1}/{ID2}/home.html

Sachant que pour chaque ID1, il y a n ID2, j’aimerais boucler sur le fichier A, puis pour boucler sur le fichier ID2.

Hassen

---

<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:** [September 9, 2013, 8:19pm UTC](https://community.gatling.io/t/feeders/577/2 "2013-09-09T20:19:00Z")

</div>

> Hello,

You were good until here. English is the preferred language here: )

> J'ai deux fichiers : un fichier A (contient ID1) et un fichier B (contient  
> ID2)
> 
> J'ai une URL de ce type :
> 
> http://…/…/{ID1}/{ID2}/home.html
> 
> Sachant que pour chaque ID1, il y a n ID2, j'aimerais boucler sur le  
> fichier A, puis pour boucler sur le fichier ID2.

In english, the question is: "I have 2 files that I'd like to use as  
feeders: one with some records with an id, and a second one whose records  
contain a foreign key to the first file records. How do I join?".

I see 2 solutions.

First: you join upstream yourself, so you get one single file, where the  
1\*n records are merged into a single field.

Then, you can you use first file as a feeder, turn your second file into a  
Map, and join into an exec.  
You can reuse the utility methods here:

> <https://github.com/gatling/gatling/blob/main/gatling-core/src/main/scala/io/gatling/core/feeder/SeparatedValuesParser.scala>

val file1 = csv("file1")

// file 2 is a Map[String, Record[String]]  
val file2 =  
SeparatedValuesParser.parse(GatlingFiles.feederResource("file2"),  
',').groupBy(record =\> record("foreignKeyColumnName"))

feed(file1)  
.exec(session =\>  
for {  
id1 \<- session("ID1").validate[String]  
val recordsWithId1InFile2 = file2(id1)  
val id2s = recordsWithId1InFile2.map(record =\> record("ID2"))  
} yield session.set("concatenatedId2s", id2s.mkString("/"))  
)  
.exec(http("Catégorie Poney").get("/${ID1}/${concatenatedId2s}"))

Cheers,

Stéphane

---

<div class="post-metadata">

**Author:** ![Hassen\_KHAIL](https://avatars.discourse-cdn.com/v4/letter/h/7ea924/32.png) [@Hassen\_KHAIL](https://community.gatling.io/u/Hassen_KHAIL)\
**Post date:** [September 9, 2013, 8:34pm UTC](https://community.gatling.io/t/feeders/577/3 "2013-09-09T20:34:37Z")

</div>

Hello Stéphane,

Sorry, I did not know about posting in english. ;o)))

At work, I implemented the solution one. But I wanted something more flexible. I do not want to maintain a file with more than 400 entries.

Thanks for the quick answer. I will try tomorrow and let you know.

Best regards  
Hassen

---

<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:** [September 9, 2013, 8:58pm UTC](https://community.gatling.io/t/feeders/577/4 "2013-09-09T20:58:35Z")

</div>

Have fun!

---

<div class="post-metadata">

**Author:** ![Hassen\_KHAIL](https://avatars.discourse-cdn.com/v4/letter/h/7ea924/32.png) [@Hassen\_KHAIL](https://community.gatling.io/u/Hassen_KHAIL)\
**Post date:** [September 10, 2013, 7:57am UTC](https://community.gatling.io/t/feeders/577/5 "2013-09-10T07:57:05Z")

</div>

Hello Stéphane,

Theres is not foreign key in my case.

The files look like that :

file 1  
languagecode,description  
…,…  
…,…

file 2  
committeecode,description

…,…  
…,…

I just want to iterate on all the records of the file 1 and for each record of the file 1, make an iteration on the file 2.

Regards  
Hassen

---

<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:** [September 10, 2013, 8:06am UTC](https://community.gatling.io/t/feeders/577/6 "2013-09-10T08:06:15Z")

</div>

Ahhhhhh

So that’s very easy: with Gatling 2, you can feed multiple records at once:  
[https://github.com/excilys/gatling/wiki/Gatling-2#wiki-http-misc](https://github.com/excilys/gatling/wiki/Gatling-2#wiki-http-misc)

.feed(feeder2, sizeOfFeeder2)

then you’ll get committeecode1, committeecode2, committeecode3, etc.

---

<div class="post-metadata">

**Author:** ![Hassen\_KHAIL](https://avatars.discourse-cdn.com/v4/letter/h/7ea924/32.png) [@Hassen\_KHAIL](https://community.gatling.io/u/Hassen_KHAIL)\
**Post date:** [September 10, 2013, 8:20am UTC](https://community.gatling.io/t/feeders/577/7 "2013-09-10T08:20:23Z")

</div>

In fact, i would like to have something like that :

languagecode1,committeecode1

languagecode1,committeecode2

languagecode1,committeecode3  
…

languagecode2,committeecode1

languagecode2,committeecode2

languagecode2,committeecode3

…

languagecode3,committeecode1

languagecode3,committeecode2

languagecode3,committeecode3

PS : I am using Gatling 1.5.2 but I can change to 2.0.x if needed

---

<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:** [September 10, 2013, 8:22am UTC](https://community.gatling.io/t/feeders/577/8 "2013-09-10T08:22:47Z")

</div>

> In fact, i would like to have something like that :
> 
> languagecode1,committeecode1  
> languagecode1,committeecode2  
> languagecode1,committeecode3  
> .....  
> languagecode2,committeecode1  
> languagecode2,committeecode2  
> languagecode2,committeecode3  
> ....  
> languagecode3,committeecode1  
> languagecode3,committeecode2  
> languagecode3,committeecode3

Yep, exactly what I answered.

> PS : I am using Gatling 1.5.2 but I can change to 2.0.x if needed

Yep, have to, Gatling 2 FEATURE.

---

<div class="post-metadata">

**Author:** ![Franck\_Michaud](https://avatars.discourse-cdn.com/v4/letter/f/58f4c7/32.png) [@Franck\_Michaud](https://community.gatling.io/u/Franck_Michaud)\
**Post date:** [September 10, 2013, 9:52am UTC](https://community.gatling.io/t/feeders/577/9 "2013-09-10T09:52:16Z")

</div>

Bonjour Stéphane,

Thanks for your work, and please forgive my English. Hope it’s OK to post this as a response.

About feeding multiple records at once, how do you iterate through them? I try, for each of my users, to post the same files to web services, with a csv file containing the name of all files to post, with their respective service:

val scn = scenario(“scenario\_name”)  
.feed(usersList)  
.feed(csv(“my\_services\_and\_files.csv”), nb\_lines)  
.repeat(nb\_lines, “file\_index”)(  
exec(  
http(“request\_global”)  
.post("""/${service}${file\_index}""")  
.body(RawFileBody("""${file}${file\_index}"""))  
)  
)

which gives me :“No attribute named ‘service’ is defined.”  
I’m using gatling 2.0.0-M3.

Thanks

---

<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:** [September 10, 2013, 10:03am UTC](https://community.gatling.io/t/feeders/577/10 "2013-09-10T10:03:47Z")

</div>

You don’t iterate: attribute names get suffixed with the index + 1.

---

<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:** [September 10, 2013, 12:27pm UTC](https://community.gatling.io/t/feeders/577/11 "2013-09-10T12:27:36Z")

</div>

?  
Just use feed the same way as in Gatling 1.

---

<div class="post-metadata">

**Author:** ![Franck\_Michaud](https://avatars.discourse-cdn.com/v4/letter/f/58f4c7/32.png) [@Franck\_Michaud](https://community.gatling.io/u/Franck_Michaud)\
**Post date:** [September 10, 2013, 1:26pm UTC](https://community.gatling.io/t/feeders/577/12 "2013-09-10T13:26:05Z")

</div>

Thanks for the quick reply.  
But I don’t get it. The fact is that I have 636000 XML file names in my CSV feeder, in a particular order, and I need my user to POST each of them in that order.

I’ve tried:

_scenario("…")_  
_.repeat(csv.data.length) {_  
_feed(csv)_  
_.exec(_  
_http(“address’”)_  
_.post("…${csvcolumn}")_

but the feeder is then a common resource shared between users. With the new feeder(csvFeeder, csvFeederLength), I would like to POST each csv entry, in order, by user. Is the solution to write 636000 POST with csvcolumn1, csvcolumn2 ?

---

<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:** [September 10, 2013, 4:20pm UTC](https://community.gatling.io/t/feeders/577/13 "2013-09-10T16:20:31Z")

</div>

Ah OK.

So what you want with your second file is not a feeder but a foreach loop: [https://github.com/excilys/gatling/wiki/Structure-Elements#wiki-foreach](https://github.com/excilys/gatling/wiki/Structure-Elements#wiki-foreach)

val seq = csv(“my\_services\_and\_files.csv”).data.toSeq // beware, you get a Seq of Records[String] (= Map[String, String])

foreach(seq, “record”) {  
// copy the record “fields” as session attributes  
exec(session =\> session(“record”).validate[Map[String, String]].map(record =\> session.setAll(record.toSeq)))  
…  
}

Get it?

Stéphane

---

<div class="post-metadata">

**Author:** ![Franck\_Michaud](https://avatars.discourse-cdn.com/v4/letter/f/58f4c7/32.png) [@Franck\_Michaud](https://community.gatling.io/u/Franck_Michaud)\
**Post date:** [September 10, 2013, 6:26pm UTC](https://community.gatling.io/t/feeders/577/14 "2013-09-10T18:26:03Z")

</div>

Get it!

Thanks for the help.

---

<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:** [September 10, 2013, 6:31pm UTC](https://community.gatling.io/t/feeders/577/15 "2013-09-10T18:31:24Z")

</div>

You’re welcome.  
Have fun!

---

<div class="post-metadata">

**Author:** ![Hassen\_KHAIL](https://avatars.discourse-cdn.com/v4/letter/h/7ea924/32.png) [@Hassen\_KHAIL](https://community.gatling.io/u/Hassen_KHAIL)\
**Post date:** [September 10, 2013, 7:35pm UTC](https://community.gatling.io/t/feeders/577/16 "2013-09-10T19:35:57Z")

</div>

I used

.feed(csv(file2.csv), 22) to get all the data from file2

In session, I have something like that now :  
committeecode1:value1,committeecode2;value2,…,committeecode22:value22

how to loop on this structure ?

Thanks in advance

---

<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:** [September 10, 2013, 7:52pm UTC](https://community.gatling.io/t/feeders/577/17 "2013-09-10T19:52:03Z")

</div>

You can’t.  
If you want to loop, use the technique I described to Franck in this same thread.

---

<div class="post-metadata">

**Author:** ![Hassen\_KHAIL](https://avatars.discourse-cdn.com/v4/letter/h/7ea924/32.png) [@Hassen\_KHAIL](https://community.gatling.io/u/Hassen_KHAIL)\
**Post date:** [September 10, 2013, 8:03pm UTC](https://community.gatling.io/t/feeders/577/18 "2013-09-10T20:03:14Z")

</div>

Ok thanks for the answer.

H.

---

<div class="post-metadata">

**Author:** ![Hassen\_KHAIL](https://avatars.discourse-cdn.com/v4/letter/h/7ea924/32.png) [@Hassen\_KHAIL](https://community.gatling.io/u/Hassen_KHAIL)\
**Post date:** [September 11, 2013, 9:57am UTC](https://community.gatling.io/t/feeders/577/19 "2013-09-11T09:57:52Z")

</div>

Hello Stephane,

val committees = csv(“committees.txt”).data.toSeq

foreach(committees, “committee”){  
.exec(  
http(“Request Committee”)  
.get("${language}/${committee}/home.html")  
.check(status.is(200))  
)  
}

${committee} return a map. How to get the key value or the value ?

Thanks

---

<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:** [September 11, 2013, 10:12am UTC](https://community.gatling.io/t/feeders/577/20 "2013-09-11T10:12:38Z")

</div>

That was exactly the point of the following line in my previous answer to Franck 😉

// copy the record “fields” as session attributes  
exec(session =\> session(“record”).validate[Map[String, String]].map(record =\> session.setAll(record.toSeq)))

[Next page](https://community.gatling.io/t/feeders/577.md?page=2)
