Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #34

Merged
merged 22 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 3 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,6 @@ nightly:
- source "$HOME/.sdkman/bin/sdkman-init.sh"
script:
- sdk env install
- ./mvnw -P pitest
# TODO Enable ITs when nightly tests are fixed
- ./mvnw -P pitest -D skipITs
- ./mvnw -P gatling -D skipITs
75 changes: 73 additions & 2 deletions .mvn/parent.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.3</version>
<version>3.3.4</version>
<relativePath/>
</parent>

Expand All @@ -34,7 +34,6 @@
<client.package>${openapi.package}.client</client.package>
<image.name>${project.groupId}/${project.artifactId}</image.name>
<image.registry>docker.io</image.registry>
<release.goal>verify</release.goal> <!-- verify | deploy -->
<spring.server>undertow</spring.server> <!-- undertow | jetty -->
<openapi.integration>ui</openapi.integration> <!-- ui | api -->

Expand All @@ -44,6 +43,8 @@

<jacoco.version>0.8.12</jacoco.version>
<archunit.version>1.3.0</archunit.version>
<gatling.version>3.12.0</gatling.version>
<gatling.maven.version>4.9.6</gatling.maven.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -103,6 +104,12 @@
<artifactId>kafka</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.gatling.highcharts</groupId>
<artifactId>gatling-charts-highcharts</artifactId>
<version>${gatling.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -342,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>
3 changes: 3 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

## Third Party Libraries Licenses
For the list of dependencies' licenses, check the Maven dependencies report.
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
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
- "15432:5432"

kafka:
image: docker.io/apache/kafka:3.7.0
image: docker.io/apache/kafka-native:3.8.0
environment:
CLUSTER_ID: 4L6g3nShT-eMCtK--X86sw
KAFKA_NODE_ID: 1
Expand Down
6 changes: 4 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</parent>

<artifactId>appointments</artifactId>
<version>0.3.7</version>
<version>0.3.8</version>

<name>Appointments</name>
<description>Application to create appointments (REST API)</description>
Expand All @@ -28,7 +28,9 @@
<client.package>${openapi.package}.client</client.package>
<spring.server>undertow</spring.server>
<openapi.integration>ui</openapi.integration>
<release.goal>deploy</release.goal>
<gatling.simulationClass>
com.github.jaguililla.appointments.GatlingSimulation
</gatling.simulationClass>
</properties>

<distributionManagement>
Expand Down
28 changes: 28 additions & 0 deletions set_up.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
///usr/bin/env java --enable-preview --source 21 -cp "*" "$0" "$@" ; exit $?

import static java.util.Map.entry;

import java.io.Console;
import java.util.List;

private Console console = System.console();

void main() {
var options = List.of(
entry("GitHub", prompt("Keep GitHub workflows and templates: (Yn)", "y")),
entry("GitLab", prompt("Keep GitLab workflows and templates: (Yn)", "y")),
entry("GitLab", prompt("Keep 'CODE_OF_CONDUCT.md' file: (Yn)", "y")),
entry("GitLab", prompt("Keep 'CONTRIBUTING.md' file: (Yn)", "y")),
entry("GitLab", prompt("Keep 'LICENSE.md' file: (Yn)", "y")),
entry("GitLab", prompt("Keep this set up file 'set_up.java' file: (Yn)", "y"))
);

// Rename artifacts, groups or base package
// Restart Git history (or delete it)
}

public String prompt(String message, String defaultValue) {
console.printf(message);
var v = console.readLine();
return v == null || v.isBlank() ? defaultValue : v;
}
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);
}
}
1 change: 1 addition & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ management.endpoints.jmx.exposure.exclude: "*"

spring:
threads.virtual.enabled: true

datasource:
url: ${JDBC_URL:jdbc:postgresql://localhost:15432/local}
username: ${JDBC_USERNAME:root}
Expand Down
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
57 changes: 57 additions & 0 deletions src/main/resources/static/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!DOCTYPE html>

<head>
<meta lang="en">
<meta charset="UTF-8">

<title>Appointments</title>

<link rel="stylesheet" href="simple.css">
<style>
:root {
--body-font-size: 1rem;
--body-line-height: 1.2;
}
</style>
</head>

<header>
<h1>Appointments</h1>
<p>Example task application</p>

<nav>
<a href="/" class="current">Appointments</a>
<a href="/">Users</a>
</nav>
</header>

<h3>Open</h3>
<table>
<thead>
<tr>
<th>Id</th>
<th>Title</th>
<th>Order</th>
</tr>
</thead>
<tbody id="appointments"></tbody>
</table>

<h3>New</h3>
<form>
<label for="title">Title</label>
<input id="title" type="text">
<label for="order">Order</label>
<input id="order" type="number">
</form>
<button onclick="add()">Add</button>

<template id="appointmentRow">
<tr>
<td>title</td>
<td>0</td>
<td><input type="checkbox" checked></td>
</tr>
</template>

<script src="main.js"></script>
62 changes: 62 additions & 0 deletions src/main/resources/static/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

const http = new XMLHttpRequest();

const tbody = document.querySelector("tbody#appointments");
const template = document.querySelector("#appointmentRow");
const titleInput = document.querySelector("#title");
const orderInput = document.querySelector("#order");

function httpSend(method, url, body, callback) {
http.open(method, url);
http.setRequestHeader('Content-type', 'application/json');
http.send(JSON.stringify(body));
http.onload = callback;
}

function httpGet(url, body, callback) {
httpSend('GET', url, body, callback);
}

function httpPost(url, body, callback) {
httpSend('POST', url, body, callback);
}

function addTask(task) {
const clone = template.content.cloneNode(true);
const td = clone.querySelectorAll("td");
const input = clone.querySelectorAll("input");
td[0].textContent = task.title;
td[1].textContent = task.order;
input.checked = task.completed;
tbody.appendChild(clone);
}

function add() {
const body = {
title: titleInput.value,
order: orderInput.valueAsNumber
};

httpPost('/appointments', body, () => {
titleInput.value = "";
orderInput.value = 0;

addTask(JSON.parse(http.responseText));
});
}

function main() {

httpGet('/appointments', null, () => {
for (const tr of tbody.children)
tr.remove();

const response = JSON.parse(http.responseText);
for (const task of response)
addTask(task);

console.log(http.responseText);
});
}

document.body.onload = main;
Loading