-
-
Save anonymous/57570cbeba8c42a58da4 to your computer and use it in GitHub Desktop.
SampleLoadTest
This file contains 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 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