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"));
}
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" + "}"));
}
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));
}
Aggregations