Gatling version: 3.13.1 (must be up to date)
Gatling flavor: scala
Hi, back to the feature request I made here
Due to project big file (for real, which caused me a pain) csv, I did try to write some extra code, tho I’m a Scala Noobie, I managed to have it run as expectation as below:
package com.CustomCsvFeeder
import scala.io.Source
import io.gatling.core.feeder._
import io.gatling.core.Predef._
object CustomCsvFeeder {
def apply(fileName: String, from: Int, to: Int): IndexedSeq[Map[String, String]] = {
val source = Source.fromFile(fileName)
try {
val lines = source.getLines().toList
if (lines.isEmpty) {
throw new IllegalArgumentException(s"CSV file $fileName is empty")
}
val headers = lines.head.split(",").map(_.trim)
val rows = lines.tail.slice(from - 1, to)
val data: IndexedSeq[Map[String, String]] = rows.map { line =>
val values = line.split(",").map(_.trim)
headers.zip(values).toMap
}.toIndexedSeq
data
} finally {
source.close()
}
}
}
This code is really ugly, but it at least can satisfy my use case to have implement as:
val csvFill = csv("my/dir/to/file.csv)
.circular
.from(rowNumber = 1)
.to(rowNumber = 1000)
Now I have a small problem, the user I got here, cannot be looped in forever
group as:
val feeder = CustomCsvFeeder
.apply("myDataSource.csv").circular
.circular
val scn = scenario("Extract ID")
.feed(feeder)
.forever{
exec(
http("Get Callback Page")
.get("/api/unknown/#{num}")
)}
setUp(
scn.inject(constantUsersPerSec(2) during (5))
).protocols(httpProtocol).maxDuration(5 minutes)
This will have a result where the users are generated as expected, with data defined in the source csv, but when it hits 10 Users (which is 2 Users / sec in 5 seconds), the user stopped sending request.
Pardon if I tried to hack Gatling. Hopefully I can get some hint for this.
Edit: Tried with Original Gatling built-in of csv feeder, got the same behavior:
package demoScript
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import com.CustomCsvFeeder._
import scala.concurrent.duration._
class demoScript extends Simulation {
val feeder= csv("search.csv").circular()
val scn = scenario("Extract ID")
.feed(feeder)
.forever{
exec(
http("Get Callback Page")
.get("https://reqres.in/api/unknown/#{num}")
)}
setUp(
scn.inject(constantUsersPerSec(1) during (10))
).maxDuration(1 minutes)
}