use of com.hotels.styx.api.extension.loadbalancing.spi.LoadBalancer in project styx by ExpediaGroup.
the class StyxBackendServiceClientTest method prefersRestrictedOriginsOverStickyOriginsWhenBothAreConfigured.
@Test
public void prefersRestrictedOriginsOverStickyOriginsWhenBothAreConfigured() {
Origin origin = originWithId("localhost:234", "App-X", "Origin-Y");
StyxHostHttpClient hostClient = mockHostClient(Flux.just(response(OK).build()));
LoadBalancer loadBalancer = mockLoadBalancer(Optional.of(remoteHost(origin, toHandler(hostClient), hostClient)));
StyxBackendServiceClient styxHttpClient = new StyxBackendServiceClient.Builder(backendService.id()).originsRestrictionCookieName("restrictedOrigin").loadBalancer(loadBalancer).metrics(metrics).build();
LiveHttpResponse response = Mono.from(styxHttpClient.sendRequest(get("/foo").cookies(requestCookie("restrictedOrigin", "Origin-Y"), requestCookie("styx_origin_" + Id.GENERIC_APP, "Origin-X")).build(), requestContext())).block();
assertThat(response.status(), is(OK));
ArgumentCaptor<LoadBalancer.Preferences> argPreferences = ArgumentCaptor.forClass(LoadBalancer.Preferences.class);
verify(loadBalancer).choose(argPreferences.capture());
assertThat(argPreferences.getValue().preferredOrigins(), is(Optional.of("Origin-Y")));
}
Aggregations