use of com.hotels.styx.api.extension.OriginsSnapshot in project styx by ExpediaGroup.
the class OriginsCommandHandlerTest method registerListener.
@BeforeEach
public void registerListener() {
originsCommand.originsChanged(new OriginsSnapshot(id("activeAppId"), activeOrigins, inactiveOrigins, disabledOrigins));
recordingOriginsCommandsListener = new RecordingOriginsCommandsListener();
eventBus.register(recordingOriginsCommandsListener);
}
use of com.hotels.styx.api.extension.OriginsSnapshot 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.api.extension.OriginsSnapshot in project styx by ExpediaGroup.
the class RoundRobinStrategyTest method refreshesAtOriginsChange.
@Test
public void refreshesAtOriginsChange() {
ActiveOrigins activeOrigins = mock(ActiveOrigins.class);
when(activeOrigins.snapshot()).thenReturn(asList(HOST_1, HOST_2, HOST_3));
strategy = new RoundRobinStrategy.Factory().create(environment, configuration, activeOrigins);
assertThat(strategy.choose(null), is(Optional.of(HOST_1)));
assertThat(strategy.choose(null), is(Optional.of(HOST_2)));
assertThat(strategy.choose(null), is(Optional.of(HOST_3)));
assertThat(strategy.choose(null), is(Optional.of(HOST_1)));
assertThat(strategy.choose(null), is(Optional.of(HOST_2)));
when(activeOrigins.snapshot()).thenReturn(asList(HOST_2, HOST_4, HOST_6));
strategy.originsChanged(new OriginsSnapshot(APP_ID, asList(HOST_2, HOST_4, HOST_6), asList(HOST_1, HOST_3), asList(HOST_5)));
assertThat(strategy.choose(null), is(Optional.of(HOST_6)));
assertThat(strategy.choose(null), is(Optional.of(HOST_2)));
assertThat(strategy.choose(null), is(Optional.of(HOST_4)));
assertThat(strategy.choose(null), is(Optional.of(HOST_6)));
assertThat(strategy.choose(null), is(Optional.of(HOST_2)));
assertThat(strategy.choose(null), is(Optional.of(HOST_4)));
}
use of com.hotels.styx.api.extension.OriginsSnapshot in project styx by ExpediaGroup.
the class OriginsInventory method notifyStateChange.
private void notifyStateChange() {
OriginsSnapshot event = new OriginsSnapshot(appId, pools(ACTIVE), pools(INACTIVE), pools(DISABLED));
inventoryListeners.announce().originsChanged(event);
eventBus.post(event);
}
use of com.hotels.styx.api.extension.OriginsSnapshot in project styx by ExpediaGroup.
the class DashboardDataTest method providesOriginStatus.
@Test
public void providesOriginStatus() {
metricRegistry.register("origins.app.app-01.status", gauge("active"));
DashboardData.Origin origin = newDashboardData().downstream().firstBackend().firstOrigin();
eventBus.post(new OriginsSnapshot(id("app"), singleton(pool(origin("app", "app-01", "localhost", 9090))), emptyList(), emptyList()));
assertThat(origin.status(), is("active"));
}
Aggregations