So, I’m new to Gatling. I noticed yesterday that when you write a chain and repeat it, it repeats exactly the same chain that was generated for the first run (with the exception of the repeat counter that I can add to string apparently). In my scenario I have raw json data and I want to add new id into the data with a function I made, it works for the first time the chain is executed but it doesn’t generate a new one each run. It’s not the only thing I would like to change between executions… so, is it possible to have different data between executions?
for insight: I want to have new Id where generateId is in the json data for every repeat
package computedatabase
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
import java.util.Calendar
import java.text.SimpleDateFormat
import scala.util.Random
class Class name removed extends Simulation {
val httpConf = http
.baseURL("https://host removed")
.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
.doNotTrackHeader("1")
.acceptLanguageHeader("en-US,en;q=0.5")
.acceptEncodingHeader("gzip, deflate")
.userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0")
val useHeaders = Map("Content-Type" -> "application/json", """system-token""" -> "***removed***")
val otherId = 123
val blaId = """"bla""""
object Buy {
val buy = repeat(1000000, "i"){
exec(http("Request ${i}")
.post("/****removed****")
.headers(useHeaders)
.body(StringBody("""{
"request":[{
"blaId":""" + blaId + """,
"otherId":""" + otherId + """,
"someId":"""" + generateId() + "${i}" + """"
}]
}""")).asJSON)}
}
val scn = scenario("***removed***").exec(Buy.buy)
setUp(scn.inject(atOnceUsers(1)).protocols(httpConf))
def generateId() : String = {
val correctFormat = new SimpleDateFormat("yyyyMMddhhmmss")
val today = Calendar.getInstance().getTime()
//correctFormat.format(today) + Random.nextPrintableChar + Random.nextPrintableChar + Random.nextInt(9999)
correctFormat.format(today)
}
}