Forin
Forin

Reputation: 1619

Load more records from Gatling feeder

I would like to inject n-rows from my csv file to Gatling feeder. The default approach of Gatling is to read and inject one row at a time. However, I cannot find anywhere, how to take and inject an eg. Array into a template.
I came up with creating a JSON template with Gatling Expressions as some of the fields. The issue is I have a JSON array with N-elements:

[
  {"myKey": ${value}, "mySecondKey": ${value2}, ...}, 
  {"myKey": ${value}, "mySecondKey": ${value2}, ...},
  {"myKey": ${value}, "mySecondKey": ${value2}, ...},
  {"myKey": ${value}, "mySecondKey": ${value2}, ...}
]

And my csv:

value,value2,... 
value,value2,... 
value,value2,... 
value,value2,... 
...

I would like to make it as efficient as possible. My data is in CSV file, so I would like to use csv feeder. Also, the size is large, so readRecords is not possible, since I'm getting out of memory.

Is there a way I can put N-records into the request body using Gatling?

Upvotes: 0

Views: 2532

Answers (2)

Stéphane LANDELLE
Stéphane LANDELLE

Reputation: 6623

From the documentation:

feed(feeder, 2)

Old Gatling versions:

Attribute names, will be suffixed. For example, if the columns are name “foo” and “bar” and you’re feeding 2 records at once, you’ll get “foo1”, “bar1”, “foo2” and “bar2” session attributes.

Modern Gatling versions:

values will be arrays containing all the values of the same key.

In this latter case, you can access a value at a given index with Gatling EL: #{foo(0)}, #{foo(1)}, #{bar(0)} and #{bar(1)}

Upvotes: 2

Exodarion
Exodarion

Reputation: 1

It seems that the documentation on this front might have changed a bit since then:

It’s also possible to feed multiple records at once. In this case, values will be arrays containing all the values of the same key.

I personally wrote this in Java, but it is easy to find the syntax for scala as well in the documentation.

The solution I used for my CSV file is to add the feeder to the scenario like:

.feed(CoreDsl.csv("pathofyourcsvfile"), NUMBER_OF_RECORDS)

To apply/receive that array data during your .exec you can do something like this:

.post("YourEndpointPath").body(StringBody(session -> yourMethod(session.get(YourStringKey))))

In this case, I am using a POST and requestBody, but the concept remains similar for GET and their corresponding queryParameters. So basically, you can use the session lambda in combination with the session.get method.

"yourMethod" can then receive this parameter as an Object[].

Upvotes: 0

Related Questions