简体   繁体   English

在Scala中使用Gatling创建动态POST / users调用

[英]Creating dynamic POST /users calls with Gatling in Scala

I am using Gatling to generate a large number of users to test performance issues on my product. 我正在使用加特林(Gatling)生成大量用户,以测试产品上的性能问题。 I need to be able to dynamically create users with unique fields (like 'email'). 我需要能够动态创建具有唯一字段(例如“电子邮件”)的用户。 So, I'm generating a random number and using it, but it isn't being re-instantiated each time, so the email is only unique on the first pass. 因此,我正在生成一个随机数并使用它,但是不会每次都重新实例化它,因此该电子邮件仅在第一次通过时才是唯一的。

object Users {

  def r = new scala.util.Random;
  def randNumb() = r.nextInt(Integer.MAX_VALUE)
  val numb = randNumb()

  val createUser = {
    exec(http("Create User")
    .post("/users")
    .body(StringBody(raw"""{"email": "qa_user_$numb@company.com" }""")))
  }
}

val runCreateUsers = scenario("Create Users").exec(Users.createUser)

setUp(
  runCreateUsers.inject(constantUsersPerSec(10) during(1 seconds))
).protocols(httpConf)

Where should I be defining my random numbers? 我应该在哪里定义我的随机数? How can I pass it into createUser? 如何将其传递给createUser?

Use a feeder : 使用进纸器

object Users {
  val createUser = exec(http("Create User")
    .post("/users")
    .body(StringBody("""{"email": "qa_user_${numb}@Marqeta.com" }""")))
}

val numbers = Iterator.continually(Map("numb" -> scala.util.Random.nextInt(Int.MaxValue)))

val runCreateUsers = scenario("Create Users")
  .feed(numbers)
  .exec(Users.createUser)

...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM