如何在Scala中为门控模拟创建随机场景



我使用下面的脚本在各种客户端上测试我的服务器。

package test
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
class Lasttest_ThinClient extends Simulation {
val httpProtocol = http
.baseUrl("http://localhost:8080")
.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
.doNotTrackHeader("1")
.acceptLanguageHeader("en-US,en;q=0.5")
.acceptEncodingHeader("gzip, deflate")
.userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0")
val scn = scenario("Lasttest: Thin Client (X Clients)")
.exec(
http("UC-0")
.get("/movingAverage/50/abbn")
)
.pause(1,3)
.exec(
http("UC-1")
.get("/getBestValue")
.queryParam("min", "2")
.queryParam("max", "250")
.queryParam("name", "abbn")
)
.pause(1,3)
.exec(
http("UC-2")
.get("/getBestValueOneYear")
.queryParam("min", "2")
.queryParam("max", "250")
.queryParam("name", "abbn")
)
.pause(1,3)
.exec(
http("UC-3")
.get("/bestSimpleAveragePortfolio")
)
.pause(1,3)
.exec(
http("UC-5")
.get("/buyHoldPortfolio")
)
.pause(1,3)
.exec(
http("UC-6")
.get("/getBestStrategy")
)
.pause(1,3)
.exec(
http("UC-7")
.get("/getBestStrategyOneYear")
)
setUp(
scn.inject(
atOnceUsers(3),
).protocols(httpProtocol)
)
}

是否存在随机化用例运行方式的可能性。使得每个客户端在7个用例中随机地从每个示例中选择3个用例。最好创建一个面向实践的场景,而不是简单地按顺序执行所有用例。

有几种工具可以用来在Gatling测试中引入随机性,例如:

  • 随机馈线
  • randomSwitch
  • 捕获随机数据的随机检查

randomSwitch可能是您想要在此处使用的。

最新更新