Skip to content

Instantly share code, notes, and snippets.

@alexandre-touret
Last active November 21, 2019 20:49
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 alexandre-touret/bdba509353c7b42de85d9a90c0352aa7 to your computer and use it in GitHub Desktop.
Save alexandre-touret/bdba509353c7b42de85d9a90c0352aa7 to your computer and use it in GitHub Desktop.
class RecordedSimulation extends Simulation {
val httpProtocol = http
.baseUrl("https://mabaseurl")
.inferHtmlResources()
.acceptHeader("*/*")
.acceptEncodingHeader("gzip, deflate")
.connectionHeader("close")
.userAgentHeader("PostmanRuntime/7.17.1")
/* randomized data information */
var feeder = Iterator.continually(Map("somedata" -> (Random.alphanumeric.take(20).mkString)))
/* ------------------------------------- */
val holder = new LinkedBlockingDeque[String]()
/* Enables to store and fetch the oauth access token */
var sharedDataFeeder= Iterator.continually(Map("variable" -> holder.takeFirst()))
/* ------------------------------------- */
val firstScenario = scenario("First Simulation")
.exec(http("first scenario")
.post("/base/url1")
.check(jsonPath("$.my_variable").find.saveAs("variable")))
.exec(session => {
holder.offerLast(session("variable").as[String])
session}
);
val secondScenario = scenario("Second Simulation")
.feed(feeder)
.feed(sharedDataFeeder)
.repeat(1){
exec(http("url1")
.post("/url1")
.headers(Map("my_header" -> "Bearer ${variable}","Content-Type" -> "application/json"))
.body(ElFileBody("recordedsimulation/anonymized_data.json")));
}
setUp(firstScenario.inject(atOnceUsers(1)),secondScenario.inject(constantConcurrentUsers(10) during (10 minutes),
rampConcurrentUsers(10) to (20) during (10 minutes))
.protocols(httpProtocol));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment