Search in sources :

Example 21 with SpringClientFactory

use of org.springframework.cloud.netflix.ribbon.SpringClientFactory in project spring-cloud-gateway by spring-cloud.

the class LoadBalancerClientFilterTests method testFilter.

private ServerWebExchange testFilter(ServerWebExchange exchange, URI uri) {
    exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, uri);
    ArgumentCaptor<ServerWebExchange> captor = ArgumentCaptor.forClass(ServerWebExchange.class);
    when(chain.filter(captor.capture())).thenReturn(Mono.empty());
    SpringClientFactory clientFactory = mock(SpringClientFactory.class);
    ILoadBalancer loadBalancer = mock(ILoadBalancer.class);
    when(clientFactory.getLoadBalancerContext("service1")).thenReturn(new RibbonLoadBalancerContext(loadBalancer));
    when(clientFactory.getLoadBalancer("service1")).thenReturn(loadBalancer);
    when(loadBalancer.chooseServer(any())).thenReturn(new Server("service1-host1", 8081));
    RibbonLoadBalancerClient client = new RibbonLoadBalancerClient(clientFactory);
    LoadBalancerClientFilter filter = new LoadBalancerClientFilter(client);
    filter.filter(exchange, chain);
    return captor.getValue();
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) MockServerWebExchange(org.springframework.mock.web.server.MockServerWebExchange) Server(com.netflix.loadbalancer.Server) SpringClientFactory(org.springframework.cloud.netflix.ribbon.SpringClientFactory) ILoadBalancer(com.netflix.loadbalancer.ILoadBalancer) RibbonLoadBalancerContext(org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerContext) RibbonLoadBalancerClient(org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient)

Example 22 with SpringClientFactory

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

the class HttpClientRibbonCommandFactoryTest method setup.

@Before
public void setup() {
    this.springClientFactory = mock(SpringClientFactory.class);
    this.zuulProperties = new ZuulProperties();
    RibbonLoadBalancingHttpClient loadBalancingHttpClient = mock(RibbonLoadBalancingHttpClient.class);
    IClientConfig clientConfig = new DefaultClientConfigImpl();
    doReturn(loadBalancingHttpClient).when(this.springClientFactory).getClient(anyString(), eq(RibbonLoadBalancingHttpClient.class));
    doReturn(clientConfig).when(this.springClientFactory).getClientConfig(anyString());
    this.ribbonCommandFactory = new HttpClientRibbonCommandFactory(springClientFactory, zuulProperties, new HashSet<FallbackProvider>());
}
Also used : ZuulProperties(org.springframework.cloud.netflix.zuul.filters.ZuulProperties) 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) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 23 with SpringClientFactory

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

the class HttpClientRibbonCommandFactoryTest method testHystrixDefaultAndRibbonSetting.

@Test
public void testHystrixDefaultAndRibbonSetting() throws Exception {
    ConfigurationManager.getConfigInstance().setProperty("hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds", 30);
    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(30, 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 24 with SpringClientFactory

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

the class HttpClientRibbonCommandFactoryTest method testRibbonTimeoutAndRibbonRetriesDefaultAndDefaultSpaceSetting.

@Test
public void testRibbonTimeoutAndRibbonRetriesDefaultAndDefaultSpaceSetting() throws Exception {
    ConfigurationManager.getConfigInstance().setProperty("service.ribbon.ConnectTimeout", 1000);
    ConfigurationManager.getConfigInstance().setProperty("service.ribbon.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(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 25 with SpringClientFactory

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

the class OkHttpRibbonCommandFactoryTest 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();
    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(6000, 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)

Aggregations

SpringClientFactory (org.springframework.cloud.netflix.ribbon.SpringClientFactory)32 DefaultClientConfigImpl (com.netflix.client.config.DefaultClientConfigImpl)26 IClientConfig (com.netflix.client.config.IClientConfig)24 Test (org.junit.Test)24 ZuulProperties (org.springframework.cloud.netflix.zuul.filters.ZuulProperties)22 RibbonCommandContext (org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext)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 RibbonLoadBalancerContext (org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerContext)5 DefaultLoadBalancerRetryHandler (com.netflix.client.DefaultLoadBalancerRetryHandler)4 RetryHandler (com.netflix.client.RetryHandler)4 LoadBalancedRetryFactory (org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory)4 RibbonLoadBalancedRetryFactory (org.springframework.cloud.netflix.ribbon.RibbonLoadBalancedRetryFactory)4 ServerIntrospector (org.springframework.cloud.netflix.ribbon.ServerIntrospector)4 Server (com.netflix.loadbalancer.Server)3 ILoadBalancer (com.netflix.loadbalancer.ILoadBalancer)2 HashSet (java.util.HashSet)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Before (org.junit.Before)2