Skip to content

Instantly share code, notes, and snippets.

/LoadTest.scala Secret

Created July 15, 2014 08:07
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/57570cbeba8c42a58da4 to your computer and use it in GitHub Desktop.
Save anonymous/57570cbeba8c42a58da4 to your computer and use it in GitHub Desktop.
SampleLoadTest
package loadTests
import java.util.concurrent.atomic.AtomicInteger
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.util.Random
class LoadTest extends Simulation {
//Url block
val httpProtocol = http.baseURL("SomeUrl")
//Number block
val deleteCounter = new AtomicInteger(1)
val randomNumber = new Random()
def someNumber = randomNumber.nextInt(40)
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("Home", "/", 3)
}
val scenarioDeleteDeclarations = scenario("Delete declarations")
.exec(goHome)
.exec(delete)
.exec(deleteConfirm)
def deleteConfirm = {
postMePlease("Confirm", "SomeUrl", 3,
Seq(("delete", "Jah")))
}
def delete = {
getIt("delete", "SomeUrlPart_1_"
+ deleteCounter.getAndIncrement
+ "_SomeUrlPart_2", 3)
}
setUp(
deleteDeclarations
)
def deleteDeclarations = {
setMeUp(scenarioDeleteDeclarations, 0, 20, 1, 1, httpProtocol)
}
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)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment