【问题标题】:Unable to evaluate EL while creating Gatling scenario创建加特林场景时无法评估 EL
【发布时间】:2016-05-25 07:25:53
【问题描述】:

我正在创建带有重复块的场景。因为我需要生成基于索引的请求。

def scnWithLoop() = scenario("scenarioName").repeat(counter, "counter") {
    exec (session => {
    val index: Integer = Integer.getInteger(session.attributes.get("counter").get.toString());
    session.set("index", index)
    session
})

exec(
      http("scenarioName")
        .post(contextPath)
        .headers(headers)
        .body(StringBody(getData("${index}".toInt)))
        .check(status.in(expectedCodes))
    ).pause(20 seconds)
}

但这不会评估 EL ${index} 并给我错误:

Caused by: java.lang.NumberFormatException: For input string: "${index}"

加特林版本:2.0.0-M3a

感谢任何帮助!!!

【问题讨论】:

  • 您尝试过使用三引号吗? """${index}"""
  • 你可以直接使用 "counter" ` .repeat(2,"counter").exec(http("${counter}"))` 不需要保存到新的会话变量,它自动创建一个。

标签: performance scala load-testing gatling


【解决方案1】:

像"${index}" 这样的会话值的方便插值仅在字符串被隐式转换为 gatling 表达式时才有效。 scala 的这种黑暗魔法将被您的表达"${index}".toInt 之类的东西打破。根据the session EL documentation,您可能必须明确使用加特林的会话:

....

例如,queryParam("latitude", "${latitude}".toInt + 24) 不会 工作,程序将在"${latitude}".toInt 作为这个字符串 无法解析为 Int。

这里的解决方案是传递一个函数:

session => session("latitude").validate[Int].map(i => i + 24).

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-04
    • 1970-01-01
    相关资源
    最近更新 更多