Search in sources :

Example 46 with Origin

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"));
}
Also used : Origin(com.hotels.styx.api.extension.Origin) ResponseTimeoutException(com.hotels.styx.api.exceptions.ResponseTimeoutException) NoAvailableHostsException(com.hotels.styx.api.exceptions.NoAvailableHostsException) OriginUnreachableException(com.hotels.styx.api.exceptions.OriginUnreachableException) MaxPendingConnectionTimeoutException(com.hotels.styx.client.connectionpool.MaxPendingConnectionTimeoutException) MaxPendingConnectionsExceededException(com.hotels.styx.client.connectionpool.MaxPendingConnectionsExceededException) BadHttpResponseException(com.hotels.styx.client.BadHttpResponseException) Id(com.hotels.styx.api.Id) MaxPendingConnectionTimeoutException(com.hotels.styx.client.connectionpool.MaxPendingConnectionTimeoutException) NoAvailableHostsException(com.hotels.styx.api.exceptions.NoAvailableHostsException) PluginException(com.hotels.styx.api.plugins.spi.PluginException) OriginUnreachableException(com.hotels.styx.api.exceptions.OriginUnreachableException) ResponseTimeoutException(com.hotels.styx.api.exceptions.ResponseTimeoutException) MaxPendingConnectionsExceededException(com.hotels.styx.client.connectionpool.MaxPendingConnectionsExceededException) BadHttpResponseException(com.hotels.styx.client.BadHttpResponseException)

Example 47 with Origin

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

Example 48 with Origin

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" + "}"));
}
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 49 with Origin

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));
}
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

Origin (com.hotels.styx.api.extension.Origin)49 Test (org.junit.jupiter.api.Test)40 RemoteHost (com.hotels.styx.api.extension.RemoteHost)15 ActiveOrigins (com.hotels.styx.api.extension.ActiveOrigins)11 Origin.newOriginBuilder (com.hotels.styx.api.extension.Origin.newOriginBuilder)11 Random (java.util.Random)9 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)8 LoadBalancer (com.hotels.styx.api.extension.loadbalancing.spi.LoadBalancer)8 HttpHandler (com.hotels.styx.api.HttpHandler)6 BackendService (com.hotels.styx.api.extension.service.BackendService)6 ConnectionSettings (com.hotels.styx.client.ConnectionSettings)6 Id (com.hotels.styx.api.Id)5 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)5 OriginUnreachableException (com.hotels.styx.api.exceptions.OriginUnreachableException)5 DisableOrigin (com.hotels.styx.client.origincommands.DisableOrigin)5 EnableOrigin (com.hotels.styx.client.origincommands.EnableOrigin)5 CentralisedMetrics (com.hotels.styx.metrics.CentralisedMetrics)5 EventBus (com.google.common.eventbus.EventBus)4 HttpInterceptor (com.hotels.styx.api.HttpInterceptor)4 Context (com.hotels.styx.api.HttpInterceptor.Context)4