英文:
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("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.
答案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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论