我正在尝试在一个函数中执行多个HTTP调用
主要:
def requestChain: ChainBuilder = {
feed(feeder(dataSource))
.exec(cleanTransactions("Revoke Transaction"))
}
现在在此方法中,我正在调用另外两个执行不同http调用的方法。第一次调用将结果(Array)保存在getLicensesForDevice_TA会话变量中。当遍历变量时,我试图基于Array中的元素进行另一个http调用。但是,似乎由于某种原因第二个调用(revokeLicense)没有执行(问题与If语句无关,我已经检查过了)。当在requestChain中调用revokeLicense direkt时,它会正确执行。
private def cleanTransactions(methodeName:String, device:String, returnCode:Integer ): ChainBuilder = {
exec(getLicensesForDevice(methodeName, device, 200))
.foreach("${getLicensesForDevice_TA}", "deleteLicensesForDevice_TA") {
exec(session => {
val gatlingTransactionID = session("deleteLicensesForDevice_TA").as[String].trim
session.set("gatlingTransactionID", gatlingTransactionID)
})
if ("${gatlingTransactionID}".contains("TestTA")){
exec(revokeLicense(methodeName,"${gatlingTransactionID}",204,false))
}else{
exec(session => {
println("No TA will be executed: ${gatlingTransactionID}" )
session
})
}
}
}
这行不通。如Gatling's documentation中所述,您不能在Scala函数中使用Gatling DSL。加特林DSL方法只是在引导时一次构建组件的构建器。
Gatling DSL组件是不可变的ActionBuilder,必须完全链接在一起,并且仅在启动时构建一次。结果是动作的工作流链。这些构建器本身不会做任何事情,不会触发任何副作用,它们只是定义。结果,在运行时在功能中创建此类DSL组件是完全没有意义的。如果要在执行流程中使用条件路径,请使用适当的DSL组件(doIf,randomSwitch等)