@ -16,6 +16,7 @@ import org.springframework.mock.http.client.MockClientHttpResponse;
@@ -16,6 +16,7 @@ import org.springframework.mock.http.client.MockClientHttpResponse;
import org.springframework.retry.policy.NeverRetryPolicy ;
import org.springframework.retry.support.RetryTemplate ;
import static org.bouncycastle.crypto.tls.ConnectionEnd.client ;
import static org.hamcrest.MatcherAssert.assertThat ;
import static org.hamcrest.Matchers.is ;
import static org.mockito.Matchers.any ;
@ -69,6 +70,25 @@ public class RetryLoadBalancerInterceptorTest {
@@ -69,6 +70,25 @@ public class RetryLoadBalancerInterceptorTest {
verify ( retryTemplate , times ( 1 ) ) . setRetryPolicy ( any ( NeverRetryPolicy . class ) ) ;
}
@Test ( expected = IllegalStateException . class )
public void interceptInvalidHost ( ) throws Throwable {
HttpRequest request = mock ( HttpRequest . class ) ;
when ( request . getURI ( ) ) . thenReturn ( new URI ( "http://foo_underscore" ) ) ;
ClientHttpResponse clientHttpResponse = new MockClientHttpResponse ( new byte [ ] { } , HttpStatus . OK ) ;
LoadBalancedRetryPolicy policy = mock ( LoadBalancedRetryPolicy . class ) ;
InterceptorRetryPolicy interceptorRetryPolicy = new InterceptorRetryPolicy ( request , policy , client , "foo" ) ;
LoadBalancedRetryPolicyFactory lbRetryPolicyFactory = mock ( LoadBalancedRetryPolicyFactory . class ) ;
when ( lbRetryPolicyFactory . create ( eq ( "foo_underscore" ) , any ( ServiceInstanceChooser . class ) ) ) . thenReturn ( policy ) ;
ServiceInstance serviceInstance = mock ( ServiceInstance . class ) ;
when ( client . choose ( eq ( "foo_underscore" ) ) ) . thenReturn ( serviceInstance ) ;
when ( client . execute ( eq ( "foo_underscore" ) , eq ( serviceInstance ) , any ( LoadBalancerRequest . class ) ) ) . thenReturn ( clientHttpResponse ) ;
lbProperties . setEnabled ( true ) ;
RetryLoadBalancerInterceptor interceptor = new RetryLoadBalancerInterceptor ( client , retryTemplate , lbProperties , lbRetryPolicyFactory ) ;
byte [ ] body = new byte [ ] { } ;
ClientHttpRequestExecution execution = mock ( ClientHttpRequestExecution . class ) ;
ClientHttpResponse rsp = interceptor . intercept ( request , body , execution ) ;
}
@Test
public void interceptNeverRetry ( ) throws Throwable {
HttpRequest request = mock ( HttpRequest . class ) ;