use of com.hotels.styx.api.extension.service.BackendService in project styx by ExpediaGroup.
the class MemoryBackedRegistryTest method addsResources.
@Test
public void addsResources() {
BackendService landing = backendService("landing", 9091);
BackendService shopping = backendService("shopping", 9090);
MemoryBackedRegistry<BackendService> registry = new MemoryBackedRegistry<>();
registry.add(landing);
registry.addListener(listener);
registry.add(shopping);
assertThat(registry.get(), containsInAnyOrder(landing, shopping));
verify(listener).onChange(eq(added(shopping)));
}
use of com.hotels.styx.api.extension.service.BackendService in project styx by ExpediaGroup.
the class DashboardDataSupplierTest method originsHaveStatuses.
@Test
public void originsHaveStatuses() throws JsonProcessingException {
MemoryBackedRegistry<BackendService> registry = new MemoryBackedRegistry<>();
DashboardDataSupplier supplier = new DashboardDataSupplier(registry, environment, styxConfig);
Origin foo1 = origin("foo1");
Origin foo2 = origin("foo2");
registry.add(backend("foo", foo1, foo2));
registry.add(backend("bar", origin("bar1")));
// Set statuses
environment.eventBus().post(new OriginsSnapshot(id("foo"), pools(foo1), pools(foo2), pools()));
DashboardData.Downstream downstream = supplier.get().downstream();
DashboardData.Backend fooBackend = downstream.backend("STYXPRES-foo");
assertThat(downstream.backendIds(), containsInAnyOrder("STYXPRES-foo", "STYXPRES-bar"));
assertThat(fooBackend.statusesByOriginId(), is(equalTo(Map.of("foo1", "active", "foo2", "inactive"))));
assertThat(fooBackend.origin("foo1").status(), is("active"));
// Set statuses again
environment.eventBus().post(new OriginsSnapshot(id("foo"), pools(), pools(foo1), pools(foo2)));
fooBackend = supplier.get().downstream().backend("STYXPRES-foo");
assertThat(fooBackend.statusesByOriginId(), is(equalTo(Map.of("foo1", "inactive", "foo2", "disabled"))));
assertThat(fooBackend.origin("foo1").status(), is("inactive"));
}
use of com.hotels.styx.api.extension.service.BackendService in project styx by ExpediaGroup.
the class OriginsHandlerTest method healthCheckIsAbsentWhenNotConfigured.
@Test
public void healthCheckIsAbsentWhenNotConfigured() throws IOException {
String originsFile = fixturesHome() + "conf/origins/origins-for-jsontest-no-healthcheck.yml";
Iterable<BackendService> expected = loadFromPath(originsFile).get();
withOriginsHandler(originsFile, handler -> {
HttpResponse response = Mono.from(handler.handle(get("/admin/configuration/origins").build(), requestContext())).block();
assertThat(response.status(), is(OK));
assertThat(response.contentType(), isValue(APPLICATION_JSON));
String body = response.bodyAs(UTF_8);
assertThat(body, not(containsString("healthCheck")));
Iterable<BackendService> result = newBackendServices(unmarshalApplications(body));
assertThat(result, is(expected));
});
}
use of com.hotels.styx.api.extension.service.BackendService in project styx by ExpediaGroup.
the class BackendServiceTest method usesResponseTimeoutOfZeroToIndicateDefaultValue.
@Test
public void usesResponseTimeoutOfZeroToIndicateDefaultValue() {
BackendService backendService = BackendService.newBackendServiceBuilder().origins(originSet).responseTimeoutMillis(0).build();
assertThat(backendService.responseTimeoutMillis(), is(DEFAULT_RESPONSE_TIMEOUT_MILLIS));
}
use of com.hotels.styx.api.extension.service.BackendService in project styx by ExpediaGroup.
the class StyxPipelineFactory method configuredPipeline.
private RoutingObject configuredPipeline(RoutingObjectFactory.Context routingObjectFactoryContext) {
boolean requestTracking = environment.configuration().get("requestTracking", Boolean.class).orElse(false);
Optional<JsonNode> rootHandlerNode = environment.configuration().get("httpPipeline", JsonNode.class);
if (rootHandlerNode.isPresent()) {
return Builtins.build(List.of("httpPipeline"), routingObjectFactoryContext, toRoutingConfigNode(rootHandlerNode.get()));
}
Registry<BackendService> registry = (Registry<BackendService>) services.get("backendServiceRegistry");
return new StaticPipelineFactory(environment, registry != null ? registry : new MemoryBackedRegistry<>(), plugins, executor, requestTracking).build();
}
Aggregations