我有以下代码
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?
答案 0 :(得分:2)
也许是更好的方法...不要依赖循环计数器,而应使用馈线
var offsetFeeder = (50 to 1000 by 50).toStream.map(i => Map("offsetCounter" -> i)).toIterator
然后在.asLongAs块内,只是
.feed(offsetFeeder)
并执行“ 04_paginateThroughCustomTransactionsView”调用
答案 1 :(得分:0)
好的,显然您可以对会话执行各种操作。在exec
部分运行呼叫(.asLongAs
)之前,您必须
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"))
)
}