Created
April 2, 2014 14:44
-
-
Save nicolaihald/9935620 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package computerdatabase | |
import io.gatling.core.Predef._ | |
import io.gatling.http.Predef._ | |
import io.gatling.http.HeaderNames._ | |
import scala.concurrent.forkjoin.ThreadLocalRandom | |
import scala.concurrent.duration._ | |
class ComputerDababase extends Simulation { | |
object Search { | |
val feeder = csv("search.csv").random | |
val search = | |
group("Search Group") { // add group | |
exec(http("Home") | |
.get("/")) | |
.pause(1) | |
.feed(feeder) | |
.exec(http("Search") | |
.get("/computers") | |
.queryParam("""f""", "${searchCriterion}") | |
.check(regex("""<a href="([^"]+)">${searchComputerName}</a>""").saveAs("computerURL"))) | |
.pause(1) | |
.exec(http("Select") | |
.get("${computerURL}") | |
.check(status.is(200))) | |
.pause(1) | |
} | |
} | |
object Browse { | |
def gotoPage(page: String) = exec(http("Page " + page) | |
.get("/computers") | |
.queryParam("""p""", page)) | |
.pause(1) | |
def gotoUntil(max: String) = repeat(max.toInt, "i") { | |
gotoPage("${i}") | |
} | |
def gotoUntil2(max: String) = exec(for (i <- 0 until max.toInt) yield gotoPage(i.toString)) | |
val browse = group("Browse Group") { // add group | |
during(30) { | |
gotoUntil2("4") | |
} | |
} | |
} | |
object Edit { | |
val headers_10 = Map("Content-Type" -> """application/x-www-form-urlencoded""") | |
val edit = group("Edit Group") { // add group | |
tryMax(2) { | |
exec(http("Form") | |
.get("/computers/new")) | |
.pause(1) | |
.exec(http("Post") | |
.post("/computers") | |
.headers(headers_10) | |
.param("""name""", """Beautiful Computer""") | |
.param("""introduced""", """2012-05-30""") | |
.param("""discontinued""", """""") | |
.param("""company""", """37"""). | |
check(status.is(_ => 200 + ThreadLocalRandom.current.nextInt(2)))) | |
}.exitHereIfFailed | |
} | |
} | |
val httpConf = http | |
.baseURL("http://localhost:9000") | |
.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") | |
.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 users = scenario("Users").exec(Search.search, Browse.browse) | |
val admins = scenario("Admins").exec(Search.search, Browse.browse, Edit.edit) | |
setUp(users.inject(rampUsers(300) over 5), | |
admins.inject(rampUsers(10) over 5)) | |
.throttle(jumpToRps(20), holdFor(10 seconds), reachRps(100) in (3 seconds), holdFor(10 seconds)) | |
.protocols(httpConf) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
searchCriterion | searchComputerName | |
---|---|---|
Macbook | MacBook Pro | |
eee | ASUS Eee PC 1005PE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment