use of org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerContext 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;
}
use of org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerContext 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;
}
use of org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerContext in project spring-cloud-gateway by spring-cloud.
the class LoadBalancerClientFilterTests method testFilter.
private ServerWebExchange testFilter(ServerWebExchange exchange, URI uri) {
exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, uri);
ArgumentCaptor<ServerWebExchange> captor = ArgumentCaptor.forClass(ServerWebExchange.class);
when(chain.filter(captor.capture())).thenReturn(Mono.empty());
SpringClientFactory clientFactory = mock(SpringClientFactory.class);
ILoadBalancer loadBalancer = mock(ILoadBalancer.class);
when(clientFactory.getLoadBalancerContext("service1")).thenReturn(new RibbonLoadBalancerContext(loadBalancer));
when(clientFactory.getLoadBalancer("service1")).thenReturn(loadBalancer);
when(loadBalancer.chooseServer(any())).thenReturn(new Server("service1-host1", 8081));
RibbonLoadBalancerClient client = new RibbonLoadBalancerClient(clientFactory);
LoadBalancerClientFilter filter = new LoadBalancerClientFilter(client);
filter.filter(exchange, chain);
return captor.getValue();
}
use of org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerContext 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;
}
use of org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerContext 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;
}
Aggregations