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) }