[英]Using Streams in Gatling repeat blocks
我在Gatling場景中看到了以下代碼(為了簡潔/隱私而修改):
val scn = scenario("X")
.repeat(numberOfLoops, "loopName") {
exec((session : Session) => {
val loopCounter = session.getTypedAttribute[Int]("loopName")
session.setAttribute("xmlInput", createXml(loopCounter))
})
.exec(
http("X")
.post("/rest/url")
.headers(headers)
.body("${xmlInput}"))
)
}
它在重復塊中命名循環,將其從會話中取出並使用它來創建唯一的輸入XML。 然后它將該XML重新粘貼到會話中,並在發布時再次提取它。
我想廢除命名循環迭代器和訪問會話的需要。 理想情況下,我想使用Stream
來生成XML。
但加特林控制循環,我不能遞歸。 我是否需要妥協,或者我能否以功能的方式使用Gatling(沒有vars或訪問會話)?
正如我所看到的,numberOfLoops和createXml似乎都不依賴於會話中存儲的任何用戶相關內容,因此循環可以在構建時解析,而不是在運行時解析。
import com.excilys.ebi.gatling.core.structure.ChainBuilder
def addXmlPost(chain: ChainBuilder, i: Int) =
chain.exec(
http("X")
.post("/rest/url")
.headers(headers)
.body(createXml(i))
)
def addXmlPostLoop(chain: ChainBuilder): ChainBuilder =
(0 until numberOfLoops).foldLeft(chain)(addXmlPost)
干杯,
斯特凡
PS:關於Gatling的首選方式是我們的Google群組: https ://groups.google.com/forum/#!forum/gatling
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.