Gatling exec 超出场景范围 - POST 请求未被调用
Gatling exec outside scenario scope - POST requests are not called
我正在尝试编写加特林性能测试,我正在使用加特林模拟的 before 和 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 请求。谁能帮忙解释一下是怎么回事?
编辑
我是 Gatling 和 Scala 的新手,所以我不确定如何调试或设置断点。似乎它默默地失败了,这让我很担心。
基于 this - Gatling DSL 在挂钩中不起作用。我希望有警告或其他东西不要浪费时间。
我必须在不使用 Gatling DSL 的情况下执行实际的 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)
val post = new HttpPost(stopEndpoint)
post.setHeader("Content-type", "application/json")
post.setEntity(new StringEntity(valuedJsonBody))
// send the post request
val client = new DefaultHttpClient
val response = client.execute(post)
println("Response:" + response)
}
我正在尝试编写加特林性能测试,我正在使用加特林模拟的 before 和 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 请求。谁能帮忙解释一下是怎么回事?
编辑 我是 Gatling 和 Scala 的新手,所以我不确定如何调试或设置断点。似乎它默默地失败了,这让我很担心。
基于 this - Gatling DSL 在挂钩中不起作用。我希望有警告或其他东西不要浪费时间。
我必须在不使用 Gatling DSL 的情况下执行实际的 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)
val post = new HttpPost(stopEndpoint)
post.setHeader("Content-type", "application/json")
post.setEntity(new StringEntity(valuedJsonBody))
// send the post request
val client = new DefaultHttpClient
val response = client.execute(post)
println("Response:" + response)
}