我正在尝试编写一个Gatling脚本,我从CSV文件中读取一个起始编号并循环,比如10次.在每次迭代中,我想增加参数的值.
看起来需要一些Scala或Java数学,但无法找到有关如何操作的信息,或者如何以及将Gatling EL与Scala或Java结合起来的位置.
感谢任何帮助或指导.
var numloop = new java.util.concurrent.atomic.AtomicInteger(0)
val scn = scenario("Scenario Name")
.asLongAs(_=> numloop.getAndIncrement() <3, exitASAP = false){
feed(csv("ids.csv")) //read ${ID} from the file
.exec(http("request")
.get("""http://finance.yahoo.com/q?s=${ID}""")
.headers(headers_1))
.pause(284 milliseconds)
//How to increment ID for the next iteration and pass in the .get method?
}
Run Code Online (Sandbox Code Playgroud)
您从Gatling的Google Group复制粘贴此代码,但此用例非常具体.您是否首先正确阅读了有关循环的文档?你的用例是什么?它如何适合基本循环?
编辑:所以问题是:我如何获得每个循环迭代和每个虚拟用户的唯一ID?
您可以为循环索引和虚拟用户ID计算一个.Session已经有一个唯一的ID但它是一个String UUID,所以它对你想做的事情来说不是很方便.
// first, let's build a Feeder that set an numeric id:
val userIdFeeder = Iterator.from(0).map(i => Map("userId" -> i))
val iterations = 1000
// set this userId to every virtual user
feed(userIdFeeder)
// loop and define the loop index
.repeat(iterations, "index") {
// set an new attribute named "id"
exec{ session =>
val userId = session("userId").as[Int]
val index = session("index").as[Int]
val id = iterations * userId + index
session.set("id", id)
}
// use id attribute, for example with EL ${id}
}
Run Code Online (Sandbox Code Playgroud)