加特林没有在会话中存储价值 [英] Gatling not storing value in session

查看:59
本文介绍了加特林没有在会话中存储价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用会话进行加特林存储值,如下所示

I am using sessions in gatling to store values, as shown below

      exec(session => {
        val id = Instant.now.toEpochMilli.toString + scala.util.Random.nextInt(1000).toString
        session.set("STARTED_PROCESS_ID",id)
        //Store the id somewhere for processing later
        session
      })
      .exec(
          http("scenario")
            .post(url)
            .header("Content-Type", "application/json")
            .header("id", session => session("STARTED_PROCESS_ID").as[String])
            .body(StringBody(body)
            .check(status.is(200))

根据文档,该值应存储在会话&标头"id"应按预期填充.但是当运行模拟时,出现以下错误

According to the documentation, the value should be stored in session & the header "id" should be populated as expected. But when running the simuation I get the following error

java.util.NoSuchElementException: No attribute named 'STARTED_PROCESS_ID' is defined
    at io.gatling.core.session.SessionAttribute.as(Session.scala:46)
    at common.HttpUtil$.$anonfun$sendPostRequestForWasStartDefLoad$1(HttpUtil.scala:557)
    at io.gatling.core.action.SessionHook.execute(SessionHook.scala:32)
    at io.gatling.core.action.Action.$bang(Action.scala:38)
    at io.gatling.core.action.Action.$bang$(Action.scala:38)

有人可以帮忙解释一下为什么会发生这种情况吗?

Can someone please help explain why is this happening ?

推荐答案

您没有正确使用Session API.请正确阅读文档.

You're not using the Session API correctly. Please properly read the documentation.

Session 是不可变的,并且 set 返回一个新实例.

Session is immutable and set returns a new instance.

exec { session =>
    val id = Instant.now.toEpochMilli.toString + scala.util.Random.nextInt(1000).toString
    session.set("STARTED_PROCESS_ID",id)
}

这篇关于加特林没有在会话中存储价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆