简体   繁体   中英

How can I parameterise information in Gatling scenarios

I need to send specific parameters to a scenario that is being reused multiple times with different payloads depending on the workflows. The following is the code that is to be reused:

var reqName = "" 
var payloadName = ""

lazy val sendInfo: ScenarioBuilder = scenario("Send info")
.exec(session => {
  reqName = session("localReqName").as[String]
  payloadName = session("localPayloadName").as[String]
  session}
)
.exec(jms(s"$reqName")
  .send
  .queue(simQueue)
  .textMessage(ElFileBody(s"$payloadName.json"))
)
.exec(session => {
  val filePath = s"$payloadName" 
  val body = new String(Files.readAllBytes(Paths.get(ClassLoader.getSystemResource(filePath).toURI)))
  logger.info("timestamp value: " + session("timestamp").as[String])
  logger.debug("Template body:\n " + body)
  session
})

I know that you can chain scenarios in Scala/Gatling but how can I pass in information like reqName and payloadName down the chain, where reqName is a parameter to indicate the name of the request where the info is being sent and payloadName is the name of the actual JSON payload for the related request:

lazy val randomInfoSend: ScenarioBuilder = scenario("Send random info payloads")
.feed(csv("IDfile.csv").circular)
.randomSwitch(
  (randomInfoType1prob) -> exec(
    feed(timeFeeder)
    .exec(session => {
       payloadName = "Info1payload.json"
       reqName ="Info1Send"
       session.set("localReqName", "Info1Send")
       session.set("localPayloadName", "Info1payload.json")
       session
     })
    .exec(sendInfo)
  ),
  (100.0 - randomInfoType1prob) -> exec(
    feed(timeFeeder)
    .exec(session => {
       payloadName = "Info2Payload.json"
       reqName ="Info2Send"
       session.set("localReqName", "Info2Send")
       session.set("localPayloadName", "Info2Payload.json")
       session
     })
    .exec(sendInfo)
)

I attempted the above but the values of that 2 specific parameters were not passed through correctly. (The IDs and timestamps were fed through correctly though) Any suggestions?

Please properly read the Session API documentation . Session is immutable so Session#set returns a new instance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM