Search in sources :

Example 6 with BackendService

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)));
}
Also used : BackendService(com.hotels.styx.api.extension.service.BackendService) Test(org.junit.jupiter.api.Test)

Example 7 with BackendService

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"));
}
Also used : Origin(com.hotels.styx.api.extension.Origin) BackendService(com.hotels.styx.api.extension.service.BackendService) MemoryBackedRegistry(com.hotels.styx.infrastructure.MemoryBackedRegistry) OriginsSnapshot(com.hotels.styx.api.extension.OriginsSnapshot) Test(org.junit.jupiter.api.Test)

Example 8 with BackendService

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));
    });
}
Also used : BackendService(com.hotels.styx.api.extension.service.BackendService) HttpResponse(com.hotels.styx.api.HttpResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 9 with BackendService

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));
}
Also used : BackendService(com.hotels.styx.api.extension.service.BackendService) Test(org.junit.jupiter.api.Test)

Example 10 with BackendService

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();
}
Also used : StaticPipelineFactory(com.hotels.styx.routing.StaticPipelineFactory) BackendService(com.hotels.styx.api.extension.service.BackendService) JsonNode(com.fasterxml.jackson.databind.JsonNode) Registry(com.hotels.styx.api.extension.service.spi.Registry) MemoryBackedRegistry(com.hotels.styx.infrastructure.MemoryBackedRegistry)

Aggregations

BackendService (com.hotels.styx.api.extension.service.BackendService)37 Test (org.junit.jupiter.api.Test)36 Registry (com.hotels.styx.api.extension.service.spi.Registry)11 JustATestException (com.hotels.styx.support.JustATestException)8 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)7 MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)7 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)7 MeterRegistry (com.hotels.styx.api.MeterRegistry)6 Resource (com.hotels.styx.api.Resource)6 MemoryBackedRegistry (com.hotels.styx.infrastructure.MemoryBackedRegistry)6 IOException (java.io.IOException)6 HttpHandler (com.hotels.styx.api.HttpHandler)5 ReloadResult (com.hotels.styx.api.extension.service.spi.Registry.ReloadResult)5 ReloadResult.reloaded (com.hotels.styx.api.extension.service.spi.Registry.ReloadResult.reloaded)5 ReloadResult.unchanged (com.hotels.styx.api.extension.service.spi.Registry.ReloadResult.unchanged)5 StyxFutures.await (com.hotels.styx.common.StyxFutures.await)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)5 List (java.util.List)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5