|
16 | 16 | import org.springframework.retry.policy.NeverRetryPolicy;
|
17 | 17 | import org.springframework.retry.support.RetryTemplate;
|
18 | 18 |
|
| 19 | +import static org.bouncycastle.crypto.tls.ConnectionEnd.client; |
19 | 20 | import static org.hamcrest.MatcherAssert.assertThat;
|
20 | 21 | import static org.hamcrest.Matchers.is;
|
21 | 22 | import static org.mockito.Matchers.any;
|
@@ -69,6 +70,25 @@ public void interceptDisableRetry() throws Throwable {
|
69 | 70 | verify(retryTemplate, times(1)).setRetryPolicy(any(NeverRetryPolicy.class));
|
70 | 71 | }
|
71 | 72 |
|
| 73 | + @Test(expected = IllegalStateException.class) |
| 74 | + public void interceptInvalidHost() throws Throwable { |
| 75 | + HttpRequest request = mock(HttpRequest.class); |
| 76 | + when(request.getURI()).thenReturn(new URI("http://foo_underscore")); |
| 77 | + ClientHttpResponse clientHttpResponse = new MockClientHttpResponse(new byte[]{}, HttpStatus.OK); |
| 78 | + LoadBalancedRetryPolicy policy = mock(LoadBalancedRetryPolicy.class); |
| 79 | + InterceptorRetryPolicy interceptorRetryPolicy = new InterceptorRetryPolicy(request, policy, client,"foo"); |
| 80 | + LoadBalancedRetryPolicyFactory lbRetryPolicyFactory = mock(LoadBalancedRetryPolicyFactory.class); |
| 81 | + when(lbRetryPolicyFactory.create(eq("foo_underscore"), any(ServiceInstanceChooser.class))).thenReturn(policy); |
| 82 | + ServiceInstance serviceInstance = mock(ServiceInstance.class); |
| 83 | + when(client.choose(eq("foo_underscore"))).thenReturn(serviceInstance); |
| 84 | + when(client.execute(eq("foo_underscore"), eq(serviceInstance), any(LoadBalancerRequest.class))).thenReturn(clientHttpResponse); |
| 85 | + lbProperties.setEnabled(true); |
| 86 | + RetryLoadBalancerInterceptor interceptor = new RetryLoadBalancerInterceptor(client, retryTemplate, lbProperties, lbRetryPolicyFactory); |
| 87 | + byte[] body = new byte[]{}; |
| 88 | + ClientHttpRequestExecution execution = mock(ClientHttpRequestExecution.class); |
| 89 | + ClientHttpResponse rsp = interceptor.intercept(request, body, execution); |
| 90 | + } |
| 91 | + |
72 | 92 | @Test
|
73 | 93 | public void interceptNeverRetry() throws Throwable {
|
74 | 94 | HttpRequest request = mock(HttpRequest.class);
|
|
0 commit comments