1
votes

I want to setup Gatling so that in one setup, I can send 3000 requests, of which 95% will use one test file, and 5% another test file. These files are retrieved as json files (called 'userFeeder' in below code. Can Gatling support the above scenario?

The code is currently as follows, which works for a request per second approach, but needs amending.

class AddUserSimulation extends Simulation {

  private val conf = ConfigFactory.load() //loads a setup file of parameters
  private val TOKEN_VALUE = "tokenvalue"
  private val userFeeder =  jsonFile("/" + conf.getString("environment") + "/testaddUser.json")

  val httpConf = http
    .baseURL(conf.getString("api.gateway.url")) // Here is the root for all relative URLs
    .header("Referer", conf.getString("referer"))
    .header("Cache-Control", "no-cache")
    .contentTypeHeader("application/json")

  val Login = new ADFSAuthentication Login

  val scnAPI = scenario("test add User") // A scenario is a chain of requests and pauses
    .feed(userFeeder.circular)
    .exec(Login.process)
    .repeat(conf.getInt("repeat.count")) {
        exec(http("test add User")
        .post("/" + conf.getString("environment") + "/users/")
        .body(StringBody("${payload}")).asJSON
        .header("Authorization", "Bearer ${"+TOKEN_VALUE+"}")
    .check(status.is(200)))
    .pause(conf.getInt("execution.pause"))
    }
  setUp(scnAPI.inject(constantUsersPerSec(11) during(30 minutes)).protocols(httpConf)) 
}

Any help is greatly appreciated.

1

1 Answers

0
votes

Sure! First set up your two feeders. Then set up two scenarios, one using the first feeder, one using the second feeder. Finally setUp both with the number of users you wish (corresponding to your distribution).

The code could look something like this:

private val firstFeeder =  jsonFile("/" + conf.getString("environment") + "/testaddUser.json")
private val secondFeeder =  jsonFile("/" + conf.getString("environment") + "/testaddUser2.json")

val scnAPI = scenario("test add User")
    .feed(firstFeeder)
    //...

val scnAPI2 = scenario("second test add User")
    .feed(secondFeeder)
    //...

setUp(scnAPI.inject(constantUsersPerSec(95) during(30 minutes)).protocols(httpConf), 
      scnAPI2.inject(constantUsersPerSec(5) during(30 minutes)).protocols(httpConf)) 

Note: This will not create exactly 3000 requests but I think you get the idea.