lundi 3 octobre 2016

Put condition in HTTP request using gatling

I want to add condition on http request. like this scenario, using API,

  1. I have one action from where I find 'Action ID'

  2. Using that 'Action Id' I check the status of that action which is 'Running/waiting/completed/etc' and save it in variable

I did this this two steps, Now I want to do

3. I have to check status on condition every 20 minutes if status is 'Running', re-check status every 20 minutes if status = 'completed' then exit oR exit after 2 Hours automatically (evenif status is in running state)

below is the code snippet what I did,

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._

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 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(session => {
                val wflowid = session.get("WorkflowID").asOption[String]
                println("Workflow ID: ========>>>>>>>> " + wflowid.getOrElse("COULD NOT FIND ID"))
                session})

        .exec(http("SaveWorkflowStatus")
                .post("""/api/actions/{$wflowid}""")
                .headers(headers_0)
                .body(StringBody(s"""{"UUID": "$UUID", "stringVariables" : {"externalFilePath" : "/Test.mp4"}}"""))
                .check(jsonPath("$.status").saveAs("WorkflowStatus")))

        .exec(session => {
                val wflowStatus = session.get("WorkflowStatus").asOption[String]
                println("Workflow Status: ========>>>>>>>> " + wflowStatus.getOrElse("COULD NOT FIND STATUS"))
                session})

        }


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

Please help. Thanks

Aucun commentaire:

Enregistrer un commentaire