Skip to content

Instantly share code, notes, and snippets.

@dacr dacr/gatling-simple.scala
Last active Jul 31, 2019

Embed
What would you like to do?
Just ONE ammonite script file to execute a load performance test using gatling !
// summary : Just ONE ammonite script file to execute a load performance test using gatling !
// keywords : gatling, ammonite, scala, load-test, performance
// publish : gist, snippet
// authors : david
// id : ea7a4259-9461-44a8-99fa-1ec6ec3c48ed
/*
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
You can’t perform that action at this time.