Gatling数据喂入器与递增值

huangapple go评论56阅读模式
英文:

Gatling data feeder with an increment value

问题

我正在寻找创建一个数据提供程序,它会递增一个整数,同时伴随一些其他值。我已经找到一种使用AtomicInteger来实现这一目标的方法。
以下代码展示了我如何实现它。是否有其他方式可以实现这一目标,例如使用Iterator.from(0).map()方法?

def getUUID = randomUUID().toString
val ordinal = new AtomicInteger(1)

val itemAttemptForPost = Iterator.continually {
  Map(
    "usedId" -> getUUID,
    "ordinal" -> ordinal.getAndIncrement()
  )
}
英文:

I'm looking to create a data feeder which increments an integer from 1 alongside some other values. I have found a way to achieve this using AtomicInteger.
Following code shows how I have implemented it. Is there any other way that I can achieve this for instance using the Iterator.from(0).map() approach.

  def getUUID = randomUUID().toString
  val ordinal = new AtomicInteger(1)

  val itemAttemptForPost = Iterator.continually {
    Map(
      "usedId" -> getUUID ,
      "ordinal" -> ordinal.getAndIncrement()
    )
  }

答案1

得分: 2

使用from(1)以保持与new AtomicInteger(1)的一致性。

Iterator.from(1).map { i =>
    Map(
        "usedId" -> randomUUID().toString,
        "ordinal" -> i
    )
}
英文:

Note: using from(1) for consistency with your new AtomicInteger(1).

Iterator.from(1).map { i =>
      Map(
      "usedId" -> randomUUID().toString,
      "ordinal" -> i
    )
}

huangapple
  • 本文由 发表于 2023年3月1日 16:25:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/75601159.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定