Skip to content

Commit

Permalink
Upgraded to support gatling 1.3.4 + Added redis and byteArrayBody sim…
Browse files Browse the repository at this point in the history
…ulations
  • Loading branch information
krishnenc committed Oct 25, 2012
1 parent 21dee11 commit ac82d0b
Show file tree
Hide file tree
Showing 15 changed files with 260 additions and 145 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -5,9 +5,9 @@ A sbt template project for writing [Gatling](https://github.com/excilys/gatling.


Depends on : Depends on :


* gatling 1.2.1 * gatling 1.3.4


* sbt 0.11.3 * sbt 0.12.0


* Scala 2.9.2 * Scala 2.9.2


Expand Down
19 changes: 13 additions & 6 deletions project/Build.scala
@@ -1,6 +1,7 @@
import sbt._ import sbt._
import Keys._ import Keys._
import com.typesafe.startscript.StartScriptPlugin import com.typesafe.startscript.StartScriptPlugin
import cc.spray.revolver.RevolverPlugin._
import classpath.ClasspathUtilities.isArchive import classpath.ClasspathUtilities.isArchive
import java.io.FileOutputStream import java.io.FileOutputStream
import sbtassembly.Plugin._ import sbtassembly.Plugin._
Expand All @@ -9,7 +10,7 @@ import AssemblyKeys._
object BuildSettings { object BuildSettings {
import Dependencies._ import Dependencies._


val buildOrganization = "org.gatling" val buildOrganization = "com.logos.gatling"
val buildVersion = "0.0.1" val buildVersion = "0.0.1"
val buildScalaVersion = "2.9.2" val buildScalaVersion = "2.9.2"


Expand All @@ -19,6 +20,7 @@ object BuildSettings {
scalaVersion := buildScalaVersion, scalaVersion := buildScalaVersion,
scalacOptions := Seq("-unchecked", "-deprecation", "-encoding", "utf8"), scalacOptions := Seq("-unchecked", "-deprecation", "-encoding", "utf8"),
javacOptions := Seq("-Xlint:unchecked", "-Xlint:deprecation","-encoding", "utf8"), javacOptions := Seq("-Xlint:unchecked", "-Xlint:deprecation","-encoding", "utf8"),
fork in test := true,
resolvers ++= Dependencies.resolutionRepos) resolvers ++= Dependencies.resolutionRepos)
val projectSettings = Defaults.defaultSettings ++ globalSettings val projectSettings = Defaults.defaultSettings ++ globalSettings
} }
Expand All @@ -29,28 +31,32 @@ object Build extends sbt.Build {


override lazy val settings = super.settings ++ globalSettings override lazy val settings = super.settings ++ globalSettings


lazy val gatlingTemplate = Project("gatling-template", lazy val gatlingTemplate = Project("gatling-sbt",
file("."), file("."),
settings = projectSettings ++ assemblySettings ++ settings = projectSettings ++ assemblySettings ++
StartScriptPlugin.startScriptForClassesSettings ++ Revolver.settings ++
StartScriptPlugin.startScriptForJarSettings ++
Seq(libraryDependencies ++= Seq( Seq(libraryDependencies ++= Seq(
Compile.logback, Compile.logback,
Compile.gatlingApp, Compile.gatlingApp,
Compile.gatlingRecorder, Compile.gatlingRecorder,
Compile.gatlingHighCharts))) Compile.gatlingHighCharts,
Compile.redis
)))
} }


object Dependencies { object Dependencies {


val resolutionRepos = Seq( val resolutionRepos = Seq(
"Scala Tools" at "http://scala-tools.org/repo-releases/", "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") "Excilys" at "http://repository.excilys.com/content/groups/public")


object V { object V {
val slf4j = "1.6.4" val slf4j = "1.6.4"
val logback = "1.0.0" val logback = "1.0.0"
val gatling = "1.2.1" val gatling = "1.3.4"
val redis = "2.7"
} }


object Compile { object Compile {
Expand All @@ -59,5 +65,6 @@ object Dependencies {
val gatlingHighCharts = "com.excilys.ebi.gatling.highcharts" % "gatling-charts-highcharts" % V.gatling % "compile" 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 logback = "ch.qos.logback" % "logback-classic" % "1.0.0" % "runtime"
val log4j = "log4j" % "log4j" % "1.2.14" % "compile" val log4j = "log4j" % "log4j" % "1.2.14" % "compile"
val redis = "net.debasishg" %% "redisclient" % V.redis % "compile"
} }
} }
2 changes: 1 addition & 1 deletion project/build.properties
@@ -1 +1 @@
sbt.version=0.11.3 sbt.version=0.12.0
2 changes: 2 additions & 0 deletions project/build.sbt
@@ -0,0 +1,2 @@
mainClass in Compile := Some("Engine")

10 changes: 7 additions & 3 deletions project/plugins.sbt
@@ -1,12 +1,16 @@
resolvers += "Another Typesafe Repo" at "http://repo.akka.io/releases/" 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 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", resolvers += Resolver.url("sbt-plugin-releases",
new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/"))(Resolver.ivyStylePatterns) 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")
9 changes: 9 additions & 0 deletions src/main/resources/application.conf
@@ -0,0 +1,9 @@
####################################
# Akka Actor Config File #
####################################

akka {
scheduler {
tick-duration = 50ms
}
}
40 changes: 32 additions & 8 deletions src/main/resources/gatling.conf
Expand Up @@ -5,36 +5,60 @@
# This file contains all the settings configurable for Gatling with their default values # This file contains all the settings configurable for Gatling with their default values


gatling { gatling {
#encoding = "utf-8" # encoding for every file manipulation made in gatling

simulation { simulation {
#timeout = 86400 # max duration of a simulation in seconds #outputDirectoryBaseName = ""
#scalaPackage = "" #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 { charting {
#noReports = false
#maxPlotPerSeries = 1000
#accuracy = 10 # in ms
indicators { indicators {
#lowerBound = 800 # in ms #lowerBound = 800 # in ms
#higherBound = 1200 # in ms #higherBound = 1200 # in ms
#percentiles = 95 # in percents #percentile1 = 95 # in percents
#percentile2 = 99 # in percents
} }
} }
http { http {
#provider = "Netty" # Choose between 'Netty', 'JDK', 'Apache' or 'Grizzly' #provider = "Netty" # Choose between 'Netty', 'JDK', 'Apache' or 'Grizzly'
#allowPoolingConnection = true #allowPoolingConnection = true
#allowSslConnectionPool = true #allowSslConnectionPool = true
#compressionEnabled = true # Set if compression should be supported or not #compressionEnabled = true # Set if compression should be supported or not
#connectionTimeout = 60000 # Timeout of the connection to the server (ms) #connectionTimeout = 60000 # Timeout of the connection to the server (ms)
#requestTimeout = 60000 # # Timeout of the requests (ms)
#idleConnectionInPoolTimeoutInMs = 60000 #idleConnectionInPoolTimeoutInMs = 60000
#idleConnectionTimeoutInMs = 60000 #idleConnectionTimeoutInMs = 60000
#ioThreadMultiplier = 2 #ioThreadMultiplier = 2
#maximumConnectionsPerHost = -1 #maximumConnectionsPerHost = -1
#maximumConnectionsTotal = -1 #maximumConnectionsTotal = -1
#maxRetry = 5 # number of times that a request should be tried again #maxRetry = 5 # number of times that a request should be tried again
#requestCompressionLevel = -1 #requestCompressionLevel = -1
#requestTimeoutInMs = 60000 #requestTimeoutInMs = 60000 # Timeout of the requests (ms)
#useProxyProperties = false #useProxyProperties = false
#userAgent = "NING/1.0" #userAgent = "NING/1.0"
#useRawUrl = false #useRawUrl = false
} }
data {
#writers = [console, file]
#reader = file
}
graphite {
#host = "localhost"
#port = 2003
#bucketWidth = 100
}
} }
1 change: 1 addition & 0 deletions src/main/resources/logback.xml
Expand Up @@ -8,6 +8,7 @@
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder> <encoder>
<pattern>%d{HH:mm:ss.SSS} [%-5level] %logger{15} - %msg%n%rEx</pattern> <pattern>%d{HH:mm:ss.SSS} [%-5level] %logger{15} - %msg%n%rEx</pattern>
<immediateFlush>false</immediateFlush>
</encoder> </encoder>
</appender> </appender>


Expand Down
55 changes: 47 additions & 8 deletions src/main/scala/Engine.scala
@@ -1,12 +1,51 @@
import com.excilys.ebi.gatling.app.{ Options, Gatling } import java.lang.System.currentTimeMillis
import com.excilys.ebi.gatling.core.util.PathHelper.path2string 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), object Engine extends Logging {
resultsFolder = Some(IDEPathHelper.resultsFolder),
requestBodiesFolder = Some(IDEPathHelper.requestBodiesFolder), /**
simulationBinariesFolder = Some(IDEPathHelper.mavenBinariesDir))).start * 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, "<directoryName>", "Generates the reports for the simulation in <directoryName>", { v: String => props.reportsOnly(v) })
opt(CLI_DATA_FOLDER, CLI_DATA_FOLDER_ALIAS, "<directoryPath>", "Uses <directoryPath> as the absolute path of the directory where feeders are stored", { v: String => props.dataDirectory(v) })
opt(CLI_RESULTS_FOLDER, CLI_RESULTS_FOLDER_ALIAS, "<directoryPath>", "Uses <directoryPath> 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, "<directoryPath>", "Uses <directoryPath> 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, "<directoryPath>", "Uses <directoryPath> to discover simulations that could be run", { v: String => props.sourcesDirectory(v) })
opt(CLI_SIMULATIONS_BINARIES_FOLDER, CLI_SIMULATIONS_BINARIES_FOLDER_ALIAS, "<directoryPath>", "Uses <directoryPath> to discover already compiled simulations", { v: String => props.binariesDirectory(v) })
opt(CLI_SIMULATION, CLI_SIMULATION_ALIAS, "<className>", "Runs <className> simulation", { v: String => props.clazz(v) })
opt(CLI_OUTPUT_DIRECTORY_BASE_NAME, CLI_OUTPUT_DIRECTORY_BASE_NAME_ALIAS, "<name>", "Use <name> 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
}
} }
12 changes: 0 additions & 12 deletions src/main/scala/Recorder.scala

This file was deleted.

11 changes: 6 additions & 5 deletions src/main/scala/advanced/SomeOtherScenario.scala
@@ -1,6 +1,7 @@
package advanced package advanced
import com.excilys.ebi.gatling.core.Predef._ import com.excilys.ebi.gatling.core.Predef._
import com.excilys.ebi.gatling.http.Predef._ import com.excilys.ebi.gatling.http.Predef._
import akka.util.duration._
import Headers._ import Headers._


object SomeOtherScenario { object SomeOtherScenario {
Expand All @@ -10,7 +11,7 @@ object SomeOtherScenario {
http("other_request_1") http("other_request_1")
.get("/") .get("/")
.check(status.is(302))) .check(status.is(302)))
.pause(0, 100, MILLISECONDS) .pause(0 milliseconds, 100 milliseconds)
.exec( .exec(
http("other_request_2") http("other_request_2")
.get("/public/login.html")) .get("/public/login.html"))
Expand All @@ -22,14 +23,14 @@ object SomeOtherScenario {
.param("username", "${username}") .param("username", "${username}")
.param("password", "${password}") .param("password", "${password}")
.check(status.is(302))) .check(status.is(302)))
.pause(0, 100, MILLISECONDS) .pause(0 milliseconds, 100 milliseconds)
.exec( .exec(
http("other_request_9") http("other_request_9")
.get("/logout") .get("/logout")
.headers(headers_9) .headers(headers_1)
.check(status.is(302))) .check(status.is(302)))
.pause(0, 100, MILLISECONDS) .pause(0 milliseconds, 100 milliseconds)
.exec( .exec(
http("other_request_10") http("other_request_10")
.get("/public/login.html")) .get("/public/login.html"))
} }
53 changes: 27 additions & 26 deletions src/main/scala/advanced/SomeScenario.scala
Expand Up @@ -2,6 +2,8 @@ package advanced
import com.excilys.ebi.gatling.core.Predef._ import com.excilys.ebi.gatling.core.Predef._
import com.excilys.ebi.gatling.http.Predef._ import com.excilys.ebi.gatling.http.Predef._
import Headers._ import Headers._
import akka.util.duration._
import bootstrap._


object SomeScenario { object SomeScenario {


Expand All @@ -11,7 +13,7 @@ object SomeScenario {
.get("/") .get("/")
.headers(headers_1) .headers(headers_1)
.check(status.is(302))) .check(status.is(302)))
.pause(0, 100, MILLISECONDS) .pause(0 milliseconds, 100 milliseconds)
.exec( .exec(
http("request_2") http("request_2")
.get("/public/login.html") .get("/public/login.html")
Expand All @@ -25,20 +27,19 @@ object SomeScenario {
.param("password", "${password}") .param("password", "${password}")
.headers(headers_3) .headers(headers_3)
.check(status.is(302))) .check(status.is(302)))
.pause(0, 100, MILLISECONDS) .pause(0 milliseconds, 100 milliseconds)
.loop( .repeat(5) {
chain exec(
.exec( http("request_4")
http("request_4") .get("/private/bank/accounts.html")
.get("/private/bank/accounts.html") .headers(headers_1)
.headers(headers_4) .check(regex("""<td class="number">ACC(\d+)</td>""").saveAs("account_id")))
.check(regex("""<td class="number">ACC(\d+)</td>""").saveAs("account_id")))
.pause(7, 8) .pause(7, 8)
.exec( .exec(
http("request_5") http("request_5")
.get("/private/bank/account/ACC${account_id}/operations.html") .get("/private/bank/account/ACC${account_id}/operations.html")
.headers(headers_5)) .headers(headers_1))
.pause(100, 200, MILLISECONDS) .pause(100 milliseconds, 200 milliseconds)
.exec( .exec(
http("request_6") http("request_6")
.get("/private/bank/account/ACC${account_id}/year/2011/month/12/page/0/operations.json") .get("/private/bank/account/ACC${account_id}/year/2011/month/12/page/0/operations.json")
Expand All @@ -47,23 +48,23 @@ object SomeScenario {
.exec( .exec(
http("request_7") http("request_7")
.get("/private/bank/account/ACC${account_id}/year/2011/month/11/operations.html") .get("/private/bank/account/ACC${account_id}/year/2011/month/11/operations.html")
.headers(headers_7)) .headers(headers_1))
.pause(100, 200, MILLISECONDS) .pause(100 milliseconds, 200 milliseconds)
.exec( .exec(
http("request_8") http("request_8")
.get("/private/bank/account/ACC${account_id}/year/2011/month/11/page/0/operations.json") .get("/private/bank/account/ACC${account_id}/year/2011/month/11/page/0/operations.json")
.headers(headers_8)) .headers(headers_8))
.pause(6, 7)).times(5) .pause(6, 7)
.doIf((session: Session) => session.getAttribute("username") != "user7", }
chain .doIf((session: Session) => session.getAttribute("username") != "user7") {
.exec( exec(
http("request_9") http("request_9")
.get("/logout") .get("/logout")
.headers(headers_9) .headers(headers_1)
.check(status.is(302))) .check(status.is(302)))
.pause(0, 100, MILLISECONDS) .pause(0 milliseconds, 100 milliseconds)
.exec( .exec(http("request_10")
http("request_10") .get("/public/login.html")
.get("/public/login.html") .headers(headers_1))
.headers(headers_9))) }
} }

0 comments on commit ac82d0b

Please sign in to comment.