java - 如何在 Gatling 脚本中添加 Status = KO?

标签 java scala performance-testing load-testing gatling

我的请求有可能失败吗? 我想将 Status = KO 放在 asLongAs() 部分。我的条件是,如果我得到 WorkflowFailed = TrueCount > 8 那么我想使用 Status = KO 使该请求失败。

我在某处看到过有关 session.markAsFailed 的内容,但如何以及在何处使用它?

谢谢。

这是代码,

class LaunchResources extends Simulation {

    val scenarioRepeatCount = Integer.getInteger("scenarioRepeatCount", 1).toInt
    val userCount = Integer.getInteger("userCount", 1).toInt
    val UUID  = System.getProperty("UUID", "24d0e03")
    val username = System.getProperty("username", "p1")
    val password = System.getProperty("password", "P12")
    val testServerUrl = System.getProperty("testServerUrl", "https://someurl.net")
    val count = new java.util.concurrent.atomic.AtomicInteger(0)

    val httpProtocol = http
        .baseURL(testServerUrl)
        .basicAuth(username, password)
        .connection("""keep-alive""")
        .contentTypeHeader("""application/vnd+json""")


    val headers_0 = Map(
        """Cache-Control""" -> """no-cache""",
        """Origin""" -> """chrome-extension://fdmmgasdw1dojojpjoooidkmcomcm""")


    val scn = scenario("LaunchAction")
        .repeat (scenarioRepeatCount) {
            exec(http("LaunchAResources")
                .post( """/api/actions""")
                .headers(headers_0)
                .body(StringBody(s"""{"UUID": "$UUID", "stringVariables" : {"externalFilePath" : "/Test.mp4"}}"""))
                .check(jsonPath("$.id").saveAs("WorkflowID")))

        .exec(http("SaveWorkflowStatus")
                .get("""/api/actions/{$WorkflowID}""")
                .headers(headers_0)
                .check(jsonPath("$.status").saveAs("WorkflowStatus")))

        }


     .asLongAs(session => session.attributes("WorkflowStatus") != "false" && count.getAndIncrement() < 8) {
        doIf(session => session("WorkflowFailed").validate[String].map(WorkflowFailed => !WorkflowFailed.contains("true")).recover(true)) 
        {
        pause(pauseTime)
        .exec(http("SaveWorkflowStatus")
                .get("""/api/actions/${WorkflowID}""")
                .headers(headers_0)
                .check(jsonPath("$.running").saveAs("WorkflowStatus"))
                .check(jsonPath("$.failed").saveAs("WorkflowFailed")))

        .exec(session => {
                val wflowStatus1 = session.get("WorkflowStatus").asOption[String]
                val wflowFailed1 = session.get("WorkflowFailed").asOption[String]
                println("Inner Loop Workflow Status: ========>>>>>>>> " + wflowStatus1.getOrElse("COULD NOT FIND STATUS"))
                println("Inner Loop Workflow Failed?? ========>>>>>>>> " + wflowFailed1.getOrElse("COULD NOT FIND STATUS"))
                println("Count =====>> " + count)
                session}) 

        }
        }   

    setUp(scn.inject(atOnceUsers(userCount))).protocols(httpProtocol)
}

最佳答案

session 中有可用的方法

exec(session => session.markAsFailed)

关于java - 如何在 Gatling 脚本中添加 Status = KO?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39991234/

相关文章:

caching - 关闭负载测试的缓存?

node.js - Jmeter Web应用性能测试疑惑?

api - Jmeter 性能测试 - 使用 JSR223 采样器从 API 和从 MongoDB 获得的结果计数差异

java - Spark 和 Google Cloud Firestore 与 SBT 的依赖性问题

java - 如何在调用者的某些条件下更新 Thread 类中变量的值

java - 如何禁用 Wildfly 10 中的计时器服务?

scala - Scala RDD 不协变的解决方法

java - 对象toString方法和里氏替换原则

scala - 无法获得 spray-json 依赖项以在游戏项目中工作

scala - 在 Spark 中导入 parquet 文件时出现内存问题