【发布时间】:2019-09-18 07:51:47
【问题描述】:
我需要在 Gatling 中提出一个请求,在该请求中我能够访问会话项目(无需表达式语言)。我需要这样做,因为我想将数据注入来自 csv 馈送器的 ByteArrayBody 请求。为了演示我的问题,我有一个小例子(没有会话的实际需要)。
以下场景运行良好:
val scnBase: ScenarioBuilder = scenario("Test scneario").repeat(1){
exec(http("Http Test test").get("http://google.de/"))
}
但那个没有(我得到了例外There were no requests sent during the simulation, reports won't be generated):
val scnBase: ScenarioBuilder = scenario("Test scneario").repeat(1){
exec(session => {
http("Http Test test").get("http://google.de/")
session
})
}
我在 IntelliJ(到目前为止运行良好)和以下(这里是最小化的)模拟文件中运行我的模拟:
package test.scala
import java.text.SimpleDateFormat
import java.util.Date
import io.gatling.core.Predef._
import io.gatling.core.body.ByteArrayBody
import io.gatling.core.structure.ScenarioBuilder
import io.gatling.http.Predef._
import io.gatling.http.protocol.HttpProtocolBuilder
import org.slf4j.LoggerFactory
import test.scala.TerminalTesterRequest.url
import test.scala.requests._
import test.scala.util.CharsetConverter
import scala.concurrent.duration._
import scala.language.postfixOps
class MySimulation extends Simulation {
//base URL (actually this URL is different, but it's not important)
val ecmsServerUri = "http://0.0.0.0"
//base Protocol
val httpProtocol: HttpProtocolBuilder = http
.baseUrl(ecmsServerUri)
.inferHtmlResources(BlackList(""".*\.js""", """.*\.css""", """.*\.gif""", """.*\.jpeg""", """.*\.jpg""", """.*\.ico""", """.*\.woff""", """.*\.(t|o)tf""", """.*\.png"""), WhiteList())
.acceptHeader("*/*")
.acceptEncodingHeader("gzip, deflate")
.acceptLanguageHeader("en,en-US;q=0.7,de-DE;q=0.3")
.userAgentHeader("Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 2.0.50727.8762)")
val scnBase: ScenarioBuilder = scenario("Test scneario").repeat(1){
exec(session => {
http("Http Test test").get("http://google.de/")
session
})
}
setUp(
scnBase.inject(constantUsersPerSec(1) during(1 seconds)).protocols(httpProtocol)
).maxDuration(5 minutes)
}
如何使用会话信息(或至少来自馈线的数据)运行 exec 请求?我正在使用 Gatling 3.1.1
【问题讨论】:
-
让您的 http builder inside 一个会话命令可确保它不会被执行,因为所有构建器都需要在启动时执行。您可以在正文请求中使用加特林 EL。
-
@JamesWarr 你说如果我在 ByteArrayBody 中使用 EL,gatling 仍然可以检测到它?
-
不,它不会 - 至少如果它是用 EBCDIC 编码的,就像我的情况一样。
-
好吧,其实可以在
ByteArrayBody的构造函数中写一个表达式。虽然这不能回答问题(因此只有评论),但它确实解决了我的问题。