0

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?

2
  • If I clearly understanding your problem - try to use batch mode which load only piece of data val csvFeeder2 = csv("foo.csv").batch(200).random
    – Amerousful
    Feb 16, 2021 at 10:45
  • What I need is to fill objects in the array by taking required amount of rows from csv file. Default Gatling approach is to read one row at the time.
    – Forin
    Feb 16, 2021 at 10:47

2 Answers 2

2

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)}

0

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[].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.