如何在Kotlin中使用Gatling?

huangapple go评论63阅读模式
英文:

How to use gatling with Kotlin?

问题

这段代码使用 Gatling 进行性能测试。您提到代码中出现了编译错误,错误信息是 "Type mismatch",要求的类型是 "List<io.gatling.core.structure.PopulationBuilder!>",但找到的类型是 "io.gatling.javaapi.core.PopulationBuilder"。您说您在阅读 Gatling 文档时看到示例似乎与上面的代码类似。

英文:

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

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

private val success = scenario(&quot;successful scenario&quot;)
    .exec(http(&quot;collector&quot;)
        .post(&quot;/v1/events&quot;)
        .body(StringBody(&quot;&quot;&quot;
            {
             body
        &quot;&quot;&quot;.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.

答案1

得分: 1

以下是翻译好的部分:

提供的代码部分是正确的。我已将其注入到官方的 Gatling 演示项目中,使用 gradle+kotlin,它运行良好(除了缺少的 apiGatewayUrl 定义)。

可能的解释:

  • 错误的 Gradle 项目配置
  • 错误的导入(在您的示例中缺失)
英文:

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)

huangapple
  • 本文由 发表于 2023年6月6日 01:24:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76408723.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定