简体   繁体   English

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

[英]How to create a Random Scenario in Scala for a Gatling Simulation

I use the script below to test my server with various clients.我使用下面的脚本来测试我的服务器与各种客户端。

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)
)
}

Is there a possibility to randomize the way the use cases get runned.是否有可能随机化用例的运行方式。 so that every client picks per example 3 out of the 7 use cases randomly.以便每个客户随机选择 7 个用例中的 3 个。 would be nice to create a Practice-oriented scenario instead of simply executing all use cases in sequence.创建一个面向实践的场景而不是简单地按顺序执行所有用例会很好。

There are several tools you can use to introduce randomness in your Gatling tests, eg:您可以使用多种工具在 Gatling 测试中引入随机性,例如:

randomSwitch is probably what you want to use here. randomSwitch可能是您想在这里使用的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM