如何正确地将会话值传递到方法feed()中,以正确进行加特林>

问题描述 投票:0回答:1
我有以下问题。当我尝试执行模拟时,出现此错误:

Generating reports... Exception in thread "main" java.lang.UnsupportedOperationException: There were no requests sent during the simulation, reports won't be generated at io.gatling.charts.report.ReportsGenerator.generateFor(ReportsGenerator.scala:49) at io.gatling.app.RunResultProcessor.generateReports(RunResultProcessor.scala:62) at io.gatling.app.RunResultProcessor.processRunResult(RunResultProcessor.scala:40) at io.gatling.app.Gatling$.start(Gatling.scala:88) at io.gatling.app.Gatling$.fromMap(Gatling.scala:41) at Engine$.delayedEndpoint$Engine$1(Engine.scala:11) at Engine$delayedInit$body.apply(Engine.scala:4) at scala.Function0.apply$mcV$sp(Function0.scala:39) at scala.Function0.apply$mcV$sp$(Function0.scala:39) at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17) at scala.App.$anonfun$main$1$adapted(App.scala:80) at scala.collection.immutable.List.foreach(List.scala:392) at scala.App.main(App.scala:80) at scala.App.main$(App.scala:78) at Engine$.main(Engine.scala:4) at Engine.main(Engine.scala) Process finished with exit code 1

下面是我的代码:

package simulations import io.gatling.core.Predef._ import io.gatling.core.scenario.Simulation import io.gatling.http.Predef._ class Load extends Simulation{ val httpProtocol = http .baseUrl("http://localhost:8080/app/") .header("Accept", "application/json") val scn = scenario("Scenario").exec(SimpleExample.simple) setUp( scn.inject(atOnceUsers(3)).protocols(httpProtocol) ) } package simulations import io.gatling.core.Predef._ import io.gatling.http.Predef._ import scala.util.Random object SimpleExample { var simple = exec(session => session .set("rndmSTR", randomString()) .set("rndmINT", randomInt()) ). exec( session => { exec(feed(Iterator.continually(Map( "game_ID" -> session("rndmINT").as[String].toInt, "game_Name" -> session("rndmSTR").as[String] )))) .exec( http("Post New Game") .post("videogames/") .body(ElFileBody("bodies/newtemplate.json")).asJson ) session } ) private def randomString() = { new Random().alphanumeric.filter(_.isLetter).take(5).mkString.toLowerCase } private def randomInt() = { new Random().nextInt(100000) } }

这是我的.json:

{ "id": "${game_ID}", "name": "${game_Name}", "releaseDate": "2020-08-11", "reviewScore": 99, "category": "Driving", "rating": "Mature" }

我知道我可以如下使用feed()方法:

package simulations import io.gatling.core.Predef._ import io.gatling.http.Predef._ import scala.util.Random object NextSimpleExample { var rndName: String = null var rndID: String = null var feeder = Iterator.continually(Map( "game_ID" -> rndID.toInt, "game_Name" -> rndName )) var simple = exec(session => session .set("rndmSTR", randomString()) .set("rndmINT", randomInt()) ). exec( session => { rndID = session("rndmINT").as[String] rndName = session("rndmSTR").as[String] session } ) .exec(feed(feeder) .exec( http("Post New Game") .post("videogames/") .body(ElFileBody("bodies/newtemplate.json")).asJson) ) private def randomString() = { new Random().alphanumeric.filter(_.isLetter).take(5).mkString.toLowerCase } private def randomInt() = { new Random().nextInt(100000) } }

但是在这种情况下,所有虚拟用户将获得相似的值...

另外,我想在下一步中使用为每个虚拟用户值生成的值。例如,在发布或放置请求的另一个正文中,在另一个.json文件中插入生成的id和名称。请帮助解决此问题。

我有以下问题。当我尝试执行模拟时,出现以下错误:生成报告...线程“ main”中的异常java.lang.UnsupportedOperationException:没有请求...

scala gatling
1个回答
0
投票
加特林DSL定义了仅创建一次的构建器,因此任何类型的参考代码,例如
© www.soinside.com 2019 - 2024. All rights reserved.