|
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. |
|
75 | 75 | * @author Olga Maciaszek-Sharma |
76 | 76 | * @author changjin wei(魏昌进) |
77 | 77 | * @author Wonsik Cheung |
| 78 | + * @author Andriy Pikozh |
78 | 79 | * @see <a href= |
79 | 80 | * "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> |
80 | 81 | */ |
@@ -164,10 +165,51 @@ void shouldRetryOnRepeatableStatusCode() throws IOException { |
164 | 165 |
|
165 | 166 | feignBlockingLoadBalancerClient.execute(request, new Request.Options()); |
166 | 167 |
|
| 168 | + verify(loadBalancerClient, times(2)).choose(eq("test"), any()); |
167 | 169 | verify(loadBalancerClient, times(2)).reconstructURI(serviceInstance, URI.create("http://test/path")); |
168 | 170 | verify(delegate, times(2)).execute(any(), any()); |
169 | 171 | } |
170 | 172 |
|
| 173 | + @Test |
| 174 | + void shouldReuseServerInstanceOnSameInstanceRetry() throws IOException { |
| 175 | + properties.getRetry().setMaxRetriesOnSameServiceInstance(1); |
| 176 | + properties.getRetry().setMaxRetriesOnNextServiceInstance(0); |
| 177 | + properties.getRetry().getRetryableStatusCodes().add(503); |
| 178 | + Request request = testRequest(); |
| 179 | + Response response = testResponse(503); |
| 180 | + when(delegate.execute(any(), any())).thenReturn(response); |
| 181 | + when(retryFactory.createRetryPolicy(any(), eq(loadBalancerClient))) |
| 182 | + .thenReturn(new BlockingLoadBalancedRetryPolicy(properties)); |
| 183 | + when(loadBalancerClient.reconstructURI(serviceInstance, URI.create("http://test/path"))) |
| 184 | + .thenReturn(URI.create("http://testhost:80/path")); |
| 185 | + |
| 186 | + feignBlockingLoadBalancerClient.execute(request, new Request.Options()); |
| 187 | + |
| 188 | + verify(loadBalancerClient, times(1)).choose(eq("test"), any()); |
| 189 | + verify(loadBalancerClient, times(2)).reconstructURI(serviceInstance, URI.create("http://test/path")); |
| 190 | + verify(delegate, times(2)).execute(any(), any()); |
| 191 | + } |
| 192 | + |
| 193 | + @Test |
| 194 | + void shouldReuseServerInstanceOnSameInstanceRetryWithBothSameAndNextRetries() throws IOException { |
| 195 | + properties.getRetry().setMaxRetriesOnSameServiceInstance(1); |
| 196 | + properties.getRetry().setMaxRetriesOnNextServiceInstance(1); |
| 197 | + properties.getRetry().getRetryableStatusCodes().add(503); |
| 198 | + Request request = testRequest(); |
| 199 | + Response response = testResponse(503); |
| 200 | + when(delegate.execute(any(), any())).thenReturn(response); |
| 201 | + when(retryFactory.createRetryPolicy(any(), eq(loadBalancerClient))) |
| 202 | + .thenReturn(new BlockingLoadBalancedRetryPolicy(properties)); |
| 203 | + when(loadBalancerClient.reconstructURI(serviceInstance, URI.create("http://test/path"))) |
| 204 | + .thenReturn(URI.create("http://testhost:80/path")); |
| 205 | + |
| 206 | + feignBlockingLoadBalancerClient.execute(request, new Request.Options()); |
| 207 | + |
| 208 | + verify(loadBalancerClient, times(2)).choose(eq("test"), any()); |
| 209 | + verify(loadBalancerClient, times(4)).reconstructURI(serviceInstance, URI.create("http://test/path")); |
| 210 | + verify(delegate, times(4)).execute(any(), any()); |
| 211 | + } |
| 212 | + |
171 | 213 | @Test |
172 | 214 | void shouldNotRetryOnDisabled() throws IOException { |
173 | 215 | properties.getRetry().setEnabled(false); |
|
0 commit comments