Sessions and pauses

Hello,

I’m trying to use Gatling 1.5.2 and one of the things I’d like to do is have how long I pause for a URL be dynamic. So, I have something like this:

val scn = scenario(“Test Scenario”)
.feed(userFeeder)
.feed(csv(fname).random)
.pauseCustom(() => java.lang.Long.parseLong("${pause}"))
.exec(
http(“Req 1”)
.get("…")
.check(status.is(200))
)

The “userFeeder” has two values: “user”, which is the username, and “pause”, which is how long I want to pause for each URL. However, I can’t seem to access the value that’s in “pause” when I try to execute the pause. In this case, and in a simpler one with the normal “pause” method, I get a parse exception.

How can I do this? Is this even possible? The documentation seems to indicate that something like I did should be possible, but it’s not working. I’d also love to be able to do something similar for how often I repeat an action as well.

Thanks.

EL expressions can’t be parsed implicitly inside a function.
And pauseCustom, as stated by its signature, can’t access the session, so cannot retrieve user data.

You can convert your data from String to Long directly in your feeder:

val feeder = csv(fname).map { record =>
record.map {
case (“pause”, value) => “pause” → value.toLong
case entry => entry
}
}.random

This is easier with Gatling 2 as feeders have a transform method for this purpose.

Hello,

Thanks, but that doesn’t seem to resolve the issue. I’m now getting a couple compilation issues. Here’s the current code:

package test

import com.excilys.ebi.gatling.core.Predef._
import com.excilys.ebi.gatling.http.Predef._
import com.excilys.ebi.gatling.jdbc.Predef._
import com.excilys.ebi.gatling.http.Headers.Names._
import akka.util.duration._
import bootstrap._
import scala.io._

class TestSim extends Simulation
{
val numUsers = Integer.getInteger(“users”, 10);
val rampUp = java.lang.Long.getLong(“ramp”, 0L);
val fname = System.getProperty(“ccodes”);

// The next two lines copy data from a file and put it into an array.
/val cCodes = new collection.mutable.ArrayBuffer[String]/
/Source.fromFile(fname).getLines.foreach(code => cCodes += code)/

val httpConf = httpConfig.baseURL(“http://localhost:8080”)
.acceptHeader(“application/json”)
/val userFeeder = Array(Map(“user” → “foo”, “pause” → 1),/
/* Map(“user” → “bar”, “pause” → 2),/
/
Map(“user” → “baz”, “pause” → 3)).random*/
val userFeeder = csv(“user.dat”).map { record =>
record.map {
case (“delay”, value) => “delay” → value.toLong
case entry => entry
}
}.random

val scn = scenario(“Test Scenario”)
.feed(userFeeder)
.feed(csv(fname).random)
.pause(delay)
.exec(
http(“Req 1”)
.get("…")
.check(status.is(200))
)

setUp(scn.users(numUsers).ramp(rampUp).protocolConfig(httpConf))
}

The errors I’m getting are:

[error] /home/dev/rmt/volt-getaor/src/main/scala/VoltGetAor.scala:31: value random is not a member of Iterator[scala.collection.immutable.Map[java.lang.String,Any]]
[error] possible cause: maybe a semicolon is missing before `value random’?
[error] }.random
[error] ^
[error] /home/dev/rmt/volt-getaor/src/main/scala/VoltGetAor.scala:40: not found: value delay
[error] .pause(delay)
[error] ^

I’ll apologize now if it’s my own stupidity, but this was thrust upon me late last week and I never programmed in Scala before.

Thanks.

There’s a toArray missing before random.

Hopefully last question: how do I access the value then in the “.pause()” call? It looks like I can simply access the userFeeder array and access a value, but then I wouldn’t know if that value is the one being referenced somewhere else in the session. The examples that come with Gatling assume that all values coming out of a feeder are accessed in strings, which is not the case here.

Ha, I’m very sorry: I realize that Gatling 1 doesn’t support dynamic pauses, only Gatling 2 does.
If that’s a feature you really need, you’ll have to migrate.