Sunday, February 7, 2016

Gatling simple simulation example

This a simple Gatling simulation example. The POST request is already explained in my earlier blog Gatling post request with JSON body
The example will run the scenario using 5 users for 10 minutes duration with no pauses.
import net.liftweb.json.DefaultFormats
import net.liftweb.json.Serialization._
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.core.scenario.Simulation

class MySimulation extends Simulation {
  case class Person(name: String)

  val createPerson = http("Create person")
    .post("/person")
    .body(StringBody(session => write(Person("Jack"))(DefaultFormats))).asJSON

  val httpProtocol = http
    .baseURL("https://localhost:8080/application")
    .disableFollowRedirect
    .disableAutoReferer
    .disableCaching
    .connectionHeader("keep-alive")

  val myScenario = scenario("My scenario").during(10) {
    exec(createPerson)
  }.inject(rampUsers(5).over(1))

  setUp(myScenario)
    .pauses(disabledPauses)
    .protocols(httpProtocol)
    .assertions(global.failedRequests.count.is(0))
}