Loop repeat counter starts at 0. I need it to start at 1.

115 views
Skip to first unread message

lbecke...@gmail.com

unread,
Dec 2, 2015, 3:58:13 PM12/2/15
to Gatling User Group
I'm trying to insert an incrementing number into the URL I'm repeatedly querying (ie: product/1, product/2, product/3):

object CallProduct {
   val callProduct = repeat(10, "i") {
    exec(http("callProduct on port ${i}")
      .post("/product/${i}")
      .headers(headers_0))
   }
}

However, I have no product/0. Everything starts at 1. How do I increment ${i} by 1 or get the counter to start at 1? I've tried a number of ways, but I always get a NumberFormatException or compile error. Thanks in advance!

Stéphane LANDELLE

unread,
Dec 2, 2015, 4:27:33 PM12/2/15
to gat...@googlegroups.com
You'll have to create a new attribute with translated value in an exec(function) or use functions everywhere instead of EL.

Stéphane Landelle
GatlingCorp CEO


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

lbecke...@gmail.com

unread,
Dec 3, 2015, 9:35:55 AM12/3/15
to Gatling User Group
Thank you for your response. Can you point me in the direction of an example of how to use exec function that integrates with the exec method I had in my previous post to actually execute the post request? I don't understand how I can have multiple exec calls that work with one another. The documentation for session and scenario do not explain how to use execs that are passed functions with those that are calling methods using dot notation. What I want to do is something like:

object CallProduct {
  val callProduct = repeat(10, "i") {

   
exec {
     session
=>
     session
.set("i","${i}".toInt+1)
   
}
     exec(http("callProduct on port ${i}")
            .post("/product/${i}")
         .headers(headers_0))
  }
}

Obviously, this doesn't work and I don't know why. Thanks for your help!

Stéphane LANDELLE

unread,
Dec 3, 2015, 10:25:44 AM12/3/15
to gat...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages