Pass an array/list/set of injection profiles to setUp?

Right now, I know I can do something like this:

`
class Foo extends Simulation {
setUp( a, b, c )
}

`

Where ‘a’, ‘b’, and ‘c’ are scenarios and injection profiles. But can I do something like this (think of this as pseudo-code)

`
class Bar extends Simulation {
val list = []
list.push( a )
list.push( b )
list.push( c )
setUp( list )
}

`

Thanks!

Yes. setUp can take an array/vararg or a List: https://github.com/gatling/gatling/blob/master/gatling-core/src/main/scala/io/gatling/core/scenario/Simulation.scala#L44-L46

Perfect. That’s what I needed, the type of variable to declare it as. Thank you!

Would you mind sharing a final implementation of how to use the setUp method with a list as input?
I am doing something similar but get a compilation error when I try to use a List of type PopulationBuilder.

My code looks roughly like this:
class MySimulation extends Simulation {

// httpConf definition with baseURL, headers, etc

// helper methods and values to drive selection logic

// discrete object definitions (each object contains a certain type of re-usable request)

/* example object

object Scenario1 {

val scenario1 = exec( http(“request_3”)
.get(“/computers/6”))
.pause(3)
.exec(http(“request_4”)
.get(“/”))
.pause(2)
}

*/

// group scenarios into formal Scenario groups/collections
val scnReads = scenario(“Reads”).exec( Scenario1.scenario1, Scenario2.scenario2 )
val scnWrites = scenario(“Writes”).exec( Scenario.scenario3 )
val scnMixed = scenario(“Mixed”).exec( Scenario1.scenario1, Scenario2.scenario2, Scenario3.scenario3 )

// function

// purpose = create a list of scenarios to be consumed by the setUp method

def buildLlist() : List[PopulationBuilder] = {
val list = List()
if (// doing writes only) {
// create list with Posts only
}
else if ( // doing reads only) {
// create list with Gets only
}
else {
// create list with Gets and Posts
}
return final list
}

setUp( buildList().inject( atOnceUsers(10)))
.protocols( httpConf )

}

When I run my code, I get an error like this>
`

16:47:09.336 [ERROR] i.g.c.ZincCompiler$ - /Users/infomaven/volumes/libraries/Gatling/gatling-charts-highcharts-bundle-2.1.4/user-files/simulations/Simulation.scala:183: not found: type PopuationBuilder

16:47:09.337 [ERROR] i.g.c.ZincCompiler$ - def buildList() : List[PopuationBuilder] = {

16:47:09.338 [ERROR] i.g.c.ZincCompiler$ - ^

16:47:09.420 [ERROR] i.g.c.ZincCompiler$ - one error found
16:47:09.421 [DEBUG] i.g.c.ZincCompiler$ - Compilation failed (CompilerInterface)
`

You have a typo.
Then, you also need to import the class.

Typo is fixed (missing "l" in PopulationBuilder class. I also enabled the import statement (it had been commented out).

However I’m still getting a compile error regarding this class. Has the syntax changed for Gatling 2.1.5?

error looks like this>

GATLING_HOME is set to /Users/infomaven/Volumes/secondary/libs/gatling/gatling-charts-highcharts-bundle-2.1.5
00:28:21.166 [ERROR] i.g.c.ZincCompiler$ - /Users/nwhit8/Volumes/secondary/libs/gatling/gatling-charts-highcharts-bundle-2.1.5/user-files/simulations/Gatling_WorkloadPicker.scala:5: object PopulationBuilder is not a member of package io.gatling.core.structure
00:28:21.168 [ERROR] i.g.c.ZincCompiler$ - import io.gatling.core.structure.PopulationBuilder
00:28:21.169 [ERROR] i.g.c.ZincCompiler$ - ^
00:28:22.683 [ERROR] i.g.c.ZincCompiler$ - /Users/infomaven/Volumes/secondary/libs/gatling/gatling-charts-highcharts-bundle-2.1.5/user-files/simulations/Gatling_WorkloadPicker.scala:92: not found: type PopulationBuilder
00:28:22.683 [ERROR] i.g.c.ZincCompiler$ - def buildList() : List[PopulationBuilder] = {
00:28:22.683 [ERROR] i.g.c.ZincCompiler$ - ^
00:28:22.825 [ERROR] i.g.c.ZincCompiler$ - two errors found

https://github.com/gatling/gatling/blob/2.1.X/gatling-core/src/main/scala/io/gatling/core/structure/ScenarioBuilder.scala#L54

This class has been renamed to PopulationBuilder in Gatling 2.2, but in Gatling 2.1.X, it’s named PopulatedScenarioBuilder.

But then, as this type is only used for a return type, you could omit it and let type inference do the job.

Mystery solved! Thanks.

I like this approach. It helped me simplify my code. Thank you.

I got it working in a Gist and am quite pleased with the results.