简体   繁体   中英

How to create a list with “grouped” in Scala through Gatling?

I am trying to make a list which groups elements in chunks of 3. I am not trying anything elaborate, just initialising a list with values and then telling it to group the elements. When I run this it claims: 'hook-64' crashed with 'juNoSuchElementException: No attribute named 'listToGroup' is defined', forwarding to the next one so I understand it is not recognising the declaration.

Here is the code:

 val SessionVal = scenario("aaa").exec{
    session =>
      val listToGroup = List(1,2,3,4,5,6,7,8)
      listToGroup.grouped(3).toList

      session
  }
  val printSessionVal = scenario("print me").exec{
    session =>
      println(session("listToGroup").as[String])
      session
  }

The call:

 def teacherResourcesPageFlow: ChainBuilder = exitBlockOnFail(
    group("Resources Calls") {
      exec(getProductCategoryIds)
         ...
         ...
        .exec(SessionVal)
        .exec(printSessionVal)
         ...
    })

Any help is greatly appreciated.

The solution was to include the line session.set("listToGroup", listToGroup) :

  val SessionVal = scenario("listArry").exec{
    session =>
      val listToGroup = List(1,2,3,4,5,6,7,8)
      listToGroup.grouped(4).toList
      session.set("listToGroup", listToGroup)
  }

There is a better way to do this through a feeder .

In your case it will look like this:

val listArry = Iterator.continually(Map("listArry" ->  List(1,2,3,4,5,6,7,8).grouped(4)))

scenario("listArry")
  .feed(listArry)

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