我有 gatling 腳本來發送帶有 10,000 個電子郵件地址陣列的 HTTP 請求,JSON 正文是這樣的:
{
"userIds": [
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
.
.
.
"[email protected]"
]
}
因此,我生成了一個包含 10,000 個隨機電子郵件地址的 ArrayList:
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\"")
}
我需要將該 ArrayList 輸入到我的場景中:
val scn = scenario("Add Users")
.exec(
http("AddUsers")
.post(path)
.header("Authorization", apiKey)
.body(StringBody("{"
"\n\t\"userIds\": "
userNames
"\n\t\n"
"}")).asJson
)
問題是我的場景中的所有請求都發送了同一個陣列,我每次都需要生成一個不同的陣列。
我想我需要將我的 ArrayList 轉換為進紙器或迭代器,但我堅持下去。
在加特林可以做這樣的事情嗎?
uj5u.com熱心網友回復:
我找到了答案。
我創建了一個函式來構建隨機電子郵件的 ArrayList:
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
}
然后我將 ArrayList 放入進紙器:
val emailsFeeder = Iterator.continually(Map("emails" -> getEmailsArray(totalEmails)))
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/486233.html
