Repeat blocks and ChainBuilder

962 views
Skip to first unread message

Larry Finkelstein

unread,
Aug 4, 2014, 4:24:20 PM8/4/14
to gat...@googlegroups.com
I was using something similar to the following with 2.0.0-M3a, but it is no longer working with 2.0.0-RC1.

My question is what do I pass in to addXmlPostLoop() for chain?  I had been passing in bootstrap, but that has been removed in RC1.

def addXmlPost(chain: ChainBuilder, i: Int) =
    chain.exec(
        http("X")
            .post("/rest/url")
            .headers(headers)
            .body(createXml(i))
    )

def addXmlPostLoop(chain: ChainBuilder): ChainBuilder =
    (0 until numberOfLoops).foldLeft(chain)(addXmlPost)

Pierre DAL-PRA

unread,
Aug 4, 2014, 4:52:19 PM8/4/14
to gat...@googlegroups.com
Hi Larry,

Using Gatling’s repeat, you can obtain a similar behaviour and rely only on Gatling’s DSL :


repeat(numberOfLoops, “i”) {
      exec(
        http(“X”)
          .post(“/rest/url”)
          .headers(headers)
          .body(StringBody(session => createXml(session(“i").as[Int])))
      )
    }

Some explanations : 

  • repeat works lilke your everyday for loop : starts at 0, repeat a specified number of times
  • the second parameter of repeat is the counter name, which is set to i here and stored in the user’s session
  • Then, you execute your request, and set the body (I used StringBody here, but it works the same for any type of body, they all allow to get data from the user’s session)
  • Then call createXml, using the counter stored in the session with session(“i").as[Int]

Here are the related Gatling 2.0.0-RC1 documentation for each “component": 

Hope this helps !

Cheers, 

Pierre

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

Larry Finkelstein

unread,
Aug 4, 2014, 5:28:08 PM8/4/14
to gat...@googlegroups.com
Thank you Pierre.  I think that will work for me, and appears to be a bit cleaner by relying only on the Gatling DSL.
Reply all
Reply to author
Forward
0 new messages