Home > Blockchain >  Problem with repeating Gatling scenario in kotlin language (possible problem with kotlin keyword &qu
Problem with repeating Gatling scenario in kotlin language (possible problem with kotlin keyword &qu

Time:08-07

I wrote such basic Gatling simulation in kotlin language based on web example:

import io.gatling.javaapi.core.Simulation
import io.gatling.javaapi.core.CoreDsl.exec
import io.gatling.javaapi.core.CoreDsl.scenario
import io.gatling.javaapi.http.HttpDsl.http

class SimpleScenariosSimulation : Simulation() {

    val httpProtocol = http.baseUrl("http://localhost").inferHtmlResources()
    val scn = scenario("repeat test").repeat(10)
    {
        exec(http("Home").get("/"))
    }

    init {
        setUp(
                scn.inject(rampUsers(10).during(5)).protocols(httpProtocol)
        )
    }

}

but intellij shows an error in line (repeat word is underlined)

    val scn = scenario("repeat test").repeat(10)

and shows a popup with

enter image description here

And when I add additional String argument to repeat function:

   val scn = scenario("repeat test").repeat(10, "")

Still this word is underlined with similar popup (this popup contains even already used way of function call!):

enter image description here

Is this caused because repeat is a keyword in Kotlin language?

How can I handle this situation?

BR, fotrenc

CodePudding user response:

Please check the official documentation, you'll see snippets for each of the supported programming languages in Gatling: Java, Kotlin and Scala.

In particular, in the repeat loop documentation:

repeat(5).on(
  exec(http("name").get("/"))
)

In short, you're missing the on that's required in the Java DSL.

CodePudding user response:

Thank you, It was the root cause of my error, final solution should look like:

import io.gatling.javaapi.core.CoreDsl.exec
import io.gatling.javaapi.core.CoreDsl.rampUsers
import io.gatling.javaapi.core.CoreDsl.scenario
import io.gatling.javaapi.http.HttpDsl
import io.gatling.javaapi.http.HttpDsl.http

class SimpleScenariosSimulation : Simulation() {

    val httpProtocol = http.baseUrl("http://localhost").inferHtmlResources()

    val scn = scenario("repeat test").repeat(10).on(
        exec(http("Home").get("/"))
    )

    init {
        setUp(
                scn.injectOpen(rampUsers(10).during(5)).protocols(httpProtocol)
        )
    }

}

CodePudding user response:

Finally I have such solution:


import io.gatling.javaapi.core.CoreDsl.exec
import io.gatling.javaapi.core.CoreDsl.rampUsers
import io.gatling.javaapi.core.CoreDsl.scenario
import io.gatling.javaapi.http.HttpDsl
import io.gatling.javaapi.http.HttpDsl.http



class SimpleScenariosSimulation : BaseSimulation() {

    val httpProtocol = http.baseUrl("https://edition.cnn.com")

    protected val site0 = "/world"
    protected val site1 = "/politics"
    protected val site2 = "/business"


    val scn0 = scenario("repeat test 0").repeat(10).on(
            exec (
                http(" Site 0")
                        .get(site0)
                        .check(HttpDsl.status().`is`(200))
            )
    )

    val scn1 = scenario("repeat test 1").repeat(10).on(
            exec (
                http("Site 1")
                        .get(site1)
                        .check(HttpDsl.status().`is`(200))
            )
    )

    val scn2 = scenario("repeat test 2").repeat(10).on(
            exec (
                http("Site 2")
                        .get(site2)
                        .check(HttpDsl.status().`is`(200))
            )
    )

    init {
        setUp(
                scn0.injectOpen(rampUsers(4).during(10))
                        .protocols(httpProtocol)
                        .andThen(scn1.injectOpen(rampUsers(3).during(10)).protocols(httpProtocol)    
.andThen(scn2.injectOpen(rampUsers(2).during(10)).protocols(httpProtocol))
                        )

        )
    }

}

what I want to achieve: consecutive executions of scn0, scn1, scn2 one by one ( it works )

scn0 - should be started by 4 gatling users during 10 seconds, it should send 10 times GET request to site0 = "/world".

scn1 - should be started by 3 gatling users during 10 seconds, it should send 10 times GET request to site1 = "/politics" .

scn2 - should be started by 2 gatling users during 10 seconds, it should send 10 times GET request to site2 = "/business".

Now what is observed: site0 = "/world" is requested 8 times (why not 4 x 10 or even 4) site1 = "/politics" is requested 6 times (why not 3 x 10 or even 3) site2 = "/business" is requested 4 times (why not 2 x 10 or even 2)

Gatling results:

---- Requests ------------------------------------------------------------------
> Global                                                   (OK=18     KO=0     )
>  Site 0                                                  (OK=8      KO=0     )
> Site 1                                                   (OK=6      KO=0     )
> Site 2                                                   (OK=4      KO=0     )

  • Related