How do I make this work? EL and Session variables.

773 views
Skip to first unread message

Greg Roodt

unread,
Jul 13, 2017, 11:44:31 PM7/13/17
to Gatling User Group
Hi

Fairly new to Gatling and a little confused about how to make use of EL and Session variables that are not strings. I've read the docs, but there must be something that I don't understand. Hopefully somebody can point me in the right direction. Basically, how can I get something like this to work?

"""
import java.util.UUID

import io.gatling.core.Predef._
import io.gatling.core.session.Expression
import io.gatling.core.structure.{ChainBuilder, ScenarioBuilder}
import io.gatling.http.Predef._
import io.gatling.http.protocol.HttpProtocolBuilder
import io.gatling.http.request.builder.HttpRequestBuilder

import scala.concurrent.duration._

class MySimulation extends Simulation {

val httpConf: HttpProtocolBuilder = http.baseURL(AppConfig.baseUrl).disableCaching

val feeder: Iterator[Map[String, Any]] = Iterator.continually(Map(
"USER_ID" -> scala.util.Random.alphanumeric.take(11).mkString,
"RESOURCE_IDS" -> Seq.fill(10)(UUID.randomUUID)))

val requestChain: List[ChainBuilder] = List(
exec(getUser("${USER_ID}")),
exec(getResources("${RESOURCE_IDS}")))

val testScenario: ScenarioBuilder = scenario("MySimulation").forever(feed(feeder).exec(requestChain))

setUp(testScenario.inject(atOnceUsers(AppConfig.userCount))).protocols(httpConf).maxDuration(1 minutes)

def getUser(userId: String): HttpRequestBuilder =
http("getUser")
.get(s"/user/$userId")

def getResources(resourceIdsExpression: Expression[List[String]]): HttpRequestBuilder = {
???
}
}
"""


Greg Roodt

unread,
Jul 16, 2017, 12:05:06 AM7/16/17
to Gatling User Group
Is anybody able to confirm that what I'm trying to do is possible or not? Any pointers to some examples out on the web?

Any help appreciated. Thanks.

slan...@gatling.io

unread,
Jul 16, 2017, 4:07:51 PM7/16/17
to gat...@googlegroups.com
No, it's not. You can pass a List of HttpRequestBuilders but not an Expression.
--
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.

Greg Roodt

unread,
Jul 16, 2017, 4:14:53 PM7/16/17
to gat...@googlegroups.com
Yes, which is working fine for me. However, I'm unable to obtain a List from a session variable when I try and I've seen in the docs that I should be using the Session. So I'm a little lost. 

Is there a way to construct a chain or list of dependent HTTP actions and then pass them for execution? All with access to state from previous requests and session variables? Even lists. 

And also to obtain a List from a feeder?




You received this message because you are subscribed to a topic in the Google Groups "Gatling User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gatling/QTj6H9DgNN0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gatling+u...@googlegroups.com.

Stéphane LANDELLE

unread,
Jul 17, 2017, 4:01:20 PM7/17/17
to gat...@googlegroups.com
You don't get it.

Having something like `def getResources(resourceIdsExpression: Expression[List[String]]): HttpRequestBuilder` wouldn't work.
The `resources` method takes HttpRequestBuilder*. It's not possible to build the HttpRequestBuilders at runtime, based on each Session's data.
What you can do is have static HttpRequestBuilders resolve each Session's data.


Stéphane Landelle
GatlingCorp CEO


To unsubscribe from this group and stop receiving emails from it, send an email to gatling+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Gatling User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gatling/QTj6H9DgNN0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gatling+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
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+unsubscribe@googlegroups.com.

Greg Roodt

unread,
Jul 17, 2017, 4:17:23 PM7/17/17
to gat...@googlegroups.com
Thanks. Yes, I'm very sure I don't get it. 😊

That's what I thought I was doing. I thought I was building static execution chain. I guess not. I know I can't dynamically build HttpRequestBuilders at runtime. 

Any tips or examples on how to do this static resolution of values as I'm attempting in my example?

I want a statically defined execution chain, but I want the request values to be dependent on session values from a feeder and previous requests in the session. 



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.

--
You received this message because you are subscribed to a topic in the Google Groups "Gatling User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gatling/QTj6H9DgNN0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gatling+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
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.

--
You received this message because you are subscribed to a topic in the Google Groups "Gatling User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gatling/QTj6H9DgNN0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gatling+u...@googlegroups.com.

slan...@gatling.io

unread,
Jul 17, 2017, 4:25:55 PM7/17/17
to gat...@googlegroups.com
Have you gone through the documentation? Even the tutorials show how to use Gatling EL. Then, also have a look at the Session page.

Greg Roodt

unread,
Jul 17, 2017, 4:38:12 PM7/17/17
to gat...@googlegroups.com
Yes, I've read it all. I can already use simple EL Strings like the tutorial. That works no problem.  I'm trying to resolve a List of values from a feeder. 

I've basically followed the same pattern as Step 01 of the tutorial. In the tutorial,.exec is called with a list Search, Browse, Edit. 

I'm trying to call .exec with a list getUser, getResources. 

Greg Roodt

unread,
Jul 20, 2017, 12:56:23 AM7/20/17
to Gatling User Group
Maybe I can only use EL with Strings? So should I be building my JSON or lists of request parameters etc in my Feeder and then reading them in EL?

In the documentation, what types are these:
val scn = scenario("Scenario Name").exec(Search.search, Browse.browse, Edit.edit)

Are those all HttpRequestBuilders?

So if they needed to post JSON or build JSON objects from Feeders and or Session values, how would it be done? The example only passes simple Strings: ${searchCriterion}





On Friday, 14 July 2017 13:44:31 UTC+10, Greg Roodt wrote:
Reply all
Reply to author
Forward
0 new messages