Search in sources :

Example 11 with LoadBalancer

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")));
}
Also used : Origin(com.hotels.styx.api.extension.Origin) Origin.newOriginBuilder(com.hotels.styx.api.extension.Origin.newOriginBuilder) LoadBalancer(com.hotels.styx.api.extension.loadbalancing.spi.LoadBalancer) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Test(org.junit.jupiter.api.Test)

Aggregations

LoadBalancer (com.hotels.styx.api.extension.loadbalancing.spi.LoadBalancer)11 Test (org.junit.jupiter.api.Test)10 Origin.newOriginBuilder (com.hotels.styx.api.extension.Origin.newOriginBuilder)8 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)7 Origin (com.hotels.styx.api.extension.Origin)7 Context (com.hotels.styx.api.HttpInterceptor.Context)6 HttpHandler (com.hotels.styx.api.HttpHandler)4 HttpInterceptor (com.hotels.styx.api.HttpInterceptor)4 RemoteHost (com.hotels.styx.api.extension.RemoteHost)4 RetryPolicy (com.hotels.styx.api.extension.retrypolicy.spi.RetryPolicy)4 RetryNTimes (com.hotels.styx.client.retry.RetryNTimes)4 Support.requestContext (com.hotels.styx.support.Support.requestContext)4 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)3 OriginUnreachableException (com.hotels.styx.api.exceptions.OriginUnreachableException)3 InOrder (org.mockito.InOrder)3 HostAndPort (com.google.common.net.HostAndPort)2 Eventual (com.hotels.styx.api.Eventual)2 HttpHeaderNames (com.hotels.styx.api.HttpHeaderNames)2 CHUNKED (com.hotels.styx.api.HttpHeaderNames.CHUNKED)2 CONTENT_LENGTH (com.hotels.styx.api.HttpHeaderNames.CONTENT_LENGTH)2