From edcc1848a3949dd299b717243dd64b2405254ec4 Mon Sep 17 00:00:00 2001 From: Andreas Gebhardt Date: Sun, 4 Aug 2024 18:40:54 +0200 Subject: [PATCH] =?UTF-8?q?extend=20snippet=20for=20=C2=BBSpring=C2=AB=20`?= =?UTF-8?q?HttpExchange`=20w/=20`@Retryable`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../agebhar1/snippets/HttpExchangeTest.kt | 5 +++ .../test/resources/wiremock/todo-stubs.json | 43 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/spring-boot/src/test/kotlin/io/github/agebhar1/snippets/HttpExchangeTest.kt b/spring-boot/src/test/kotlin/io/github/agebhar1/snippets/HttpExchangeTest.kt index 74bf7d4..2afa1ee 100644 --- a/spring-boot/src/test/kotlin/io/github/agebhar1/snippets/HttpExchangeTest.kt +++ b/spring-boot/src/test/kotlin/io/github/agebhar1/snippets/HttpExchangeTest.kt @@ -8,6 +8,9 @@ import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.TestConfiguration import org.springframework.context.annotation.Bean +import org.springframework.retry.annotation.Backoff +import org.springframework.retry.annotation.EnableRetry +import org.springframework.retry.annotation.Retryable import org.springframework.test.context.junit.jupiter.SpringExtension import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.RequestBody @@ -34,6 +37,7 @@ data class ToDo( accept = ["application/json"], contentType = "application/json" ) +@Retryable(backoff = Backoff(delay = 100, multiplier = 1.5, random = true)) interface ToDosService { @GetExchange fun getAll(): List @@ -81,6 +85,7 @@ class HttpExchangeTest(@Autowired private val client: ToDosService) { } @TestConfiguration + @EnableRetry class Configuration { @Bean fun client(): ToDosService { diff --git a/spring-boot/src/test/resources/wiremock/todo-stubs.json b/spring-boot/src/test/resources/wiremock/todo-stubs.json index 3e33636..c61176a 100644 --- a/spring-boot/src/test/resources/wiremock/todo-stubs.json +++ b/spring-boot/src/test/resources/wiremock/todo-stubs.json @@ -1,7 +1,35 @@ { "mappings": [ + { + "id": "31b4072f-d674-4742-ad07-17822eab7e70", + "scenarioName": "GET /todos retryable", + "requiredScenarioState": "Started", + "newScenarioState": "failed#1", + "request": { + "urlPath": "/todos", + "method": "GET" + }, + "response": { + "fault": "CONNECTION_RESET_BY_PEER" + } + }, + { + "id": "ef561638-cc98-49b3-a191-8be8eba1b7bd", + "scenarioName": "GET /todos retryable", + "requiredScenarioState": "failed#1", + "newScenarioState": "success", + "request": { + "urlPath": "/todos", + "method": "GET" + }, + "response": { + "fault": "MALFORMED_RESPONSE_CHUNK" + } + }, { "id": "ff4d49aa-5e41-42fe-8a65-79ceb56f6558", + "scenarioName": "GET /todos retryable", + "requiredScenarioState": "success", "request": { "urlPath": "/todos", "method": "GET" @@ -84,8 +112,23 @@ } } }, + { + "id": "9a54599a-475a-4e23-a98b-32503d5dbf22", + "scenarioName": "POST /todos retryable", + "requiredScenarioState": "Started", + "newScenarioState": "success", + "request": { + "urlPath": "/todos", + "method": "POST" + }, + "response": { + "status": 500 + } + }, { "id": "e5a243d5-e5d4-4230-9784-8a301492e8c0", + "scenarioName": "POST /todos retryable", + "requiredScenarioState": "success", "request": { "urlPath": "/todos", "method": "POST",