Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active April 2, 2023 10:12
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save dacr/88c797b05ee968be145eccc77e498888 to your computer and use it in GitHub Desktop.
Save dacr/88c797b05ee968be145eccc77e498888 to your computer and use it in GitHub Desktop.
Just ONE ammonite script file to execute a load performance test using gatling ! / published by https://github.com/dacr/code-examples-manager #ea7a4259-9461-44a8-99fa-1ec6ec3c48ed/6bc5335f1571c83edc6278c55499c9c7ae43a5c0
// summary : Just ONE ammonite script file to execute a load performance test using gatling !
// keywords : scala, gatling, ammonite, scala, load-test, performance
// publish : gist
// authors : David Crosson
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
// id : ea7a4259-9461-44a8-99fa-1ec6ec3c48ed
// created-on : 2018-09-22T07:41:07Z
// managed-by : https://github.com/dacr/code-examples-manager
// 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