use of org.springframework.cloud.netflix.ribbon.SpringClientFactory 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.SpringClientFactory in project spring-cloud-netflix by spring-cloud.
the class HttpClientRibbonCommandFactoryTest method testRibbonTimeoutAndRibbonRetriesDefaultAndNameSpaceSetting.
@Test
public void testRibbonTimeoutAndRibbonRetriesDefaultAndNameSpaceSetting() throws Exception {
ConfigurationManager.getConfigInstance().setProperty("service.test.ConnectTimeout", 1000);
ConfigurationManager.getConfigInstance().setProperty("service.test.ReadTimeout", 1000);
SpringClientFactory springClientFactory = mock(SpringClientFactory.class);
ZuulProperties zuulProperties = new ZuulProperties();
RibbonLoadBalancingHttpClient loadBalancingHttpClient = mock(RibbonLoadBalancingHttpClient.class);
IClientConfig clientConfig = new DefaultClientConfigImpl();
clientConfig.set(IClientConfigKey.Keys.ConnectTimeout, 100);
clientConfig.set(IClientConfigKey.Keys.ReadTimeout, 500);
doReturn(loadBalancingHttpClient).when(springClientFactory).getClient(anyString(), eq(RibbonLoadBalancingHttpClient.class));
doReturn(clientConfig).when(springClientFactory).getClientConfig(anyString());
HttpClientRibbonCommandFactory ribbonCommandFactory = new HttpClientRibbonCommandFactory(springClientFactory, zuulProperties, new HashSet<FallbackProvider>());
RibbonCommandContext context = mock(RibbonCommandContext.class);
doReturn("service").when(context).getServiceId();
HttpClientRibbonCommand ribbonCommand = ribbonCommandFactory.create(context);
assertEquals(1200, ribbonCommand.getProperties().executionTimeoutInMilliseconds().get().intValue());
}
use of org.springframework.cloud.netflix.ribbon.SpringClientFactory in project spring-cloud-netflix by spring-cloud.
the class HttpClientRibbonCommandFactoryTest method testRibbonCommandRetriesAndRibbonCommandTimeoutSetting.
@Test
public void testRibbonCommandRetriesAndRibbonCommandTimeoutSetting() throws Exception {
ConfigurationManager.getConfigInstance().setProperty("service.ribbon.ConnectTimeout", 1000);
ConfigurationManager.getConfigInstance().setProperty("service.ribbon.ReadTimeout", 1000);
ConfigurationManager.getConfigInstance().setProperty("service.ribbon.MaxAutoRetries", 1);
ConfigurationManager.getConfigInstance().setProperty("service.ribbon.MaxAutoRetriesNextServer", 2);
SpringClientFactory springClientFactory = mock(SpringClientFactory.class);
ZuulProperties zuulProperties = new ZuulProperties();
RibbonLoadBalancingHttpClient loadBalancingHttpClient = mock(RibbonLoadBalancingHttpClient.class);
IClientConfig clientConfig = new DefaultClientConfigImpl();
clientConfig.set(IClientConfigKey.Keys.ConnectTimeout, 100);
clientConfig.set(IClientConfigKey.Keys.ReadTimeout, 500);
doReturn(loadBalancingHttpClient).when(springClientFactory).getClient(anyString(), eq(RibbonLoadBalancingHttpClient.class));
doReturn(clientConfig).when(springClientFactory).getClientConfig(anyString());
HttpClientRibbonCommandFactory ribbonCommandFactory = new HttpClientRibbonCommandFactory(springClientFactory, zuulProperties, new HashSet<FallbackProvider>());
RibbonCommandContext context = mock(RibbonCommandContext.class);
doReturn("service").when(context).getServiceId();
HttpClientRibbonCommand ribbonCommand = ribbonCommandFactory.create(context);
assertEquals(12000, ribbonCommand.getProperties().executionTimeoutInMilliseconds().get().intValue());
}
use of org.springframework.cloud.netflix.ribbon.SpringClientFactory in project spring-cloud-netflix by spring-cloud.
the class HttpClientRibbonCommandFactoryTest method testRibbonRetriesAndRibbonTimeoutSetting.
@Test
public void testRibbonRetriesAndRibbonTimeoutSetting() throws Exception {
ConfigurationManager.getConfigInstance().setProperty("service.ribbon.MaxAutoRetries", 1);
ConfigurationManager.getConfigInstance().setProperty("service.ribbon.MaxAutoRetriesNextServer", 2);
SpringClientFactory springClientFactory = mock(SpringClientFactory.class);
ZuulProperties zuulProperties = new ZuulProperties();
RibbonLoadBalancingHttpClient loadBalancingHttpClient = mock(RibbonLoadBalancingHttpClient.class);
IClientConfig clientConfig = new DefaultClientConfigImpl();
clientConfig.set(IClientConfigKey.Keys.ConnectTimeout, 100);
clientConfig.set(IClientConfigKey.Keys.ReadTimeout, 500);
doReturn(loadBalancingHttpClient).when(springClientFactory).getClient(anyString(), eq(RibbonLoadBalancingHttpClient.class));
doReturn(clientConfig).when(springClientFactory).getClientConfig(anyString());
HttpClientRibbonCommandFactory ribbonCommandFactory = new HttpClientRibbonCommandFactory(springClientFactory, zuulProperties, new HashSet<FallbackProvider>());
RibbonCommandContext context = mock(RibbonCommandContext.class);
doReturn("service").when(context).getServiceId();
HttpClientRibbonCommand ribbonCommand = ribbonCommandFactory.create(context);
assertEquals(3600, ribbonCommand.getProperties().executionTimeoutInMilliseconds().get().intValue());
}
use of org.springframework.cloud.netflix.ribbon.SpringClientFactory in project spring-cloud-netflix by spring-cloud.
the class HttpClientRibbonCommandFactoryTest method testHystrixCommandAndRibbonSetting.
@Test
public void testHystrixCommandAndRibbonSetting() throws Exception {
ConfigurationManager.getConfigInstance().setProperty("hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds", 30);
ConfigurationManager.getConfigInstance().setProperty("hystrix.command.service.execution.isolation.thread.timeoutInMilliseconds", 50);
ConfigurationManager.getConfigInstance().setProperty("service.ribbon.ConnectTimeout", 1000);
ConfigurationManager.getConfigInstance().setProperty("service.ribbon.ReadTimeout", 1000);
ConfigurationManager.getConfigInstance().setProperty("service.ribbon.MaxAutoRetries", 1);
ConfigurationManager.getConfigInstance().setProperty("service.ribbon.MaxAutoRetriesNextServer", 2);
SpringClientFactory springClientFactory = mock(SpringClientFactory.class);
ZuulProperties zuulProperties = new ZuulProperties();
RibbonLoadBalancingHttpClient loadBalancingHttpClient = mock(RibbonLoadBalancingHttpClient.class);
IClientConfig clientConfig = new DefaultClientConfigImpl();
clientConfig.set(IClientConfigKey.Keys.ConnectTimeout, 100);
clientConfig.set(IClientConfigKey.Keys.ReadTimeout, 500);
doReturn(loadBalancingHttpClient).when(springClientFactory).getClient(anyString(), eq(RibbonLoadBalancingHttpClient.class));
doReturn(clientConfig).when(springClientFactory).getClientConfig(anyString());
HttpClientRibbonCommandFactory ribbonCommandFactory = new HttpClientRibbonCommandFactory(springClientFactory, zuulProperties, new HashSet<FallbackProvider>());
RibbonCommandContext context = mock(RibbonCommandContext.class);
doReturn("service").when(context).getServiceId();
HttpClientRibbonCommand ribbonCommand = ribbonCommandFactory.create(context);
assertEquals(50, ribbonCommand.getProperties().executionTimeoutInMilliseconds().get().intValue());
}
Aggregations