Skip to content

Commit 737848c

Browse files
committed
Gatling load test demo
1 parent 5c8961e commit 737848c

8 files changed

Lines changed: 405 additions & 0 deletions

File tree

‎gatling/pom.xml‎

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>org.baeldung</groupId>
6+
<artifactId>gatling</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
9+
<properties>
10+
<maven.compiler.source>1.8</maven.compiler.source>
11+
<maven.compiler.target>1.8</maven.compiler.target>
12+
<scala.version>2.11.7</scala.version>
13+
<encoding>UTF-8</encoding>
14+
<gatling.version>2.2.0</gatling.version>
15+
<scala-maven-plugin.version>3.2.2</scala-maven-plugin.version>
16+
</properties>
17+
18+
<dependencyManagement>
19+
<dependencies>
20+
<dependency>
21+
<groupId>io.gatling</groupId>
22+
<artifactId>gatling-app</artifactId>
23+
<version>${gatling.version}</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>io.gatling</groupId>
27+
<artifactId>gatling-recorder</artifactId>
28+
<version>${gatling.version}</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>io.gatling.highcharts</groupId>
32+
<artifactId>gatling-charts-highcharts</artifactId>
33+
<version>${gatling.version}</version>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.scala-lang</groupId>
37+
<artifactId>scala-library</artifactId>
38+
<version>${scala.version}</version>
39+
</dependency>
40+
</dependencies>
41+
</dependencyManagement>
42+
43+
<dependencies>
44+
<dependency>
45+
<groupId>io.gatling.highcharts</groupId>
46+
<artifactId>gatling-charts-highcharts</artifactId>
47+
</dependency>
48+
<dependency>
49+
<groupId>io.gatling</groupId>
50+
<artifactId>gatling-app</artifactId>
51+
</dependency>
52+
<dependency>
53+
<groupId>io.gatling</groupId>
54+
<artifactId>gatling-recorder</artifactId>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.scala-lang</groupId>
58+
<artifactId>scala-library</artifactId>
59+
</dependency>
60+
</dependencies>
61+
62+
<build>
63+
<testSourceDirectory>src/test/scala</testSourceDirectory>
64+
<pluginManagement>
65+
<plugins>
66+
<plugin>
67+
<groupId>net.alchim31.maven</groupId>
68+
<artifactId>scala-maven-plugin</artifactId>
69+
<version>${scala-maven-plugin.version}</version>
70+
</plugin>
71+
</plugins>
72+
</pluginManagement>
73+
<plugins>
74+
<plugin>
75+
<groupId>net.alchim31.maven</groupId>
76+
<artifactId>scala-maven-plugin</artifactId>
77+
<executions>
78+
<execution>
79+
<goals>
80+
<goal>testCompile</goal>
81+
</goals>
82+
<configuration>
83+
<args>
84+
<arg>-Ybackend:GenBCode</arg>
85+
<arg>-Ydelambdafy:method</arg>
86+
<arg>-target:jvm-1.8</arg>
87+
<arg>-deprecation</arg>
88+
<arg>-feature</arg>
89+
<arg>-unchecked</arg>
90+
<arg>-language:implicitConversions</arg>
91+
<arg>-language:postfixOps</arg>
92+
</args>
93+
</configuration>
94+
</execution>
95+
</executions>
96+
</plugin>
97+
<plugin>
98+
<groupId>io.gatling</groupId>
99+
<artifactId>gatling-maven-plugin</artifactId>
100+
<version>${gatling.version}</version>
101+
<executions>
102+
<execution>
103+
<phase>test</phase>
104+
<goals><goal>execute</goal></goals>
105+
</execution>
106+
</executions>
107+
</plugin>
108+
</plugins>
109+
</build>
110+
</project>
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#########################
2+
# Gatling Configuration #
3+
#########################
4+
5+
# This file contains all the settings configurable for Gatling with their default values
6+
7+
gatling {
8+
core {
9+
#outputDirectoryBaseName = "" # The prefix for each simulation result folder (then suffixed by the report generation timestamp)
10+
#runDescription = "" # The description for this simulation run, displayed in each report
11+
#encoding = "utf-8" # Encoding to use throughout Gatling for file and string manipulation
12+
#simulationClass = "" # The FQCN of the simulation to run (when used in conjunction with noReports, the simulation for which assertions will be validated)
13+
#mute = false # When set to true, don't ask for simulation name nor run description (currently only used by Gatling SBT plugin)
14+
#elFileBodiesCacheMaxCapacity = 200 # Cache size for request body EL templates, set to 0 to disable
15+
#rawFileBodiesCacheMaxCapacity = 200 # Cache size for request body Raw templates, set to 0 to disable
16+
#rawFileBodiesInMemoryMaxSize = 1000 # Below this limit, raw file bodies will be cached in memory
17+
18+
extract {
19+
regex {
20+
#cacheMaxCapacity = 200 # Cache size for the compiled regexes, set to 0 to disable caching
21+
}
22+
xpath {
23+
#cacheMaxCapacity = 200 # Cache size for the compiled XPath queries, set to 0 to disable caching
24+
}
25+
jsonPath {
26+
#cacheMaxCapacity = 200 # Cache size for the compiled jsonPath queries, set to 0 to disable caching
27+
#preferJackson = false # When set to true, prefer Jackson over Boon for JSON-related operations
28+
}
29+
css {
30+
#cacheMaxCapacity = 200 # Cache size for the compiled CSS selectors queries, set to 0 to disable caching
31+
}
32+
}
33+
34+
directory {
35+
#data = user-files/data # Folder where user's data (e.g. files used by Feeders) is located
36+
#bodies = user-files/bodies # Folder where bodies are located
37+
#simulations = user-files/simulations # Folder where the bundle's simulations are located
38+
#reportsOnly = "" # If set, name of report folder to look for in order to generate its report
39+
#binaries = "" # If set, name of the folder where compiles classes are located: Defaults to GATLING_HOME/target.
40+
#results = results # Name of the folder where all reports folder are located
41+
}
42+
}
43+
charting {
44+
#noReports = false # When set to true, don't generate HTML reports
45+
#maxPlotPerSeries = 1000 # Number of points per graph in Gatling reports
46+
#useGroupDurationMetric = false # Switch group timings from cumulated response time to group duration.
47+
indicators {
48+
#lowerBound = 800 # Lower bound for the requests' response time to track in the reports and the console summary
49+
#higherBound = 1200 # Higher bound for the requests' response time to track in the reports and the console summary
50+
#percentile1 = 50 # Value for the 1st percentile to track in the reports, the console summary and Graphite
51+
#percentile2 = 75 # Value for the 2nd percentile to track in the reports, the console summary and Graphite
52+
#percentile3 = 95 # Value for the 3rd percentile to track in the reports, the console summary and Graphite
53+
#percentile4 = 99 # Value for the 4th percentile to track in the reports, the console summary and Graphite
54+
}
55+
}
56+
http {
57+
#fetchedCssCacheMaxCapacity = 200 # Cache size for CSS parsed content, set to 0 to disable
58+
#fetchedHtmlCacheMaxCapacity = 200 # Cache size for HTML parsed content, set to 0 to disable
59+
#perUserCacheMaxCapacity = 200 # Per virtual user cache size, set to 0 to disable
60+
#warmUpUrl = "http://gatling.io" # The URL to use to warm-up the HTTP stack (blank means disabled)
61+
#enableGA = true # Very light Google Analytics, please support
62+
ssl {
63+
keyStore {
64+
#type = "" # Type of SSLContext's KeyManagers store
65+
#file = "" # Location of SSLContext's KeyManagers store
66+
#password = "" # Password for SSLContext's KeyManagers store
67+
#algorithm = "" # Algorithm used SSLContext's KeyManagers store
68+
}
69+
trustStore {
70+
#type = "" # Type of SSLContext's TrustManagers store
71+
#file = "" # Location of SSLContext's TrustManagers store
72+
#password = "" # Password for SSLContext's TrustManagers store
73+
#algorithm = "" # Algorithm used by SSLContext's TrustManagers store
74+
}
75+
}
76+
ahc {
77+
#keepAlive = true # Allow pooling HTTP connections (keep-alive header automatically added)
78+
#connectTimeout = 60000 # Timeout when establishing a connection
79+
#pooledConnectionIdleTimeout = 60000 # Timeout when a connection stays unused in the pool
80+
#readTimeout = 60000 # Timeout when a used connection stays idle
81+
#maxRetry = 2 # Number of times that a request should be tried again
82+
#requestTimeout = 60000 # Timeout of the requests
83+
#acceptAnyCertificate = true # When set to true, doesn't validate SSL certificates
84+
#httpClientCodecMaxInitialLineLength = 4096 # Maximum length of the initial line of the response (e.g. "HTTP/1.0 200 OK")
85+
#httpClientCodecMaxHeaderSize = 8192 # Maximum size, in bytes, of each request's headers
86+
#httpClientCodecMaxChunkSize = 8192 # Maximum length of the content or each chunk
87+
#webSocketMaxFrameSize = 10240000 # Maximum frame payload size
88+
#sslEnabledProtocols = [TLSv1.2, TLSv1.1, TLSv1] # Array of enabled protocols for HTTPS, if empty use the JDK defaults
89+
#sslEnabledCipherSuites = [] # Array of enabled cipher suites for HTTPS, if empty use the JDK defaults
90+
#sslSessionCacheSize = 0 # SSLSession cache size, set to 0 to use JDK's default
91+
#sslSessionTimeout = 0 # SSLSession timeout in seconds, set to 0 to use JDK's default (24h)
92+
#useOpenSsl = false # if OpenSSL should be used instead of JSSE (requires tcnative jar)
93+
#useNativeTransport = false # if native transport should be used instead of Java NIO (requires netty-transport-native-epoll, currently Linux only)
94+
#usePooledMemory = true # if Gatling should use pooled memory
95+
#tcpNoDelay = true
96+
#soReuseAddress = false
97+
#soLinger = -1
98+
#soSndBuf = -1
99+
#soRcvBuf = -1
100+
}
101+
dns {
102+
#queryTimeout = 5000 # Timeout of each DNS query in millis
103+
#maxQueriesPerResolve = 3 # Maximum allowed number of DNS queries for a given name resolution
104+
}
105+
}
106+
data {
107+
#writers = [console, file] # The list of DataWriters to which Gatling write simulation data (currently supported : console, file, graphite, jdbc)
108+
console {
109+
#light = false # When set to true, displays a light version without detailed request stats
110+
}
111+
file {
112+
#bufferSize = 8192 # FileDataWriter's internal data buffer size, in bytes
113+
}
114+
leak {
115+
#noActivityTimeout = 30 # Period, in seconds, for which Gatling may have no activity before considering a leak may be happening
116+
}
117+
graphite {
118+
#light = false # only send the all* stats
119+
#host = "localhost" # The host where the Carbon server is located
120+
#port = 2003 # The port to which the Carbon server listens to (2003 is default for plaintext, 2004 is default for pickle)
121+
#protocol = "tcp" # The protocol used to send data to Carbon (currently supported : "tcp", "udp")
122+
#rootPathPrefix = "gatling" # The common prefix of all metrics sent to Graphite
123+
#bufferSize = 8192 # GraphiteDataWriter's internal data buffer size, in bytes
124+
#writeInterval = 1 # GraphiteDataWriter's write interval, in seconds
125+
}
126+
}
127+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
4+
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
5+
<encoder>
6+
<pattern>%d{HH:mm:ss.SSS} [%-5level] %logger{15} - %msg%n%rEx</pattern>
7+
<immediateFlush>false</immediateFlush>
8+
</encoder>
9+
</appender>
10+
11+
<!-- Uncomment for logging ALL HTTP request and responses -->
12+
<!-- <logger name="io.gatling.http.ahc" level="TRACE" /> -->
13+
<!-- <logger name="io.gatling.http.response" level="TRACE" /> -->
14+
<!-- Uncomment for logging ONLY FAILED HTTP request and responses -->
15+
<!-- <logger name="io.gatling.http.ahc" level="DEBUG" /> -->
16+
<!-- <logger name="io.gatling.http.response" level="DEBUG" /> -->
17+
18+
<root level="WARN">
19+
<appender-ref ref="CONSOLE" />
20+
</root>
21+
22+
</configuration>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
recorder {
2+
core {
3+
#mode = "Proxy"
4+
#encoding = "utf-8" # The encoding used for reading/writing request bodies and the generated simulation
5+
#outputFolder = "" # The folder where generated simulation will we written
6+
#package = "" # The package's name of the generated simulation
7+
#className = "RecordedSimulation" # The name of the generated Simulation class
8+
#thresholdForPauseCreation = 100 # The minimum time, in milliseconds, that must pass between requests to trigger a pause creation
9+
#saveConfig = false # When set to true, the configuration from the Recorder GUI overwrites this configuration
10+
#headless = false # When set to true, run the Recorder in headless mode instead of the GUI
11+
#harFilePath = "" # The path of the HAR file to convert
12+
}
13+
filters {
14+
#filterStrategy = "Disabled" # The selected filter resources filter strategy (currently supported : "Disabled", "BlackList", "WhiteList")
15+
#whitelist = [] # The list of ressources patterns that are part of the Recorder's whitelist
16+
#blacklist = [] # The list of ressources patterns that are part of the Recorder's blacklist
17+
}
18+
http {
19+
#automaticReferer = true # When set to false, write the referer + enable 'disableAutoReferer' in the generated simulation
20+
#followRedirect = true # When set to false, write redirect requests + enable 'disableFollowRedirect' in the generated simulation
21+
#removeCacheHeaders = true # When set to true, removes from the generated requests headers leading to request caching
22+
#inferHtmlResources = true # When set to true, add inferred resources + set 'inferHtmlResources' with the configured blacklist/whitelist in the generated simulation
23+
#checkResponseBodies = false # When set to true, save response bodies as files and add raw checks in the generated simulation
24+
}
25+
proxy {
26+
#port = 8000 # Local port used by Gatling's Proxy for HTTP/HTTPS
27+
https {
28+
#mode = "SelfSignedCertificate" # The selected "HTTPS mode" (currently supported : "SelfSignedCertificate", "ProvidedKeyStore", "GatlingCertificateAuthority", "CustomCertificateAuthority")
29+
keyStore {
30+
#path = "" # The path of the custom key store
31+
#password = "" # The password for this key store
32+
#type = "JKS" # The type of the key store (currently supported: "JKS")
33+
}
34+
certificateAuthority {
35+
#certificatePath = "" # The path of the custom certificate
36+
#privateKeyPath = "" # The certificate's private key path
37+
}
38+
}
39+
outgoing {
40+
#host = "" # The outgoing proxy's hostname
41+
#username = "" # The username to use to connect to the outgoing proxy
42+
#password = "" # The password corresponding to the user to use to connect to the outgoing proxy
43+
#port = 0 # The HTTP port to use to connect to the outgoing proxy
44+
#sslPort = 0 # If set, The HTTPS port to use to connect to the outgoing proxy
45+
}
46+
}
47+
netty {
48+
#maxInitialLineLength = 10000 # Maximum length of the initial line of the response (e.g. "HTTP/1.0 200 OK")
49+
#maxHeaderSize = 20000 # Maximum size, in bytes, of each request's headers
50+
#maxChunkSize = 8192 # Maximum length of the content or each chunk
51+
#maxContentLength = 100000000 # Maximum length of the aggregated content of each response
52+
}
53+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import io.gatling.app.Gatling
2+
import io.gatling.core.config.GatlingPropertiesBuilder
3+
4+
object Engine extends App {
5+
6+
val props = new GatlingPropertiesBuilder
7+
props.dataDirectory(IDEPathHelper.dataDirectory.toString)
8+
props.resultsDirectory(IDEPathHelper.resultsDirectory.toString)
9+
props.bodiesDirectory(IDEPathHelper.bodiesDirectory.toString)
10+
props.binariesDirectory(IDEPathHelper.mavenBinariesDirectory.toString)
11+
12+
Gatling.fromMap(props.build)
13+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import java.nio.file.Path
2+
3+
import io.gatling.commons.util.PathHelper._
4+
5+
object IDEPathHelper {
6+
7+
val gatlingConfUrl: Path = getClass.getClassLoader.getResource("gatling.conf").toURI
8+
val projectRootDir = gatlingConfUrl.ancestor(3)
9+
10+
val mavenSourcesDirectory = projectRootDir / "src" / "test" / "scala"
11+
val mavenResourcesDirectory = projectRootDir / "src" / "test" / "resources"
12+
val mavenTargetDirectory = projectRootDir / "target"
13+
val mavenBinariesDirectory = mavenTargetDirectory / "test-classes"
14+
15+
val dataDirectory = mavenResourcesDirectory / "data"
16+
val bodiesDirectory = mavenResourcesDirectory / "bodies"
17+
18+
val recorderOutputDirectory = mavenSourcesDirectory
19+
val resultsDirectory = mavenTargetDirectory / "gatling"
20+
21+
val recorderConfigFile = mavenResourcesDirectory / "recorder.conf"
22+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import io.gatling.recorder.GatlingRecorder
2+
import io.gatling.recorder.config.RecorderPropertiesBuilder
3+
4+
object Recorder extends App {
5+
6+
val props = new RecorderPropertiesBuilder
7+
props.simulationOutputFolder(IDEPathHelper.recorderOutputDirectory.toString)
8+
props.simulationPackage("org.baeldung")
9+
props.bodiesFolder(IDEPathHelper.bodiesDirectory.toString)
10+
11+
GatlingRecorder.fromMap(props.build, Some(IDEPathHelper.recorderConfigFile))
12+
}

0 commit comments

Comments
 (0)