如何解决使用 Gatling 发出动态请求
我想使用 Gatling 发出动态请求。 使用 Gatling 我们正在使用 rest-API,我们将向其发布 SMS 请求,我希望每个请求都应该使用不同的 mob 发送来完成。
exec(http("Sms Delivery")
.post(s"/deliveries")
.body(StringBody(
s"""{ "template":
|{ "type":"inline","inline":
| { "channels":
| "sms":{ "body":{ "layout":"{greeting}","fragments":{ "greeting":{"en-US":"ABC123 Interested to hear about some jobs?"}}}} }} },| "recipients":[ { "contactDetails":{ "mobileNumber" : "+1${Random.nextInt(123123123)}" } }],| "requester": "${UUID.random.toString}"}""".stripMargin)).asJson
.check(status.is(202))
.check(jsonPath("$.messageId").ofType[String])
)
}
setUp(
scenario("Create message-Cmd")
.exec(createMessageServiceSms()).inject(
rampConcurrentUsers(0) to (6) during(1),constantConcurrentUsers(5) during (testTime seconds)
)
)
假设 Gatling 发送了 100 个请求,对于所有这些请求,我的 mob no 对于每个请求都保持不变,比如说 +12011705515
。
但是,我想要的都没有。应该不一样。
解决方法
该字符串仅创建一次,然后解析为 Expression Language,这允许您在 session attributes 中进行替换。
如果您想要自定义函数,例如创建 UUID
和调用 Random.nextInt
,您需要将函数传递给 StringBody
。
StringBody(_ =>
s"""{ "template":
|{ "type":"inline","inline":
| { "channels":
| "sms":{ "body":{ "layout":"{greeting}","fragments":{ "greeting":{"en-US":"ABC123 Interested to hear about some jobs?"}}}} }} },| "recipients":[ { "contactDetails":{ "mobileNumber" : "+1${Random.nextInt(123123123)}" } }],| "requester": "${UUID.random.toString}"}""".stripMargin)
)
我们丢弃的参数是虚拟用户的 Session
。
值得注意的是,mobileNumber
的数字可能太少,但这与创建动态请求相比是另一个问题。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。