Skip to content

Instantly share code, notes, and snippets.

@mburrows02
Created July 29, 2014 14:06
Show Gist options
  • Save mburrows02/f31836ed062473c787be to your computer and use it in GitHub Desktop.
Save mburrows02/f31836ed062473c787be to your computer and use it in GitHub Desktop.
Basic Simulation with heaviside
package computerdatabase
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
class BasicSimulation extends Simulation {
val httpConf = http
.baseURL("http://computer-database.herokuapp.com") // Here is the root for all relative URLs
.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") // Here are the common headers
.doNotTrackHeader("1")
.acceptLanguageHeader("en-US,en;q=0.5")
.acceptEncodingHeader("gzip, deflate")
.userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0")
val headers_10 = Map("Content-Type" -> """application/x-www-form-urlencoded""") // Note the headers specific to a given request
val scn = scenario("Scenario Name") // A scenario is a chain of requests and pauses
.exec(http("request_1")
.get("/"))
.exec(http("request_2")
.get("/computers?f=macbook"))
.exec(http("request_3")
.get("/computers/6"))
.exec(http("request_4")
.get("/"))
.exec(http("request_5")
.get("/computers?p=1"))
.exec(http("request_6")
.get("/computers?p=2"))
.exec(http("request_7")
.get("/computers?p=3"))
.exec(http("request_8")
.get("/computers?p=4"))
.pause(5)
.exec(http("request_9")
.get("/computers/new"))
.pause(1)
.exec(http("request_10") // Here's an example of a POST request
.post("/computers")
.headers(headers_10)
.formParam("""name""", """Beautiful Computer""") // Note the triple double quotes: used in Scala for protecting a whole chain of characters (no need for backslash)
.formParam("""introduced""", """2012-05-30""")
.formParam("""discontinued""", """""")
.formParam("""company""", """37"""))
setUp(scn.inject(heavisideUsers(5) over(5), atOnceUsers(1)).protocols(httpConf))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment