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 28, 2024
1 parent 531fab2 commit cc0cdcf
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 9 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,15 @@ The verification requests can be executed with: `src/test/resources/requests.sh`
`PORT=9090 src/test/resources/requests.sh` if you want to run them to a different port.

The health check endpoint is: http://localhost:18080/actuator/health

### Stress Testing (Gatling)
[Gatling settings] can be overridden creating a `gatling.conf` file at the test resources. The
configuration options and their default values can be checked [here][gatlingDefaults].

Those parameters can also be overwritten by system properties from the command line. I.e.:
`-D gatling.core.encoding=utf-8`

To run the Gatling test, execute `./mvnw gatling:test` at the shell.

[Gatling settings]: https://docs.gatling.io/reference/script/core/configuration
[gatlingDefaults]: https://github.com/gatling/gatling/blob/main/gatling-core/src/main/resources/gatling-defaults.conf
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public ResponseEntity<AppointmentResponse> createAppointment(
final var createdAppointment = appointmentsService.create(appointment, users);

final var responseAppointment = AppointmentsMapper.appointmentResponse(createdAppointment);
return ResponseEntity.ofNullable(responseAppointment);
return ResponseEntity.status(201).body(responseAppointment);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public ResponseEntity<UserResponse> createUser(final UserRequest userRequest) {
final var createdUser = appointmentsService.create(user);

final var responseUser = UsersMapper.userResponse(createdUser);
return ResponseEntity.ofNullable(responseUser);
return ResponseEntity.status(201).body(responseUser);
}
}
4 changes: 2 additions & 2 deletions src/main/resources/openapi/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ paths:
schema:
$ref: 'schemas.yml#/components/schemas/UserRequest'
responses:
"200":
"201":
description: OK
content:
application/json:
Expand All @@ -36,7 +36,7 @@ paths:
schema:
$ref: 'schemas.yml#/components/schemas/AppointmentRequest'
responses:
"200":
"201":
description: OK
content:
application/json:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void appointments_can_be_created_read_and_deleted() {
.endTimestamp(LocalDateTime.now())
);
var response = client.getResponseBody(AppointmentResponse.class);
assertEquals(200, client.getResponseStatus().value());
assertEquals(201, client.getResponseStatus().value());
assertTrue(getLastMessage().startsWith("Appointment created at"));
client.get("/appointments/" + response.getId());
assertEquals(200, client.getResponseStatus().value());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@
public class GatlingSimulation extends Simulation {

private ChainBuilder appointmentsCrud = exec(
http("Create").post("/appointments").check(status().is(201)),
http("Create")
.post("/appointments")
.body(StringBody(""))
.check(status().is(201))
.check(jmesPath("id").saveAs("id")),
pause(1),
http("Read").get("/appointments").check(status().is(200)),
http("Read")
.get("/appointments/#{id}")
.check(status().is(200)),
pause(1),
http("Delete").delete("/appointments").check(status().is(200)),
pause(1)
http("Delete")
.delete("/appointments/#{id}")
.check(status().is(200))
);

{
Expand Down

0 comments on commit cc0cdcf

Please sign in to comment.