SlideShare a Scribd company logo
© Gatling 2015.All rights reserved.
Requirements
Background in programming
1. Object oriented language mostly
2. Functional programming is a plus, but optional
Experience
1. Gatling?
2. Scala?
1
© Gatling 2015.All rights reserved.
LoadTesting Done Right
http://gatling.io
Guillaume Corré
@notdryft
2
© Gatling 2015.All rights reserved.
Workshop Schedule
1. Architecture
2. Usage
3. Exercises
3
© Gatling 2015.All rights reserved.
Workshop Schedule
1. Architecture
2. Usage
3. Exercises
4
© Gatling 2015.All rights reserved.
Gatling:Architecture
Designed for:
1. Complex use cases
2. High Performance
3. Maintainability
5
© Gatling 2015.All rights reserved.
Gatling:Architecture
High Performance
Optimize thread usage:
1. Non Blocking IO
2. Message oriented orchestration
6
© Gatling 2015.All rights reserved.
Gatling:Architecture
High Performance
7
© Gatling 2015.All rights reserved.
Gatling:Architecture
Maintainability
Code
1. Real programming language
2. DSL
3. API
8
© Gatling 2015.All rights reserved.
Gatling:Architecture
Maintainability
Why?
1. Versioning
2. Refactoring
3. Peer review
4. Composition
9
© Gatling 2015.All rights reserved.
Gatling:Architecture
Maintainability
10
class Simple extends Simulation {
val scn = scenario("simple")
.exec(
http("home")
.get("http://gatling.io")
.check(status.is(200)))
setUp(
scn.inject(
atOnceUsers(1)))
}
© Gatling 2015.All rights reserved.
Workshop Schedule
1. Architecture
2. Usage
3. Exercises
11
© Gatling 2015.All rights reserved.
Gatling: Usage
12
© Gatling 2015.All rights reserved.
Usage: DSL
Extensive documentation:
http://gatling.io/#/docs
Cheat-sheet:
http://gatling.io/docs/2.1.7/cheat-sheet.html
13
© Gatling 2015.All rights reserved.
Usage:Very Fast Track
Step 1: Create a Simulation class
14
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
class Simple extends Simulation {
}
© Gatling 2015.All rights reserved.
Usage:Very Fast Track
Step 2: Create a Scenario
15
import …
class Simple extends Simulation {
val scn = scenario("simple")
}
© Gatling 2015.All rights reserved.
Usage:Very Fast Track
Step 3: Chain Actions
16
import …
class Simple extends Simulation {
val scn = scenario("simple")
.exec(
http("home")
.get("http://gatling.io"))
}
© Gatling 2015.All rights reserved.
Usage:Very Fast Track
Step 4: Check your requests are fine
17
import …
class Simple extends Simulation {
val scn = scenario("simple")
.exec(
http("home")
.get("http://gatling.io")
.check(status.is(200))
}
© Gatling 2015.All rights reserved.
Usage:Very Fast Track
Step 5: Set up and inject users
18
import …
class Simple extends Simulation {
val scn = scenario("simple")
.exec(
http("home")
.get("http://gatling.io")
.check(status.is(200))
setUp(scn.inject(atOnceUsers(1)))
}
© Gatling 2015.All rights reserved.
Usage:Very Fast Track
Step 6: Make things dynamic
19
// Set up virtual users with feeders
feed(csv("credentials.csv"))
© Gatling 2015.All rights reserved.
Usage:Very Fast Track
Step 6: Make things dynamic
20
// Capture response data with checks
http("request")
.get("url")
.check(css("someSelector").saveAs("someVariable"))
© Gatling 2015.All rights reserved.
Usage:Very Fast Track
Step 6: Make things dynamic
21
// Craft requests with the Expression Language
http("request")
.get("/foo?bar=${someVariable}")
© Gatling 2015.All rights reserved.
Usage:Very Fast Track
Step 6: Make things dynamic
22
// Use functions
exec { session =>
println(session)
session
}
© Gatling 2015.All rights reserved.
Usage:Very Fast Track
Expressions
23
type Expression[T] = Session => Validation[T]
© Gatling 2015.All rights reserved.
Workshop Schedule
1. Architecture
2. Usage
3. Exercises
24
© Gatling 2015.All rights reserved.
Workshop
4 exercises
1. Ranged from (almost) easy to difficult
2. Each pinpoint different specifics of Gatling
Url
bit.ly/gatling-workshop
Documentation reminder
http://gatling.io/#/docs
http://gatling.io/docs/2.1.7/cheat-sheet.html
25
© Gatling 2015.All rights reserved.
Exercise 1:
1. First Request
What happens if you don't do any checks?
1. Gatling adds a status check by default
26
© Gatling 2015.All rights reserved.
Exercise 1:
1. First Request
Are there any defaults? If so, which?
1. status.in
2. All statuses of the 20x family
3. 304
27
© Gatling 2015.All rights reserved.
Exercise 1:
3. Checks
Which check should you use to fetch the title ?
1. Regex
1. Most the time harder to maintain
2. Still does the job pretty well
2. XPath
1. HTML needs to be strict and well formed
3. CSS is easy to read and fast
1. css("#logo-section a", "title")
28
© Gatling 2015.All rights reserved.
Exercise 1:
3. Checks
What happens when a check matches more than a
single element?
1. exists by default
2. And, if you don’t specify a fetch method but try to save,
Gatling will add a find(0) before saveAs
29
© Gatling 2015.All rights reserved.
Exercise 1:
4. Information retrieval
30
Which check should you use to fetch the menu links ?
1. css("#main-menu-inner > ul > li > a", "href")
© Gatling 2015.All rights reserved.
Exercise 1:
4. Information retrieval
How can you save all matches?
1. findAll
31
© Gatling 2015.All rights reserved.
Exercise 1:
4. Information retrieval
How can you access the “menuLinks” attribute?
1. Use the exec { session => … } syntax
2. session(“menuLinks”) for extraction
3. Then, either
1. as[Type]
2. asOption[Type]
3. validate[Type]
4. Validate recommended unless you know what you are
doing
32
© Gatling 2015.All rights reserved.
Exercise 1:
4. Iterate over menu links
Which DSL element should you use?
1. foreach
2. Takes an Expression[String] as its first argument
1. Which is a function of Session toValidation[String]
3. Gatling does the EL conversion for you
33
© Gatling 2015.All rights reserved.
Exercise 1:
4. Iterate over menu links
How do think it works behind the hood?
1. Iterate over each element
2. Put current element into the session as an attribute
3. Run the action block with the new session
34
© Gatling 2015.All rights reserved.
Exercise 2:
1. Fetch the login page
Which baseURL should you use?
1. Gatling doesn’t add a / before concatenating
2. One of the following
1. baseURL(“https://github.com”) and get(“/login”)
2. baseURL(“https://github.com/“) and get(“login”)
3. Prefer the first one
35
© Gatling 2015.All rights reserved.
Exercise 2:
1. Fetch the login page
Which check should you use?
1. The general idea is to make sure you are on the page you
requested
2. css(".auth-form form h1").is("Sign in")
36
© Gatling 2015.All rights reserved.
Exercise 2:
2.1. Performing the login
Which request should you do?
1. /session
Which HTTP method does it need to use?
2. POST
37
© Gatling 2015.All rights reserved.
Exercise 2:
2.2. Specifying additional parameters
Do you think these are generated or provided?
1. Generated by Github, provided in the HTML.
Where can you fetch thoses?
2. Add a check to the previous request
3. css(".auth-form form input[name='authenticity_token']",
“value").saveAs("authenticityToken")
38
© Gatling 2015.All rights reserved.
Exercise 2:
3. Checks
Which checks should you use to be sure you are
logged in?
1. Check for content, titles, css, etc.
2. css(“.logged_in”)
3. exists is a default
39
© Gatling 2015.All rights reserved.
Exercise 2:
4. Feeding the credentials
Which feeder file format could you use?
1. Multiple formats are handled by Gatling
1. CSV,TSV, etc.
2. Just beware of malformed files
40
© Gatling 2015.All rights reserved.
Exercise 2:
4. Feeding the credentials
How does the session interact with the feeder?
1. A feeder outputs lines of CSV (and else) files into the
session
2. One line per user, with different methods of retrieval
1. Queue, failure when reading is over
2. Random
3. Shuffle, which is a shuffle + queue
4. Circular
3. If you want more, you can skip the feeding to Gatling and
fetch the records yourself
41
© Gatling 2015.All rights reserved.
Exercise 3:
1. Create gist
Think of multiple ways to load the templates
1. StringBody
2. RawFileBody
3. ELFileBody, with parsed content
42
© Gatling 2015.All rights reserved.
Exercise 3:
1. Create gist
Which one is better in this case?
1. All are good
2. Still, scala can handle string template pretty well
3. => StringBody
43
© Gatling 2015.All rights reserved.
Exercise 4:
Part 1. 1. Start simple
Is using java.util.Random a good idea in this case?
What could happen if you do?
1. Random is synchronized
2. Multiples threads would block each other when fetching
3. ThreadLocalRandom is not
4. It creates a single Random for eachThread, resolving
conflicts
44
© Gatling 2015.All rights reserved.
Exercise 4:
Part 1. 4.A twist
How does Gatling execute requests?
1. Each requests are launched in sequence
2. They cannot overlap
3. And cannot be launched asynchronously
How should we proceed instead?
45
© Gatling 2015.All rights reserved.
Exercise 4:
Part 1. 4.A twist
How does Gatling execute requests?
1. Each requests are launched in sequence
2. They cannot overlap
3. And cannot be launched asynchronously
How should we proceed instead?
4. We can use the resources mechanism
5. Not its purpose, but it will work
46
© Gatling 2015.All rights reserved.
Exercise 4:
Part 1I. 2. Making the queries
Is the number of tiles requested really fixed?
1. What about edges ?
2. Will reduce the number of tiles
3. We can reduce the bounds, excluding the edges
47
© Gatling 2015.All rights reserved.
Exercise 4:
Part 1I. 2. Making the queries
Mixing Gatling’s EL and Scala’s String Macro
1. This a Gatling EL:“${variableName}”
2. Theses are Scala Macros:
1. s”$variableName”
2. s”${variableName}
How?
48
© Gatling 2015.All rights reserved.
Exercise 4:
Part 1I. 2. Making the queries
Mixing Gatling’s EL and Scala’s String Macro
1. This a Gatling EL:“${variableName}”
2. Theses are Scala Macros:
1. s”$variableName”
2. s”${variableName}
How?
1. Escape Gatling’s EL when in a Scala String Macro
1. s”$${gatlingVariable}/${otherVariable}”
2. will output “${gatlingVariable}/variableContent”
49
© Gatling 2015.All rights reserved.
Workshop
Solutions
1. Not available yet
Url
bit.ly/gatling-workshop-solutions
50
© Gatling 2015.All rights reserved.
© Gatling 2015.All rights reserved.
http://gatling.io
http://github.com/gatling/gatling
@GatlingTool

More Related Content

PDF
Gatling - Bordeaux JUG
ODP
Performance Test Automation With Gatling
PDF
Gatling workshop lets test17
PPTX
ODP
Boost your App with Gatling
PDF
Hands On, Duchess 10/17/2012
ODP
Gatling
PDF
Three Lessons about Gatling and Microservices
Gatling - Bordeaux JUG
Performance Test Automation With Gatling
Gatling workshop lets test17
Boost your App with Gatling
Hands On, Duchess 10/17/2012
Gatling
Three Lessons about Gatling and Microservices

What's hot (20)

PPTX
Gatling overview
PPTX
Gatling Tool in Action at Devoxx 2012
PDF
Gatling Performance Workshop
PDF
Continuous performance: Load testing for developers with gatling @ JavaOne 2016
PDF
Continuous performance: Load testing for developers with gatling
PDF
Load test REST APIs using gatling
PPTX
Open Source Load Testing: JMeter, Gatling and Taurus
PDF
100 tests per second - 40 releases per week
PPTX
JavaScript Metaprogramming with ES 2015 Proxy
PDF
How to go about testing in React?
PDF
[FullStack NYC 2019] Effective Unit Tests for JavaScript
PDF
Understanding Reactive Programming
PDF
Continuous performance management with Gatling
PPTX
Testing in Scala. Adform Research
PPTX
Migration from AngularJS to Angular
PDF
prohuddle-utPLSQL v3 - Ultimate unit testing framework for Oracle
ODP
Apache JMeter Introduction
PPTX
The new React
PPTX
J meter understanding
PDF
Effective java item 80 prefer executors, tasks, and streams to threads
Gatling overview
Gatling Tool in Action at Devoxx 2012
Gatling Performance Workshop
Continuous performance: Load testing for developers with gatling @ JavaOne 2016
Continuous performance: Load testing for developers with gatling
Load test REST APIs using gatling
Open Source Load Testing: JMeter, Gatling and Taurus
100 tests per second - 40 releases per week
JavaScript Metaprogramming with ES 2015 Proxy
How to go about testing in React?
[FullStack NYC 2019] Effective Unit Tests for JavaScript
Understanding Reactive Programming
Continuous performance management with Gatling
Testing in Scala. Adform Research
Migration from AngularJS to Angular
prohuddle-utPLSQL v3 - Ultimate unit testing framework for Oracle
Apache JMeter Introduction
The new React
J meter understanding
Effective java item 80 prefer executors, tasks, and streams to threads
Ad

Viewers also liked (9)

PDF
Las palmas devops: Pruebas de carga web
PDF
TYPO3 Camp Stuttgart 2015 - Continuous Delivery with Open Source Tools
PDF
Automated Testing Talk from Meet Magento New York 2014
PPTX
Gatling Tool in Action at DevoxxFR 2012
PDF
Démo Gatling au Performance User Group de Casablanca - 25 sept 2014
PDF
DSLing your System For Scalability Testing Using Gatling - Dublin Scala User ...
PDF
はじめての Gatling
PPTX
Customer Scale: Stateless Sessions and Managing High-Volume Digital Services
PDF
アドテク×Scala×パフォーマンスチューニング
Las palmas devops: Pruebas de carga web
TYPO3 Camp Stuttgart 2015 - Continuous Delivery with Open Source Tools
Automated Testing Talk from Meet Magento New York 2014
Gatling Tool in Action at DevoxxFR 2012
Démo Gatling au Performance User Group de Casablanca - 25 sept 2014
DSLing your System For Scalability Testing Using Gatling - Dublin Scala User ...
はじめての Gatling
Customer Scale: Stateless Sessions and Managing High-Volume Digital Services
アドテク×Scala×パフォーマンスチューニング
Ad

Similar to TestWorks Conf Performance testing made easy with gatling - Guillaume Corré (20)

PDF
Load testing in Zonky with Gatling
PDF
API Performance testing with Gatling
PDF
Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Confer...
PPTX
EPAM AQA: Let`s make a (s)hot with gatling 3.0+
PDF
Gatling - JUGL, 2012-09-13
PPTX
Stress test your backend with Gatling
PPTX
Stress test data pipeline
PDF
JDD 2017: Performance tests with Gatling (Andrzej Ludwikowski)
PDF
Gatling.pptx
PDF
Performance tests with Gatling (extended)
PPTX
Gatling
PDF
Gatling - Paris Perf User Group
PDF
Gatling @ Scala.Io 2013
PDF
Performance tests with gatling
ODP
Gatling - Stress test tool
PDF
GatlingJAX2022.pdf
PPT
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
PDF
Cool Jvm Tools to Help you Test - Aylesbury Testers Version
PDF
"Scala in Goozy", Alexey Zlobin
PPTX
Gatling and Page Object: a way to performance testing
Load testing in Zonky with Gatling
API Performance testing with Gatling
Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Confer...
EPAM AQA: Let`s make a (s)hot with gatling 3.0+
Gatling - JUGL, 2012-09-13
Stress test your backend with Gatling
Stress test data pipeline
JDD 2017: Performance tests with Gatling (Andrzej Ludwikowski)
Gatling.pptx
Performance tests with Gatling (extended)
Gatling
Gatling - Paris Perf User Group
Gatling @ Scala.Io 2013
Performance tests with gatling
Gatling - Stress test tool
GatlingJAX2022.pdf
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
Cool Jvm Tools to Help you Test - Aylesbury Testers Version
"Scala in Goozy", Alexey Zlobin
Gatling and Page Object: a way to performance testing

More from Xebia Nederland BV (20)

PDF
The 10 tip recipe for business model innovation
PDF
Scan je teams!
PDF
Holacracy: een nieuwe bodem voor de Scrum taart
PDF
3* Scrum Master
PDF
Judo Strategy
PDF
Agile en Scrum buiten IT
PDF
PDF
Creating the right products
PDF
Videoscribe je agile transitie
PDF
Sketchnote je Product Backlog Items & Sprint Retrospectives
PDF
Why we need test automation, but it’s not the right question
PDF
Testen in de transitie naar continuous delivery
PPTX
Becoming an agile enterprise, focus on the test ingredient
PDF
How DUO started with Continuous Delivery and changed their way of Testing
PDF
Become a digital company - Case KPN / Xebia
PDF
Building a Docker powered feature driven delivery pipeline at hoyhoy.nl
PPTX
Webinar Xebia & bol.com
PDF
TestWorks Conf The magic of models for 1000% test automation - Machiel van de...
PDF
TestWorks Conf Serenity BDD in action - John Ferguson Smart
PDF
TestWorks Conf Scalable QA with docker - Maarten van den Ende and Adé Mochtar
The 10 tip recipe for business model innovation
Scan je teams!
Holacracy: een nieuwe bodem voor de Scrum taart
3* Scrum Master
Judo Strategy
Agile en Scrum buiten IT
Creating the right products
Videoscribe je agile transitie
Sketchnote je Product Backlog Items & Sprint Retrospectives
Why we need test automation, but it’s not the right question
Testen in de transitie naar continuous delivery
Becoming an agile enterprise, focus on the test ingredient
How DUO started with Continuous Delivery and changed their way of Testing
Become a digital company - Case KPN / Xebia
Building a Docker powered feature driven delivery pipeline at hoyhoy.nl
Webinar Xebia & bol.com
TestWorks Conf The magic of models for 1000% test automation - Machiel van de...
TestWorks Conf Serenity BDD in action - John Ferguson Smart
TestWorks Conf Scalable QA with docker - Maarten van den Ende and Adé Mochtar

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Approach and Philosophy of On baking technology
PDF
KodekX | Application Modernization Development
PPTX
Big Data Technologies - Introduction.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPT
Teaching material agriculture food technology
Building Integrated photovoltaic BIPV_UPV.pdf
A Presentation on Artificial Intelligence
Review of recent advances in non-invasive hemoglobin estimation
Understanding_Digital_Forensics_Presentation.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Reach Out and Touch Someone: Haptics and Empathic Computing
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Diabetes mellitus diagnosis method based random forest with bat algorithm
NewMind AI Monthly Chronicles - July 2025
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Dropbox Q2 2025 Financial Results & Investor Presentation
Approach and Philosophy of On baking technology
KodekX | Application Modernization Development
Big Data Technologies - Introduction.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Encapsulation_ Review paper, used for researhc scholars
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Teaching material agriculture food technology

TestWorks Conf Performance testing made easy with gatling - Guillaume Corré

  • 1. © Gatling 2015.All rights reserved. Requirements Background in programming 1. Object oriented language mostly 2. Functional programming is a plus, but optional Experience 1. Gatling? 2. Scala? 1
  • 2. © Gatling 2015.All rights reserved. LoadTesting Done Right http://gatling.io Guillaume Corré @notdryft 2
  • 3. © Gatling 2015.All rights reserved. Workshop Schedule 1. Architecture 2. Usage 3. Exercises 3
  • 4. © Gatling 2015.All rights reserved. Workshop Schedule 1. Architecture 2. Usage 3. Exercises 4
  • 5. © Gatling 2015.All rights reserved. Gatling:Architecture Designed for: 1. Complex use cases 2. High Performance 3. Maintainability 5
  • 6. © Gatling 2015.All rights reserved. Gatling:Architecture High Performance Optimize thread usage: 1. Non Blocking IO 2. Message oriented orchestration 6
  • 7. © Gatling 2015.All rights reserved. Gatling:Architecture High Performance 7
  • 8. © Gatling 2015.All rights reserved. Gatling:Architecture Maintainability Code 1. Real programming language 2. DSL 3. API 8
  • 9. © Gatling 2015.All rights reserved. Gatling:Architecture Maintainability Why? 1. Versioning 2. Refactoring 3. Peer review 4. Composition 9
  • 10. © Gatling 2015.All rights reserved. Gatling:Architecture Maintainability 10 class Simple extends Simulation { val scn = scenario("simple") .exec( http("home") .get("http://gatling.io") .check(status.is(200))) setUp( scn.inject( atOnceUsers(1))) }
  • 11. © Gatling 2015.All rights reserved. Workshop Schedule 1. Architecture 2. Usage 3. Exercises 11
  • 12. © Gatling 2015.All rights reserved. Gatling: Usage 12
  • 13. © Gatling 2015.All rights reserved. Usage: DSL Extensive documentation: http://gatling.io/#/docs Cheat-sheet: http://gatling.io/docs/2.1.7/cheat-sheet.html 13
  • 14. © Gatling 2015.All rights reserved. Usage:Very Fast Track Step 1: Create a Simulation class 14 import io.gatling.core.Predef._ import io.gatling.http.Predef._ import scala.concurrent.duration._ class Simple extends Simulation { }
  • 15. © Gatling 2015.All rights reserved. Usage:Very Fast Track Step 2: Create a Scenario 15 import … class Simple extends Simulation { val scn = scenario("simple") }
  • 16. © Gatling 2015.All rights reserved. Usage:Very Fast Track Step 3: Chain Actions 16 import … class Simple extends Simulation { val scn = scenario("simple") .exec( http("home") .get("http://gatling.io")) }
  • 17. © Gatling 2015.All rights reserved. Usage:Very Fast Track Step 4: Check your requests are fine 17 import … class Simple extends Simulation { val scn = scenario("simple") .exec( http("home") .get("http://gatling.io") .check(status.is(200)) }
  • 18. © Gatling 2015.All rights reserved. Usage:Very Fast Track Step 5: Set up and inject users 18 import … class Simple extends Simulation { val scn = scenario("simple") .exec( http("home") .get("http://gatling.io") .check(status.is(200)) setUp(scn.inject(atOnceUsers(1))) }
  • 19. © Gatling 2015.All rights reserved. Usage:Very Fast Track Step 6: Make things dynamic 19 // Set up virtual users with feeders feed(csv("credentials.csv"))
  • 20. © Gatling 2015.All rights reserved. Usage:Very Fast Track Step 6: Make things dynamic 20 // Capture response data with checks http("request") .get("url") .check(css("someSelector").saveAs("someVariable"))
  • 21. © Gatling 2015.All rights reserved. Usage:Very Fast Track Step 6: Make things dynamic 21 // Craft requests with the Expression Language http("request") .get("/foo?bar=${someVariable}")
  • 22. © Gatling 2015.All rights reserved. Usage:Very Fast Track Step 6: Make things dynamic 22 // Use functions exec { session => println(session) session }
  • 23. © Gatling 2015.All rights reserved. Usage:Very Fast Track Expressions 23 type Expression[T] = Session => Validation[T]
  • 24. © Gatling 2015.All rights reserved. Workshop Schedule 1. Architecture 2. Usage 3. Exercises 24
  • 25. © Gatling 2015.All rights reserved. Workshop 4 exercises 1. Ranged from (almost) easy to difficult 2. Each pinpoint different specifics of Gatling Url bit.ly/gatling-workshop Documentation reminder http://gatling.io/#/docs http://gatling.io/docs/2.1.7/cheat-sheet.html 25
  • 26. © Gatling 2015.All rights reserved. Exercise 1: 1. First Request What happens if you don't do any checks? 1. Gatling adds a status check by default 26
  • 27. © Gatling 2015.All rights reserved. Exercise 1: 1. First Request Are there any defaults? If so, which? 1. status.in 2. All statuses of the 20x family 3. 304 27
  • 28. © Gatling 2015.All rights reserved. Exercise 1: 3. Checks Which check should you use to fetch the title ? 1. Regex 1. Most the time harder to maintain 2. Still does the job pretty well 2. XPath 1. HTML needs to be strict and well formed 3. CSS is easy to read and fast 1. css("#logo-section a", "title") 28
  • 29. © Gatling 2015.All rights reserved. Exercise 1: 3. Checks What happens when a check matches more than a single element? 1. exists by default 2. And, if you don’t specify a fetch method but try to save, Gatling will add a find(0) before saveAs 29
  • 30. © Gatling 2015.All rights reserved. Exercise 1: 4. Information retrieval 30 Which check should you use to fetch the menu links ? 1. css("#main-menu-inner > ul > li > a", "href")
  • 31. © Gatling 2015.All rights reserved. Exercise 1: 4. Information retrieval How can you save all matches? 1. findAll 31
  • 32. © Gatling 2015.All rights reserved. Exercise 1: 4. Information retrieval How can you access the “menuLinks” attribute? 1. Use the exec { session => … } syntax 2. session(“menuLinks”) for extraction 3. Then, either 1. as[Type] 2. asOption[Type] 3. validate[Type] 4. Validate recommended unless you know what you are doing 32
  • 33. © Gatling 2015.All rights reserved. Exercise 1: 4. Iterate over menu links Which DSL element should you use? 1. foreach 2. Takes an Expression[String] as its first argument 1. Which is a function of Session toValidation[String] 3. Gatling does the EL conversion for you 33
  • 34. © Gatling 2015.All rights reserved. Exercise 1: 4. Iterate over menu links How do think it works behind the hood? 1. Iterate over each element 2. Put current element into the session as an attribute 3. Run the action block with the new session 34
  • 35. © Gatling 2015.All rights reserved. Exercise 2: 1. Fetch the login page Which baseURL should you use? 1. Gatling doesn’t add a / before concatenating 2. One of the following 1. baseURL(“https://github.com”) and get(“/login”) 2. baseURL(“https://github.com/“) and get(“login”) 3. Prefer the first one 35
  • 36. © Gatling 2015.All rights reserved. Exercise 2: 1. Fetch the login page Which check should you use? 1. The general idea is to make sure you are on the page you requested 2. css(".auth-form form h1").is("Sign in") 36
  • 37. © Gatling 2015.All rights reserved. Exercise 2: 2.1. Performing the login Which request should you do? 1. /session Which HTTP method does it need to use? 2. POST 37
  • 38. © Gatling 2015.All rights reserved. Exercise 2: 2.2. Specifying additional parameters Do you think these are generated or provided? 1. Generated by Github, provided in the HTML. Where can you fetch thoses? 2. Add a check to the previous request 3. css(".auth-form form input[name='authenticity_token']", “value").saveAs("authenticityToken") 38
  • 39. © Gatling 2015.All rights reserved. Exercise 2: 3. Checks Which checks should you use to be sure you are logged in? 1. Check for content, titles, css, etc. 2. css(“.logged_in”) 3. exists is a default 39
  • 40. © Gatling 2015.All rights reserved. Exercise 2: 4. Feeding the credentials Which feeder file format could you use? 1. Multiple formats are handled by Gatling 1. CSV,TSV, etc. 2. Just beware of malformed files 40
  • 41. © Gatling 2015.All rights reserved. Exercise 2: 4. Feeding the credentials How does the session interact with the feeder? 1. A feeder outputs lines of CSV (and else) files into the session 2. One line per user, with different methods of retrieval 1. Queue, failure when reading is over 2. Random 3. Shuffle, which is a shuffle + queue 4. Circular 3. If you want more, you can skip the feeding to Gatling and fetch the records yourself 41
  • 42. © Gatling 2015.All rights reserved. Exercise 3: 1. Create gist Think of multiple ways to load the templates 1. StringBody 2. RawFileBody 3. ELFileBody, with parsed content 42
  • 43. © Gatling 2015.All rights reserved. Exercise 3: 1. Create gist Which one is better in this case? 1. All are good 2. Still, scala can handle string template pretty well 3. => StringBody 43
  • 44. © Gatling 2015.All rights reserved. Exercise 4: Part 1. 1. Start simple Is using java.util.Random a good idea in this case? What could happen if you do? 1. Random is synchronized 2. Multiples threads would block each other when fetching 3. ThreadLocalRandom is not 4. It creates a single Random for eachThread, resolving conflicts 44
  • 45. © Gatling 2015.All rights reserved. Exercise 4: Part 1. 4.A twist How does Gatling execute requests? 1. Each requests are launched in sequence 2. They cannot overlap 3. And cannot be launched asynchronously How should we proceed instead? 45
  • 46. © Gatling 2015.All rights reserved. Exercise 4: Part 1. 4.A twist How does Gatling execute requests? 1. Each requests are launched in sequence 2. They cannot overlap 3. And cannot be launched asynchronously How should we proceed instead? 4. We can use the resources mechanism 5. Not its purpose, but it will work 46
  • 47. © Gatling 2015.All rights reserved. Exercise 4: Part 1I. 2. Making the queries Is the number of tiles requested really fixed? 1. What about edges ? 2. Will reduce the number of tiles 3. We can reduce the bounds, excluding the edges 47
  • 48. © Gatling 2015.All rights reserved. Exercise 4: Part 1I. 2. Making the queries Mixing Gatling’s EL and Scala’s String Macro 1. This a Gatling EL:“${variableName}” 2. Theses are Scala Macros: 1. s”$variableName” 2. s”${variableName} How? 48
  • 49. © Gatling 2015.All rights reserved. Exercise 4: Part 1I. 2. Making the queries Mixing Gatling’s EL and Scala’s String Macro 1. This a Gatling EL:“${variableName}” 2. Theses are Scala Macros: 1. s”$variableName” 2. s”${variableName} How? 1. Escape Gatling’s EL when in a Scala String Macro 1. s”$${gatlingVariable}/${otherVariable}” 2. will output “${gatlingVariable}/variableContent” 49
  • 50. © Gatling 2015.All rights reserved. Workshop Solutions 1. Not available yet Url bit.ly/gatling-workshop-solutions 50
  • 51. © Gatling 2015.All rights reserved.
  • 52. © Gatling 2015.All rights reserved. http://gatling.io http://github.com/gatling/gatling @GatlingTool