Search code examples
scalagatling

Cannot resolve overloaded method 'exec'


I am new to Gatling with Scala, i have created a simple chaining of scenarios and while compiling the below code in Intellij, i am facing the error "Cannot resolve overloaded method 'exec'". I have set up my project using sbt and added gatling plugin. The error are coming for val scenario1, scenario2, scenario3

package gatlingAssignment

import io.gatling.core.Predef._
import io.gatling.core.structure.ScenarioBuilder
import io.gatling.http.Predef._
import io.gatling.http.request.builder.HttpRequestBuilder

import scala.concurrent.duration._

class GetUsers extends Simulation {

  val baseUrl = "https://reqres.in/api"

  object HttpRequests {
    val baseUrl = "https://reqres.in/api"

    val createUserInfo: HttpRequestBuilder = http("Create user info")
      .post(baseUrl + "/users")
      .body(
        StringBody(
          """{ "name": "${name}", "job": "${job}", "id": "${id}" }"""
        )
      )
      .asJson
      .header("content-type", "application/json")
      .check(status is 201)

    val getUsers: HttpRequestBuilder = http("Get all users")
      .get(baseUrl + "/users")
      .queryParam("page", "2")
      .check(status is 200)

    val updateUserInfo: HttpRequestBuilder = http("Update user info")
      .put(baseUrl + "/users/2")
      .body(
        StringBody(
          """{ "name": "${name}", "job": "${job}", "id": "${id}" }"""
        )
      )
      .asJson
      .header("content-type", "application/json")
      .check(status is 200)
  }

  object Scenarios {

    import HttpRequests._

    val feeder = csv("src/user_data.csv").random

    val userScenario: ScenarioBuilder = scenario("User scenario")
      .feed(feeder)
      .exec(createUserInfo)
      .exec(getUsers)
      .exec(updateUserInfo)

    val scenario1: ScenarioBuilder = scenario("Scenario 1")
      .exec(userScenario.inject(atOnceUsers(50)))

    val scenario2: ScenarioBuilder = scenario("Scenario 2")
      .exec(userScenario.inject(constantUsersPerSec(20) during (15 seconds)))

    val scenario3: ScenarioBuilder = scenario("Scenario 3")
      .exec(userScenario.inject(rampUsersPerSec(1) to 100 during (30 seconds)))

    val chainedScenario: ScenarioBuilder = scenario("Chained scenario")
      .exec(scenario1)
      .exec(scenario2)
      .exec(scenario3)
  }

  object LoadTest {

    import Scenarios._

    setUp(
      chainedScenario.inject(nothingFor(5 seconds))
    ).assertions(
      global.responseTime.max.lt(4000)
    ).maxDuration(1 minute)
  }

}

I am having a hard time in compiling the above code, had refer the gatling documentation but was of no avail.


Solution

  • val scenario1: ScenarioBuilder = scenario("Scenario 1")
          .exec(userScenario.inject(atOnceUsers(50)))
    

    There's nothing of the sort anywhere in the exec documentation that could make think that it can accept a PopulationBuilder (the return type of inject).

    Also, setUp must be called directly inside your Simulation class.

    I guess what you're trying to do is actually:

      setUp(
        userScenario.inject(
          nothingFor(5.seconds),
          atOnceUsers(50),
          constantUsersPerSec(20).during(15.seconds),
          rampUsersPerSec(1).to(100).during(30.seconds)
        )
      )