|
1 | 1 | /* |
2 | | - * Copyright 2013-2022 the original author or authors. |
| 2 | + * Copyright 2013-2023 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
74 | 74 | * "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> |
75 | 75 | * @author Olga Maciaszek-Sharma |
76 | 76 | * @author Wonsik Cheung |
| 77 | + * @author Andriy Pikozh |
77 | 78 | */ |
78 | 79 | @ExtendWith(MockitoExtension.class) |
79 | 80 | class RetryableFeignBlockingLoadBalancerClientTests { |
@@ -158,10 +159,51 @@ void shouldRetryOnRepeatableStatusCode() throws IOException { |
158 | 159 |
|
159 | 160 | feignBlockingLoadBalancerClient.execute(request, new Request.Options()); |
160 | 161 |
|
| 162 | + verify(loadBalancerClient, times(2)).choose(eq("test"), any()); |
161 | 163 | verify(loadBalancerClient, times(2)).reconstructURI(serviceInstance, URI.create("http://test/path")); |
162 | 164 | verify(delegate, times(2)).execute(any(), any()); |
163 | 165 | } |
164 | 166 |
|
| 167 | + @Test |
| 168 | + void shouldReuseServerInstanceOnSameInstanceRetry() throws IOException { |
| 169 | + properties.getRetry().setMaxRetriesOnSameServiceInstance(1); |
| 170 | + properties.getRetry().setMaxRetriesOnNextServiceInstance(0); |
| 171 | + properties.getRetry().getRetryableStatusCodes().add(503); |
| 172 | + Request request = testRequest(); |
| 173 | + Response response = testResponse(503); |
| 174 | + when(delegate.execute(any(), any())).thenReturn(response); |
| 175 | + when(retryFactory.createRetryPolicy(any(), eq(loadBalancerClient))) |
| 176 | + .thenReturn(new BlockingLoadBalancedRetryPolicy(properties)); |
| 177 | + when(loadBalancerClient.reconstructURI(serviceInstance, URI.create("http://test/path"))) |
| 178 | + .thenReturn(URI.create("http://testhost:80/path")); |
| 179 | + |
| 180 | + feignBlockingLoadBalancerClient.execute(request, new Request.Options()); |
| 181 | + |
| 182 | + verify(loadBalancerClient, times(1)).choose(eq("test"), any()); |
| 183 | + verify(loadBalancerClient, times(2)).reconstructURI(serviceInstance, URI.create("http://test/path")); |
| 184 | + verify(delegate, times(2)).execute(any(), any()); |
| 185 | + } |
| 186 | + |
| 187 | + @Test |
| 188 | + void shouldReuseServerInstanceOnSameInstanceRetryWithBothSameAndNextRetries() throws IOException { |
| 189 | + properties.getRetry().setMaxRetriesOnSameServiceInstance(1); |
| 190 | + properties.getRetry().setMaxRetriesOnNextServiceInstance(1); |
| 191 | + properties.getRetry().getRetryableStatusCodes().add(503); |
| 192 | + Request request = testRequest(); |
| 193 | + Response response = testResponse(503); |
| 194 | + when(delegate.execute(any(), any())).thenReturn(response); |
| 195 | + when(retryFactory.createRetryPolicy(any(), eq(loadBalancerClient))) |
| 196 | + .thenReturn(new BlockingLoadBalancedRetryPolicy(properties)); |
| 197 | + when(loadBalancerClient.reconstructURI(serviceInstance, URI.create("http://test/path"))) |
| 198 | + .thenReturn(URI.create("http://testhost:80/path")); |
| 199 | + |
| 200 | + feignBlockingLoadBalancerClient.execute(request, new Request.Options()); |
| 201 | + |
| 202 | + verify(loadBalancerClient, times(2)).choose(eq("test"), any()); |
| 203 | + verify(loadBalancerClient, times(4)).reconstructURI(serviceInstance, URI.create("http://test/path")); |
| 204 | + verify(delegate, times(4)).execute(any(), any()); |
| 205 | + } |
| 206 | + |
165 | 207 | @Test |
166 | 208 | void shouldNotRetryOnDisabled() throws IOException { |
167 | 209 | properties.getRetry().setEnabled(false); |
|
0 commit comments