I have gatling script to send HTTP request with an array of 10,000 email addresses, the JSON body is like this one:
{
"userIds": [
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
.
.
.
"[email protected]"
]
}
So, I generate an ArrayList of 10,000 random email addresses:
val emails = new util.ArrayList[String]
for(i <- 1 to 10000) {
emails.add("\"" Random.alphanumeric.take(8).mkString.toLowerCase
"@" Random.alphanumeric.take(10).mkString.toLowerCase ".com\"")
}
And I need to feed that ArrayList into my scenario:
val scn = scenario("Add Users")
.exec(
http("AddUsers")
.post(path)
.header("Authorization", apiKey)
.body(StringBody("{"
"\n\t\"userIds\": "
userNames
"\n\t\n"
"}")).asJson
)
The problem is that the same array sent to all the requests in my scenario, and I need to generate a different array every time.
I guess I need to convert my ArrayList to a feeder or an Iterator but I'm stuck on it.
Is it possible to do such thing in Gatling?
CodePudding user response:
I found the answer.
I created a function to build the ArrayList of random emails:
def getEmailsArray(count: Integer): util.ArrayList[String] = {
val emails = new util.ArrayList[String]
for (i <- 1 to count) {
emails.add("\"" Random.alphanumeric.take(8).mkString.toLowerCase
"@" Random.alphanumeric.take(10).mkString.toLowerCase ".com\"")
}
emails
}
Then I get the ArrayList into a feeder:
val emailsFeeder = Iterator.continually(Map("emails" -> getEmailsArray(totalEmails)))