use of com.hotels.styx.api.Id 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.Id 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.Id in project styx by ExpediaGroup.
the class OriginHealthStatusMonitorFactoryTest method createsScheduledOriginStatusMonitor.
@Test
public void createsScheduledOriginStatusMonitor() {
HealthCheckConfig healthCheckConfig = newHealthCheckConfigBuilder().uri("/version.txt").interval(5, MILLISECONDS).build();
OriginHealthCheckFunction checkFunction = (client, origin, callback) -> {
};
assertThat(factory.create(id, healthCheckConfig, () -> checkFunction, mock(HttpClient.class)), is(instanceOf(AnomalyExcludingOriginHealthStatusMonitor.class)));
}
use of com.hotels.styx.api.Id in project styx by ExpediaGroup.
the class IdTest method checkEquality.
@Test
public void checkEquality() {
Id base = id("one");
Id same = id("one");
Id different = id("two");
assertThat(base.equals(null), is(false));
assertThat(base.equals(base), is(true));
assertThat(base.equals(same), is(true));
assertThat(base.equals(different), is(false));
}
use of com.hotels.styx.api.Id in project styx by ExpediaGroup.
the class OriginsInventory method handleSetOriginsEvent.
private void handleSetOriginsEvent(SetOriginsEvent event) {
Map<Id, Origin> newOriginsMap = event.newOrigins.stream().collect(toMap(Origin::id, o -> o));
OriginChanges originChanges = new OriginChanges();
concat(this.origins.keySet().stream(), newOriginsMap.keySet().stream()).collect(toSet()).forEach(originId -> {
Origin origin = newOriginsMap.get(originId);
if (isNewOrigin(originId, origin)) {
MonitoredOrigin monitoredOrigin = addMonitoredEndpoint(origin);
originChanges.addOrReplaceOrigin(originId, monitoredOrigin);
} else if (isUpdatedOrigin(originId, origin)) {
MonitoredOrigin monitoredOrigin = changeMonitoredEndpoint(origin);
originChanges.addOrReplaceOrigin(originId, monitoredOrigin);
} else if (isUnchangedOrigin(originId, origin)) {
LOG.info("Existing origin has been left unchanged. Origin={}:{}", appId, origin);
originChanges.keepExistingOrigin(originId, this.origins.get(originId));
} else if (isRemovedOrigin(originId, origin)) {
removeMonitoredEndpoint(originId);
originChanges.noteRemovedOrigin();
}
});
this.origins = originChanges.updatedOrigins();
if (originChanges.changed()) {
notifyStateChange();
}
}
Aggregations