如何以 50 为步长递增计数器?

How can I increment a counter in steps of 50?

我有以下代码

package lts

import io.gatling.core.Predef._
import io.gatling.http.Predef._

class BankingSimulation extends BaseSimulation {
  val paginateThroughCustomTransactionsView = scenario("Scenario 04: Paginate through custom transactions view")
    .feed(csv("scenario04.csv").circular)
    .exec(http("04_paginateThroughCustomTransactionsView")
      .get("/api/savings/transactions?viewfilter=${viewEncodedkey}&offset=0&limit=50")
      .header("accept", "application/json")
      .check(jsonPath("$..encodedKey").saveAs("myEncodedKey"))
    )
    .asLongAs("${myEncodedKey.exists()}","offsetCounter", exitASAP = false) {
      exec(http("04_paginateThroughCustomTransactionsView")
        .get("/api/savings/transactions?viewfilter=${viewEncodedkey}&offset=${offsetCounter}&limit=50")
        .header("accept", "application/json")
        .check(jsonPath("$..encodedKey").saveAs("myEncodedKey"))
      )
    }


  setUp(
 paginateThroughCustomTransactionsView.inject(incrementConcurrentUsers(1).times(1).eachLevelLasting(1))
  ).protocols(httpProtocol)
}

现在场景有效,但 offsetCounter 每次递增 1。我怎样才能将它增加 50?

好的,显然您可以对会话进行各种操作。在 运行 .asLongAs 部分的调用(exec)之前,您必须

exec {session =>
 val offsetCounter = session("counter").as[Int] * 50
 session.set("offsetCounter", offsetCounter)
}

所以代码变成

val paginateThroughCustomTransactionsView = scenario("Scenario 04: Paginate through custom transactions view")
    .feed(csv("scenario04.csv").circular)
    .exec(http("04_paginateThroughCustomTransactionsView")
      .get("/api/savings/transactions?viewfilter=${viewEncodedkey}&offset=0&limit=50")
      .header("accept", "application/json")
      .check(jsonPath("$..encodedKey").saveAs("myEncodedKey"))
    )
    .asLongAs("${myEncodedKey.exists()}","counter", exitASAP = false) {
      exec {session =>
        val offsetCounter = session("counter").as[Int] * 50
        session.set("offsetCounter", offsetCounter)
      }
      .exec(http("04_paginateThroughCustomTransactionsView")
        .get("/api/savings/transactions?viewfilter=${viewEncodedkey}&offset=${offsetCounter}&limit=50")
        .header("accept", "application/json")
        .check(jsonPath("$..encodedKey").saveAs("myEncodedKey"))
      )
    }

也许是更好的方法...不要依赖循环计数器并改用进纸器

var offsetFeeder = (50 to 1000 by 50).toStream.map(i => Map("offsetCounter" -> i)).toIterator

然后在你的 .asLongAs 块中,

.feed(offsetFeeder)

并执行您的“04_paginateThroughCustomTransactionsView”调用