Skip to content

Instantly share code, notes, and snippets.

/LoadTest.scala Secret

Created July 15, 2014 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/f26b7a0334ce15a6fe17 to your computer and use it in GitHub Desktop.
Save anonymous/f26b7a0334ce15a6fe17 to your computer and use it in GitHub Desktop.
SampleLoadTest
import java.util.concurrent.atomic.AtomicInteger
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.util.Random
class LoadTest extends Simulation {
val httpProtocol = http.baseURL("someUrl")
val deleteCounter = new AtomicInteger(1)
val randomNumber = new Random()
def getIt(requestTitle: String,
requestURL: String,
pause: Int) = {
exec(http(requestTitle).get(Session => requestURL)).pause(pause) //Session => doesn't work here
}
def postMePlease(requestTitle: String,
requestURL: String,
pause: Int,
listOfParams: Seq[(String, String)]) = {
exec(http(requestTitle)
.post(requestURL)
.formParamSeq(Session => listOfParams)) //Session => doesn't work here
.pause(pause)
}
def goHome = {
getIt("HomePage", "/", 3)
}
def delete = {
getIt("PressDelete", "/", "SomeUrlFirstPart_"
+ deleteCounter.getAndIncrement //This part of url I need to be different for all sessions
+ "_SomeUrlSecondPart", 3)
}
def deleteConfirm = {
postMePlease("ConfirmDelete", "SomeUrl", 3,
.formParamSeq(Seq(
("delete", "Jah")))
}
def setMeUp(scenarioName: io.gatling.core.structure.ScenarioBuilder,
delayTime: Int,
usersFromStart: Int,
rampUpUsers: Int,
rampUpDuration: Int,
protocolName: io.gatling.http.config.HttpProtocolBuilder) = {
scenarioName.inject(
nothingFor(delayTime),
atOnceUsers(usersFromStart),
rampUsers(rampUpUsers) over (rampUpDuration))
.protocols(protocolName)
}
val scenarioDeleteDeclarations = scenario("Delete")
.exec(goHome)
.exec(delete)
.exec(deleteConfirm)
setUp (
setMeUp(scenarioDeleteDeclarations, 0, 45, 1, 1, httpProtocol)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment