关于scala:加特林加油机加长数字(不是随机的)

Gatling feeder with increment number (not random)

我正在寻找帮助来创建简单的供稿器,以使整数从0开始递增。
我发现很多供料器示例可以生成随机UUID,电子邮件,字符串...
我看过文件
但是没有什么可以增加整数(我感觉有些与new java.util.concurrent.atomic.AtomicInteger(0)相关的东西,但是我无法使用某些东西),而且我也不希望在"?nfinite"行内创建一些CSV或文件。

所以我拥有的是

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  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,对我来说效果很好:

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

在那之后,您只需要在场景中添加'feed'方法即可:

1
2
3
scenario("scenario")
    .feed(userId)
    .exec(request)

Iterator.from(0).map(i =>"userId" -> i)就足够了,加特林(Gatling)照顾进料器螺纹的安全性。