Search in sources :

Example 6 with OriginsSnapshot

use of com.hotels.styx.api.extension.OriginsSnapshot 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 7 with OriginsSnapshot

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

the class OriginsInventoryHandlerTest method prettyPrintsOriginsSnapshot.

@Test
public void prettyPrintsOriginsSnapshot() {
    EventBus eventBus = new EventBus();
    OriginsInventoryHandler handler = new OriginsInventoryHandler(eventBus);
    Set<Origin> disabledOrigins = generateOrigins(2);
    eventBus.post(new OriginsSnapshot(APP_ID, pool(emptySet()), pool(emptySet()), pool(disabledOrigins)));
    HttpResponse response = Mono.from(handler.handle(get("/?pretty=1").build(), requestContext())).block();
    assertThat(body(response).replace("\r\n", "\n"), matchesRegex("\\{\n" + "  \"" + APP_ID + "\" : \\{\n" + "    \"appId\" : \"" + APP_ID + "\",\n" + "    \"activeOrigins\" : \\[ ],\n" + "    \"inactiveOrigins\" : \\[ ],\n" + "    \"disabledOrigins\" : \\[ \\{\n" + "      \"id\" : \"origin.\",\n" + "      \"host\" : \"localhost:....\"\n" + "    }, \\{\n" + "      \"id\" : \"origin.\",\n" + "      \"host\" : \"localhost:....\"\n" + "    } ]\n" + "  }\n" + "}"));
}
Also used : Origin(com.hotels.styx.api.extension.Origin) HttpResponse(com.hotels.styx.api.HttpResponse) EventBus(com.google.common.eventbus.EventBus) OriginsSnapshot(com.hotels.styx.api.extension.OriginsSnapshot) Test(org.junit.jupiter.api.Test)

Example 8 with OriginsSnapshot

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

the class OriginsInventoryHandlerTest method respondsWithCorrectSnapshot.

@Test
public void respondsWithCorrectSnapshot() throws IOException {
    EventBus eventBus = new EventBus();
    OriginsInventoryHandler handler = new OriginsInventoryHandler(eventBus);
    Set<Origin> activeOrigins = generateOrigins(3);
    Set<Origin> inactiveOrigins = generateOrigins(4);
    Set<Origin> disabledOrigins = generateOrigins(2);
    eventBus.post(new OriginsSnapshot(APP_ID, pool(activeOrigins), pool(inactiveOrigins), pool(disabledOrigins)));
    HttpResponse response = Mono.from(handler.handle(get("/").build(), requestContext())).block();
    assertThat(response.bodyAs(UTF_8).split("\n").length, is(1));
    Map<Id, OriginsSnapshot> output = deserialiseJson(response.bodyAs(UTF_8));
    assertThat(output.keySet(), contains(APP_ID));
    OriginsSnapshot snapshot = output.get(APP_ID);
    assertThat(snapshot.appId(), is(APP_ID));
    assertThat(snapshot.activeOrigins(), is(activeOrigins));
    assertThat(snapshot.inactiveOrigins(), is(inactiveOrigins));
    assertThat(snapshot.disabledOrigins(), is(disabledOrigins));
}
Also used : Origin(com.hotels.styx.api.extension.Origin) HttpResponse(com.hotels.styx.api.HttpResponse) EventBus(com.google.common.eventbus.EventBus) Id(com.hotels.styx.api.Id) OriginsSnapshot(com.hotels.styx.api.extension.OriginsSnapshot) Test(org.junit.jupiter.api.Test)

Aggregations

OriginsSnapshot (com.hotels.styx.api.extension.OriginsSnapshot)8 Test (org.junit.jupiter.api.Test)6 Origin (com.hotels.styx.api.extension.Origin)3 EventBus (com.google.common.eventbus.EventBus)2 HttpResponse (com.hotels.styx.api.HttpResponse)2 BackendService (com.hotels.styx.api.extension.service.BackendService)2 MemoryBackedRegistry (com.hotels.styx.infrastructure.MemoryBackedRegistry)2 Id (com.hotels.styx.api.Id)1 ActiveOrigins (com.hotels.styx.api.extension.ActiveOrigins)1 BackendServices (com.hotels.styx.applications.BackendServices)1 BackendServices.newBackendServices (com.hotels.styx.applications.BackendServices.newBackendServices)1 StubConnectionFactory (com.hotels.styx.client.connectionpool.stubs.StubConnectionFactory)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1