use of com.hotels.styx.api.extension.RemoteHost in project styx by ExpediaGroup.
the class StyxBackendServiceClientTest method hostHeaderIsOverwrittenWhenOverrideHostHeaderIsTrue.
@Test
public void hostHeaderIsOverwrittenWhenOverrideHostHeaderIsTrue() {
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();
styxHttpClient.sendRequest(testRequest, requestContext);
ArgumentCaptor<LiveHttpRequest> updatedRequest = ArgumentCaptor.forClass(LiveHttpRequest.class);
verify(httpHandler).handle(updatedRequest.capture(), eq(requestContext));
assertThat(updatedRequest.getValue().header(HttpHeaderNames.HOST).get(), is(updatedHostName));
}
use of com.hotels.styx.api.extension.RemoteHost in project styx by ExpediaGroup.
the class BusyConnectionsStrategyTest method tieBreaksOriginsWithEqualMetric.
@Test
public void tieBreaksOriginsWithEqualMetric() {
RemoteHost hostOne = remoteHost(ORIGIN_ONE, mock(HttpHandler.class), lbMetrics(3));
RemoteHost hostTwo = remoteHost(ORIGIN_TWO, mock(HttpHandler.class), lbMetrics(3));
RemoteHost hostThree = remoteHost(ORIGIN_THREE, mock(HttpHandler.class), lbMetrics(3));
when(activeOrigins.snapshot()).thenReturn(asList(hostOne, hostTwo, hostThree));
List<RemoteHost> results = new ArrayList<>();
for (int i = 0; i < 100; i++) {
results.add(strategy.choose(null).get());
}
assertThat(count(hostOne, results), greaterThan(10L));
assertThat(count(hostTwo, results), greaterThan(10L));
assertThat(count(hostThree, results), greaterThan(10L));
}
use of com.hotels.styx.api.extension.RemoteHost in project styx by ExpediaGroup.
the class BusyConnectionsStrategyTest method favoursOriginsWithLessBusyConnectionCount.
@Test
public void favoursOriginsWithLessBusyConnectionCount() {
RemoteHost hostOne = remoteHost(ORIGIN_ONE, mock(HttpHandler.class), lbMetrics(4));
RemoteHost hostTwo = remoteHost(ORIGIN_TWO, mock(HttpHandler.class), lbMetrics(3));
RemoteHost hostThree = remoteHost(ORIGIN_THREE, mock(HttpHandler.class), lbMetrics(6));
when(activeOrigins.snapshot()).thenReturn(asList(hostOne, hostTwo, hostThree));
Optional<RemoteHost> sortedPool = strategy.choose(null);
assertThat(sortedPool, is(Optional.of(hostTwo)));
}
use of com.hotels.styx.api.extension.RemoteHost in project styx by ExpediaGroup.
the class PowerOfTwoStrategyTest method choosesBetterOfTwoRandomChoices.
@Test
public void choosesBetterOfTwoRandomChoices() {
ActiveOrigins activeOrigins = mock(ActiveOrigins.class);
when(activeOrigins.snapshot()).thenReturn(allOrigins);
Random rng = new Random(RNG_SEED);
int first = rng.nextInt(4);
assert (first == 2);
int second = rng.nextInt(4);
assert (second == 0);
PowerOfTwoStrategy loadBalancer = new PowerOfTwoStrategy(activeOrigins, new Random(RNG_SEED));
Optional<RemoteHost> chosenOne = loadBalancer.choose(mock(LoadBalancer.Preferences.class));
assertThat(chosenOne.get(), is(betterOf(allOrigins.get(first), allOrigins.get(second))));
}
use of com.hotels.styx.api.extension.RemoteHost in project styx by ExpediaGroup.
the class PowerOfTwoStrategyTest method choosesSoleOriginOutOfOne.
@Test
public void choosesSoleOriginOutOfOne() {
ActiveOrigins activeOrigins = mock(ActiveOrigins.class);
when(activeOrigins.snapshot()).thenReturn(asList(HOST_ONE));
PowerOfTwoStrategy loadBalancer = new PowerOfTwoStrategy(activeOrigins, new Random(RNG_SEED));
for (int i = 0; i < 10; i++) {
Optional<RemoteHost> chosenOne = loadBalancer.choose(mock(LoadBalancer.Preferences.class));
assertThat(chosenOne.get(), is(HOST_ONE));
}
}
Aggregations