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();
}
Aggregations