Skip to content

Commit

Permalink
Release 2.2.0 (#2)
Browse files Browse the repository at this point in the history
* [skip ci] Update project to latest tag parer-retry-2.2.0

* Update pom.xml

* Update CI

* Update SNAPSHOT version

* [maven-release-plugin] prepare release parer-retry-2.2.0

* [maven-release-plugin] prepare for next development iteration

---------

Co-authored-by: parerworker <DevPARER@regione.emilia-romagna.it>
Co-authored-by: GitHub Actions <actions@github.com>
  • Loading branch information
3 people authored Sep 16, 2024
1 parent b4569a8 commit 60d1afd
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ jobs:
compile:
uses: RegioneER/parer-github-template/.github/workflows/compile.yml@v1
with:
java: '8'
java: '11'
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ jobs:
uses: RegioneER/parer-github-template/.github/workflows/release.yml@v1
with:
version: ${{ inputs.version }}
java: '8'
java: '11'
26 changes: 13 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>it.eng.parer</groupId>
<artifactId>parer-retry</artifactId>
<version>2.1.1-SNAPSHOT</version>
<version>2.2.1-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<!-- 3d party libraries-->
<spring-retry.version>1.3.4</spring-retry.version>
<junit-jupiter.version>5.10.3</junit-jupiter.version>
</properties>
<name>parer-retry</name>
<description>Libreria utilizzata per effettuare chiamate http configurando meccanismi di retry secondo alcune policy configurate</description>

<parent>
<groupId>it.eng.parer</groupId>
<artifactId>parer-pom</artifactId>
<version>4.2.0</version>
<version>6.4.0</version>
</parent>

<distributionManagement>
Expand Down Expand Up @@ -56,7 +56,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.32</version>
<version>${slf4j.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -71,17 +71,17 @@
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
<version>1.7.32</version>
<version>${slf4j.version}</version>
</dependency>
</dependencies>
<scm>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/it/eng/parer/retry/ParerRetryConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected void setRetryTemplate(RetryTemplate retryTemplate) {
* callback, ovvero metodo che deve essere eseguito
* @param fallback
* fallback, ovvero metodo che deve essere eseguito in caso falliscano tutti i tentativi di re-invio
*
*
* @return Risultato atteso
*
* @throws E
Expand All @@ -82,7 +82,7 @@ public <R, E extends Throwable> R execute(RetryCallback<R, E> metodo, RecoveryCa
* Eccezione per cui si effettua il retry
* @param metodo
* callback, ovvero metodo che deve essere eseguito
*
*
* @return Risultato atteso
*
* @throws E
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class ParerRetryConfigurationBuilder {
*
* @param timeout
* in ms
*
*
* @return {@link ParerRetryConfigurationBuilder}
*/
public ParerRetryConfigurationBuilder withTimeout(long timeout) {
Expand All @@ -64,7 +64,7 @@ public ParerRetryConfigurationBuilder withTimeout(long timeout) {
*
* @param maxAttemps
* numero massimo di tentativi
*
*
* @return {@link ParerRetryConfigurationBuilder}
*/
public ParerRetryConfigurationBuilder withMaxAttemps(int maxAttemps) {
Expand All @@ -79,7 +79,7 @@ public ParerRetryConfigurationBuilder withMaxAttemps(int maxAttemps) {
*
* @param backOffPeriod
* espresso in ms
*
*
* @return {@link ParerRetryConfigurationBuilder}
*/
public ParerRetryConfigurationBuilder withBackoffPeriod(long backOffPeriod) {
Expand All @@ -96,7 +96,7 @@ public ParerRetryConfigurationBuilder withBackoffPeriod(long backOffPeriod) {
* timeout di apertura
* @param resetTimeout
* timeout di reset
*
*
* @return {@link ParerRetryConfigurationBuilder}
*/
public ParerRetryConfigurationBuilder withCircuitBreaker(long openTimeout, long resetTimeout) {
Expand All @@ -110,7 +110,7 @@ public ParerRetryConfigurationBuilder withCircuitBreaker(long openTimeout, long
*
* @param compositePolicy
* valore da assegnare alla logica di valutazione delle policy composite
*
*
* @return {@link ParerRetryConfigurationBuilder}
*/
public ParerRetryConfigurationBuilder withOptimisticCompositePolicy(boolean compositePolicy) {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/it/eng/parer/retry/RestRetryInterceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,6 @@ private class SpringHttpRequestWrapper implements HttpRequest {
this.hr = hr;
}

@Override
public HttpMethod getMethod() {
return hr.getMethod();
}

@Override
public URI getURI() {
return newUri;
Expand All @@ -158,6 +153,11 @@ public URI getURI() {
public HttpHeaders getHeaders() {
return hr.getHeaders();
}

@Override
public String getMethodValue() {
return hr.getMethodValue();
}
}

}
72 changes: 38 additions & 34 deletions src/test/java/it/eng/parer/retry/TestRetry.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@

package it.eng.parer.retry;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ByteArrayResource;
Expand Down Expand Up @@ -58,7 +61,7 @@ public class TestRetry {

private String preferredEndpoint;

@BeforeClass
@BeforeAll
public static void setUpClass() {
BAD_ENDPOINTS.add(URI.create(CRYPTO_LOCALE));
BAD_ENDPOINTS.add(URI.create("Br0kenUr1"));
Expand All @@ -68,11 +71,11 @@ public static void setUpClass() {
BAD_ENDPOINTS.add(URI.create("../../"));
}

@AfterClass
@AfterAll
public static void tearDownClass() {
}

@Before
@BeforeEach
public void setUp() {
restTemplate = new RestTemplate();

Expand All @@ -85,12 +88,12 @@ public void setUp() {
preferredEndpoint = CRYPTO_TEST_OKD;
}

@After
@AfterEach
public void tearDown() {
}

@Test
public void testTST() {
void testTST() {
log.info("Test configurazione predefinita");
HttpEntity<MultiValueMap<String, Object>> requestEntity = buildValidRequestEntity();

Expand All @@ -101,32 +104,34 @@ public void testTST() {
restTemplate.getInterceptors().add(new RestRetryInterceptor(BAD_ENDPOINTS, retryClient));

String parerTST = restTemplate.postForObject(endpoint, requestEntity, String.class);
Assert.assertNotNull(parerTST);
assertNotNull(parerTST);
}

@Test(expected = RestClientException.class)
public void testTSTWithNoValidURL() {
@Test
void testTSTWithNoValidURL() {

log.info("Test senza URL raggiungibili");
HttpEntity<MultiValueMap<String, Object>> requestEntity = buildValidRequestEntity();

String preferredEndpoint = "http://localhost:8090/api/tst";
String endpoint = "http://localhost:8090/api/tst";

ParerRetryConfiguration retryClient = ParerRetryConfiguration.defaultInstance();
restTemplate.getInterceptors().removeIf(i -> true);
restTemplate.getInterceptors().add(new RestRetryInterceptor(BAD_ENDPOINTS, retryClient));

restTemplate.postForObject(preferredEndpoint, requestEntity, Object.class);
assertThrows(RestClientException.class,
() -> restTemplate.postForObject(endpoint, requestEntity, Object.class));

}

@Test
public void testTSTWithSomeBadURI() {
void testTSTWithSomeBadURI() {

log.info("Test con alcune URL raggiungibili");

HttpEntity<MultiValueMap<String, Object>> requestEntity = buildValidRequestEntity();

String preferredEndpoint = "http://localhost:8090/api/tst";
String endpoint = "http://localhost:8090/api/tst";

// Endpoint errati
List<URI> endPoints = new ArrayList<>(BAD_ENDPOINTS);
Expand All @@ -137,19 +142,19 @@ public void testTSTWithSomeBadURI() {
restTemplate.getInterceptors().removeIf(i -> true);
restTemplate.getInterceptors().add(new RestRetryInterceptor(endPoints, retryClient));

String parerTST = restTemplate.postForObject(preferredEndpoint, requestEntity, String.class);
Assert.assertNotNull(parerTST);
String parerTST = restTemplate.postForObject(endpoint, requestEntity, String.class);
assertNotNull(parerTST);

}

@Test(expected = Exception.class)
public void testTSTWitoutMandatoryParameter() {
@Test
void testTSTWitoutMandatoryParameter() {

log.info("Test senza parametro obbligatorio");

HttpEntity<MultiValueMap<String, Object>> requestEntity = buildInvalidRequestEntity();

String preferredEndpoint = "http://localhost:8090/api/tst";
String endpoint = "http://localhost:8090/api/tst";

// Endpoint errati
List<URI> endPoints = new ArrayList<>(BAD_ENDPOINTS);
Expand All @@ -161,21 +166,20 @@ public void testTSTWitoutMandatoryParameter() {
restTemplate.getInterceptors().removeIf(i -> true);
restTemplate.getInterceptors().add(new RestRetryInterceptor(endPoints, retryClient));

String parerTST = restTemplate.postForObject(preferredEndpoint, requestEntity, String.class);
Assert.assertNotNull(parerTST);
assertThrows(Exception.class, () -> restTemplate.postForObject(endpoint, requestEntity, String.class));
}

/**
* Test policy composita con logica "ottimistica": timeout molto piccolo e molte retry. Effettuerà tutte le retry.
*
*/
@Test
public void testOptimisticParameter() {
void testOptimisticParameter() {

log.info("Test con policy composita e logica ottimistica");
HttpEntity<MultiValueMap<String, Object>> requestEntity = buildValidRequestEntity();

String preferredEndpoint = "http://localhost:8090/api/tst";
String endpoint = "http://localhost:8090/api/tst";

// Endpoint errati
List<URI> endPoints = new ArrayList<>(BAD_ENDPOINTS);
Expand All @@ -188,20 +192,20 @@ public void testOptimisticParameter() {
restTemplate.getInterceptors().removeIf(i -> true);
restTemplate.getInterceptors().add(new RestRetryInterceptor(endPoints, retryClientConfiguration));

String parerTST = restTemplate.postForObject(preferredEndpoint, requestEntity, String.class);
Assert.assertNotNull(parerTST);
String parerTST = restTemplate.postForObject(endpoint, requestEntity, String.class);
assertNotNull(parerTST);
}

/**
* Test policy composita con logica "pessimistica": timeout molto piccolo e molte retry. Effettuerà solo la prima.
*
*/
@Test(expected = RestClientException.class)
public void testPessimisticParameter() {
@Test
void testPessimisticParameter() {
log.info("Test con policy composita e logica pessimistica");
HttpEntity<MultiValueMap<String, Object>> requestEntity = buildValidRequestEntity();

String preferredEndpoint = "http://localhost:8090/api/tst";
String endpoint = "http://localhost:8090/api/tst";

// Endpoint errati
List<URI> endPoints = new ArrayList<>(BAD_ENDPOINTS);
Expand All @@ -214,8 +218,8 @@ public void testPessimisticParameter() {
restTemplate.getInterceptors().removeIf(i -> true);
restTemplate.getInterceptors().add(new RestRetryInterceptor(endPoints, retryClientConfiguration));

String parerTST = restTemplate.postForObject(preferredEndpoint, requestEntity, String.class);
Assert.assertNotNull(parerTST);
assertThrows(RestClientException.class,
() -> restTemplate.postForObject(endpoint, requestEntity, String.class));
}

private HttpEntity<MultiValueMap<String, Object>> buildValidRequestEntity() {
Expand Down

0 comments on commit 60d1afd

Please sign in to comment.