-
-
Save venkata-qa/5a14a6748a3aa8425909432605dbdbad to your computer and use it in GitHub Desktop.
Gatling simulation with dynamic scenarios and injection profiles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package test | |
| import io.gatling.core.Predef._ | |
| import io.gatling.core.structure.PopulatedScenarioBuilder | |
| import io.gatling.core.controller.inject.InjectionStep | |
| import io.gatling.http.Predef._ | |
| import io.gatling.jdbc.Predef._ | |
| import scala.concurrent.duration._ | |
| import scala.collection.mutable.ArraySeq | |
| import org.json.JSONArray; | |
| import org.json.JSONObject; | |
| class CustomSimulation extends Simulation { | |
| val baseURL = "http://www.example.com" | |
| val httpConf = http.baseURL(baseURL) | |
| val rawTestList = System.getProperty("testCases") | |
| val loginScn = scenario("Login").exec(session => { | |
| println("Logging in...") | |
| session | |
| }) | |
| val registerScn = scenario("Register").exec(session => { | |
| println("Registering...") | |
| session | |
| }) | |
| val scenarioNames = Map ( | |
| "Login" -> loginScn, | |
| "Register" -> registerScn | |
| ) | |
| def scnList() : Seq[PopulatedScenarioBuilder] = { | |
| var testList = new JSONArray(rawTestList) | |
| var scnList = new ArraySeq[PopulatedScenarioBuilder](testList.length()) | |
| for(i <- 0 until testList.length()) { | |
| //For each scenario | |
| var testCase = testList.getJSONObject(i) | |
| val injectionSteps = testCase.getJSONArray("inject") | |
| var injectStepList = new ArraySeq[InjectionStep](injectionSteps.length()) | |
| for(j <- 0 until injectionSteps.length()) { | |
| //For each injection step | |
| var step = injectionSteps.getJSONObject(j) | |
| var stepType = step.getString("type") | |
| var stepArgs = step.getJSONArray("args") | |
| injectStepList(j) = stepType match { | |
| case "rampUsers" => rampUsers(stepArgs.getInt(0)) over(stepArgs.getInt(1)) | |
| case "heavisideUsers" => heavisideUsers(stepArgs.getInt(0)) over(stepArgs.getInt(1)) | |
| case "atOnceUsers" => atOnceUsers(stepArgs.getInt(0)) | |
| case "constantUsersPerSec" => constantUsersPerSec(stepArgs.getInt(0)) during(stepArgs.getInt(1)) | |
| case "rampUsersPerSec" => rampUsersPerSec(stepArgs.getInt(0)) to(stepArgs.getInt(1)) during(stepArgs.getInt(2)) | |
| case "nothingFor" => nothingFor(stepArgs.getInt(0)) | |
| } | |
| } | |
| scnList(i) = scenarioNames(testCase.getString("case")).inject(injectStepList:_*) | |
| } | |
| scnList | |
| } | |
| setUp(scnList:_*).protocols(httpConf) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package test | |
| import io.gatling.core.Predef._ | |
| import io.gatling.core.structure.PopulatedScenarioBuilder | |
| import io.gatling.core.controller.inject.InjectionStep | |
| import io.gatling.http.Predef._ | |
| import io.gatling.jdbc.Predef._ | |
| import scala.concurrent.duration._ | |
| import scala.collection.mutable.ArraySeq | |
| import org.json.JSONArray; | |
| import org.json.JSONObject; | |
| class CustomSimulation extends Simulation { | |
| val baseURL = "http://www.example.com" | |
| val httpConf = http.baseURL(baseURL) | |
| val rawTestList = System.getProperty("testCases") | |
| val loginScn = scenario("Login").exec(session => { | |
| println("Logging in...") | |
| session | |
| }) | |
| val registerScn = scenario("Register").exec(session => { | |
| println("Registering...") | |
| session | |
| }) | |
| val scenarioNames = Map ( | |
| "Login" -> loginScn, | |
| "Register" -> registerScn | |
| ) | |
| def getInjectionStep(stepType:String, stepArgs:JSONArray) : InjectionStep = { | |
| stepType match { | |
| case "rampUsers" => rampUsers(stepArgs.getInt(0)) over(stepArgs.getInt(1)) | |
| case "heavisideUsers" => heavisideUsers(stepArgs.getInt(0)) over(stepArgs.getInt(1)) | |
| case "atOnceUsers" => atOnceUsers(stepArgs.getInt(0)) | |
| case "constantUsersPerSec" => constantUsersPerSec(stepArgs.getInt(0)) during(stepArgs.getInt(1)) | |
| case "rampUsersPerSec" => rampUsersPerSec(stepArgs.getInt(0)) to(stepArgs.getInt(1)) during(stepArgs.getInt(2)) | |
| case "nothingFor" => nothingFor(stepArgs.getInt(0)) | |
| } | |
| } | |
| def scnList() : Seq[PopulatedScenarioBuilder] = { | |
| var testList = new JSONArray(rawTestList) | |
| var scnList = new ArraySeq[PopulatedScenarioBuilder](testList.length()) | |
| for(i <- 0 until testList.length()) { | |
| //For each scenario | |
| var testCase = testList.getJSONObject(i) | |
| val injectionSteps = testCase.getJSONArray("inject") | |
| var injectStepList = new ArraySeq[InjectionStep](injectionSteps.length()) | |
| for(j <- 0 until injectionSteps.length()) { | |
| //For each injection step | |
| var step = injectionSteps.getJSONObject(j) | |
| var stepType = step.getString("type") | |
| var stepArgs = step.getJSONArray("args") | |
| injectStepList(j) = getInjectionStep(stepType, stepArgs) | |
| } | |
| scnList(i) = scenarioNames(testCase.getString("case")).inject(injectStepList:_*) | |
| } | |
| scnList | |
| } | |
| setUp(scnList:_*).protocols(httpConf) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment