Skip to content

Instantly share code, notes, and snippets.

@mvillafuertem
Forked from dacr/gatling-simple.sc
Created May 8, 2020 13:51
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 mvillafuertem/2a0f24545a57a44d9531d9e64086ba77 to your computer and use it in GitHub Desktop.
Save mvillafuertem/2a0f24545a57a44d9531d9e64086ba77 to your computer and use it in GitHub Desktop.
Just ONE ammonite script file to execute a load performance test using gatling ! #ea7a4259-9461-44a8-99fa-1ec6ec3c48ed/cb9ae6dd7c07d7f534a416c586bc5182a8244daa
// summary : Just ONE ammonite script file to execute a load performance test using gatling !
// keywords : scala, gatling, ammonite, scala, load-test, performance
// publish : gist, snippet
// authors : David Crosson
// id : ea7a4259-9461-44a8-99fa-1ec6ec3c48ed
// execution : scala ammonite script (http://ammonite.io/) - run as follow 'amm scriptname.sc'
/*
A performance load script file directly executable using ammonite, run on all OS (linux / Mac / Windows), just install ammonite REPL (http://ammonite.io).
All required dependencies are **automatically resolved and downloaded** when first started.
This example requires a direct internet connection access, or change the baseURL to a local one.
If you do not have a direct internet connection access, you can install the httpbin.org application locally :
```
docker run -p 8099:80 kennethreitz/httpbin
```
And change the baseUrl in script file to `http://localhost:8099/`.
Run the script as follow :
```
amm gatling-simple.scala
```
or if you uncomment the shebang :
```
./gatling-simple.scala
```
*/
import $ivy.`io.gatling:gatling-http:3.1.2`
import $ivy.`io.gatling:gatling-app:3.1.2`
import $ivy.`io.gatling.highcharts:gatling-charts-highcharts:3.1.2`
import $ivy.`ch.qos.logback:logback-classic:1.2.3`
import io.gatling.app.Gatling
import io.gatling.core.config.GatlingPropertiesBuilder
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
import org.slf4j.{LoggerFactory, Logger}
val rootLogger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME).asInstanceOf[ch.qos.logback.classic.Logger]
rootLogger.setLevel(ch.qos.logback.classic.Level.ERROR)
class GatlingSimple extends Simulation {
def config = {
http
.baseUrl("https://httpbin.org/")
.userAgentHeader("curl/7.58.0")
.disableFollowRedirect
}
def assertions = List(
global.responseTime.mean.lt(90),
global.successfulRequests.percent.gt(90)
)
def scn =
scenario("Simple load").during(30 seconds) {
exec(
http("get200")
.get("/")
.check(status.is(200)) )
.pause(1000 milliseconds, 2000 milliseconds)
.exec(
http("get401")
.get("/status/401")
.check(status.is(401)) )
.pause(2000 milliseconds, 4000 milliseconds)
}
setUp(scn.inject(rampUsers(10) during (10 seconds)))
.protocols(config)
.assertions(assertions)
}
val props =
new GatlingPropertiesBuilder()
.simulationClass(classOf[GatlingSimple].getName)
.resultsDirectory("/tmp")
//.noReports()
.build
Gatling.fromMap(props)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment