Skip to content

Commit

Permalink
Trying to get gatling working
Browse files Browse the repository at this point in the history
  • Loading branch information
cjmalloy committed Mar 27, 2024
1 parent 0f30db8 commit d7a2012
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/gatling.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Gatling Load Test

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '21'

- name: Load Test
run: ./mvnw gatling:test
30 changes: 30 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<start-class>jasper.JasperApplication</start-class>
<argLine>-Djava.security.egd=file:/dev/./urandom -Xmx256m</argLine>
<gatling-maven-plugin.version>4.6.0</gatling-maven-plugin.version>
<gatling.version>3.9.5</gatling.version>
<jhipster-framework.version>7.7.0</jhipster-framework.version>
<lombok.version>1.18.30</lombok.version>
<testcontainers.version>1.19.7</testcontainers.version>
Expand Down Expand Up @@ -363,6 +365,12 @@
<artifactId>postgresql</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.gatling.highcharts</groupId>
<artifactId>gatling-charts-highcharts</artifactId>
<version>${gatling.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit5-api</artifactId>
Expand Down Expand Up @@ -430,6 +438,28 @@
</includes>
</configuration>
</plugin>
<plugin>
<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin</artifactId>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin</artifactId>
<version>${gatling-maven-plugin.version}</version>
<configuration>
<runMultipleSimulations>true</runMultipleSimulations>
<configFolder>${project.basedir}/src/test/gatling/conf</configFolder>
<resourcesFolder>${project.basedir}/src/test/resources/gatling</resourcesFolder>
<simulationsFolder>${project.basedir}src/test/java/simulations/computerdatabase</simulationsFolder>
<includes>
<include>simulations.computerdatabase.ComputerDatabaseSimulation</include>
</includes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package simulations.computerdatabase;

import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.*;

import io.gatling.javaapi.core.*;
import io.gatling.javaapi.http.*;

import java.util.concurrent.ThreadLocalRandom;

/**
* This sample is based on our official tutorials:
* <ul>
* <li><a href="https://gatling.io/docs/gatling/tutorials/quickstart">Gatling quickstart tutorial</a>
* <li><a href="https://gatling.io/docs/gatling/tutorials/advanced">Gatling advanced tutorial</a>
* </ul>
*/
public class ComputerDatabaseSimulation extends Simulation {

HttpProtocolBuilder httpProtocol =
http.baseUrl("https://computer-database.gatling.io")
.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
.acceptLanguageHeader("en-US,en;q=0.5")
.acceptEncodingHeader("gzip, deflate")
.userAgentHeader(
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/119.0");

FeederBuilder<String> feeder = csv("search.csv").random();

ChainBuilder search =
// Execute actions sequentially
exec(
http("Home").get("/"),
pause(1),
feed(feeder),
http("Search")
.get("/computers?f=#{searchCriterion}")
.check(css("a:contains('#{searchComputerName}')", "href").saveAs("computerUrl")),
pause(1),
http("Select").get("#{computerUrl}").check(status().is(200)),
pause(1)
);

// Repeat is a loop resolved at RUNTIME
ChainBuilder browse =
// Note how we force the counter name, so we can reuse it
repeat(4, "i").on(
http("Page #{i}").get("/computers?p=#{i}"),
pause(1)
);

// Note we should be using a feeder here
// Let's demonstrate how we can retry: let's make the request fail randomly and retry a given
// number of times
ChainBuilder edit =
// Let's try at max 2 times
tryMax(2)
.on(
http("Form").get("/computers/new"),
pause(1),
http("Post")
.post("/computers")
.formParam("name", "Beautiful Computer")
.formParam("introduced", "2012-05-30")
.formParam("discontinued", "")
.formParam("company", "37")
.check(
status()
.is(
// We do a check on a condition that's been customized with
// a lambda. It will be evaluated every time a user executes
// the request.
session -> 200 + ThreadLocalRandom.current().nextInt(2)
)
)
)
// If the chain didn't finally succeed, have the user exit the whole scenario
.exitHereIfFailed();

ScenarioBuilder users = scenario("Users").exec(search, browse);
ScenarioBuilder admins = scenario("Admins").exec(search, browse, edit);

{
setUp(
users.injectOpen(rampUsers(10).during(10)),
admins.injectOpen(rampUsers(2).during(10))
).protocols(httpProtocol);
}
}
3 changes: 3 additions & 0 deletions src/test/resources/gatling/search.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
searchCriterion,searchComputerName
Macbook,MacBook Pro
eee,ASUS Eee PC 1005PE

0 comments on commit d7a2012

Please sign in to comment.