Browse Source

Merge remote-tracking branch 'origin/3.1.x'

pull/782/head
Olga Maciaszek-Sharma 2 years ago
parent
commit
8fa27ddf56
  1. 8
      spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java
  2. 16
      spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClientTests.java
  3. 3
      spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/XForwardedHeadersTransformerTests.java

8
spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java

@ -67,6 +67,7 @@ import static org.springframework.cloud.openfeign.loadbalancer.LoadBalancerUtils
* *
* @author Olga Maciaszek-Sharma * @author Olga Maciaszek-Sharma
* @author changjin wei(魏昌进) * @author changjin wei(魏昌进)
* @author Wonsik Cheung
* @since 2.2.6 * @since 2.2.6
*/ */
@SuppressWarnings({ "rawtypes", "unchecked" }) @SuppressWarnings({ "rawtypes", "unchecked" })
@ -184,6 +185,7 @@ public class RetryableFeignBlockingLoadBalancerClient implements Client {
} }
org.springframework.cloud.client.loadbalancer.Response<ServiceInstance> lbResponse = new DefaultResponse( org.springframework.cloud.client.loadbalancer.Response<ServiceInstance> lbResponse = new DefaultResponse(
retrievedServiceInstance); retrievedServiceInstance);
LoadBalancerProperties loadBalancerProperties = loadBalancerClientFactory.getProperties(serviceId);
Response response = LoadBalancerUtils.executeWithLoadBalancerLifecycleProcessing(delegate, options, Response response = LoadBalancerUtils.executeWithLoadBalancerLifecycleProcessing(delegate, options,
feignRequest, lbRequest, lbResponse, supportedLifecycleProcessors, feignRequest, lbRequest, lbResponse, supportedLifecycleProcessors,
retrievedServiceInstance != null); retrievedServiceInstance != null);
@ -231,8 +233,10 @@ public class RetryableFeignBlockingLoadBalancerClient implements Client {
retryTemplate.setListeners(retryListeners); retryTemplate.setListeners(retryListeners);
} }
retryTemplate.setRetryPolicy(retryPolicy == null ? new NeverRetryPolicy() retryTemplate.setRetryPolicy(
: new InterceptorRetryPolicy(toHttpRequest(request), retryPolicy, loadBalancerClient, serviceId)); !loadBalancerClientFactory.getProperties(serviceId).getRetry().isEnabled() || retryPolicy == null
? new NeverRetryPolicy() : new InterceptorRetryPolicy(toHttpRequest(request), retryPolicy,
loadBalancerClient, serviceId));
return retryTemplate; return retryTemplate;
} }

16
spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClientTests.java

@ -57,6 +57,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
@ -73,6 +74,7 @@ import static org.mockito.Mockito.when;
* *
* @author Olga Maciaszek-Sharma * @author Olga Maciaszek-Sharma
* @author changjin wei(魏昌进) * @author changjin wei(魏昌进)
* @author Wonsik Cheung
* @see <a href= * @see <a href=
* "https://github.com/spring-cloud/spring-cloud-commons/blob/main/spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/blocking/client/BlockingLoadBalancerClientTests.java">BlockingLoadBalancerClientTests</a> * "https://github.com/spring-cloud/spring-cloud-commons/blob/main/spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/blocking/client/BlockingLoadBalancerClientTests.java">BlockingLoadBalancerClientTests</a>
*/ */
@ -166,6 +168,20 @@ class RetryableFeignBlockingLoadBalancerClientTests {
verify(delegate, times(2)).execute(any(), any()); verify(delegate, times(2)).execute(any(), any());
} }
@Test
void shouldNotRetryOnDisabled() throws IOException {
properties.getRetry().setEnabled(false);
Request request = testRequest();
when(delegate.execute(any(), any())).thenThrow(new IOException());
when(retryFactory.createRetryPolicy(any(), eq(loadBalancerClient)))
.thenReturn(new BlockingLoadBalancedRetryPolicy(properties));
assertThatThrownBy(() -> feignBlockingLoadBalancerClient.execute(request, new Request.Options()))
.isInstanceOf(IOException.class);
verify(delegate, times(1)).execute(any(), any());
}
@Test @Test
void shouldExposeResponseBodyOnRetry() throws IOException { void shouldExposeResponseBodyOnRetry() throws IOException {
properties.getRetry().getRetryableStatusCodes().add(503); properties.getRetry().getRetryableStatusCodes().add(503);

3
spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/XForwardedHeadersTransformerTests.java

@ -37,8 +37,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
/** /**
* Tests for * Tests for {@link XForwardedHeadersTransformer}.
* {@link XForwardedHeadersTransformer}.
* *
* @author changjin wei(魏昌进) * @author changjin wei(魏昌进)
*/ */

Loading…
Cancel
Save