I am trying to write gatling performance test where I am using the before and after blocks of the Gatling Simulation to make one-time HTTP post requests against the service.
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 and CallStop and CallSet are not making POST request for some reason.
The only POST request called is the one defined within the scenario PublishMessageRoundRobin
which calls exec and creates post against endpoint.
they are defined very similar way here is one of them
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
}
}
I see the println statements above but there is no POST request. Can someone help explain what is going on?
EDIT I am new to Gatling and Scala so I am not sure how to debug or have breakpoints. It seems that it fails silently which is concerning to me.