Search in sources :

Example 26 with BackendService

use of com.hotels.styx.api.extension.service.BackendService in project styx by ExpediaGroup.

the class DashboardDataTest method providesBackendTotalConnections.

@Test
public void providesBackendTotalConnections() {
    BackendServices backendServices = newBackendServices(application("app", origin("app-01", "localhost", 9090), origin("app-02", "localhost", 9091)));
    MemoryBackedRegistry<BackendService> backendServicesRegistry = new MemoryBackedRegistry<>();
    backendServices.forEach(backendServicesRegistry::add);
    metricRegistry.register("origins.app.app-01.connectionspool.available-connections", gauge(100));
    metricRegistry.register("origins.app.app-01.connectionspool.busy-connections", gauge(300));
    metricRegistry.register("origins.app.app-01.connectionspool.pending-connections", gauge(500));
    metricRegistry.register("origins.app.app-02.connectionspool.available-connections", gauge(200));
    metricRegistry.register("origins.app.app-02.connectionspool.busy-connections", gauge(400));
    metricRegistry.register("origins.app.app-02.connectionspool.pending-connections", gauge(600));
    DashboardData.Backend backend = newDashboardData(backendServicesRegistry).downstream().firstBackend();
    DashboardData.ConnectionsPoolsAggregate connectionsPool = backend.totalConnections();
    assertThat(connectionsPool.available(), is(300));
    assertThat(connectionsPool.busy(), is(700));
    assertThat(connectionsPool.pending(), is(1100));
}
Also used : BackendService(com.hotels.styx.api.extension.service.BackendService) BackendServices(com.hotels.styx.applications.BackendServices) BackendServices.newBackendServices(com.hotels.styx.applications.BackendServices.newBackendServices) MemoryBackedRegistry(com.hotels.styx.infrastructure.MemoryBackedRegistry) Test(org.junit.jupiter.api.Test)

Example 27 with BackendService

use of com.hotels.styx.api.extension.service.BackendService in project styx by ExpediaGroup.

the class DashboardDataTest method providesBackendStatuses.

@Test
public void providesBackendStatuses() {
    BackendServices backendServices = newBackendServices(application("app", origin("app-01", "localhost", 9090), origin("app-02", "localhost", 9091)));
    MemoryBackedRegistry<BackendService> backendServicesRegistry = new MemoryBackedRegistry<>();
    backendServices.forEach(backendServicesRegistry::add);
    DashboardData.Backend backend = newDashboardData(backendServicesRegistry).downstream().firstBackend();
    eventBus.post(new OriginsSnapshot(id("app"), singleton(pool(origin("app", "app-01", "localhost", 9090))), emptyList(), singleton(pool(origin("app", "app-02", "localhost", 9091)))));
    assertThat(backend.statuses(), containsInAnyOrder("active", "disabled"));
}
Also used : BackendService(com.hotels.styx.api.extension.service.BackendService) BackendServices(com.hotels.styx.applications.BackendServices) BackendServices.newBackendServices(com.hotels.styx.applications.BackendServices.newBackendServices) MemoryBackedRegistry(com.hotels.styx.infrastructure.MemoryBackedRegistry) OriginsSnapshot(com.hotels.styx.api.extension.OriginsSnapshot) Test(org.junit.jupiter.api.Test)

Example 28 with BackendService

use of com.hotels.styx.api.extension.service.BackendService in project styx by ExpediaGroup.

the class OriginsHandlerTest method respondsToRequestWithJsonResponse.

@Test
public void respondsToRequestWithJsonResponse() throws IOException {
    String originsFile = fixturesHome() + "conf/origins/origins-for-jsontest.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));
        Iterable<BackendService> result = newBackendServices(unmarshalApplications(response.bodyAs(UTF_8)));
        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 29 with BackendService

use of com.hotels.styx.api.extension.service.BackendService in project styx by ExpediaGroup.

the class OriginsHandlerTest method respondsWithEmptyArrayWhenNoOrigins.

@Test
public void respondsWithEmptyArrayWhenNoOrigins() {
    Registry<BackendService> backendServicesRegistry = new MemoryBackedRegistry<>();
    OriginsHandler handler = new OriginsHandler(backendServicesRegistry);
    HttpResponse response = Mono.from(handler.handle(get("/admin/configuration/origins").build(), requestContext())).block();
    assertThat(response.status(), is(OK));
    assertThat(response.contentType(), isValue(APPLICATION_JSON));
    assertThat(response.bodyAs(UTF_8), is("[]"));
}
Also used : BackendService(com.hotels.styx.api.extension.service.BackendService) MemoryBackedRegistry(com.hotels.styx.infrastructure.MemoryBackedRegistry) HttpResponse(com.hotels.styx.api.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 30 with BackendService

use of com.hotels.styx.api.extension.service.BackendService in project styx by ExpediaGroup.

the class YamlApplicationsProviderTest method stickySessionIsDisabledByDefault.

@Test
public void stickySessionIsDisabledByDefault() {
    YamlApplicationsProvider config = loadFromPath("classpath:conf/origins/origins-for-configtest.yml");
    BackendService app = applicationFor(config, "shopping");
    assertThat(app.stickySessionConfig().stickySessionEnabled(), CoreMatchers.is(false));
}
Also used : BackendService(com.hotels.styx.api.extension.service.BackendService) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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