Skip to content

Commit

Permalink
Added Basic Example
Browse files Browse the repository at this point in the history
  • Loading branch information
krishnenc committed May 18, 2012
1 parent df958e4 commit 68651b3
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 17 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,8 @@
gatling-sbt gatling-sbt
=========== ===========


A sbt template project for writing [Gatling](https://github.com/excilys/gatling.git) simulations in eclipse A sbt template project for writing [Gatling](https://github.com/excilys/gatling.git) simulations in Eclipse.

Depends on gatiling 1.1.6
sbt 0.11.3
Scala 2.9.2
11 changes: 11 additions & 0 deletions src/main/resources/data/user_credentials.csv
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,11 @@
username,password
user1,password1
user2,password2
user3,password3
user4,password4
user5,password5
user6,password6
user7,password7
user8,password8
user9,password9
user10,password10
11 changes: 11 additions & 0 deletions src/main/resources/data/user_information.csv
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,11 @@
username,password,account_id
user1,password1,4
user2,password2,7
user3,password3,10
user4,password4,13
user5,password5,17
user6,password6,21
user7,password7,23
user8,password8,27
user9,password9,29
user10,password10,34
2 changes: 0 additions & 2 deletions src/main/scala/Engine.scala
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import com.excilys.ebi.gatling.core.util.PathHelper.path2string


object Engine extends App { object Engine extends App {


println(IDEPathHelper.mavenBinariesDir)

new Gatling(Options( new Gatling(Options(
dataFolder = Some(IDEPathHelper.dataFolder), dataFolder = Some(IDEPathHelper.dataFolder),
resultsFolder = Some(IDEPathHelper.resultsFolder), resultsFolder = Some(IDEPathHelper.resultsFolder),
Expand Down
122 changes: 118 additions & 4 deletions src/main/scala/FooSimulation.scala
Original file line number Original file line Diff line number Diff line change
@@ -1,9 +1,123 @@
import com.excilys.ebi.gatling.core.Predef.Simulation package basic


class FooSimulation extends Simulation { import com.excilys.ebi.gatling.core.Predef._
import com.excilys.ebi.gatling.http.Predef._

class BasicExampleSimulation extends Simulation {


def apply = { def apply = {
// This is where your simulation should be coded
List() val urlBase = "http://excilys-bank-web.cloudfoundry.com"

val httpConf = httpConfig.baseURL(urlBase)

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")

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",
"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")

val headers_7 = headers_1 ++ Map(
"Referer" -> "http://excilys-bank-web.cloudfoundry.com/private/bank/account/ACC4/operations.html")

val headers_8 = 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)
.exec(
http("request_2")
.get("/public/login.html")
.headers(headers_1))
.pause(12, 13)
.feed(csv("user_information.csv"))
.exec(
http("request_3")
.post("/login")
.param("username", "${username}")
.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))
.pause(7, 8)
.exec(
http("request_5")
.get("/private/bank/account/ACC${account_id}/operations.html")
.headers(headers_5))
.pause(100, 200, MILLISECONDS)
.exec(
http("request_6")
.get("/private/bank/account/ACC${account_id}/year/2011/month/12/page/0/operations.json")
.headers(headers_6))
.pause(4, 5)
.exec(
http("request_7")
.get("/private/bank/account/ACC${account_id}/year/2011/month/11/operations.html")
.headers(headers_7))
.pause(100, 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(
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))

List(scn.configure.users(10).ramp(10).protocolConfig(httpConf))
} }
} }
21 changes: 11 additions & 10 deletions src/main/scala/IDEPathHelper.scala
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ import scala.tools.nsc.io.Path
object IDEPathHelper { object IDEPathHelper {


val gatlingConfUrl = getClass.getClassLoader.getResource("gatling.conf").getPath val gatlingConfUrl = getClass.getClassLoader.getResource("gatling.conf").getPath
val projectRootDir = File(gatlingConfUrl).parents(2) val projectRootDir = File(gatlingConfUrl).parents(0)


val mavenSourcesDir = projectRootDir / "src" / "main" / "scala" val projectSourceDir = File(gatlingConfUrl).parents(3)
val mavenResourcesDir = projectRootDir / "src" / "main" / "resources"
val mavenTargetDir = projectRootDir / "target" val mavenSourcesDir = projectSourceDir / "src" / "main" / "scala"
//val mavenBinariesDir = mavenTargetDir / "classes" val mavenResourcesDir = projectSourceDir / "src" / "main" / "resources"
val mavenTargetDir = projectSourceDir / "target"


val mavenBinariesDir = "/home/logos/Desktop/gatling-sbt/target/scala-2.9.2/classes" val mavenBinariesDir = projectRootDir


val dataFolder = mavenResourcesDir / "data" val dataFolder = projectSourceDir / "userfiles/data"
val requestBodiesFolder = mavenResourcesDir / "request-bodies" val requestBodiesFolder = projectSourceDir / "userfiles/request-bodies"


val recorderOutputFolder = mavenSourcesDir val recorderOutputFolder = mavenSourcesDir
val resultsFolder = mavenTargetDir / "gatling-results" val resultsFolder = projectSourceDir / "results"
} }
11 changes: 11 additions & 0 deletions userfiles/data/user_credentials.csv
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,11 @@
username,password
user1,password1
user2,password2
user3,password3
user4,password4
user5,password5
user6,password6
user7,password7
user8,password8
user9,password9
user10,password10
11 changes: 11 additions & 0 deletions userfiles/data/user_information.csv
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,11 @@
username,password,account_id
user1,password1,4
user2,password2,7
user3,password3,10
user4,password4,13
user5,password5,17
user6,password6,21
user7,password7,23
user8,password8,27
user9,password9,29
user10,password10,34

0 comments on commit 68651b3

Please sign in to comment.