Gatling 计算表达式语言
Gatling Evaluate Expression Language
Gatling parses Strings parameter values and turn them into functions that will compute a result based on the data stored into the Session when they will be evaluated.
有没有办法在 exec 中手动执行此操作?
我有多个使用 EL 属性的请求正文模板,发送的请求会因馈线而异
我目前的代码是这样的:
// Body itself contains attributes say ${uuid}
val body1 = Source.fromResource("body1.json")
val body2 = Source.fromResource("body2.json")
val scn: ScenarioBuilder = scenario("Dynamic body")
.feed(feeder)
.exec(session => {
if(session("requestType").as[String].equals("first"))
session.set("request", body1)
else
session.set("request", body2)
session
}
.exec(http("Http Call")
.post(url)
.body(StringBody("${request}"))
// This won't evaluate the nested attribute and body will remain ${uuid} instead of an actual UUID
)
我预计不会有评估嵌套 EL 属性的方法,但有没有办法使用会话变量手动评估它?类似于
.exec(session => {
val evaluatedBody = merge(body1, session)
session("request", evaluatedBody)
session
})
我看到 ELCompiler 在其他一些问题中被引用,但不确定从哪里导入它以及如何将它与会话值一起使用
您应该使用带有文件路径参数的 ElFileBody
,它可以是一个函数。
val scn = scenario("Dynamic body")
.feed(feeder)
.exec(http("Http Call")
.post(url)
.body(
ElFileBody(session =>
session("requestType").as[String] match {
case "first" => "body1.json"
case _ => "body2.json"
}
)
)
)
Gatling parses Strings parameter values and turn them into functions that will compute a result based on the data stored into the Session when they will be evaluated.
有没有办法在 exec 中手动执行此操作?
我有多个使用 EL 属性的请求正文模板,发送的请求会因馈线而异
我目前的代码是这样的:
// Body itself contains attributes say ${uuid}
val body1 = Source.fromResource("body1.json")
val body2 = Source.fromResource("body2.json")
val scn: ScenarioBuilder = scenario("Dynamic body")
.feed(feeder)
.exec(session => {
if(session("requestType").as[String].equals("first"))
session.set("request", body1)
else
session.set("request", body2)
session
}
.exec(http("Http Call")
.post(url)
.body(StringBody("${request}"))
// This won't evaluate the nested attribute and body will remain ${uuid} instead of an actual UUID
)
我预计不会有评估嵌套 EL 属性的方法,但有没有办法使用会话变量手动评估它?类似于
.exec(session => {
val evaluatedBody = merge(body1, session)
session("request", evaluatedBody)
session
})
我看到 ELCompiler 在其他一些问题中被引用,但不确定从哪里导入它以及如何将它与会话值一起使用
您应该使用带有文件路径参数的 ElFileBody
,它可以是一个函数。
val scn = scenario("Dynamic body")
.feed(feeder)
.exec(http("Http Call")
.post(url)
.body(
ElFileBody(session =>
session("requestType").as[String] match {
case "first" => "body1.json"
case _ => "body2.json"
}
)
)
)