Scala动态场景
Scala dynamic scenario
有没有办法创建像这样的动态场景?下面的代码给出错误未找到:类型 scenario def my_test() : scenario = {.我认为方案不需要导入
def my_test() : scenario = {
if(condition)
scenario(build_name)
.exec(http("post"+build_name+"content")
.post(end_point_url)
.header("Authorization", "Bearer "+ token)
.body(RawFileBody(input_file_path)).asXml
.check(status is 200))
else
scenario(build_name)
.exec(http("post"+build_name+"content")
.post(end_point_url)
.header("Authorization", "Bearer "+ token)
.body(RawFileBody(input_file_path)).asJson
.check(status is 200))
}
setUp(my_test()
.inject(
nothingFor(2 seconds),
constantUsersPerSec(users).during(10 seconds)
))
.assertions(
global.responseTime.mean.lt(threshold = mean_response_time),
global.successfulRequests.percent.gte(minSuccessPercent)
)
.protocols(httpConf)
.assertions(
forAll.responseTime.max.lt(threshold = responseTime)
)
编辑
当我尝试
def my_test() = {
if(condition)
scenario(build_name)
.exec(http("post"+build_name+"content")
.post(end_point_url)
.header("Authorization", "Bearer "+ token)
.body(RawFileBody(input_file_path)).asXml
.check(status is 200))
else
scenario(build_name)
.exec(http("post"+build_name+"content")
.post(end_point_url)
.header("Authorization", "Bearer "+ token)
.body(RawFileBody(input_file_path)).asJson
.check(status is 200))
}
出现以下错误
17:10:01.582 [main][ERROR][ZincCompiler.scala:151] i.g.c.ZincCompiler$
- ... .scala:132:2: method my_test has return statement; needs result type
return scenario(build_name)
^ 17:10:01.645 [main][ERROR][ZincCompiler.scala:122] i.g.c.ZincCompiler$ - one error found 17:10:01.648 [main][ERROR][ZincCompiler.scala:219] i.g.c.ZincCompiler$ - Compilation crashed sbt.internal.inc.CompileFailed: null
at sbt.internal.inc.AnalyzingCompiler.call(AnalyzingCompiler.scala:242)
编辑
感谢为此做出贡献的所有人post。我必须使用导入语句 io.gatling.core.structure.{PopulationBuilder, ScenarioBuilder} 将场景修改为 ScenarioBuilder,如前所述
正如编译器所说,scenario
是未知的(顺便说一下,它实际上不是 Gatling 类型)而且它不是 return 由您的方法编辑的类型。
您可以删除 return 类型并让编译器为您推断它,或者编写正确的 return 类型。
编辑:Gatling 使用的 Zinc 编译器需要明确的 return 类型,因此您必须找到正确的类型(可能是 ScenarioBuilder
)。
有没有办法创建像这样的动态场景?下面的代码给出错误未找到:类型 scenario def my_test() : scenario = {.我认为方案不需要导入
def my_test() : scenario = {
if(condition)
scenario(build_name)
.exec(http("post"+build_name+"content")
.post(end_point_url)
.header("Authorization", "Bearer "+ token)
.body(RawFileBody(input_file_path)).asXml
.check(status is 200))
else
scenario(build_name)
.exec(http("post"+build_name+"content")
.post(end_point_url)
.header("Authorization", "Bearer "+ token)
.body(RawFileBody(input_file_path)).asJson
.check(status is 200))
}
setUp(my_test()
.inject(
nothingFor(2 seconds),
constantUsersPerSec(users).during(10 seconds)
))
.assertions(
global.responseTime.mean.lt(threshold = mean_response_time),
global.successfulRequests.percent.gte(minSuccessPercent)
)
.protocols(httpConf)
.assertions(
forAll.responseTime.max.lt(threshold = responseTime)
)
编辑 当我尝试
def my_test() = {
if(condition)
scenario(build_name)
.exec(http("post"+build_name+"content")
.post(end_point_url)
.header("Authorization", "Bearer "+ token)
.body(RawFileBody(input_file_path)).asXml
.check(status is 200))
else
scenario(build_name)
.exec(http("post"+build_name+"content")
.post(end_point_url)
.header("Authorization", "Bearer "+ token)
.body(RawFileBody(input_file_path)).asJson
.check(status is 200))
}
出现以下错误
17:10:01.582 [main][ERROR][ZincCompiler.scala:151] i.g.c.ZincCompiler$
- ... .scala:132:2: method my_test has return statement; needs result type
return scenario(build_name)
^ 17:10:01.645 [main][ERROR][ZincCompiler.scala:122] i.g.c.ZincCompiler$ - one error found 17:10:01.648 [main][ERROR][ZincCompiler.scala:219] i.g.c.ZincCompiler$ - Compilation crashed sbt.internal.inc.CompileFailed: null
at sbt.internal.inc.AnalyzingCompiler.call(AnalyzingCompiler.scala:242)
编辑
感谢为此做出贡献的所有人post。我必须使用导入语句 io.gatling.core.structure.{PopulationBuilder, ScenarioBuilder} 将场景修改为 ScenarioBuilder,如前所述
正如编译器所说,scenario
是未知的(顺便说一下,它实际上不是 Gatling 类型)而且它不是 return 由您的方法编辑的类型。
您可以删除 return 类型并让编译器为您推断它,或者编写正确的 return 类型。
编辑:Gatling 使用的 Zinc 编译器需要明确的 return 类型,因此您必须找到正确的类型(可能是 ScenarioBuilder
)。