diff --git a/README.md b/README.md index dc9a0d6..cba3216 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ A sbt template project for writing [Gatling](https://github.com/excilys/gatling. Depends on : -* gatling 1.2.1 +* gatling 1.3.4 -* sbt 0.11.3 +* sbt 0.12.0 * Scala 2.9.2 diff --git a/project/Build.scala b/project/Build.scala index 8701db2..7a08399 100755 --- a/project/Build.scala +++ b/project/Build.scala @@ -1,6 +1,7 @@ import sbt._ import Keys._ import com.typesafe.startscript.StartScriptPlugin +import cc.spray.revolver.RevolverPlugin._ import classpath.ClasspathUtilities.isArchive import java.io.FileOutputStream import sbtassembly.Plugin._ @@ -9,7 +10,7 @@ import AssemblyKeys._ object BuildSettings { import Dependencies._ - val buildOrganization = "org.gatling" + val buildOrganization = "com.logos.gatling" val buildVersion = "0.0.1" val buildScalaVersion = "2.9.2" @@ -19,6 +20,7 @@ object BuildSettings { scalaVersion := buildScalaVersion, scalacOptions := Seq("-unchecked", "-deprecation", "-encoding", "utf8"), javacOptions := Seq("-Xlint:unchecked", "-Xlint:deprecation","-encoding", "utf8"), + fork in test := true, resolvers ++= Dependencies.resolutionRepos) val projectSettings = Defaults.defaultSettings ++ globalSettings } @@ -29,28 +31,32 @@ object Build extends sbt.Build { override lazy val settings = super.settings ++ globalSettings - lazy val gatlingTemplate = Project("gatling-template", + lazy val gatlingTemplate = Project("gatling-sbt", file("."), settings = projectSettings ++ assemblySettings ++ - StartScriptPlugin.startScriptForClassesSettings ++ + Revolver.settings ++ + StartScriptPlugin.startScriptForJarSettings ++ Seq(libraryDependencies ++= Seq( Compile.logback, Compile.gatlingApp, Compile.gatlingRecorder, - Compile.gatlingHighCharts))) + Compile.gatlingHighCharts, + Compile.redis + ))) } object Dependencies { val resolutionRepos = Seq( "Scala Tools" at "http://scala-tools.org/repo-releases/", - "Typesafe repo" at "http://repo.typesafe.com/typesafe/releases", + "Typesafe repo" at "http://repo.typesafe.com/typesafe/releases","Local Maven Repository" at "file://"+Path.userHome.absolutePath+"/.m2/repository", "Excilys" at "http://repository.excilys.com/content/groups/public") object V { val slf4j = "1.6.4" val logback = "1.0.0" - val gatling = "1.2.1" + val gatling = "1.3.4" + val redis = "2.7" } object Compile { @@ -59,5 +65,6 @@ object Dependencies { val gatlingHighCharts = "com.excilys.ebi.gatling.highcharts" % "gatling-charts-highcharts" % V.gatling % "compile" val logback = "ch.qos.logback" % "logback-classic" % "1.0.0" % "runtime" val log4j = "log4j" % "log4j" % "1.2.14" % "compile" + val redis = "net.debasishg" %% "redisclient" % V.redis % "compile" } } diff --git a/project/build.properties b/project/build.properties index d428711..a8c2f84 100755 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=0.11.3 +sbt.version=0.12.0 diff --git a/project/build.sbt b/project/build.sbt new file mode 100644 index 0000000..7133e3d --- /dev/null +++ b/project/build.sbt @@ -0,0 +1,2 @@ +mainClass in Compile := Some("Engine") + diff --git a/project/plugins.sbt b/project/plugins.sbt index 04c87bf..d350bc4 100755 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,12 +1,16 @@ resolvers += "Another Typesafe Repo" at "http://repo.akka.io/releases/" +resolvers += Resolver.url("artifactory", url("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases"))(Resolver.ivyStylePatterns) + resolvers += Classpaths.typesafeResolver -addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.0.0") +addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.1.0") + +addSbtPlugin("com.typesafe.startscript" % "xsbt-start-script-plugin" % "0.5.3") -addSbtPlugin("com.typesafe.startscript" % "xsbt-start-script-plugin" % "0.5.2") +addSbtPlugin("cc.spray" % "sbt-revolver" % "0.6.1") resolvers += Resolver.url("sbt-plugin-releases", new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/"))(Resolver.ivyStylePatterns) -addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.8.1") +addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.8.4") diff --git a/src/main/resources/application.conf b/src/main/resources/application.conf new file mode 100644 index 0000000..caa0769 --- /dev/null +++ b/src/main/resources/application.conf @@ -0,0 +1,9 @@ +#################################### +# Akka Actor Config File # +#################################### + +akka { + scheduler { + tick-duration = 50ms + } +} diff --git a/src/main/resources/gatling.conf b/src/main/resources/gatling.conf index 0eaea9b..8fd584a 100644 --- a/src/main/resources/gatling.conf +++ b/src/main/resources/gatling.conf @@ -5,26 +5,41 @@ # This file contains all the settings configurable for Gatling with their default values gatling { - #encoding = "utf-8" # encoding for every file manipulation made in gatling - simulation { - #timeout = 86400 # max duration of a simulation in seconds - #scalaPackage = "" + #outputDirectoryBaseName = "" + #runDescription = run + #encoding = "utf-8" # encoding for every file manipulation made in gatling + #class = "" + } + timeOut { + #simulation = 86400 # in s + #actor = 5 # in s + } + directory { + #data = user-files/data + #requestBodies = user-files/request-bodies + #simulations = user-files/simulations + #reportsOnly = "" + #binaries = "" + #results = results } charting { + #noReports = false + #maxPlotPerSeries = 1000 + #accuracy = 10 # in ms indicators { #lowerBound = 800 # in ms #higherBound = 1200 # in ms - #percentiles = 95 # in percents + #percentile1 = 95 # in percents + #percentile2 = 99 # in percents } } http { - #provider = "Netty" # Choose between 'Netty', 'JDK', 'Apache' or 'Grizzly' + #provider = "Netty" # Choose between 'Netty', 'JDK', 'Apache' or 'Grizzly' #allowPoolingConnection = true #allowSslConnectionPool = true #compressionEnabled = true # Set if compression should be supported or not #connectionTimeout = 60000 # Timeout of the connection to the server (ms) - #requestTimeout = 60000 # # Timeout of the requests (ms) #idleConnectionInPoolTimeoutInMs = 60000 #idleConnectionTimeoutInMs = 60000 #ioThreadMultiplier = 2 @@ -32,9 +47,18 @@ gatling { #maximumConnectionsTotal = -1 #maxRetry = 5 # number of times that a request should be tried again #requestCompressionLevel = -1 - #requestTimeoutInMs = 60000 + #requestTimeoutInMs = 60000 # Timeout of the requests (ms) #useProxyProperties = false #userAgent = "NING/1.0" #useRawUrl = false } + data { + #writers = [console, file] + #reader = file + } + graphite { + #host = "localhost" + #port = 2003 + #bucketWidth = 100 + } } \ No newline at end of file diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 5bd7787..b73472d 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -8,6 +8,7 @@ %d{HH:mm:ss.SSS} [%-5level] %logger{15} - %msg%n%rEx + false diff --git a/src/main/scala/Engine.scala b/src/main/scala/Engine.scala index 3243451..c85e58b 100644 --- a/src/main/scala/Engine.scala +++ b/src/main/scala/Engine.scala @@ -1,12 +1,51 @@ -import com.excilys.ebi.gatling.app.{ Options, Gatling } -import com.excilys.ebi.gatling.core.util.PathHelper.path2string +import java.lang.System.currentTimeMillis +import java.util.{ Map => JMap } +import com.excilys.ebi.gatling.app.Gatling +import com.excilys.ebi.gatling.app.CommandLineConstants._ +import com.excilys.ebi.gatling.charts.report.ReportsGenerator +import com.excilys.ebi.gatling.core.config.{ GatlingFiles, GatlingPropertiesBuilder } +import com.excilys.ebi.gatling.core.config.GatlingConfiguration +import com.excilys.ebi.gatling.core.config.GatlingConfiguration.configuration +import com.excilys.ebi.gatling.core.runner.{ Runner, Selection } +import com.excilys.ebi.gatling.core.scenario.configuration.Simulation +import com.excilys.ebi.gatling.core.util.FileHelper.formatToFilename -object Engine extends App { +import grizzled.slf4j.Logging +import scopt.OptionParser - new Gatling(Options( - dataFolder = Some(IDEPathHelper.dataFolder), - resultsFolder = Some(IDEPathHelper.resultsFolder), - requestBodiesFolder = Some(IDEPathHelper.requestBodiesFolder), - simulationBinariesFolder = Some(IDEPathHelper.mavenBinariesDir))).start + +object Engine extends Logging { + + /** + * Entry point of Application + * + * @param args Arguments of the main method + */ + def main(args: Array[String]) { + + println(IDEPathHelper.requestBodiesFolder.toString) + val arguments = Array("--data-folder" , IDEPathHelper.dataFolder.toString, "--simulations-folder" , IDEPathHelper.mavenSourcesDir.toString , + "--request-bodies-folder" , IDEPathHelper.requestBodiesFolder.toString, "--results-folder" , IDEPathHelper.resultsFolder.toString) + val props = new GatlingPropertiesBuilder + val cliOptsParser = new OptionParser("gatling") { + opt(CLI_NO_REPORTS, CLI_NO_REPORTS_ALIAS, "Runs simulation but does not generate reports", { props.noReports }) + opt(CLI_REPORTS_ONLY, CLI_REPORTS_ONLY_ALIAS, "", "Generates the reports for the simulation in ", { v: String => props.reportsOnly(v) }) + opt(CLI_DATA_FOLDER, CLI_DATA_FOLDER_ALIAS, "", "Uses as the absolute path of the directory where feeders are stored", { v: String => props.dataDirectory(v) }) + opt(CLI_RESULTS_FOLDER, CLI_RESULTS_FOLDER_ALIAS, "", "Uses as the absolute path of the directory where results are stored", { v: String => props.resultsDirectory(v) }) + opt(CLI_REQUEST_BODIES_FOLDER, CLI_REQUEST_BODIES_FOLDER_ALIAS, "", "Uses as the absolute path of the directory where request bodies are stored", { v: String => props.requestBodiesDirectory(v) }) + opt(CLI_SIMULATIONS_FOLDER, CLI_SIMULATIONS_FOLDER_ALIAS, "", "Uses to discover simulations that could be run", { v: String => props.sourcesDirectory(v) }) + opt(CLI_SIMULATIONS_BINARIES_FOLDER, CLI_SIMULATIONS_BINARIES_FOLDER_ALIAS, "", "Uses to discover already compiled simulations", { v: String => props.binariesDirectory(v) }) + opt(CLI_SIMULATION, CLI_SIMULATION_ALIAS, "", "Runs simulation", { v: String => props.clazz(v) }) + opt(CLI_OUTPUT_DIRECTORY_BASE_NAME, CLI_OUTPUT_DIRECTORY_BASE_NAME_ALIAS, "", "Use for the base name of the output directory", { v: String => props.outputDirectoryBaseName(v) }) + } + // if arguments are incorrect, usage message is displayed + if (cliOptsParser.parse(arguments)) + fromMap(props.build) + } + + def fromMap(props: JMap[String, Any]) { + GatlingConfiguration.setUp(props) + new Gatling().start + } } \ No newline at end of file diff --git a/src/main/scala/Recorder.scala b/src/main/scala/Recorder.scala deleted file mode 100644 index b3b2a77..0000000 --- a/src/main/scala/Recorder.scala +++ /dev/null @@ -1,12 +0,0 @@ -/* -import com.excilys.ebi.gatling.core.util.PathHelper.path2string -import com.excilys.ebi.gatling.recorder.configuration.CommandLineOptionsConstants.{ REQUEST_BODIES_FOLDER_OPTION, PACKAGE_OPTION, OUTPUT_FOLDER_OPTION } -import com.excilys.ebi.gatling.recorder.ui.GatlingHttpProxyUI - -import IDEPathHelper.{ requestBodiesFolder, recorderOutputFolder } - -object Recorder extends App { - - GatlingHttpProxyUI.main(Array(OUTPUT_FOLDER_OPTION, recorderOutputFolder, PACKAGE_OPTION, "org.krishnen.gatling", REQUEST_BODIES_FOLDER_OPTION, requestBodiesFolder)) -} -*/ diff --git a/src/main/scala/advanced/SomeOtherScenario.scala b/src/main/scala/advanced/SomeOtherScenario.scala index 2ac44ec..edf8154 100644 --- a/src/main/scala/advanced/SomeOtherScenario.scala +++ b/src/main/scala/advanced/SomeOtherScenario.scala @@ -1,6 +1,7 @@ package advanced import com.excilys.ebi.gatling.core.Predef._ import com.excilys.ebi.gatling.http.Predef._ +import akka.util.duration._ import Headers._ object SomeOtherScenario { @@ -10,7 +11,7 @@ object SomeOtherScenario { http("other_request_1") .get("/") .check(status.is(302))) - .pause(0, 100, MILLISECONDS) + .pause(0 milliseconds, 100 milliseconds) .exec( http("other_request_2") .get("/public/login.html")) @@ -22,14 +23,14 @@ object SomeOtherScenario { .param("username", "${username}") .param("password", "${password}") .check(status.is(302))) - .pause(0, 100, MILLISECONDS) + .pause(0 milliseconds, 100 milliseconds) .exec( http("other_request_9") .get("/logout") - .headers(headers_9) + .headers(headers_1) .check(status.is(302))) - .pause(0, 100, MILLISECONDS) + .pause(0 milliseconds, 100 milliseconds) .exec( http("other_request_10") .get("/public/login.html")) -} +} \ No newline at end of file diff --git a/src/main/scala/advanced/SomeScenario.scala b/src/main/scala/advanced/SomeScenario.scala index 726edf2..0bf0987 100644 --- a/src/main/scala/advanced/SomeScenario.scala +++ b/src/main/scala/advanced/SomeScenario.scala @@ -2,6 +2,8 @@ package advanced import com.excilys.ebi.gatling.core.Predef._ import com.excilys.ebi.gatling.http.Predef._ import Headers._ +import akka.util.duration._ +import bootstrap._ object SomeScenario { @@ -11,7 +13,7 @@ object SomeScenario { .get("/") .headers(headers_1) .check(status.is(302))) - .pause(0, 100, MILLISECONDS) + .pause(0 milliseconds, 100 milliseconds) .exec( http("request_2") .get("/public/login.html") @@ -25,20 +27,19 @@ object SomeScenario { .param("password", "${password}") .headers(headers_3) .check(status.is(302))) - .pause(0, 100, MILLISECONDS) - .loop( - chain - .exec( - http("request_4") - .get("/private/bank/accounts.html") - .headers(headers_4) - .check(regex("""ACC(\d+)""").saveAs("account_id"))) + .pause(0 milliseconds, 100 milliseconds) + .repeat(5) { + exec( + http("request_4") + .get("/private/bank/accounts.html") + .headers(headers_1) + .check(regex("""ACC(\d+)""").saveAs("account_id"))) .pause(7, 8) .exec( http("request_5") .get("/private/bank/account/ACC${account_id}/operations.html") - .headers(headers_5)) - .pause(100, 200, MILLISECONDS) + .headers(headers_1)) + .pause(100 milliseconds, 200 milliseconds) .exec( http("request_6") .get("/private/bank/account/ACC${account_id}/year/2011/month/12/page/0/operations.json") @@ -47,23 +48,23 @@ object SomeScenario { .exec( http("request_7") .get("/private/bank/account/ACC${account_id}/year/2011/month/11/operations.html") - .headers(headers_7)) - .pause(100, 200, MILLISECONDS) + .headers(headers_1)) + .pause(100 milliseconds, 200 milliseconds) .exec( http("request_8") .get("/private/bank/account/ACC${account_id}/year/2011/month/11/page/0/operations.json") .headers(headers_8)) - .pause(6, 7)).times(5) - .doIf((session: Session) => session.getAttribute("username") != "user7", - chain - .exec( - http("request_9") - .get("/logout") - .headers(headers_9) - .check(status.is(302))) - .pause(0, 100, MILLISECONDS) - .exec( - http("request_10") - .get("/public/login.html") - .headers(headers_9))) + .pause(6, 7) + } + .doIf((session: Session) => session.getAttribute("username") != "user7") { + exec( + http("request_9") + .get("/logout") + .headers(headers_1) + .check(status.is(302))) + .pause(0 milliseconds, 100 milliseconds) + .exec(http("request_10") + .get("/public/login.html") + .headers(headers_1)) + } } \ No newline at end of file diff --git a/src/main/scala/basic/BasicExampleSimulation.scala b/src/main/scala/basic/BasicExampleSimulation.scala index 4fcc343..696660b 100644 --- a/src/main/scala/basic/BasicExampleSimulation.scala +++ b/src/main/scala/basic/BasicExampleSimulation.scala @@ -1,84 +1,44 @@ package basic -import com.excilys.ebi.gatling.core.Predef.MILLISECONDS -import com.excilys.ebi.gatling.core.Predef.Simulation -import com.excilys.ebi.gatling.core.Predef.chain -import com.excilys.ebi.gatling.core.Predef.checkBuilderToCheck -import com.excilys.ebi.gatling.core.Predef.csv -import com.excilys.ebi.gatling.core.Predef.extractorCheckBuilderToMatcherCheckBuilder -import com.excilys.ebi.gatling.core.Predef.scenario -import com.excilys.ebi.gatling.core.Predef.stringToSessionFunction -import com.excilys.ebi.gatling.core.Predef.toSessionFunction -import com.excilys.ebi.gatling.core.feeder.SourceBasedFeederBuilder.feederBuilderToFeeder -import com.excilys.ebi.gatling.http.Predef.http -import com.excilys.ebi.gatling.http.Predef.httpConfig -import com.excilys.ebi.gatling.http.Predef.status -import com.excilys.ebi.gatling.http.Predef.toHttpProtocolConfiguration -import com.excilys.ebi.gatling.http.request.builder.AbstractHttpRequestBuilder.toActionBuilder +import com.excilys.ebi.gatling.core.Predef._ +import com.excilys.ebi.gatling.http.Predef._ +import com.excilys.ebi.gatling.jdbc.Predef._ +import com.excilys.ebi.gatling.http.Headers.Names._ +import akka.util.duration._ +import bootstrap._ class BasicExampleSimulation extends Simulation { def apply = { - val urlBase = "http://excilys-bank-web.cloudfoundry.com" - - val httpConf = httpConfig.baseURL(urlBase) + val httpConf = httpConfig + .baseURL("http://excilys-bank-web.cloudfoundry.com") + .acceptCharsetHeader("ISO-8859-1,utf-8;q=0.7,*;q=0.7") + .acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") + .acceptEncodingHeader("gzip, deflate") + .acceptLanguageHeader("fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3") + .hostHeader("excilys-bank-web.cloudfoundry.com") + .disableFollowRedirect val headers_1 = Map( - "Accept" -> "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", - "Accept-Charset" -> "ISO-8859-1,utf-8;q=0.7,*;q=0.7", - "Accept-Encoding" -> "gzip,deflate", - "Accept-Language" -> "fr,en-us;q=0.7,en;q=0.3", - "Host" -> "excilys-bank-web.cloudfoundry.com", - "Keep-Alive" -> "115", - "User-Agent" -> "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110422 Ubuntu/9.10 (karmic) Firefox/3.6.17") - - val headers_3 = headers_1 ++ Map( - "Content-Length" -> "33", - "Content-Type" -> "application/x-www-form-urlencoded", - "Referer" -> "http://excilys-bank-web.cloudfoundry.com/public/login.html") - - val headers_4 = headers_1 ++ Map( - "Referer" -> "http://excilys-bank-web.cloudfoundry.com/public/login.html") + "Keep-Alive" -> "115") - val headers_5 = headers_1 ++ Map( - "Referer" -> "http://excilys-bank-web.cloudfoundry.com/private/bank/accounts.html") - - val headers_6 = Map( - "Accept" -> "application/json, text/javascript, */*; q=0.01", - "Accept-Charset" -> "ISO-8859-1,utf-8;q=0.7,*;q=0.7", - "Accept-Encoding" -> "gzip,deflate", - "Accept-Language" -> "fr,en-us;q=0.7,en;q=0.3", - "Host" -> "excilys-bank-web.cloudfoundry.com", + val headers_3 = Map( "Keep-Alive" -> "115", - "Referer" -> "http://excilys-bank-web.cloudfoundry.com/private/bank/account/ACC4/operations.html", - "User-Agent" -> "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110422 Ubuntu/9.10 (karmic) Firefox/3.6.17", - "X-Requested-With" -> "XMLHttpRequest") + "Content-Type" -> "application/x-www-form-urlencoded") - val headers_7 = headers_1 ++ Map( - "Referer" -> "http://excilys-bank-web.cloudfoundry.com/private/bank/account/ACC4/operations.html") - - val headers_8 = Map( + val headers_6 = Map( "Accept" -> "application/json, text/javascript, */*; q=0.01", - "Accept-Charset" -> "ISO-8859-1,utf-8;q=0.7,*;q=0.7", - "Accept-Encoding" -> "gzip,deflate", - "Accept-Language" -> "fr,en-us;q=0.7,en;q=0.3", - "Host" -> "excilys-bank-web.cloudfoundry.com", "Keep-Alive" -> "115", - "Referer" -> "http://excilys-bank-web.cloudfoundry.com/private/bank/account/ACC4/year/2011/month/11/operations.html", - "User-Agent" -> "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110422 Ubuntu/9.10 (karmic) Firefox/3.6.17", "X-Requested-With" -> "XMLHttpRequest") - val headers_9 = headers_1 ++ Map( - "Referer" -> "http://excilys-bank-web.cloudfoundry.com/private/bank/account/ACC4/year/2011/month/11/operations.html") - val scn = scenario("Scenario name") .exec( http("request_1") .get("/") .headers(headers_1) .check(status.is(302))) - .pause(0, 100, MILLISECONDS) + .pause(0 milliseconds, 100 milliseconds) .exec( http("request_2") .get("/public/login.html") @@ -92,19 +52,18 @@ class BasicExampleSimulation extends Simulation { .param("password", "${password}") .headers(headers_3) .check(status.is(302))) - .pause(0, 100, MILLISECONDS) - .loop( - chain - .exec( + .pause(0 milliseconds, 100 milliseconds) + .repeat(5) { + exec( http("request_4") .get("/private/bank/accounts.html") - .headers(headers_4)) + .headers(headers_1)) .pause(7, 8) .exec( http("request_5") .get("/private/bank/account/ACC${account_id}/operations.html") - .headers(headers_5)) - .pause(100, 200, MILLISECONDS) + .headers(headers_1)) + .pause(100 milliseconds, 200 milliseconds) .exec( http("request_6") .get("/private/bank/account/ACC${account_id}/year/2011/month/12/page/0/operations.json") @@ -113,23 +72,23 @@ class BasicExampleSimulation extends Simulation { .exec( http("request_7") .get("/private/bank/account/ACC${account_id}/year/2011/month/11/operations.html") - .headers(headers_7)) - .pause(100, 200, MILLISECONDS) + .headers(headers_1)) + .pause(100 milliseconds, 200 milliseconds) .exec( http("request_8") .get("/private/bank/account/ACC${account_id}/year/2011/month/11/page/0/operations.json") - .headers(headers_8)) - .pause(6, 7)).times(5) - .exec( + .headers(headers_6)) + .pause(6, 7) + }.exec( http("request_9") .get("/logout") - .headers(headers_9) + .headers(headers_1) .check(status.is(302))) - .pause(0, 100, MILLISECONDS) + .pause(0 milliseconds, 100 milliseconds) .exec( http("request_10") .get("/public/login.html") - .headers(headers_9)) + .headers(headers_1)) List(scn.configure.users(10).ramp(10).protocolConfig(httpConf)) } diff --git a/src/main/scala/other/ByteArrayBodySimulation.scala b/src/main/scala/other/ByteArrayBodySimulation.scala new file mode 100644 index 0000000..0954299 --- /dev/null +++ b/src/main/scala/other/ByteArrayBodySimulation.scala @@ -0,0 +1,49 @@ +package other + +import com.excilys.ebi.gatling.core.Predef._ +import com.excilys.ebi.gatling.http.Predef._ +import com.excilys.ebi.gatling.jdbc.Predef._ +import com.excilys.ebi.gatling.http.Headers.Names._ +import com.excilys.ebi.gatling.redis.Predef.redisFeeder +import akka.util.duration._ +import bootstrap._ +import com.redis._ +import serialization._ + + +class ByteArrayBodySimulation extends Simulation { + val redisPool = new RedisClientPool("localhost", 6379) + + def apply = { + val urlBase = "http://localhost:8080" + val httpConf = httpConfig.baseURL(urlBase) + + val header = Map( + "Content-Type" -> "application/octet-stream") + + val scn = scenario("Scenario name") + .repeat(10) { + exec((session: Session) => { + http("Protocol Buffer - hola").post("/hola") + .headers(header) + .byteArrayBody(getByteArrayBody(session)) + session + }) + .pause(7, 8) + } + List(scn.configure.users(10).ramp(1).protocolConfig(httpConf)) + } + + val getByteArrayBody = (session: Session) => { + import Parse.Implicits.parseByteArray + //LOAD your binary data onto this list beforehand + redisPool.withClient(client => + client.lpop("TEST")).getOrElse { + println("There are not enough records in the redis list: '" + + "TEST" + "'.\nPlease add records or use another feeder strategy.\nStopping simulation here...") + redisPool.close + sys.exit + } + } +} + diff --git a/src/main/scala/other/RedisSimulation.scala b/src/main/scala/other/RedisSimulation.scala new file mode 100644 index 0000000..6e9cb50 --- /dev/null +++ b/src/main/scala/other/RedisSimulation.scala @@ -0,0 +1,31 @@ +package other + +import com.excilys.ebi.gatling.core.Predef._ +import com.excilys.ebi.gatling.http.Predef._ +import com.excilys.ebi.gatling.jdbc.Predef._ +import com.excilys.ebi.gatling.http.Headers.Names._ +import com.excilys.ebi.gatling.redis.Predef.redisFeeder +import akka.util.duration._ +import bootstrap._ +import com.redis._ +import serialization._ + +class RedisSimulation extends Simulation { + val redisPool = new RedisClientPool("localhost", 6379) + + def apply = { + val urlBase = "http://192.168.1.132:88" + val httpConf = httpConfig.baseURL(urlBase) + val scn = scenario("Scenario name") + .feed(redisFeeder(redisPool, "URLS")) + .repeat(10) { + exec((session: Session) => { + http("request_redis") + .get("/inject_mo?${URLS}") + session + }) + .pause(7, 8) + } + List(scn.configure.users(10).ramp(10).protocolConfig(httpConf)) + } +} \ No newline at end of file