Search in sources :

Example 1 with RibbonLoadBalancingHttpClient

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

the class RibbonClientConfigurationTests method clients.

private List<AbstractLoadBalancerAwareClient> clients() {
    ArrayList<AbstractLoadBalancerAwareClient> clients = new ArrayList<>();
    clients.add(new OverrideRestClient(this.config, this.inspector));
    clients.add(new RibbonLoadBalancingHttpClient(this.config, this.inspector));
    clients.add(new OkHttpLoadBalancingClient(this.config, this.inspector));
    return clients;
}
Also used : OverrideRestClient(org.springframework.cloud.netflix.ribbon.RibbonClientConfiguration.OverrideRestClient) AbstractLoadBalancerAwareClient(com.netflix.client.AbstractLoadBalancerAwareClient) OkHttpLoadBalancingClient(org.springframework.cloud.netflix.ribbon.okhttp.OkHttpLoadBalancingClient) RibbonLoadBalancingHttpClient(org.springframework.cloud.netflix.ribbon.apache.RibbonLoadBalancingHttpClient) ArrayList(java.util.ArrayList)

Example 2 with RibbonLoadBalancingHttpClient

use of org.springframework.cloud.netflix.ribbon.apache.RibbonLoadBalancingHttpClient 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());
}
Also used : ZuulProperties(org.springframework.cloud.netflix.zuul.filters.ZuulProperties) FallbackProvider(org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider) RibbonCommandContext(org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext) SpringClientFactory(org.springframework.cloud.netflix.ribbon.SpringClientFactory) RibbonLoadBalancingHttpClient(org.springframework.cloud.netflix.ribbon.apache.RibbonLoadBalancingHttpClient) IClientConfig(com.netflix.client.config.IClientConfig) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl) Test(org.junit.Test)

Example 3 with RibbonLoadBalancingHttpClient

use of org.springframework.cloud.netflix.ribbon.apache.RibbonLoadBalancingHttpClient 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());
}
Also used : ZuulProperties(org.springframework.cloud.netflix.zuul.filters.ZuulProperties) FallbackProvider(org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider) RibbonCommandContext(org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext) SpringClientFactory(org.springframework.cloud.netflix.ribbon.SpringClientFactory) RibbonLoadBalancingHttpClient(org.springframework.cloud.netflix.ribbon.apache.RibbonLoadBalancingHttpClient) IClientConfig(com.netflix.client.config.IClientConfig) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl) Test(org.junit.Test)

Example 4 with RibbonLoadBalancingHttpClient

use of org.springframework.cloud.netflix.ribbon.apache.RibbonLoadBalancingHttpClient 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());
}
Also used : ZuulProperties(org.springframework.cloud.netflix.zuul.filters.ZuulProperties) FallbackProvider(org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider) RibbonCommandContext(org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext) SpringClientFactory(org.springframework.cloud.netflix.ribbon.SpringClientFactory) RibbonLoadBalancingHttpClient(org.springframework.cloud.netflix.ribbon.apache.RibbonLoadBalancingHttpClient) IClientConfig(com.netflix.client.config.IClientConfig) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl) Test(org.junit.Test)

Example 5 with RibbonLoadBalancingHttpClient

use of org.springframework.cloud.netflix.ribbon.apache.RibbonLoadBalancingHttpClient 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());
}
Also used : ZuulProperties(org.springframework.cloud.netflix.zuul.filters.ZuulProperties) FallbackProvider(org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider) RibbonCommandContext(org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext) SpringClientFactory(org.springframework.cloud.netflix.ribbon.SpringClientFactory) RibbonLoadBalancingHttpClient(org.springframework.cloud.netflix.ribbon.apache.RibbonLoadBalancingHttpClient) IClientConfig(com.netflix.client.config.IClientConfig) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl) Test(org.junit.Test)

Aggregations

RibbonLoadBalancingHttpClient (org.springframework.cloud.netflix.ribbon.apache.RibbonLoadBalancingHttpClient)14 DefaultClientConfigImpl (com.netflix.client.config.DefaultClientConfigImpl)11 IClientConfig (com.netflix.client.config.IClientConfig)11 Test (org.junit.Test)11 SpringClientFactory (org.springframework.cloud.netflix.ribbon.SpringClientFactory)11 RibbonCommandContext (org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext)11 ZuulProperties (org.springframework.cloud.netflix.zuul.filters.ZuulProperties)11 FallbackProvider (org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider)11 AbstractLoadBalancerAwareClient (com.netflix.client.AbstractLoadBalancerAwareClient)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 Before (org.junit.Before)1 MockingDetails (org.mockito.MockingDetails)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 OverrideRestClient (org.springframework.cloud.netflix.ribbon.RibbonClientConfiguration.OverrideRestClient)1 OkHttpLoadBalancingClient (org.springframework.cloud.netflix.ribbon.okhttp.OkHttpLoadBalancingClient)1 HttpClientRibbonCommand (org.springframework.cloud.netflix.zuul.filters.route.apache.HttpClientRibbonCommand)1