global variable

hi,

I’d like to share a variable between all users, something like this

val urlBase = “http://monsite.com

val httpConf = httpConfig.baseURL(urlBase)

val headers = Map(
“Accept” → “”“text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8"”"
)

var i=10000

val scn = scenario(“Test WebService”)
.pause(0, 100, MILLISECONDS)
.exec(
http(“Execute request”)
.post(“/monService”)
.headers(headers)
increment i
.fileBody(“monTemplate”,Map(“transactionId” → i))
.check(
regex(“”“OK”“”).exists
)
)

Is this possible and how can i do it ?
Best regards,

Hi,

You could write:

var i = new java.util.concurrent.atomic.AtomicInteger(10000)

val scn = scenario(“Test WebService”)
.pause(0, 100, MILLISECONDS)
.exec((session:Session) => session.setAttribute(“transactionId”, i.getAndDecrement)) // store new transactionId in the user’s Session
.exec(
http(“Execute request”)
.post("/monService")
.headers(headers)
.fileBody(“monTemplate”) // session attributes are automatically available from template, so just use the “transactionId” variable there
.check(regex(""“OK”""))) // no need for exists as it’s the default

Cheers,

Stephane

2012/5/9 mediamana <mediamana@free.fr>

hi Stephane,

The problem is that var i should be the same for all users.
The transactionId should be unique.

With your solution 2 users can have the same value, isn’t it ?

2012/5/9 mediamana <mediamana@free.fr>

hi Stephane,

The problem is that var i should be the same for all users.
The transactionId should be unique.

With your solution 2 users can have the same value, isn’t it ?

No.
I feel like you don’t understand that a scenario is the definition of a workflow. Every step (what we call Action) is executed every time a “user” passes into it.
So in this case, i is incremented every time is Action is run.

PS: My mistake: i should be a val and not a var.

Does the transactionId need to be a counter or does it just need to be
unique? Having an atomic increment in the middle of your test might
prove to be a bottleneck. It's simple enough to generate a random ID
with very high likelihood of being unique without having shared state
between all the actors.

Chris

Actually, I started writing a sentence like “you shouldn’t share state, that’s a bad idea”, but erased it as AtomicInteger was designed to be very fast (or am I wrong?).
So I don’t know exactly if having a random ID generator would prove faster than an AtomicInteger here. The answer is probably… it may, or not…

If you want an UUID generator, there’s one embedded in Akka.

You can do something like: new com.eaio.uuid.UUID().toString

Cheers,

Steph

2012/5/9 Chris Carrier <ctcarrier@gmail.com>