如何在Gatling中按顺序执行场景?

时间:2017-05-19 08:52:56

标签: java scala gatling scala-gatling

我有两个场景 第一个" getAssets"方案将获取所有资产ID并将其保存在列表中,第二种方案" fetchMetadata" 将迭代这些ID。

我必须执行" getAssets"方案仅一次来获取所有ID,并且" fetchMetadata"场景直到给定的持续时间仅在完成第一个场景后

如何在Chain中执行这两种方案(顺序)?

以下是代码,但它不会按顺序执行方案。

import java.util.concurrent.ThreadLocalRandom
import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.http.Predef._

class getAssetsMetadata extends Simulation {
    val getAssetURL = System.getProperty("getAssetURL", "https://performancetesting.net")
    val username = System.getProperty("username", "performanceuser")
    val password = System.getProperty("password", "performanceuser")
    val limit = Integer.getInteger("limit", 1000).toInt
    val userCount = Integer.getInteger("userCount", 100).toInt
    val duration = Integer.getInteger("duration",1).toInt //in minutes

    var IdList: Seq[String] = _   

    val httpProtocol = http
        .basicAuth(username, password)
        .baseURL(getAssetURL)
        .contentTypeHeader("""application/vnd.v1+json""")

    def getAssets = exec(http("List of Assets")
            .get(s"""/api/assets;limit=$limit""")
            .check(jsonPath("$.assets[*].id").findAll.transform {v => IdList = v; v }.saveAs("IdList"))
            )

    def fetchMetadata = exec(_.set("IdList", IdList))
        .exec(http("Metadata Request")
            .get("""/api/assets/${IdList.random()}/metadata""")
            )

    // Chain scenarios      
    var scn1 = scenario("Scenario 1")
            .exec(getAssets)
    var scn2 = scenario("Scenario 2")       
            .exec(fetchMetadata)
    setUp(scn1.inject(atOnceUsers(1)), scn2.inject(constantUsersPerSec(userCount) during(duration minutes))).protocols(httpProtocol)
    }

0 个答案:

没有答案