use of com.hotels.styx.api.extension.RemoteHost in project styx by ExpediaGroup.
the class StyxBackendServiceClientTest method updatedRequestWithUpdatedHostHeaderIsPresentInResponseWhenOverrideHostHeaderIsTrue.
@Test
public void updatedRequestWithUpdatedHostHeaderIsPresentInResponseWhenOverrideHostHeaderIsTrue() {
HttpInterceptor.Context requestContext = requestContext();
StyxHostHttpClient hostClient = mock(StyxHostHttpClient.class);
HttpHandler httpHandler = mock(HttpHandler.class);
Origin origin = newOriginBuilder(updatedHostName, 9090).applicationId(GENERIC_APP).build();
RemoteHost remoteHost = remoteHost(origin, httpHandler, hostClient);
LoadBalancer loadBalancer = mockLoadBalancer(Optional.of(remoteHost));
when(httpHandler.handle(any(), any())).thenReturn(Eventual.of(testResponse));
StyxBackendServiceClient styxHttpClient = new StyxBackendServiceClient.Builder(backendService.id()).originStatsFactory(mock(OriginStatsFactory.class)).originsRestrictionCookieName("someCookie").originIdHeader("origin-id").loadBalancer(loadBalancer).retryPolicy(new RetryNTimes(0)).metrics(metrics).overrideHostHeader(true).build();
Publisher<LiveHttpResponse> responsePublisher = styxHttpClient.sendRequest(testRequest, requestContext);
StepVerifier.create(responsePublisher).expectNextMatches(it -> it.request().header(HttpHeaderNames.HOST).isPresent() && it.request().header(HttpHeaderNames.HOST).get().equals(updatedHostName)).verifyComplete();
}
use of com.hotels.styx.api.extension.RemoteHost in project styx by ExpediaGroup.
the class StyxBackendServiceClientTest method originalRequestIsPresentInResponseWhenOverrideHostHeaderIsFalse.
@Test
public void originalRequestIsPresentInResponseWhenOverrideHostHeaderIsFalse() {
HttpInterceptor.Context requestContext = requestContext();
StyxHostHttpClient hostClient = mock(StyxHostHttpClient.class);
HttpHandler httpHandler = mock(HttpHandler.class);
Origin origin = newOriginBuilder(incomingHostname, 9090).applicationId(GENERIC_APP).build();
RemoteHost remoteHost = remoteHost(origin, httpHandler, hostClient);
LoadBalancer loadBalancer = mockLoadBalancer(Optional.of(remoteHost));
when(httpHandler.handle(any(), any())).thenReturn(Eventual.of(testResponse));
StyxBackendServiceClient styxHttpClient = new StyxBackendServiceClient.Builder(backendService.id()).originStatsFactory(mock(OriginStatsFactory.class)).originsRestrictionCookieName("someCookie").originIdHeader("origin-id").loadBalancer(loadBalancer).retryPolicy(new RetryNTimes(0)).metrics(metrics).overrideHostHeader(false).build();
Publisher<LiveHttpResponse> responsePublisher = styxHttpClient.sendRequest(testRequest, requestContext);
StepVerifier.create(responsePublisher).expectNextMatches(it -> it.request().header(HttpHeaderNames.HOST).isPresent() && it.request().header(HttpHeaderNames.HOST).get().equals(incomingHostname)).verifyComplete();
}
use of com.hotels.styx.api.extension.RemoteHost in project styx by ExpediaGroup.
the class BusyConnectionsStrategyTest method copesWithOnlyOneActiveOrigin.
@Test
public void copesWithOnlyOneActiveOrigin() {
RemoteHost hostOne = remoteHost(ORIGIN_ONE, mock(HttpHandler.class), lbMetrics(4));
when(activeOrigins.snapshot()).thenReturn(asList(hostOne));
Optional<RemoteHost> sortedPool = strategy.choose(null);
assertThat(sortedPool, is(Optional.of(hostOne)));
}
use of com.hotels.styx.api.extension.RemoteHost in project styx by ExpediaGroup.
the class PowerOfTwoStrategyTest method returnsEmptyWhenNoOriginsAreAvailable.
@Test
public void returnsEmptyWhenNoOriginsAreAvailable() {
ActiveOrigins activeOrigins = mock(ActiveOrigins.class);
when(activeOrigins.snapshot()).thenReturn(asList());
PowerOfTwoStrategy loadBalancer = new PowerOfTwoStrategy(activeOrigins, new Random(RNG_SEED));
Optional<RemoteHost> chosenOne = loadBalancer.choose(mock(LoadBalancer.Preferences.class));
assertThat(chosenOne, is(Optional.empty()));
}
use of com.hotels.styx.api.extension.RemoteHost in project styx by ExpediaGroup.
the class OriginRestrictionLoadBalancingStrategyTest method dontDelegateWhenOriginRestrictionCookieMatches.
@Test
public void dontDelegateWhenOriginRestrictionCookieMatches() {
Random mockRandom = mock(Random.class);
when(mockRandom.nextInt(eq(1))).thenReturn(0);
strategy = new OriginRestrictionLoadBalancingStrategy(new ActiveOrigins() {
@Override
public Iterable<RemoteHost> snapshot() {
return origins;
}
@Override
public String getApplicationId() {
return null;
}
@Override
public List<Origin> origins() {
return null;
}
}, delegate, mockRandom);
strategy.choose(lbPreference(Optional.of("origin-1")));
strategy.choose(lbPreference(Optional.of("origin-1")));
strategy.choose(lbPreference(Optional.of("origin-1")));
strategy.choose(lbPreference(Optional.of("origin-1")));
strategy.choose(lbPreference(Optional.of("origin-1")));
strategy.choose(lbPreference(Optional.of("origin-1")));
verify(delegate, never()).choose(any(LoadBalancer.Preferences.class));
}
Aggregations