带增量编号的加特林进纸器(非随机)

Gatling feeder with increment number (not random)

我正在寻求帮助来创建简单的馈线以从 0 递增一个整数。 我发现了很多生成随机 UUID、电子邮件、字符串的馈线示例…… 我看过 the doc 但是没有增加整数的方法(我觉得有些东西与 new java.util.concurrent.atomic.AtomicInteger(0) 相关,但我无法找到有用的东西),而且我不是在寻找在“无限”行中创建一些 CSV 或文件。

所以我有的是

  val userId = Iterator.continually(
    Map("userId" -> CAN'T FIND WHAT TO PUT HERE TO HAVE INCREMENT INTEGER FROM 0
  )

  object CreateUser {
    val createUser = exec(
        http("Create a random user")
          .post("/users"))
          .body(StringBody("""{
            "Username": "Test-${userId}"
          }""")).asJSON
  }

  val httpConf = http
    .baseUrl("https://api.some.site/v1/")

  val users = scenario("Create Users").exec(CreateUser.createUser)

  setUp(
    users.inject(rampUsers(100) during (10 seconds)),
  ).protocols(httpConf)

感谢您的帮助

我尝试使用 AtomicInteger,它对我来说效果很好:

val id = new AtomicInteger(0)
val userId: Iterator[Map[String, Int]] = Iterator.continually(Map("userId" -> id.getAndIncrement()))

之后,您只需将 'feed' 方法添加到您的方案中:

scenario("scenario")
    .feed(userId)
    .exec(request)

Iterator.from(0).map(i => "userId" -> i) 就足够了,Gatling 负责喂料线程的安全。