Store result from ArrayBuffer in session

89 views
Skip to first unread message

COTTET Julien

unread,
Apr 22, 2014, 5:31:30 AM4/22/14
to gat...@googlegroups.com
Il want to do something like : 

.get("/rest/historisation/findUserHistory")
      .check(jsonPath("$..historique-recherche[*].id-variante").findAll.saveAs("IDS_VAR_HISTO"))
    )
    .exec(session => {
      session.set("ID_VAR", "${IDS_VAR_HISTO.random}")
    })


But when i'm accessing the value of my session variable i got : "${IDS_VAR_HISTO.random}"

How can i store the random result in an attribute of my session ?

I want to put the result from differents chains and not only from "IDS_VAR_HISTO" but from "IDS_VAR_HISTO", "IDS_VAR_CNIT", etc.
This aims to get always my id from "${ID_VAR} independently of the chain.

Thank you in advance for helping me.

Nicolas Rémond

unread,
Apr 22, 2014, 5:37:56 AM4/22/14
to gat...@googlegroups.com
Which version of Gatling are you using ?


--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

COTTET Julien

unread,
Apr 22, 2014, 7:24:13 AM4/22/14
to gat...@googlegroups.com
I'm on Gatling 2.0.0-M3a

Nicolas Rémond

unread,
Apr 22, 2014, 11:28:43 AM4/22/14
to gat...@googlegroups.com
Hi,
   .exec(session => {
      session.set("ID_VAR", "${IDS_VAR_HISTO.random}")
    })

The red expression is a regular String, it won't be interpreted as an EL-Expression.
Why do you do this in an extra step ?


If you really need to store that in the session, I would recommand to do something like that :

  import java.util.concurrent.ThreadLocalRandom
  import io.gatling.core.validation.Success


    .exec(http("TODO").get("/rest/historisation/findUserHistory")
      .check(jsonPath("$..historique-recherche[*].id-variante").ofType[Long].findAll.saveAs("IDS_VAR_HISTO"))
    )
    .exec(session => {
      session("IDS_VAR_HISTO").validate[Seq[Long]] match {
        case Success(ids) => 
          val index = ThreadLocalRandom.current.nextInt(ids.size)
          session.set("ID_VAR", ids(index))
        case _ => session
      }
    })


Does it help ?

Regards
Nicolas




Reply all
Reply to author
Forward
0 new messages