Skip to content

Commit

Permalink
extend snippet for »Spring« HttpExchange w/ @Retryable
Browse files Browse the repository at this point in the history
  • Loading branch information
agebhar1 committed Aug 4, 2024
1 parent 59e74ed commit edcc184
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<ToDo>
Expand Down Expand Up @@ -81,6 +85,7 @@ class HttpExchangeTest(@Autowired private val client: ToDosService) {
}

@TestConfiguration
@EnableRetry
class Configuration {
@Bean
fun client(): ToDosService {
Expand Down
43 changes: 43 additions & 0 deletions spring-boot/src/test/resources/wiremock/todo-stubs.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit edcc184

Please sign in to comment.