我正在尝试编写加特林性能测试,我正在使用before and after加特林模拟的块,用于针对服务发出一次性 HTTP POST 请求。
class MyTest extends Simulation {
// Some code here
// and definitions
val myScenario = scenario("Vary number of ...")
.exec(PublishMessageRoundRobin(pConfigTest, testTitle + "-" + numX, numY))
// extract the nodes
val nodes : Array[String] = endpoints.split(endpointDelimiter)
//
// create consumers with desired configurations at endpoint prior to scenario run
// then start them
//
before {
var endpoint = ""
//
// TODO: based on run parameter, decide if we should pre-run producers
//
for( elt <- 1 to numX ) {
endpoint = "http://" + nodes(elt-1) + cEndpoint + setConfig
CallSet( myobj, endpoint )
endpoint = "http://" + nodes(elt-1) + cEndpoint + start
CallStart( myobj, endpoint )
}
}
if (testMode == "debug") {
setUp(
myScenario.inject(
atOnceUsers(1)
)
).protocols(httpConf)
} else if (testMode == "open") {
setUp(
myScenario.inject(
rampConcurrentUsers(20) to (200) during (durationInMinutes minutes),
)
).protocols(httpConf)
}
// stop all consumers
after {
var endpoint = ""
for( elt <- 1 to numX ) {
endpoint = "http://" + nodes(elt-1) + cEndpoint + stop
CallStop(myobj, endpoint)
}
}
}
由于某种原因,CallStart、CallStop 和 CallSet 未发出 POST 请求。
调用的唯一 POST 请求是场景中定义的请求PublishMessageRoundRobin
它调用 exec 并针对端点创建 post。
它们的定义方式非常相似,这是其中之一
def CallStop(consumerConfig : ConsumerConfig, stopEndpoint : String ) = {
val jsonBody = consumerConfig.asJson
val valuedJsonBody = Printer.noSpaces.copy(dropNullValues = true).print(jsonBody)
println(valuedJsonBody)
println("stopEndpoint-" + stopEndpoint)
exec(http("StopConsumer-" + stopEndpoint)
.post(stopEndpoint)
.header(HttpHeaderNames.ContentType, HttpHeaderValues.ApplicationJson)
.body(StringBody(valuedJsonBody))
.check(status.is(200))
.check(bodyString.saveAs("serverResponse"))
)
.exec { session =>
println("server_response: " + session("serverResponse").as[String])
session
}
}
我看到上面的 println 语句,但没有 POST 请求。有人可以帮助解释发生了什么事吗?
EDIT我是 Gatting 和 Scala 的新手,所以我不知道如何调试或设置断点。似乎它默默地失败了,这与我有关。