Search in sources :

Example 1 with RibbonLoadBalancedRetryFactory

use of org.springframework.cloud.netflix.ribbon.RibbonLoadBalancedRetryFactory in project spring-cloud-netflix by spring-cloud.

the class RibbonLoadBalancingHttpClientTests method setupClientForRetry.

private RetryableRibbonLoadBalancingHttpClient setupClientForRetry(int retriesNextServer, int retriesSameServer, boolean retryable, boolean retryOnAllOps, String serviceName, String host, int port, CloseableHttpClient delegate, ILoadBalancer lb, String statusCodes, BackOffPolicy backOffPolicy, boolean isSecure, RetryListener[] retryListeners) throws Exception {
    ServerIntrospector introspector = mock(ServerIntrospector.class);
    RetryHandler retryHandler = new DefaultLoadBalancerRetryHandler(retriesSameServer, retriesNextServer, retryable);
    doReturn(new Server(host, port)).when(lb).chooseServer(eq(serviceName));
    DefaultClientConfigImpl clientConfig = new DefaultClientConfigImpl();
    clientConfig.set(CommonClientConfigKey.OkToRetryOnAllOperations, retryOnAllOps);
    clientConfig.set(CommonClientConfigKey.MaxAutoRetriesNextServer, retriesNextServer);
    clientConfig.set(CommonClientConfigKey.MaxAutoRetries, retriesSameServer);
    clientConfig.set(RibbonLoadBalancedRetryPolicy.RETRYABLE_STATUS_CODES, statusCodes);
    clientConfig.set(CommonClientConfigKey.IsSecure, isSecure);
    clientConfig.setClientName(serviceName);
    RibbonLoadBalancerContext context = new RibbonLoadBalancerContext(lb, clientConfig, retryHandler);
    SpringClientFactory clientFactory = mock(SpringClientFactory.class);
    doReturn(context).when(clientFactory).getLoadBalancerContext(eq(serviceName));
    doReturn(clientConfig).when(clientFactory).getClientConfig(eq(serviceName));
    LoadBalancedRetryFactory factory = new RibbonLoadBalancedRetryFactory(clientFactory) {

        @Override
        public RetryListener[] createRetryListeners(String service) {
            return retryListeners;
        }

        @Override
        public BackOffPolicy createBackOffPolicy(String service) {
            return backOffPolicy;
        }
    };
    RetryableRibbonLoadBalancingHttpClient client = new RetryableRibbonLoadBalancingHttpClient(delegate, clientConfig, introspector, factory);
    client.setLoadBalancer(lb);
    ReflectionTestUtils.setField(client, "delegate", delegate);
    return client;
}
Also used : Server(com.netflix.loadbalancer.Server) DefaultLoadBalancerRetryHandler(com.netflix.client.DefaultLoadBalancerRetryHandler) RetryHandler(com.netflix.client.RetryHandler) SpringClientFactory(org.springframework.cloud.netflix.ribbon.SpringClientFactory) ServerIntrospector(org.springframework.cloud.netflix.ribbon.ServerIntrospector) DefaultLoadBalancerRetryHandler(com.netflix.client.DefaultLoadBalancerRetryHandler) RibbonLoadBalancerContext(org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerContext) RibbonLoadBalancedRetryFactory(org.springframework.cloud.netflix.ribbon.RibbonLoadBalancedRetryFactory) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl) RibbonLoadBalancedRetryFactory(org.springframework.cloud.netflix.ribbon.RibbonLoadBalancedRetryFactory) LoadBalancedRetryFactory(org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory) RetryListener(org.springframework.retry.RetryListener)

Example 2 with RibbonLoadBalancedRetryFactory

use of org.springframework.cloud.netflix.ribbon.RibbonLoadBalancedRetryFactory in project spring-cloud-netflix by spring-cloud.

the class SpringRetryEnabledOkHttpClientTests method setupClientForServerValidation.

private RetryableOkHttpLoadBalancingClient setupClientForServerValidation(String serviceName, String host, int port, OkHttpClient delegate, ILoadBalancer lb) throws Exception {
    ServerIntrospector introspector = mock(ServerIntrospector.class);
    RetryHandler retryHandler = new DefaultLoadBalancerRetryHandler(1, 1, true);
    DefaultClientConfigImpl clientConfig = new DefaultClientConfigImpl();
    clientConfig.set(CommonClientConfigKey.OkToRetryOnAllOperations, true);
    clientConfig.set(CommonClientConfigKey.MaxAutoRetriesNextServer, 0);
    clientConfig.set(CommonClientConfigKey.MaxAutoRetries, 1);
    clientConfig.set(RibbonLoadBalancedRetryPolicy.RETRYABLE_STATUS_CODES, "");
    clientConfig.set(CommonClientConfigKey.IsSecure, false);
    clientConfig.setClientName(serviceName);
    RibbonLoadBalancerContext context = new RibbonLoadBalancerContext(lb, clientConfig, retryHandler);
    SpringClientFactory clientFactory = mock(SpringClientFactory.class);
    doReturn(context).when(clientFactory).getLoadBalancerContext(eq(serviceName));
    doReturn(clientConfig).when(clientFactory).getClientConfig(eq(serviceName));
    LoadBalancedRetryFactory factory = new RibbonLoadBalancedRetryFactory(clientFactory);
    RetryableOkHttpLoadBalancingClient client = new RetryableOkHttpLoadBalancingClient(delegate, clientConfig, introspector, factory);
    client.setLoadBalancer(lb);
    ReflectionTestUtils.setField(client, "delegate", delegate);
    return client;
}
Also used : DefaultLoadBalancerRetryHandler(com.netflix.client.DefaultLoadBalancerRetryHandler) RetryHandler(com.netflix.client.RetryHandler) SpringClientFactory(org.springframework.cloud.netflix.ribbon.SpringClientFactory) ServerIntrospector(org.springframework.cloud.netflix.ribbon.ServerIntrospector) DefaultLoadBalancerRetryHandler(com.netflix.client.DefaultLoadBalancerRetryHandler) RibbonLoadBalancerContext(org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerContext) RibbonLoadBalancedRetryFactory(org.springframework.cloud.netflix.ribbon.RibbonLoadBalancedRetryFactory) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl) RibbonLoadBalancedRetryFactory(org.springframework.cloud.netflix.ribbon.RibbonLoadBalancedRetryFactory) LoadBalancedRetryFactory(org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory)

Example 3 with RibbonLoadBalancedRetryFactory

use of org.springframework.cloud.netflix.ribbon.RibbonLoadBalancedRetryFactory in project spring-cloud-netflix by spring-cloud.

the class RibbonLoadBalancingHttpClientTests method setupClientForServerValidation.

private RetryableRibbonLoadBalancingHttpClient setupClientForServerValidation(String serviceName, String host, int port, CloseableHttpClient delegate, ILoadBalancer lb) throws Exception {
    ServerIntrospector introspector = mock(ServerIntrospector.class);
    RetryHandler retryHandler = new DefaultLoadBalancerRetryHandler(1, 1, true);
    DefaultClientConfigImpl clientConfig = new DefaultClientConfigImpl();
    clientConfig.set(CommonClientConfigKey.OkToRetryOnAllOperations, true);
    clientConfig.set(CommonClientConfigKey.MaxAutoRetriesNextServer, 0);
    clientConfig.set(CommonClientConfigKey.MaxAutoRetries, 1);
    clientConfig.set(RibbonLoadBalancedRetryPolicy.RETRYABLE_STATUS_CODES, "");
    clientConfig.set(CommonClientConfigKey.IsSecure, false);
    clientConfig.setClientName(serviceName);
    RibbonLoadBalancerContext context = new RibbonLoadBalancerContext(lb, clientConfig, retryHandler);
    SpringClientFactory clientFactory = mock(SpringClientFactory.class);
    doReturn(context).when(clientFactory).getLoadBalancerContext(eq(serviceName));
    doReturn(clientConfig).when(clientFactory).getClientConfig(eq(serviceName));
    LoadBalancedRetryFactory factory = new RibbonLoadBalancedRetryFactory(clientFactory);
    RetryableRibbonLoadBalancingHttpClient client = new RetryableRibbonLoadBalancingHttpClient(delegate, clientConfig, introspector, factory);
    client.setLoadBalancer(lb);
    ReflectionTestUtils.setField(client, "delegate", delegate);
    return client;
}
Also used : DefaultLoadBalancerRetryHandler(com.netflix.client.DefaultLoadBalancerRetryHandler) RetryHandler(com.netflix.client.RetryHandler) SpringClientFactory(org.springframework.cloud.netflix.ribbon.SpringClientFactory) ServerIntrospector(org.springframework.cloud.netflix.ribbon.ServerIntrospector) DefaultLoadBalancerRetryHandler(com.netflix.client.DefaultLoadBalancerRetryHandler) RibbonLoadBalancerContext(org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerContext) RibbonLoadBalancedRetryFactory(org.springframework.cloud.netflix.ribbon.RibbonLoadBalancedRetryFactory) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl) RibbonLoadBalancedRetryFactory(org.springframework.cloud.netflix.ribbon.RibbonLoadBalancedRetryFactory) LoadBalancedRetryFactory(org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory)

Example 4 with RibbonLoadBalancedRetryFactory

use of org.springframework.cloud.netflix.ribbon.RibbonLoadBalancedRetryFactory in project spring-cloud-netflix by spring-cloud.

the class RibbonLoadBalancingHttpClientTests method setupClientForRetry.

private RetryableRibbonLoadBalancingHttpClient setupClientForRetry(int retriesNextServer, int retriesSameServer, boolean retryable, boolean retryOnAllOps, String serviceName, String host, int port, CloseableHttpClient delegate, ILoadBalancer lb, String statusCodes, BackOffPolicy backOffPolicy, boolean isSecure) throws Exception {
    ServerIntrospector introspector = mock(ServerIntrospector.class);
    RetryHandler retryHandler = new DefaultLoadBalancerRetryHandler(retriesSameServer, retriesNextServer, retryable);
    doReturn(new Server(host, port)).when(lb).chooseServer(eq(serviceName));
    DefaultClientConfigImpl clientConfig = new DefaultClientConfigImpl();
    clientConfig.set(CommonClientConfigKey.OkToRetryOnAllOperations, retryOnAllOps);
    clientConfig.set(CommonClientConfigKey.MaxAutoRetriesNextServer, retriesNextServer);
    clientConfig.set(CommonClientConfigKey.MaxAutoRetries, retriesSameServer);
    clientConfig.set(RibbonLoadBalancedRetryPolicy.RETRYABLE_STATUS_CODES, statusCodes);
    clientConfig.set(CommonClientConfigKey.IsSecure, isSecure);
    clientConfig.setClientName(serviceName);
    RibbonLoadBalancerContext context = new RibbonLoadBalancerContext(lb, clientConfig, retryHandler);
    SpringClientFactory clientFactory = mock(SpringClientFactory.class);
    doReturn(context).when(clientFactory).getLoadBalancerContext(eq(serviceName));
    doReturn(clientConfig).when(clientFactory).getClientConfig(eq(serviceName));
    LoadBalancedRetryFactory factory = new RibbonLoadBalancedRetryFactory(clientFactory) {

        @Override
        public BackOffPolicy createBackOffPolicy(String service) {
            return backOffPolicy;
        }
    };
    RetryableRibbonLoadBalancingHttpClient client = new RetryableRibbonLoadBalancingHttpClient(delegate, clientConfig, introspector, factory);
    client.setLoadBalancer(lb);
    ReflectionTestUtils.setField(client, "delegate", delegate);
    return client;
}
Also used : Server(com.netflix.loadbalancer.Server) DefaultLoadBalancerRetryHandler(com.netflix.client.DefaultLoadBalancerRetryHandler) RetryHandler(com.netflix.client.RetryHandler) SpringClientFactory(org.springframework.cloud.netflix.ribbon.SpringClientFactory) ServerIntrospector(org.springframework.cloud.netflix.ribbon.ServerIntrospector) DefaultLoadBalancerRetryHandler(com.netflix.client.DefaultLoadBalancerRetryHandler) RibbonLoadBalancerContext(org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerContext) RibbonLoadBalancedRetryFactory(org.springframework.cloud.netflix.ribbon.RibbonLoadBalancedRetryFactory) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl) RibbonLoadBalancedRetryFactory(org.springframework.cloud.netflix.ribbon.RibbonLoadBalancedRetryFactory) LoadBalancedRetryFactory(org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory)

Aggregations

DefaultLoadBalancerRetryHandler (com.netflix.client.DefaultLoadBalancerRetryHandler)4 RetryHandler (com.netflix.client.RetryHandler)4 DefaultClientConfigImpl (com.netflix.client.config.DefaultClientConfigImpl)4 LoadBalancedRetryFactory (org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory)4 RibbonLoadBalancedRetryFactory (org.springframework.cloud.netflix.ribbon.RibbonLoadBalancedRetryFactory)4 RibbonLoadBalancerContext (org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerContext)4 ServerIntrospector (org.springframework.cloud.netflix.ribbon.ServerIntrospector)4 SpringClientFactory (org.springframework.cloud.netflix.ribbon.SpringClientFactory)4 Server (com.netflix.loadbalancer.Server)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 RetryListener (org.springframework.retry.RetryListener)1