Scala 我如何在Gatling的http请求上获得随机URL?
我想得到一个关于Gatling http请求的随机URL 我的场景定义如下:Scala 我如何在Gatling的http请求上获得随机URL?,scala,http,random,request,gatling,Scala,Http,Random,Request,Gatling,我想得到一个关于Gatling http请求的随机URL 我的场景定义如下: import io.gatling.core.Predef._ import io.gatling.http.Predef._ import scala.concurrent.duration._ import scala.util.Random class testSimulation extends Simulation { val httpConf = http.baseURL("OURURL")
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
import scala.util.Random
class testSimulation extends Simulation {
val httpConf = http.baseURL("OURURL")
val scn = scenario("View HomePages")
.exec(
http("Home page")
.get("/" + new Random().nextInt())
.resources(
http("genericons.css").get("/wp-content/themes/twentyfifteen/genericons/generi$
http("style.css").get("/wp-content/themes/twentyfifteen/style.css?ver=4.2.3"),
http("jquery.js").get("/wp-includes/js/jquery/jquery.js?ver=1.11.2"),
http("jquery-migrate.min.js").get("/wp-includes/js/jquery/jquery-migrate.min.j$
http("skip-link-focus-fix.js").get("/wp-content/themes/twentyfifteen/js/skip-l$
http("functions.js").get("/wp-content/themes/twentyfifteen/js/functions.js?ver$
http("wp-emoji-release.min.js").get("/wp-includes/js/wp-emoji-release.min.js?v$
http("wp-emoji-release.min.js").get("/wp-includes/js/wp-emoji-release.min.js?v$
http("skip-link-focus-fix.js").get("/wp-content/themes/twentyfifteen/js/skip-l$
http("functions.js").get("/wp-content/themes/twentyfifteen/js/functions.js?ver$
)
)
setUp(
scn.inject
(
rampUsersPerSec(1) to(300) during(60 seconds),
constantUsersPerSec(300) during(600 seconds)
)
.protocols(httpConf)
)
}
我只生成了一个随机数,而不是每个请求生成一个随机数。你知道怎么解决吗?谢谢 您正在传递一个值,因此当然
new Random().nextInt
在构建模拟时只被调用一次
你必须传递一个函数。只有这样,每次都会对其进行评估
.get(session => "/" + new Random().nextInt())
我对加特林不熟悉。仅查看scala,它会显示参数,包括对
scenario.exec
的Random.nextInt调用,会立即在val行上执行。让随机化器被多次调用的通常方法是将其放入一个执行多次的函数中,这反过来可能取决于scenario.exec()
是否可以将函数作为参数,或者您是否可以以适合您的用例的适当方式扩展它作为参数的类。