use of com.hotels.styx.api.extension.service.BackendService in project styx by ExpediaGroup.
the class BackendServicesRouterTest method selectsUsingSingleSlashPath.
@Test
public void selectsUsingSingleSlashPath() throws Exception {
Registry.Changes<BackendService> changes = added(appA().newCopy().path("/").build(), appB().newCopy().path("/appB/hotel/details.html").build());
BackendServicesRouter router = new BackendServicesRouter(serviceClientFactory, environment, executor);
router.onChange(changes);
LiveHttpRequest request = get("/").build();
Optional<HttpHandler> route = router.route(request, context);
assertThat(proxyTo(route, request).header(ORIGIN_ID_DEFAULT), isValue(APP_A));
}
use of com.hotels.styx.api.extension.service.BackendService in project styx by ExpediaGroup.
the class BackendServicesRouterTest method deregistersAndReregistersMetricsAppropriately.
// This test exists due to a real bug we had when reloading in prod
@Test
public void deregistersAndReregistersMetricsAppropriately() {
MeterRegistry metrics = new MicrometerRegistry(new SimpleMeterRegistry());
Environment environment = new Environment.Builder().registry(metrics).build();
MeterRegistry meterRegistry = environment.meterRegistry();
BackendServicesRouter router = new BackendServicesRouter(new StyxBackendServiceClientFactory(environment), environment, executor);
router.onChange(added(backendService(APP_B, "/appB/", 9094, "appB-01", 9095, "appB-02")));
Tags tags01 = Tags.of(APPID_TAG, APP_B, ORIGINID_TAG, "appB-01");
Tags tags02 = Tags.of(APPID_TAG, APP_B, ORIGINID_TAG, "appB-02");
assertThat(meterRegistry.find("proxy.client.originHealthStatus").tags(tags01).gauge().value(), is(1.0));
assertThat(meterRegistry.find("proxy.client.originHealthStatus").tags(tags02).gauge().value(), is(1.0));
BackendService appMinusOneOrigin = backendService(APP_B, "/appB/", 9094, "appB-01");
router.onChange(updated(appMinusOneOrigin));
assertThat(meterRegistry.find("proxy.client.originHealthStatus").tags(tags01).gauge().value(), is(1.0));
assertThat(meterRegistry.find("proxy.client.originHealthStatus").tags(tags02).gauge(), is(nullValue()));
}
use of com.hotels.styx.api.extension.service.BackendService in project styx by ExpediaGroup.
the class BackendServicesRouterTest method closesClientWhenBackendServicesAreUpdated.
@Test
public void closesClientWhenBackendServicesAreUpdated() {
BackendServiceClient firstClient = mock(BackendServiceClient.class);
BackendServiceClient secondClient = mock(BackendServiceClient.class);
BackendServiceClientFactory clientFactory = mock(BackendServiceClientFactory.class);
when(clientFactory.createClient(any(BackendService.class), any(OriginsInventory.class), any(OriginStatsFactory.class))).thenReturn(firstClient).thenReturn(secondClient);
BackendServicesRouter router = new BackendServicesRouter(clientFactory, environment, executor);
BackendService bookingApp = appB();
router.onChange(added(bookingApp));
ArgumentCaptor<OriginsInventory> originsInventory = forClass(OriginsInventory.class);
verify(clientFactory).createClient(eq(bookingApp), originsInventory.capture(), any(OriginStatsFactory.class));
BackendService bookingAppMinusOneOrigin = bookingAppMinusOneOrigin();
router.onChange(updated(bookingAppMinusOneOrigin));
assertThat(originsInventory.getValue().closed(), is(true));
verify(clientFactory).createClient(eq(bookingAppMinusOneOrigin), any(OriginsInventory.class), any(OriginStatsFactory.class));
}
use of com.hotels.styx.api.extension.service.BackendService in project styx by ExpediaGroup.
the class BackendServicesRouterTest method closesClientWhenBackendServicesAreRemoved.
@Test
public void closesClientWhenBackendServicesAreRemoved() {
BackendServiceClient firstClient = mock(BackendServiceClient.class);
BackendServiceClient secondClient = mock(BackendServiceClient.class);
ArgumentCaptor<OriginsInventory> originsInventory = forClass(OriginsInventory.class);
BackendServiceClientFactory clientFactory = mock(BackendServiceClientFactory.class);
when(clientFactory.createClient(any(BackendService.class), any(OriginsInventory.class), any(OriginStatsFactory.class))).thenReturn(firstClient).thenReturn(secondClient);
BackendServicesRouter router = new BackendServicesRouter(clientFactory, environment, executor);
BackendService bookingApp = appB();
router.onChange(added(bookingApp));
verify(clientFactory).createClient(eq(bookingApp), originsInventory.capture(), any(OriginStatsFactory.class));
router.onChange(removed(bookingApp));
assertThat(originsInventory.getValue().closed(), is(true));
}
use of com.hotels.styx.api.extension.service.BackendService 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));
}
Aggregations