Search in sources :

Example 11 with FallbackProvider

use of org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider in project spring-cloud-netflix by spring-cloud.

the class OkHttpRibbonCommandFactoryTest method testRibbonAndRibbonRetriesDefaultSetting.

@Test
public void testRibbonAndRibbonRetriesDefaultSetting() throws Exception {
    SpringClientFactory springClientFactory = mock(SpringClientFactory.class);
    ZuulProperties zuulProperties = new ZuulProperties();
    OkHttpLoadBalancingClient loadBalancingHttpClient = mock(OkHttpLoadBalancingClient.class);
    IClientConfig clientConfig = new DefaultClientConfigImpl();
    clientConfig.set(IClientConfigKey.Keys.ConnectTimeout, 100);
    clientConfig.set(IClientConfigKey.Keys.ReadTimeout, 500);
    doReturn(loadBalancingHttpClient).when(springClientFactory).getClient(anyString(), eq(OkHttpLoadBalancingClient.class));
    doReturn(clientConfig).when(springClientFactory).getClientConfig(anyString());
    OkHttpRibbonCommandFactory commandFactory = new OkHttpRibbonCommandFactory(springClientFactory, zuulProperties, new HashSet<FallbackProvider>());
    RibbonCommandContext context = mock(RibbonCommandContext.class);
    doReturn("service").when(context).getServiceId();
    OkHttpRibbonCommand ribbonCommand = commandFactory.create(context);
    assertEquals(1200, ribbonCommand.getProperties().executionTimeoutInMilliseconds().get().intValue());
}
Also used : ZuulProperties(org.springframework.cloud.netflix.zuul.filters.ZuulProperties) OkHttpLoadBalancingClient(org.springframework.cloud.netflix.ribbon.okhttp.OkHttpLoadBalancingClient) FallbackProvider(org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider) RibbonCommandContext(org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext) SpringClientFactory(org.springframework.cloud.netflix.ribbon.SpringClientFactory) IClientConfig(com.netflix.client.config.IClientConfig) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl) Test(org.junit.Test)

Example 12 with FallbackProvider

use of org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider in project spring-cloud-netflix by spring-cloud.

the class OkHttpRibbonCommandFactoryTest 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();
    OkHttpLoadBalancingClient loadBalancingHttpClient = mock(OkHttpLoadBalancingClient.class);
    IClientConfig clientConfig = new DefaultClientConfigImpl();
    clientConfig.set(IClientConfigKey.Keys.ConnectTimeout, 100);
    clientConfig.set(IClientConfigKey.Keys.ReadTimeout, 500);
    doReturn(loadBalancingHttpClient).when(springClientFactory).getClient(anyString(), eq(OkHttpLoadBalancingClient.class));
    doReturn(clientConfig).when(springClientFactory).getClientConfig(anyString());
    OkHttpRibbonCommandFactory commandFactory = new OkHttpRibbonCommandFactory(springClientFactory, zuulProperties, new HashSet<FallbackProvider>());
    RibbonCommandContext context = mock(RibbonCommandContext.class);
    doReturn("service").when(context).getServiceId();
    OkHttpRibbonCommand ribbonCommand = commandFactory.create(context);
    assertEquals(3600, ribbonCommand.getProperties().executionTimeoutInMilliseconds().get().intValue());
}
Also used : ZuulProperties(org.springframework.cloud.netflix.zuul.filters.ZuulProperties) OkHttpLoadBalancingClient(org.springframework.cloud.netflix.ribbon.okhttp.OkHttpLoadBalancingClient) FallbackProvider(org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider) RibbonCommandContext(org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext) SpringClientFactory(org.springframework.cloud.netflix.ribbon.SpringClientFactory) IClientConfig(com.netflix.client.config.IClientConfig) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl) Test(org.junit.Test)

Example 13 with FallbackProvider

use of org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider in project spring-cloud-netflix by spring-cloud.

the class OkHttpRibbonCommandFactoryTest method testDefaultRibbonSetting.

@Test
public void testDefaultRibbonSetting() throws Exception {
    SpringClientFactory springClientFactory = mock(SpringClientFactory.class);
    ZuulProperties zuulProperties = new ZuulProperties();
    OkHttpLoadBalancingClient loadBalancingHttpClient = mock(OkHttpLoadBalancingClient.class);
    IClientConfig clientConfig = new DefaultClientConfigImpl();
    doReturn(loadBalancingHttpClient).when(springClientFactory).getClient(anyString(), eq(OkHttpLoadBalancingClient.class));
    doReturn(clientConfig).when(springClientFactory).getClientConfig(anyString());
    OkHttpRibbonCommandFactory commandFactory = new OkHttpRibbonCommandFactory(springClientFactory, zuulProperties, new HashSet<FallbackProvider>());
    RibbonCommandContext context = mock(RibbonCommandContext.class);
    doReturn("service").when(context).getServiceId();
    OkHttpRibbonCommand ribbonCommand = commandFactory.create(context);
    assertEquals(4000, ribbonCommand.getProperties().executionTimeoutInMilliseconds().get().intValue());
}
Also used : ZuulProperties(org.springframework.cloud.netflix.zuul.filters.ZuulProperties) OkHttpLoadBalancingClient(org.springframework.cloud.netflix.ribbon.okhttp.OkHttpLoadBalancingClient) FallbackProvider(org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider) RibbonCommandContext(org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext) SpringClientFactory(org.springframework.cloud.netflix.ribbon.SpringClientFactory) IClientConfig(com.netflix.client.config.IClientConfig) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl) Test(org.junit.Test)

Example 14 with FallbackProvider

use of org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider 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));
}
Also used : FallbackProvider(org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider) RibbonLoadBalancingHttpClient(org.springframework.cloud.netflix.ribbon.apache.RibbonLoadBalancingHttpClient)

Example 15 with FallbackProvider

use of org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider in project spring-cloud-netflix by spring-cloud.

the class OkHttpRibbonCommandFactory method create.

@Override
public OkHttpRibbonCommand create(final RibbonCommandContext context) {
    final String serviceId = context.getServiceId();
    FallbackProvider fallbackProvider = getFallbackProvider(serviceId);
    final OkHttpLoadBalancingClient client = this.clientFactory.getClient(serviceId, OkHttpLoadBalancingClient.class);
    client.setLoadBalancer(this.clientFactory.getLoadBalancer(serviceId));
    return new OkHttpRibbonCommand(serviceId, client, context, zuulProperties, fallbackProvider, clientFactory.getClientConfig(serviceId));
}
Also used : OkHttpLoadBalancingClient(org.springframework.cloud.netflix.ribbon.okhttp.OkHttpLoadBalancingClient) FallbackProvider(org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider)

Aggregations

FallbackProvider (org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider)23 Test (org.junit.Test)21 DefaultClientConfigImpl (com.netflix.client.config.DefaultClientConfigImpl)20 IClientConfig (com.netflix.client.config.IClientConfig)20 SpringClientFactory (org.springframework.cloud.netflix.ribbon.SpringClientFactory)20 RibbonCommandContext (org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext)20 ZuulProperties (org.springframework.cloud.netflix.zuul.filters.ZuulProperties)20 RibbonLoadBalancingHttpClient (org.springframework.cloud.netflix.ribbon.apache.RibbonLoadBalancingHttpClient)11 OkHttpLoadBalancingClient (org.springframework.cloud.netflix.ribbon.okhttp.OkHttpLoadBalancingClient)11 ClientHttpResponse (org.springframework.http.client.ClientHttpResponse)1