use of com.hotels.styx.infrastructure.MemoryBackedRegistry in project styx by ExpediaGroup.
the class StyxServerTest method disablesResourceLeakDetectionByDefault.
@Test
public void disablesResourceLeakDetectionByDefault() {
StyxServerComponents config = new StyxServerComponents.Builder().registry(new MicrometerRegistry(new CompositeMeterRegistry())).configuration(EMPTY_CONFIGURATION).additionalServices(Map.of("backendServiceRegistry", new RegistryServiceAdapter(new MemoryBackedRegistry<>()))).build();
new StyxServer(config);
assertThat(ResourceLeakDetector.getLevel(), is(DISABLED));
}
use of com.hotels.styx.infrastructure.MemoryBackedRegistry in project styx by ExpediaGroup.
the class DashboardDataSupplierTest method originsHaveStatuses.
@Test
public void originsHaveStatuses() throws JsonProcessingException {
MemoryBackedRegistry<BackendService> registry = new MemoryBackedRegistry<>();
DashboardDataSupplier supplier = new DashboardDataSupplier(registry, environment, styxConfig);
Origin foo1 = origin("foo1");
Origin foo2 = origin("foo2");
registry.add(backend("foo", foo1, foo2));
registry.add(backend("bar", origin("bar1")));
// Set statuses
environment.eventBus().post(new OriginsSnapshot(id("foo"), pools(foo1), pools(foo2), pools()));
DashboardData.Downstream downstream = supplier.get().downstream();
DashboardData.Backend fooBackend = downstream.backend("STYXPRES-foo");
assertThat(downstream.backendIds(), containsInAnyOrder("STYXPRES-foo", "STYXPRES-bar"));
assertThat(fooBackend.statusesByOriginId(), is(equalTo(Map.of("foo1", "active", "foo2", "inactive"))));
assertThat(fooBackend.origin("foo1").status(), is("active"));
// Set statuses again
environment.eventBus().post(new OriginsSnapshot(id("foo"), pools(), pools(foo1), pools(foo2)));
fooBackend = supplier.get().downstream().backend("STYXPRES-foo");
assertThat(fooBackend.statusesByOriginId(), is(equalTo(Map.of("foo1", "inactive", "foo2", "disabled"))));
assertThat(fooBackend.origin("foo1").status(), is("inactive"));
}
use of com.hotels.styx.infrastructure.MemoryBackedRegistry in project styx by ExpediaGroup.
the class StyxPipelineFactory method configuredPipeline.
private RoutingObject configuredPipeline(RoutingObjectFactory.Context routingObjectFactoryContext) {
boolean requestTracking = environment.configuration().get("requestTracking", Boolean.class).orElse(false);
Optional<JsonNode> rootHandlerNode = environment.configuration().get("httpPipeline", JsonNode.class);
if (rootHandlerNode.isPresent()) {
return Builtins.build(List.of("httpPipeline"), routingObjectFactoryContext, toRoutingConfigNode(rootHandlerNode.get()));
}
Registry<BackendService> registry = (Registry<BackendService>) services.get("backendServiceRegistry");
return new StaticPipelineFactory(environment, registry != null ? registry : new MemoryBackedRegistry<>(), plugins, executor, requestTracking).build();
}
use of com.hotels.styx.infrastructure.MemoryBackedRegistry 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.infrastructure.MemoryBackedRegistry in project styx by ExpediaGroup.
the class DashboardDataTest method providesBackendTotalConnections.
@Test
public void providesBackendTotalConnections() {
BackendServices backendServices = newBackendServices(application("app", origin("app-01", "localhost", 9090), origin("app-02", "localhost", 9091)));
MemoryBackedRegistry<BackendService> backendServicesRegistry = new MemoryBackedRegistry<>();
backendServices.forEach(backendServicesRegistry::add);
metricRegistry.register("origins.app.app-01.connectionspool.available-connections", gauge(100));
metricRegistry.register("origins.app.app-01.connectionspool.busy-connections", gauge(300));
metricRegistry.register("origins.app.app-01.connectionspool.pending-connections", gauge(500));
metricRegistry.register("origins.app.app-02.connectionspool.available-connections", gauge(200));
metricRegistry.register("origins.app.app-02.connectionspool.busy-connections", gauge(400));
metricRegistry.register("origins.app.app-02.connectionspool.pending-connections", gauge(600));
DashboardData.Backend backend = newDashboardData(backendServicesRegistry).downstream().firstBackend();
DashboardData.ConnectionsPoolsAggregate connectionsPool = backend.totalConnections();
assertThat(connectionsPool.available(), is(300));
assertThat(connectionsPool.busy(), is(700));
assertThat(connectionsPool.pending(), is(1100));
}
Aggregations