Feeder reading multiple lines and foreach

I’m trying to run foreach on multiple records of feeder but foreach is not executing and no errors are shown

  scenario("my scenario")
    .feed(myFeeder, 5) //read 5 lines as array?
    .foreach("#{columnName}", "attrName") { session =>  //iterate over array

But if i change code to repeat, everything works (so file could be read)

scenario("my scenario")
  .repeat(5) { // read 5 lines one by one
      .exec { session =>

With gatling v 3.7.6 i can see keys in session like “columnName1”, “columnName2”, etc…
With gatling 3.9.1 or higher i can see key “columnName” but i don’t know its type so i cant do anything with it.

So what is the problem with combination like:

.feed(myFeeder, 5)
.foreach("#{columnName}", "attrName")

Different types, so foreach can’t iterate? or problem with feeder?
csv file has enough lines to read.

Here you have a little hints: :slight_smile:

This is not correct and has never been.
The second parameter list of foreach takes a chain, not a function.

.foreach("#{columnName}", "attrName") {
  exec { session =>
1 Like

Thank you for your reply, i’ve missed exec block when copied an example. My project compiles and runs but foreach don’t iterate over records of csv file.

Thank you. Example with UUID looks like what i want but with combination of gatling foreach.

Its not critical for me, i’ve used repeat instead.

I just want to know if i can use foreach for feeder records which were stored in array like this

Make sure to upgrade to the latest version (3.9.5 atm).
If you still experience an issue, please build a simple yet complete reproducer someone else can run on his side.

Here is an example

Found error in log:

Condition evaluation crashed with message ‘Can’t cast ‘[Ljava.lang.Object;@7cafc344’ of type class [Ljava.lang.Object; into interface scala.collection.immutable.Seq’, exiting loop

below works for me without error :slight_smile:

I wondering how to cast in better way Object[] to ArrayList<String> - any suggestions @slandelle ? :smirk:

PR with Solution: Case0023foreachFromUUIDfeederFiveRecordsAtTheSameTimeSimulation by gemiusz · Pull Request #18 · gemiusz/gatling-examples-maven-java · GitHub
Any comments and sugestions are welcome :hearts:

Direct Link to Simulation code:

Yes, but putting objects from object array to ArrayList looks like a workaround. When working with api (gatling) expecting things to work without this step.
Like reading lines and storing them directly in Seq or ArrayList not in Object

As I see in Gatling source code (gatling/ForEach.java at main · gatling/gatling · GitHub) there is foreach in almost all methods so there must be List :slight_smile:

OK, this is actually a bug. Indeed, foreach doesn’t support arrays, only Seq and List. Investigating.

1 Like

Fixed: Core: Make foreach support arrays · Issue #4420 · gatling/gatling · GitHub

Should be released in 3.9.6 (no ETA at the moment).

1 Like

Hi @slandelle,
I have looked in Commit Make foreach support arrays, close #4420 · gatling/gatling@1ae49cb · GitHub
and I’m wondering why there aren’t any changes in JAVA code gatling/ForEach.java at main · gatling/gatling · GitHub
How your changes will appile to Java code if there are only List<?>, String, Function<Session, List<?>> types that can be used ?

Actually, I’m not satisfied with this solution.
I’m going with Core: Change multiple feed to generate either java.util.List or Scala Seq instead of Array (BREAKING CHANGE) · Issue #4423 · gatling/gatling · GitHub instead.


1 Like