use of com.hotels.styx.api.extension.service.BackendService in project styx by ExpediaGroup.
the class BackendServicesRouterTest method selectsServiceBasedOnPath.
@Test
public void selectsServiceBasedOnPath() throws Exception {
Registry.Changes<BackendService> changes = added(appA().newCopy().path("/").build(), appB().newCopy().path("/appB/hotel/details.html").build());
BackendServicesRouter router = new BackendServicesRouter(serviceClientFactory, environment, executor);
router.onChange(changes);
LiveHttpRequest request = get("/appB/hotel/details.html").build();
Optional<HttpHandler> route = router.route(request, context);
assertThat(proxyTo(route, request).header(ORIGIN_ID_DEFAULT), isValue(APP_B));
}
use of com.hotels.styx.api.extension.service.BackendService in project styx by ExpediaGroup.
the class BackendServicesRouterTest method selectsUsingSingleSlashPathIfAppsAreProvidedInOppositeOrder.
@Test
public void selectsUsingSingleSlashPathIfAppsAreProvidedInOppositeOrder() throws Exception {
Registry.Changes<BackendService> changes = added(appB().newCopy().path("/appB/hotel/details.html").build(), appA().newCopy().path("/").build());
BackendServicesRouter router = new BackendServicesRouter(serviceClientFactory, environment, executor);
router.onChange(changes);
LiveHttpRequest request = get("/").build();
Optional<HttpHandler> route = router.route(request, context);
assertThat(proxyTo(route, request).header(ORIGIN_ID_DEFAULT), isValue(APP_A));
}
use of com.hotels.styx.api.extension.service.BackendService in project styx by ExpediaGroup.
the class StyxBackendServiceClientFactoryTest method usesTheOriginSpecifiedInTheStickySessionCookie.
@Test
public void usesTheOriginSpecifiedInTheStickySessionCookie() {
BackendService backendService = newBackendServiceBuilder().origins(newOriginBuilder("localhost", 9091).id("x").build(), newOriginBuilder("localhost", 9092).id("y").build(), newOriginBuilder("localhost", 9093).id("z").build()).stickySessionConfig(newStickySessionConfigBuilder().enabled(true).build()).build();
BackendServiceClient styxBackendServiceClient = new StyxBackendServiceClientFactory(environment).createClient(backendService, newOriginsInventoryBuilder(environment.centralisedMetrics(), backendService).hostClientFactory((pool) -> {
if (pool.getOrigin().id().equals(id("x"))) {
return hostClient(response(OK).header("X-Origin-Id", "x").build());
} else if (pool.getOrigin().id().equals(id("y"))) {
return hostClient(response(OK).header("X-Origin-Id", "y").build());
} else {
return hostClient(response(OK).header("X-Origin-Id", "z").build());
}
}).build(), new CachingOriginStatsFactory(environment.centralisedMetrics()));
LiveHttpRequest requestz = get("/some-req").cookies(requestCookie(STICKY_COOKIE, id("z").toString())).build();
LiveHttpRequest requestx = get("/some-req").cookies(requestCookie(STICKY_COOKIE, id("x").toString())).build();
LiveHttpRequest requesty = get("/some-req").cookies(requestCookie(STICKY_COOKIE, id("y").toString())).build();
LiveHttpResponse responsez = Mono.from(styxBackendServiceClient.sendRequest(requestz, requestContext())).block();
LiveHttpResponse responsex = Mono.from(styxBackendServiceClient.sendRequest(requestx, requestContext())).block();
LiveHttpResponse responsey = Mono.from(styxBackendServiceClient.sendRequest(requesty, requestContext())).block();
assertThat(responsex.header("X-Origin-Id").get(), is("x"));
assertThat(responsey.header("X-Origin-Id").get(), is("y"));
assertThat(responsez.header("X-Origin-Id").get(), is("z"));
}
use of com.hotels.styx.api.extension.service.BackendService in project styx by ExpediaGroup.
the class FileBackedBackendServicesRegistryTest method yamlBackendReaderReadsBackendServicesFromByteStream.
@Test
public void yamlBackendReaderReadsBackendServicesFromByteStream() throws IOException {
Resource resource = newResource("classpath:/backends/origins.yml");
Iterable<BackendService> backendServices = new YAMLBackendServicesReader().read(bytes(resource.inputStream(), true));
assertThat(iterableToList(backendServices).size(), is(3));
}
use of com.hotels.styx.api.extension.service.BackendService in project styx by ExpediaGroup.
the class FileBackedBackendServicesRegistryTest method serviceStarts_logsInfoWhenReloadFails.
@Test
public void serviceStarts_logsInfoWhenReloadFails() {
FileBackedRegistry<BackendService> delegate = mock(FileBackedRegistry.class);
when(delegate.fileName()).thenReturn("/monitored/origins.yml");
when(delegate.reload()).thenReturn(completedFuture(failed("md5-hash: 9034890345289043, Failed to load file", new JustATestException())));
registry = new FileBackedBackendServicesRegistry(delegate, FileMonitor.DISABLED);
try {
registry.startService().get();
} catch (Throwable any) {
// pass
} finally {
assertThat(log.lastMessage(), is(loggingEvent(ERROR, "Backend services reload failed. reason='Initial load', md5-hash: 9034890345289043, Failed to load file, file='/monitored/origins.yml'", JustATestException.class, JustATestException.DEFAULT_MESSAGE)));
}
}
Aggregations