Search code examples
scalagatling

Gatling: How can I load a range from a JSON feeder file?


I have a feeder file with 10k objects and I would like to load objects 6000 to 6999. What I currently do is load the JSON, convert it to a list[object], extract the range and convert it back to JSON with the necessary range and then reload it as feeder... This seems very excessive to me and I was wondering if there is a way to do it at the reading JSON feeder file stage:

val feeder: FileBasedFeederBuilder[Any] = jsonFile(feederJson)

Thanks


Solution

  • What you say can be accomplished just like this:

    val feeder = jsonFile("foo.json")
      .readRecords
      .filter { record =>
        val id = record("id").asInstanceOf[Int]
        id < 7000 && id > 5999
      }
      .toArray
    
    val useCaseScenario: ScenarioBuilder =
      scenario("aaa")
        .feed(feeder)
    ...