|
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;
|
@@ -72,6 +73,25 @@ public void interceptDisableRetry() throws Throwable {
|
72 | 73 | verify(lbRequestFactory).createRequest(request, body, execution);
|
73 | 74 | }
|
74 | 75 |
|
| 76 | + @Test(expected = IllegalStateException.class) |
| 77 | + public void interceptInvalidHost() throws Throwable { |
| 78 | + HttpRequest request = mock(HttpRequest.class); |
| 79 | + when(request.getURI()).thenReturn(new URI("http://foo_underscore")); |
| 80 | + ClientHttpResponse clientHttpResponse = new MockClientHttpResponse(new byte[]{}, HttpStatus.OK); |
| 81 | + LoadBalancedRetryPolicy policy = mock(LoadBalancedRetryPolicy.class); |
| 82 | + InterceptorRetryPolicy interceptorRetryPolicy = new InterceptorRetryPolicy(request, policy, client,"foo"); |
| 83 | + LoadBalancedRetryPolicyFactory lbRetryPolicyFactory = mock(LoadBalancedRetryPolicyFactory.class); |
| 84 | + when(lbRetryPolicyFactory.create(eq("foo_underscore"), any(ServiceInstanceChooser.class))).thenReturn(policy); |
| 85 | + ServiceInstance serviceInstance = mock(ServiceInstance.class); |
| 86 | + when(client.choose(eq("foo_underscore"))).thenReturn(serviceInstance); |
| 87 | + when(client.execute(eq("foo_underscore"), eq(serviceInstance), any(LoadBalancerRequest.class))).thenReturn(clientHttpResponse); |
| 88 | + lbProperties.setEnabled(true); |
| 89 | + RetryLoadBalancerInterceptor interceptor = new RetryLoadBalancerInterceptor(client, retryTemplate, lbProperties, lbRetryPolicyFactory); |
| 90 | + byte[] body = new byte[]{}; |
| 91 | + ClientHttpRequestExecution execution = mock(ClientHttpRequestExecution.class); |
| 92 | + ClientHttpResponse rsp = interceptor.intercept(request, body, execution); |
| 93 | + } |
| 94 | + |
75 | 95 | @Test
|
76 | 96 | public void interceptNeverRetry() throws Throwable {
|
77 | 97 | HttpRequest request = mock(HttpRequest.class);
|
|
0 commit comments