Search in sources :

Example 11 with RibbonCommandContext

use of org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext 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)

Example 12 with RibbonCommandContext

use of org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext 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());
}
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 13 with RibbonCommandContext

use of org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext 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());
}
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 14 with RibbonCommandContext

use of org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext 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());
}
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 15 with RibbonCommandContext

use of org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext 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());
}
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

RibbonCommandContext (org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext)43 Test (org.junit.Test)38 DefaultClientConfigImpl (com.netflix.client.config.DefaultClientConfigImpl)21 IClientConfig (com.netflix.client.config.IClientConfig)20 SpringClientFactory (org.springframework.cloud.netflix.ribbon.SpringClientFactory)20 ZuulProperties (org.springframework.cloud.netflix.zuul.filters.ZuulProperties)20 FallbackProvider (org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider)20 RibbonLoadBalancingHttpClient (org.springframework.cloud.netflix.ribbon.apache.RibbonLoadBalancingHttpClient)11 OkHttpLoadBalancingClient (org.springframework.cloud.netflix.ribbon.okhttp.OkHttpLoadBalancingClient)11 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)7 RibbonRequestCustomizer (org.springframework.cloud.netflix.ribbon.support.RibbonRequestCustomizer)6 URI (java.net.URI)4 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)4 HttpRequest (com.netflix.client.http.HttpRequest)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 Request (okhttp3.Request)2 HttpEntityEnclosingRequest (org.apache.http.HttpEntityEnclosingRequest)2