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 = {
???
}
}
“”"
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.
No, it’s not. You can pass a List of HttpRequestBuilders but not an Expression.
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 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.
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.
Have you gone through the documentation? Even the tutorials show how to use Gatling EL. Then, also have a look at the Session page.
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.
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: