Skip to content

Commit

Permalink
Implement Gatling stress tests :wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jaguililla committed Sep 30, 2024
1 parent cfe887b commit bec901d
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 17 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,18 @@ jobs:
restore-keys: "${{ runner.os }}-maven-"
- name: Install SDKMAN
run: curl -s "https://get.sdkman.io?rcupdate=false" | bash
- name: Build Application
- name: Mutation Test Application
run: |
source "$HOME/.sdkman/bin/sdkman-init.sh"
sdk env install
./mvnw -P pitest
- name: Load Test Application
run: |
source "$HOME/.sdkman/bin/sdkman-init.sh"
sdk env install
./mvnw -P gatling
- name: Build Client
run: |
export CLIENT_PATH='target/generated-sources/openapi'
Expand Down
1 change: 1 addition & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,4 @@ nightly:
- sdk env install
# TODO Enable ITs when nightly tests are fixed
- ./mvnw -P pitest -D skipITs
- ./mvnw -P gatling -D skipITs
70 changes: 64 additions & 6 deletions .mvn/parent.xml
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,6 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin</artifactId>
<version>${gatling.maven.version}</version>
</plugin>
</plugins>
</build>

Expand Down Expand Up @@ -355,5 +349,69 @@
</plugins>
</reporting>
</profile>

<profile>
<id>gatling</id>

<build>
<defaultGoal>post-integration-test</defaultGoal>

<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<id>docker-up</id>
<goals>
<goal>exec</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<executable>docker</executable>
<arguments>
<argument>compose</argument>
<argument>--profile=local</argument>
<argument>up</argument>
<argument>-d</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>docker-down</id>
<goals>
<goal>exec</goal>
</goals>
<phase>post-integration-test</phase>
<configuration>
<executable>docker</executable>
<arguments>
<argument>compose</argument>
<argument>--profile=local</argument>
<argument>rm</argument>
<argument>-sfv</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin</artifactId>
<version>${gatling.maven.version}</version>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
<phase>integration-test</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
10 changes: 10 additions & 0 deletions set_up.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
///usr/bin/env java --enable-preview --source 21 -cp "*" "$0" "$@" ; exit $?

void main() {
System.out.println("Set up project");
// Ask to keep Git hosting files
// Ask to keep extra documents
// Ask to keep this file
// Rename artifacts, groups or base package
// Restart Git history (or delete it)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.*;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.getProperty;

import io.gatling.javaapi.core.*;

Expand All @@ -11,13 +14,18 @@

public class GatlingSimulation extends Simulation {

private ChainBuilder appointmentsList = exec(
private static final long SCENARIO_SECONDS = parseLong(getProperty("scenario.seconds", "30"));
private static final int MAX_USERS = parseInt(getProperty("max.users", "20"));
private static final int USERS_RAMP_SECONDS = parseInt(getProperty("users.ramp.seconds", "5"));
private static final String BASE_URL = getProperty("base.url", "http://localhost:18080");

private final ChainBuilder appointmentsList = during(SCENARIO_SECONDS).on(
http("List")
.get("/appointments")
.check(status().is(200))
);

private ChainBuilder appointmentsCrud = exec(
private final ChainBuilder appointmentsCrud = during(SCENARIO_SECONDS).on(
http("Create")
.post("/appointments")
.header("Content-Type", "application/json")
Expand All @@ -31,32 +39,28 @@ public class GatlingSimulation extends Simulation {
))
.check(status().is(201))
.check(jmesPath("id").saveAs("id")),
pause(1),
http("Read")
.get("/appointments/#{id}")
.check(status().is(200)),
pause(1),
http("Delete")
.delete("/appointments/#{id}")
.check(status().is(200))
);

{
var baseUrl = "http://localhost:18080";
var httpProtocol = http.baseUrl(baseUrl);
var httpProtocol = http.baseUrl(BASE_URL);
var feeder = Stream
.generate(UUID::randomUUID)
.map(UUID::toString)
.<Map<String, Object>>map(it -> Map.of("id", it))
.iterator();

var users = scenario("Appointments").feed(feeder).exec(appointmentsCrud);
var crud = scenario("Appointments CRUD").exec(appointmentsCrud);
var crud = scenario("Appointments CRUD").feed(feeder).exec(appointmentsCrud);
var list = scenario("Appointments List").exec(appointmentsList);

setUp(
crud.injectOpen(rampUsers(10).during(10)),
list.injectOpen(rampUsers(10).during(10))
crud.injectOpen(rampUsers(MAX_USERS).during(USERS_RAMP_SECONDS)),
list.injectOpen(rampUsers(MAX_USERS).during(USERS_RAMP_SECONDS))
)
.protocols(httpProtocol);
}
Expand Down

0 comments on commit bec901d

Please sign in to comment.