Search code examples
kotlingatling

How to use gatling with Kotlin?


I am using Gatling for performance testing. I have one simulation as below:

private val httpProtocol = http
    .baseUrl(apiGatewayUrl)
    .acceptHeader("application/json")
    .header("A", "foo")
    .header("B", "bar")
    .header("C", "3")

private val success = scenario("successful scenario")
    .exec(http("collector")
        .post("/v1/events")
        .body(StringBody("""
            {
             body
        """.trimIndent())))

init {
    setUp(
       success.injectOpen(constantUsersPerSec(5.0).during(5),
           rampUsers(10).during(10),
           constantUsersPerSec(10.0).during(20)
       )
    ).protocols()
}

This code gived me compilation error:

Type mismatch. Required: List<io.gatling.core.structure.PopulationBuilder!>! Found: io.gatling.javaapi.core.PopulationBuilder

I was reading gatling docs and the examples seems to do in a similar way as above.


Solution

  • The piece of code you've provided is correct. I've injected it in the official Gatling demo project for gradle+kotlin and it works fine (except for the missing apiGatewayUrl definition).

    Possible explanation:

    • wrong gradle project configuration
    • wrong imports (missing from your sample)