[Gatling] Customize your scripts based on scenario
Sometimes record function may not fulfill your requirement, in this case you need write scala script yourself according to gatling document.
Below is a simple sample to test two APIs: employee & health check
package me.hongmeng.stress.test
import io.gatling.core.Predef._
import io.gatling.http.Predef._
class SimpleSimulation extends Simulation {
val hostname = "http://localhost:8080"
val httpProtocol = http
.baseURL(hostname)
.inferHtmlResources()
.acceptHeader("*/*")
.contentTypeHeader("application/json")
.userAgentHeader("Gatling/2.3.1")
val headers = Map("accept-encoding" -> "gzip, deflate", "cache-control" -> "no-cache")
val employeeScenario = scenario("create_experiment_simulation")
.exec(
http("employee")
.post("/v1/employees")
.headers(headers)
.body(
StringBody("{"name": "xiaowang","major": "software"}")
)
)
val healthScenario = scenario("health_simulation")
.exec(
http("health_check")
.get("/actuator/health")
.headers(headers)
)
setUp(
employeeScenario.inject(atOnceUsers(10)),
healthScenario.inject(atOnceUsers(10))
).protocols(httpProtocol)
}
Reply