use of org.springframework.cloud.netflix.ribbon.apache.RibbonLoadBalancingHttpClient in project spring-cloud-netflix by spring-cloud.
the class HttpClientRibbonCommandFactoryTest method testDefaultRibbonSetting.
@Test
public void testDefaultRibbonSetting() throws Exception {
SpringClientFactory springClientFactory = mock(SpringClientFactory.class);
ZuulProperties zuulProperties = new ZuulProperties();
RibbonLoadBalancingHttpClient loadBalancingHttpClient = mock(RibbonLoadBalancingHttpClient.class);
IClientConfig clientConfig = new DefaultClientConfigImpl();
doReturn(loadBalancingHttpClient).when(springClientFactory).getClient(anyString(), eq(RibbonLoadBalancingHttpClient.class));
doReturn(clientConfig).when(springClientFactory).getClientConfig(anyString());
HttpClientRibbonCommandFactory commandFactory = new HttpClientRibbonCommandFactory(springClientFactory, zuulProperties, new HashSet<FallbackProvider>());
RibbonCommandContext context = mock(RibbonCommandContext.class);
doReturn("service").when(context).getServiceId();
HttpClientRibbonCommand ribbonCommand = commandFactory.create(context);
assertEquals(4000, ribbonCommand.getProperties().executionTimeoutInMilliseconds().get().intValue());
}
use of org.springframework.cloud.netflix.ribbon.apache.RibbonLoadBalancingHttpClient in project spring-cloud-netflix by spring-cloud.
the class HttpClientRibbonCommandFactoryTest method testRibbonCommandRetriesAndRibbonCommandTimeoutPartOfSetting.
@Test
public void testRibbonCommandRetriesAndRibbonCommandTimeoutPartOfSetting() throws Exception {
ConfigurationManager.getConfigInstance().setProperty("service.ribbon.ConnectTimeout", 1000);
ConfigurationManager.getConfigInstance().setProperty("service.ribbon.MaxAutoRetries", 1);
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(6000, ribbonCommand.getProperties().executionTimeoutInMilliseconds().get().intValue());
}
use of org.springframework.cloud.netflix.ribbon.apache.RibbonLoadBalancingHttpClient in project spring-cloud-netflix by spring-cloud.
the class HttpClientRibbonCommandFactoryTest method testHystrixTimeoutValueRibbonTimeouts.
@Test
public void testHystrixTimeoutValueRibbonTimeouts() throws Exception {
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.apache.RibbonLoadBalancingHttpClient in project spring-cloud-netflix by spring-cloud.
the class HttpClientRibbonCommandFactoryTest method testRibbonTimeoutAndRibbonNameSpaceRetriesDefaultAndDefaultSpaceSetting.
@Test
public void testRibbonTimeoutAndRibbonNameSpaceRetriesDefaultAndDefaultSpaceSetting() throws Exception {
ConfigurationManager.getConfigInstance().setProperty("service.ribbon.ConnectTimeout", 1000);
ConfigurationManager.getConfigInstance().setProperty("service.ribbon.ReadTimeout", 1000);
ConfigurationManager.getConfigInstance().setProperty("service.test.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(4000, ribbonCommand.getProperties().executionTimeoutInMilliseconds().get().intValue());
}
use of org.springframework.cloud.netflix.ribbon.apache.RibbonLoadBalancingHttpClient in project spring-cloud-netflix by spring-cloud.
the class HttpClientRibbonCommandFactory method create.
@Override
public HttpClientRibbonCommand create(final RibbonCommandContext context) {
FallbackProvider zuulFallbackProvider = getFallbackProvider(context.getServiceId());
final String serviceId = context.getServiceId();
final RibbonLoadBalancingHttpClient client = this.clientFactory.getClient(serviceId, RibbonLoadBalancingHttpClient.class);
client.setLoadBalancer(this.clientFactory.getLoadBalancer(serviceId));
return new HttpClientRibbonCommand(serviceId, client, context, zuulProperties, zuulFallbackProvider, clientFactory.getClientConfig(serviceId));
}
Aggregations