Run multiple scenarios based on a condition

5,771 views
Skip to first unread message

Daniel Ortiz

unread,
Mar 11, 2014, 4:56:27 PM3/11/14
to gat...@googlegroups.com
Hello All, I'm starting using Gatling as well as Scala. I have a project running multiple scenarios and it is working fine, now the requirement extended to run only the passed scenarios via command prompt. By now my working file is:
 
 

class SimulationAllScenarios extends Simulation {
var conf = ConfigFactory.load()
var environment: String = System.getProperty("env")
environment = environment.toLowerCase()
var baseUrl = conf.getString(environment.concat(".baseUrl"))

var scenarioConf = ConfigFactory.load("scenarioProperties.conf")

val httpsProtocol = http.baseURL(baseUrl).disableFollowRedirect

setUp(PageOneScenario.scn.inject(ramp(scenarioConf.getInt("PageOne.Users")) over (scenarioConf.getInt("PageOne.RampUpTime"))),
              PageTwoScenario.scn.inject(ramp(scenarioConf.getInt("PageTwo.Users")) over (scenarioConf.getInt("PageTwo.RampUpTime")))
              PageThreeScenario.scn.inject(ramp(scenarioConf.getInt("PageThree.Users")) over (scenarioConf.getInt("PageThree.RampUpTime")))
)
.protocols(httpsProtocol)
}

Now I want to modify the class to run optionally the scenarios depending on the system property variable, for example
mvn clean install -Denv=QA -Dscenario=PageTwo,PageThree
This command should run only the scenario two. I know that I can run another simulation but I have 18 different scenarios and most of the times I will run the 18 scenarios, but sometimes I have to run 5 or 6 scenarios at the same time.

Is this possibly or I'm dreaming? I saw that setUp parameters are scenario: ProfiledScenarioBuilder, scenarios: ProfiledScenarioBuilder* so the second parameter is like an Array in Java? because I tried to pass an array and it's not working. in Java we have the ... so I thought it was the same.

Thank you in advance

Stéphane Landelle

unread,
Mar 11, 2014, 5:31:08 PM3/11/14
to gat...@googlegroups.com
ProfiledScenarios are not run sequentially, but concurrently. It's the way to have different populations with different behaviors inside the same simulation.
Would that meet your needs?


--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daniel Ortiz

unread,
Mar 11, 2014, 5:58:40 PM3/11/14
to gat...@googlegroups.com
Yes I know they run concurrently and that is fine, something I need in pseudocode:
mvn clean install -Denv=QA -Dscenario=PageTwo,PageThree

Simulation class:
read properties for env
create scenarios based on the scenario system property
setUp(with the created scenarios) This will run such scenarios concurrently
done

Daniel Ortiz

unread,
Mar 11, 2014, 6:53:34 PM3/11/14
to gat...@googlegroups.com
I found what I need, I will create an Array with the selected scenarios and pass to the setUp function with the _* operator

Thank you for  the support

Stéphane Landelle

unread,
Mar 11, 2014, 8:28:10 PM3/11/14
to gat...@googlegroups.com
Exactly, I was about to reply.

You're a quick learner  :)
Have fun!

Vu Nguyen

unread,
Jun 24, 2014, 8:49:07 PM6/24/14
to gat...@googlegroups.com

Hi Stephane,

I'm a beginner at both Scala and Gatling.  I'm currently using Gatling 2.0.0-M3a, and I'm very interested in the approach of passing test case as a command line parameter as suggested by Daniel Ortiz.  Based on the instructions provided in this thread, I made an attempt to use the splat operator (provided below), but got stuck at the compiler error, even after some googling.

Could you please provide some guidance?

Thank you much.

Vu
---


class userSimulation extends Simulation {

     def getOption(a:String,b:String):String = { Option(System.getProperty(a)).getOrElse(b) }

     val server = getOption("server","default")
     val tests = getOption("tests","default")
     val users = getOption("users","default").toInt
     val time = getOption("time","default").toInt

     val httpScenarios = Map (
          "testOne" -> List(
                                   scn1.inject(ramp(users user) over(time seconds))
                             ),
          "testTwo"   -> List(
                                     scn2.inject(ramp(users user) over(time seconds)),
                                     scn3.inject(ramp(users user) over(time seconds))
                             )
     )

     val httpProtocol = http
          .baseURL(server)
          .disableFollowRedirect

     setUp(httpScenarios(tests):_*).protocols(httpProtocol)

}

---

$ JAVA_OPTS='-Dserver=https://server.com -Dtest=testOne -Dusers=100 -Dtime=100' ${GATLING_HOME}/bin/gatling.sh -s userSimulation

no `: _*' annotation allowed here
(such annotations are only allowed in arguments to *-parameters)

Stéphane Landelle

unread,
Jun 25, 2014, 9:34:36 AM6/25/14
to gat...@googlegroups.com
setUp signature was too strict in 2M3 and wouldn't allow you to do that directly (so we changed it in upcoming version).

use:

val scns = httpScenarios(tests)

setUp(scns.head, scns.tail:_*).protocols(httpProtocol


--

Vu Nguyen

unread,
Jun 27, 2014, 1:35:14 AM6/27/14
to gat...@googlegroups.com

I'd never thought of such solution.

Thank you very much, Stephane for your help.

Vu
---

CyberNinja

unread,
Aug 25, 2016, 2:07:38 AM8/25/16
to Gatling User Group
Hi Stephen,

I am trying to create a scenario with step up load. I created a map to contain my steps. However, I am getting the "no :_* annotation allowed here" error. Can you advise how to apply your solution in this case?

val Params = 1 to pNumSteps map { i => 
workload(pPacing, (pNumSteps - i + 3) * (pRampTime+pStepTime))
 .inject(
nothingFor((i-1) * (pRampTime+pStepTime) seconds),
rampUsers(pVusers) over (pRampTime seconds),
nothingFor(pStepTime seconds))
}
setUp(scenario("Nothing").inject(nothingFor(1 seconds)),
Params:_*)
.protocols(httpProtocol)
.maxDuration(pTestDuration seconds)

Stéphane LANDELLE

unread,
Aug 25, 2016, 6:14:38 AM8/25/16
to gat...@googlegroups.com
This answer was for an older Gatling version. setUp now takes only one parameter: either an `Iterable` or a varargs. Concatenate your first nothingFor and your Params into one single Iterable.

Stéphane Landelle
GatlingCorp CEO


To unsubscribe from this group and stop receiving emails from it, send an email to gatling+unsubscribe@googlegroups.com.

CyberNinja

unread,
Aug 25, 2016, 6:37:26 AM8/25/16
to Gatling User Group
Thanks Stephane.

I have got rid of the nothingFor and it works. Will do the concatenation now.

setUp(ionStepParams:_*)

Thanks for your quick response as always.

CyberNinja

unread,
Aug 25, 2016, 7:07:43 AM8/25/16
to Gatling User Group
So this doesn't work?

setUp(ionStepParams:_*, pomStepParams:_*)

both args have step up load in it. I want to run the steps of both in parallel.

Stéphane LANDELLE

unread,
Aug 25, 2016, 7:14:30 AM8/25/16
to gat...@googlegroups.com

This answer was for an older Gatling version. setUp now takes only one parameter: either an `Iterable` or a varargs. Concatenate your first nothingFor and your Params into one single Iterable.

Sorry, I meant "inject" here.

CyberNinja

unread,
Aug 25, 2016, 7:23:23 AM8/25/16
to Gatling User Group
Sorry, I am still bit confused. An example would be easier to understand? May be if you can modify the one I sent, would be great.

Stéphane LANDELLE

unread,
Aug 25, 2016, 8:45:38 AM8/25/16
to gat...@googlegroups.com

Stéphane Landelle
GatlingCorp CEO


--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+unsubscribe@googlegroups.com.

CyberNinja

unread,
Aug 26, 2016, 1:22:39 AM8/26/16
to Gatling User Group
 
 .inject(
 nothingFor
((i-1) * (pRampTime+pStepTime) seconds),
 rampUsers
(pVusers) over (pRampTime seconds),
 nothingFor
(pStepTime seconds))

and passing multiple such 'inject' to setUp using

setUp(ionStepParams:_*, pomStepParams:_*)

So if setUp(ionStepParams:_*) works, the above should also work.

To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.

Vu Nguyen

unread,
Aug 26, 2016, 8:20:48 PM8/26/16
to Gatling User Group
setUp(ionStepParams:_*, pomStepParams:_*)

So if setUp(ionStepParams:_*) works, the above should also work.

Should not

1. You're passing TWO varargs to setUp.  According to Stephane (and codes), setUp now takes only ONE parameter: either an `Iterable` or a varargs

2. A method has a field that can contain a variable number of arguments, the varargs field must be the last field in the method signature.

CyberNinja

unread,
Aug 26, 2016, 11:12:27 PM8/26/16
to Gatling User Group
Ok its clear now. My exposure to scala is only as much as my exposure to Gatling :)
Having multiple varargs would be good have. I am not sure whether the simulation setUp I have is common or not. I am clueless to implement it any other way.

Thanks for the second link. That cleared the my doubts. Have a good day.

CyberNinja

unread,
Aug 30, 2016, 6:12:46 AM8/30/16
to Gatling User Group
 >     Having multiple varargs would be good have. I am not sure whether the simulation setUp I have is common or not. I am clueless to implement it any other way.

I have to take this statement back. I was able to create a single varargs to cater for my both scenarios. :-). Simpler than I thought.

var j = 0
var k = 0
val Params = 1 to pNumSteps map { i => {
if(i%2==0){
k = k + 1
workloadType1(k, pPacing, ((pNumSteps - k + 3) * (pRampTime+pStepTime)))
 .inject(
nothingFor((k-1) * (pRampTime+pStepTime) seconds),
rampUsers(pVusers) over (pRampTime seconds),
nothingFor(pStepTime seconds))
}
else {
j = j + 1
workloadType2(j, pPacing, ((pNumSteps - j + 3) * (pRampTime+pStepTime)))
 .inject(
nothingFor((j-1) * (pRampTime+pStepTime) seconds),
rampUsers(pVusers) over (pRampTime seconds),
nothingFor(pStepTime seconds))
}
}
}
Reply all
Reply to author
Forward
0 new messages