如何使用 feeder 启动 gatling 场景

How to start gatling scenario with feeder

我有一个测试单个端点的简单场景。我在使用 DSL 时遇到问题。无法弄清楚如何使用馈线启动场景。我必须先进行无用的调用才能使其编译。

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)

}

我怎样才能摆脱

exec(
      http("Home")
        .get("/")
    ) // first call .get("/") is useless. I've added it only to make it compile

feed 可作为顶级函数使用,类似于 exec 本身:

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

你可以在 Feeders documentation 中看到它。