Search in sources :

Example 1 with RibbonLoadBalancerClient

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

Aggregations

ILoadBalancer (com.netflix.loadbalancer.ILoadBalancer)1 Server (com.netflix.loadbalancer.Server)1 RibbonLoadBalancerClient (org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient)1 RibbonLoadBalancerContext (org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerContext)1 SpringClientFactory (org.springframework.cloud.netflix.ribbon.SpringClientFactory)1 MockServerWebExchange (org.springframework.mock.web.server.MockServerWebExchange)1 ServerWebExchange (org.springframework.web.server.ServerWebExchange)1