How to work with suffixed attributes in Session Map ( Gatling 2.0.2)

I have a use case where I need to pull 1000 rows from my CSV feeder file, extract column 1 from each row and create a list of userIds that will be injected into a JSON payload.

Final Format/Appearance of the list >

`
“recipient_user_id”: [

“123456”,

“758899”,

"7903567”

]

`

It was shockingly easy to get raw data from my CSV feeder file - thanks to the Gatling team.

All it took was this>

`

.feed( idFeeder,1000 )
/// feeder is using ‘random’ strategy

`

The list is made by using StringBuilder, but I’m finding this is awkward for more than a handful of rows…and I need to do this for 1000 rows total.

How would you approach doing this operation for Id1- Id1000?

Is there a way to address suffixed Userids suffixes in the Map without calling them explicitly?

Here is a sample of how they look in the Gatling Session>

Session:POST-MIA,7273882443754027664-0,Map(Name522 → lname500029646, Email80 → zRJ500051738@bh.exacttarget.com, Id352 → 500075980, Id811 → 500096094, , Id970 → 500080954, …),1443056956200,0,KO,List(),)

And the method that builds the list is below. (if this is bad Scala, I apologize in advance…I’ve not had as much bandwidth as I would like to study the language).

`
def buildList( session: Session ) : String = {

val sb = new StringBuilder

sb ++=""".concat( session.get(“Id1”).as[String]).concat("",")

sb ++= “”".concat(session.get(“Id2”).as[String]).concat("",")

sb ++= “”".concat(session.get(“Id3”).as[String]).concat("",")

sb ++= “”".concat(session.get(“Id4”).as[String]).concat("",")

sb ++= “”".concat(session.get(“Id5”).as[String]).concat("",")

sb ++= “”".concat(session.get(“Id6”).as[String]).concat(""")

val theList = sb.toString()

theList

}

`

This function passes a String variable to another function that assembles the entire JSON payload using values from other feeders and the session.

something like this…

`
//… first part of the Post is omitted for brevity

.body( StringBody(

generatePayload( “${fromFeeder1}”, “${theList}”, “${fromfeeder2}”)

)).asJSON
`

Thanks in advance.

To make it easier, use more scala.

You can either loop through 1…1000 to build the string, or you can loop over the feed and build a list which you then call mkstring on to turn it into json. Personally, I think the latter would be easier.

mkString() is a heck of a method, and Scala isn’t bad either :slight_smile:

I got it to work as required.