Skip to content

Commit

Permalink
Merge branch 'release/1.2.2'
Browse files Browse the repository at this point in the history
Aggiunto lo scenario di test JMeter per il nuovi servizi JAX-RS introdotti con le entità `Horse` e `Owner`
  • Loading branch information
amusarra committed May 11, 2024
2 parents d40e24f + acd1ec3 commit aeeee84
Show file tree
Hide file tree
Showing 13 changed files with 4,144 additions and 141 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Deprecated
### Security

## [1.2.2] - 2024-05-11

### Changed
- Aggiunta gestione del metodo CRUD di Update per la classe di entità `Horse` e `Owner`
- Aggiunto lo scenario di test JMeter per il nuovi servizi JAX-RS introdotti con le entità `Horse` e `Owner`
- Aggiornamento del file README.md con le istruzioni per l'esecuzione dello scenario di test JMeter

### Fixed
- Eliminazione di alcuni listener jp@gc - JMeter Plugins per il test di carico con JMeter e Taurus

## [1.2.1] - 2024-05-10

### Changed
Expand Down
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,36 @@ test di carico (dai dati letti dal file jtl `kpi.jtl` locato in `target/taurus/%

![Throughput del sistema](src/doc/resources/images/jmeter_jtl_transazioni_secondo_1.jpg)

Figura 7 - Throughput del sistema

Anche da questo grafico è possibile vedere come il throughput del sistema sia influenzato dal protocollo utilizzato
e il protocollo HTTP/2 over TLS con compressione GZIP sia quello che offre le migliori performance.

Figura 7 - Throughput del sistema
Dalla release [1.2.2](https://github.com/amusarra/eventbus-logging-filter-jaxrs/releases/tag/v1.2.2) del progetto, è disponibile lo scenario di Load Testing per testare i servizi JAX-RS collegati alle
due entità ORM (Object Relational Mapping) che sono state implementate nel progetto e introdotte dalla release [1.2.0](https://github.com/amusarra/eventbus-logging-filter-jaxrs/releases/tag/v1.2.0).

Per eseguire lo scenario di Load Testing, è possibile utilizzare il file jmx `src/test/jmeter/scenario_2.jmx`, di cui
potete vedere la struttura aprendolo con JMeter. A seguire è mostrata la struttura del Test Plan di JMeter.

![Configurazione Test Plan di JMeter Scenario 2](src/doc/resources/images/jmeter_configurazione_piano_test_scenario_2.jpg)

Figura 8 - Configurazione del Test Plan di JMeter (scenario 2 `src/test/jmeter/scenario_2.jmx`)

È possibile eseguire questo scenario sempre con Taurus utilizzando comando `bzt` come mostrato in precedenza. A seguire
è riportato il comando per eseguire lo scenario di Load Testing con Taurus.

```shell script
# Esegui lo scenario di Load Testing con Taurus
bzt -o modules.jmeter.properties.numberOfThreads=1 \
-o modules.jmeter.properties.rampUpPeriod=5 \
-o modules.jmeter.properties.loopCount=25 \
-o modules.jmeter.properties.httpProtocol=https \
-o modules.jmeter.properties.httpPort=8443 \
-o modules.jmeter.properties.ipOrFQDN=127.0.0.1 \
src/test/jmeter/taurus/config.yml \
src/test/jmeter/scenario_2.jmx
```
Console 13 - Esecuzione dello scenario di Load Testing con Taurus

## Guida ai servizi e alle estensioni utilizzate

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>it.dontesta.eventbus</groupId>
<artifactId>eventbus-logging-filter-jaxrs</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>

<name>eventbus-logging-filter-jaxrs</name>
<description>Event Bus Logging Filter JAX-RS</description>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
@Cacheable
public class Owner extends PanacheEntity {

@Column(length = 60)
@Column(length = 60, nullable = false)
public String name;

@Column(length = 60)
@Column(length = 60, nullable = false)
public String surname;

@Column(length = 60, unique = true)
@Column(length = 60, nullable = false, unique = true)
public String email;

@Column(length = 20)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package it.dontesta.eventbus.ws.resources.endpoint.repository.v1;

import it.dontesta.eventbus.orm.panache.entity.Horse;
import it.dontesta.eventbus.orm.panache.entity.Owner;
import it.dontesta.eventbus.orm.panache.repository.HorseRepository;
import jakarta.inject.Inject;
import jakarta.transaction.Transactional;
Expand All @@ -9,12 +10,15 @@
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.jboss.logging.Logger;

/**
Expand Down Expand Up @@ -80,6 +84,52 @@ public Response createHorse(@NotNull Horse horse) {
return Response.ok(horse).status(Response.Status.CREATED).build();
}

/**
* This method updates a horse.
*
* @param id The ID of the horse.
* @param horse The horse to update.
* @return The updated horse.
*/
@PUT
@Path("{id}")
@Transactional
public Horse updateHorse(@NotNull Long id, @NotNull Horse horse) {
Horse entity = horseRepository.findById(id);

if (entity == null) {
throw new WebApplicationException("Horse with id of %d not found".formatted(id),
Response.Status.NOT_FOUND);
}

entity.name = horse.name;
entity.sex = horse.sex;
entity.coat = horse.coat;
entity.breed = horse.breed;
entity.dateOfBirth = horse.dateOfBirth;

entity.owners.forEach(owner -> {
log.debug("Existing owner: %s".formatted(owner.name));
});

// Create a Set of owner IDs from entity.owners
Set<Long> entityOwnerIds = entity.owners.stream().map(owner -> owner.id).collect(Collectors.toSet());

// Filter the owners of horse.owners that are not present in entity.owners
List<Owner> newOwners = horse.owners.stream()
.filter(horseOwner -> !entityOwnerIds.contains(horseOwner.id))
.collect(Collectors.toList());

// Create the new owners with the IDs and add them to entity.owners
newOwners.forEach(horseOwner -> {
Owner owner = new Owner();
owner.id = horseOwner.id;
entity.owners.add(owner);
});

return entity;
}

/**
* This method deletes a horse by its ID.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.WebApplicationException;
Expand Down Expand Up @@ -75,6 +76,62 @@ public Response createOwner(@NotNull Owner owner) {
return Response.ok(owner).status(Response.Status.CREATED).build();
}

/**
* Update existing owner.
*
* @param owner The owner to update.
* @return The updated owner.
*/
@PUT
@Transactional
public Owner updateOwner(@NotNull Owner owner) {
if (owner.id == null) {
throw new WebApplicationException("Owner ID was not set on request.",
Response.Status.BAD_REQUEST);
}

Owner existingOwner = ownerRepository.findById(owner.id);

if (existingOwner == null) {
throw new WebApplicationException("Owner with id of %d not found".formatted(owner.id),
Response.Status.NOT_FOUND);
}

// Update the owner
// This code is not the best way to update an entity
if (owner.name != null) {
existingOwner.name = owner.name;
}
if (owner.surname != null) {
existingOwner.surname = owner.surname;
}
if (owner.email != null) {
existingOwner.email = owner.email;
}
if (owner.phoneNumber != null) {
existingOwner.phoneNumber = owner.phoneNumber;
}
if (owner.address != null) {
existingOwner.address = owner.address;
}
if (owner.city != null) {
existingOwner.city = owner.city;
}
if (owner.state != null) {
existingOwner.state = owner.state;
}
if (owner.zipCode != null) {
existingOwner.zipCode = owner.zipCode;
}
if (owner.country != null) {
existingOwner.country = owner.country;
}

ownerRepository.persist(existingOwner);

return existingOwner;
}

/**
* Delete existing owner.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,29 @@ void testCreateHorse() {

@Test
@Order(6)
void testUpdateHorse() {
String json = """
{
"name": "Whisper updated",
"coat": "Gray",
"breed": "Pura Raza Española - PRE",
"sex": "M",
"dateOfBirth": "2024-05-01",
"owners": [{"id": 3}]
}
""";

given()
.contentType(ContentType.JSON)
.body(json)
.when().put("/api/rest/repository/horse/v1/4")
.then()
.statusCode(Response.Status.OK.getStatusCode())
.body("name", is("Whisper updated"));
}

@Test
@Order(7)
void testDeleteHorseByIdSuccess() {
given()
.when().delete("/api/rest/repository/horse/v1/1")
Expand All @@ -91,7 +114,7 @@ void testDeleteHorseByIdSuccess() {
}

@Test
@Order(7)
@Order(8)
void testDeleteHorseByIdNotFound() {
given()
.when().delete("/api/rest/repository/horse/v1/100")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,33 @@ void testCreateOwner() {

@Test
@Order(6)
void testUpdateOwner() {
String json = """
{
"id": 1,
"name": "John Updated 3",
"surname": "Doe",
"email": "[email protected]",
"phoneNumber": "123456789",
"address": "Via Roma 3",
"city": "Rome",
"state": "RM",
"zipCode": "00100",
"country": "Italy"
}
""";

given()
.contentType(ContentType.JSON)
.body(json)
.when().put("/api/rest/repository/owner/v1")
.then()
.statusCode(Response.Status.OK.getStatusCode())
.body("name", is("John Updated 3"));
}

@Test
@Order(7)
void testDeleteOwnerByIdNotFound() {
given()
.when().delete("/api/rest/repository/owner/v1/100")
Expand Down
Loading

0 comments on commit aeeee84

Please sign in to comment.