Run you first gatling load test using scala
Gatling is a neat tool. You can create your load tests by just coding in scala. Jmeter allows you to do so through a plugin or beanshell but it is not as direct as the way gatling does so.
I will start by adding the gatling plugin
1 | addSbtPlugin( "io.gatling" % "gatling-sbt" % "3.0.0" ) |
The next step is to changed the build.sbt
01 02 03 04 05 06 07 08 09 10 | version := "0.1" scalaVersion := "2.12.8" enablePlugins(GatlingPlugin) scalacOptions := Seq( "-encoding" , "UTF-8" , "-target:jvm-1.8" , "-deprecation" , "-feature" , "-unchecked" , "-language:implicitConversions" , "-language:postfixOps" ) libraryDependencies + = "io.gatling.highcharts" % "gatling-charts-highcharts" % "3.1.2" % "test,it" libraryDependencies + = "io.gatling" % "gatling-test-framework" % "3.1.2" % "test,it" |
The above are no different than what you can find on the official site when it comes to sbt commands and gatling.
Our next step is to add a simple http test. Be aware that you should add it in the directories src/test or src/it since, as it is instructed from the sbt dependencies for the binaries to take effect on these directories.
I shall put this test on src/test/scala/com/gkatzioura/BasicSimulation.scala
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 | package com.gkatzioura import io.gatling.core.Predef._ import io.gatling.http.Predef._ import scala.concurrent.duration._ class BasicSimulation extends Simulation { .doNotTrackHeader( "1" ) val scn = scenario( "BasicSimulation" ) .exec(http( "request_1" ) .get( "/" )) .pause( 5 ) setUp(scn.inject(atOnceUsers( 1 ))).protocols(httpConf) } |
Afterwards testing is simple. You go to sbt mode and execute the test.
1 2 3 | sbt >gatling:testOnly com.gkatzioura.BasicSimulation >gatling: test |
The first command instructs to run just one test, the second one shall run everything.
That’s it! Pretty simple.
Published on Java Code Geeks with permission by Emmanouil Gkatziouras, partner at our JCG program. See the original article here: Run you first gatling load test using scala. Opinions expressed by Java Code Geeks contributors are their own. |