mirror of
https://github.com/pcvolkmer/etl-processor.git
synced 2025-04-19 17:26:51 +00:00
feat: do not retry on validation issues (#89)
This will prevent retry if response is HTTP 400 or HTTP 422.
This commit is contained in:
parent
56a63b276e
commit
98b971d7db
@ -55,6 +55,7 @@ import org.springframework.retry.support.RetryTemplateBuilder
|
|||||||
import org.springframework.scheduling.annotation.EnableScheduling
|
import org.springframework.scheduling.annotation.EnableScheduling
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder
|
import org.springframework.security.crypto.password.PasswordEncoder
|
||||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager
|
import org.springframework.security.provisioning.InMemoryUserDetailsManager
|
||||||
|
import org.springframework.web.client.HttpClientErrorException
|
||||||
import org.springframework.web.client.RestTemplate
|
import org.springframework.web.client.RestTemplate
|
||||||
import reactor.core.publisher.Sinks
|
import reactor.core.publisher.Sinks
|
||||||
import java.io.BufferedInputStream
|
import java.io.BufferedInputStream
|
||||||
@ -224,6 +225,8 @@ class AppConfiguration {
|
|||||||
fun retryTemplate(configProperties: AppConfigProperties): RetryTemplate {
|
fun retryTemplate(configProperties: AppConfigProperties): RetryTemplate {
|
||||||
return RetryTemplateBuilder()
|
return RetryTemplateBuilder()
|
||||||
.notRetryOn(IllegalArgumentException::class.java)
|
.notRetryOn(IllegalArgumentException::class.java)
|
||||||
|
.notRetryOn(HttpClientErrorException.BadRequest::class.java)
|
||||||
|
.notRetryOn(HttpClientErrorException.UnprocessableEntity::class.java)
|
||||||
.exponentialBackoff(2.seconds.toJavaDuration(), 1.25, 5.seconds.toJavaDuration())
|
.exponentialBackoff(2.seconds.toJavaDuration(), 1.25, 5.seconds.toJavaDuration())
|
||||||
.customPolicy(SimpleRetryPolicy(configProperties.maxRetryAttempts))
|
.customPolicy(SimpleRetryPolicy(configProperties.maxRetryAttempts))
|
||||||
.withListener(object : RetryListener {
|
.withListener(object : RetryListener {
|
||||||
|
@ -22,6 +22,8 @@ package dev.dnpm.etl.processor.output
|
|||||||
import de.ukw.ccc.bwhc.dto.*
|
import de.ukw.ccc.bwhc.dto.*
|
||||||
import dev.dnpm.etl.processor.PatientPseudonym
|
import dev.dnpm.etl.processor.PatientPseudonym
|
||||||
import dev.dnpm.etl.processor.RequestId
|
import dev.dnpm.etl.processor.RequestId
|
||||||
|
import dev.dnpm.etl.processor.config.AppConfigProperties
|
||||||
|
import dev.dnpm.etl.processor.config.AppConfiguration
|
||||||
import dev.dnpm.etl.processor.config.RestTargetProperties
|
import dev.dnpm.etl.processor.config.RestTargetProperties
|
||||||
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
@ -30,6 +32,7 @@ import org.junit.jupiter.params.ParameterizedTest
|
|||||||
import org.junit.jupiter.params.provider.MethodSource
|
import org.junit.jupiter.params.provider.MethodSource
|
||||||
import org.springframework.http.HttpMethod
|
import org.springframework.http.HttpMethod
|
||||||
import org.springframework.http.HttpStatus
|
import org.springframework.http.HttpStatus
|
||||||
|
import org.springframework.retry.backoff.NoBackOffPolicy
|
||||||
import org.springframework.retry.policy.SimpleRetryPolicy
|
import org.springframework.retry.policy.SimpleRetryPolicy
|
||||||
import org.springframework.retry.support.RetryTemplateBuilder
|
import org.springframework.retry.support.RetryTemplateBuilder
|
||||||
import org.springframework.test.web.client.ExpectedCount
|
import org.springframework.test.web.client.ExpectedCount
|
||||||
@ -91,14 +94,15 @@ class RestDipMtbFileSenderTest {
|
|||||||
fun shouldRetryOnMtbFileHttpRequestError(requestWithResponse: RequestWithResponse) {
|
fun shouldRetryOnMtbFileHttpRequestError(requestWithResponse: RequestWithResponse) {
|
||||||
val restTemplate = RestTemplate()
|
val restTemplate = RestTemplate()
|
||||||
val restTargetProperties = RestTargetProperties("http://localhost:9000/api", null, null, false)
|
val restTargetProperties = RestTargetProperties("http://localhost:9000/api", null, null, false)
|
||||||
val retryTemplate = RetryTemplateBuilder().customPolicy(SimpleRetryPolicy(3)).build()
|
val retryTemplate = AppConfiguration().retryTemplate(AppConfigProperties("http://localhost:9000"))
|
||||||
|
retryTemplate.setBackOffPolicy(NoBackOffPolicy())
|
||||||
|
|
||||||
this.mockRestServiceServer = MockRestServiceServer.createServer(restTemplate)
|
this.mockRestServiceServer = MockRestServiceServer.createServer(restTemplate)
|
||||||
this.restMtbFileSender = RestDipMtbFileSender(restTemplate, restTargetProperties, retryTemplate)
|
this.restMtbFileSender = RestDipMtbFileSender(restTemplate, restTargetProperties, retryTemplate)
|
||||||
|
|
||||||
val expectedCount = when (requestWithResponse.httpStatus) {
|
val expectedCount = when (requestWithResponse.httpStatus) {
|
||||||
// OK - No Retry
|
// OK - No Retry
|
||||||
HttpStatus.OK, HttpStatus.CREATED -> ExpectedCount.max(1)
|
HttpStatus.OK, HttpStatus.CREATED, HttpStatus.UNPROCESSABLE_ENTITY, HttpStatus.BAD_REQUEST -> ExpectedCount.max(1)
|
||||||
// Request failed - Retry max 3 times
|
// Request failed - Retry max 3 times
|
||||||
else -> ExpectedCount.max(3)
|
else -> ExpectedCount.max(3)
|
||||||
}
|
}
|
||||||
@ -120,14 +124,15 @@ class RestDipMtbFileSenderTest {
|
|||||||
fun shouldRetryOnDeleteHttpRequestError(requestWithResponse: RequestWithResponse) {
|
fun shouldRetryOnDeleteHttpRequestError(requestWithResponse: RequestWithResponse) {
|
||||||
val restTemplate = RestTemplate()
|
val restTemplate = RestTemplate()
|
||||||
val restTargetProperties = RestTargetProperties("http://localhost:9000/api", null, null, false)
|
val restTargetProperties = RestTargetProperties("http://localhost:9000/api", null, null, false)
|
||||||
val retryTemplate = RetryTemplateBuilder().customPolicy(SimpleRetryPolicy(3)).build()
|
val retryTemplate = AppConfiguration().retryTemplate(AppConfigProperties("http://localhost:9000"))
|
||||||
|
retryTemplate.setBackOffPolicy(NoBackOffPolicy())
|
||||||
|
|
||||||
this.mockRestServiceServer = MockRestServiceServer.createServer(restTemplate)
|
this.mockRestServiceServer = MockRestServiceServer.createServer(restTemplate)
|
||||||
this.restMtbFileSender = RestDipMtbFileSender(restTemplate, restTargetProperties, retryTemplate)
|
this.restMtbFileSender = RestDipMtbFileSender(restTemplate, restTargetProperties, retryTemplate)
|
||||||
|
|
||||||
val expectedCount = when (requestWithResponse.httpStatus) {
|
val expectedCount = when (requestWithResponse.httpStatus) {
|
||||||
// OK - No Retry
|
// OK - No Retry
|
||||||
HttpStatus.OK, HttpStatus.CREATED -> ExpectedCount.max(1)
|
HttpStatus.OK, HttpStatus.CREATED, HttpStatus.UNPROCESSABLE_ENTITY, HttpStatus.BAD_REQUEST -> ExpectedCount.max(1)
|
||||||
// Request failed - Retry max 3 times
|
// Request failed - Retry max 3 times
|
||||||
else -> ExpectedCount.max(3)
|
else -> ExpectedCount.max(3)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user