1

I have simple scenario that tests single endpoint. I have problems with DSL. Can't figure out how to start scenario with feeder. I have to make useless call first in order to make it compile.

class GetDataSimulation extends Simulation {


  val httpProtocol = http
    .baseUrl("http://localhost:8080") // Here is the root for all relative URLs
    .header("Content-Type", "application/json")
    .header("Accept", "application/json")

  object GetData {
    val feeder = csv("data.csv").shuffle.circular
    val getData = exec(
      http("Home")
        .get("/")
    ) // first call .get("/") is useless. I've added it only to make it compile
      .pause(1.millisecond)
      .feed(feeder)  // start feeder, want to start scenario from here.
      .exec(
        http("GetData") // interpolate params using CSV feeder.
          .get("/api/v1/data?firstParam=${firstParam}&secondParam=${secondParam}") 
      )
      .pause(1)

  }

  setUp(
    constantUsers.inject(constantUsersPerSec(3).during(60.seconds))
  ).protocols(httpProtocol)

}

how can I get rid of

exec(
      http("Home")
        .get("/")
    ) // first call .get("/") is useless. I've added it only to make it compile
Capacytron
  • 3,425
  • 6
  • 47
  • 80

1 Answers1

3

feed is available as a top level function, similar to exec itself:

    val getData = feed(feeder)
      .exec(
        http("GetData") // interpolate params using CSV feeder.
          .get("/api/v1/data?firstParam=${firstParam}&secondParam=${secondParam}") 
      )
      .pause(1)

You can see it in the Feeders documentation.

knittl
  • 246,190
  • 53
  • 318
  • 364
  • 1
    > io.gatling.core.feeder._ to have the function available. The standard io.gatling.core.Predef._ is enough. Generally speaking, try to stick to the standard imports: one for core and one for the specific protocol, typically http. – Stéphane LANDELLE May 28 '21 at 15:52
  • Thanks for helping here @knittl :) I've deleted my own similar answer. Still, I recommend you update your answer wrt my above comment. Cheers – Stéphane LANDELLE May 28 '21 at 15:56
  • @StéphaneLANDELLE thanks, I wasn't sure if the import is needed (it is visible in the last example in the docs). Thought I'd mention it in case OP has problems still :) – knittl May 28 '21 at 15:58
  • Could you please show me the location in the doc? Looks like an error to me. – Stéphane LANDELLE May 28 '21 at 16:01
  • @StéphaneLANDELLE it's in the last code sample at the link from the answer. Below the text "Here’s how you can randomly inject an issue, depending on the project:" – but maybe the import is needed for something else – knittl May 28 '21 at 16:02
  • Thanks a lot! Will fix! – Stéphane LANDELLE May 28 '21 at 16:33