use of com.hotels.styx.api.extension.Origin in project styx by ExpediaGroup.
the class HttpErrorStatusMetricsTest method backendFaultArgs.
private static Stream<Arguments> backendFaultArgs() {
Id appId = Id.id("fakeApp");
Id originId = Id.id("fakeApp1");
Origin origin = Origin.newOriginBuilder("fakeHost", 9999).applicationId(appId).id(originId.toString()).build();
Exception cause = new Exception();
return Stream.of(Arguments.of(new NoAvailableHostsException(appId), "noHostsLiveForApplication"), Arguments.of(new OriginUnreachableException(origin, cause), "cannotConnect"), Arguments.of(new BadHttpResponseException(origin, cause), "badHttpResponse"), Arguments.of(new MaxPendingConnectionTimeoutException(origin, 1), "connectionsHeldTooLong"), Arguments.of(new MaxPendingConnectionsExceededException(origin, 1, 1), "tooManyConnections"), Arguments.of(new ResponseTimeoutException(origin, "test", 1, 1, 1, 1), "responseTooSlow"));
}
use of com.hotels.styx.api.extension.Origin in project styx by ExpediaGroup.
the class DashboardDataTest method unsubscribesFromEventBus.
@Test
public void unsubscribesFromEventBus() {
EventBus eventBus = mock(EventBus.class);
MemoryBackedRegistry<BackendService> backendServicesRegistry = new MemoryBackedRegistry<>();
backendServicesRegistry.add(application("app", origin("app-01", "localhost", 9090)));
backendServicesRegistry.add(application("test", origin("test-01", "localhost", 9090)));
DashboardData dashbaord = new DashboardData(metricRegistry, backendServicesRegistry, "styx-prod1-presentation-01", new Version("releaseTag"), eventBus);
// Twice for each backend. One during backend construction, another from BackendServicesRegistry listener callback.
verify(eventBus, times(4)).register(any(DashboardData.Origin.class));
dashbaord.unregister();
verify(eventBus, times(4)).unregister(any(DashboardData.Origin.class));
}
use of com.hotels.styx.api.extension.Origin 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.Origin 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