Search in sources :

Example 1 with OriginsSnapshot

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);
}
Also used : OriginsSnapshot(com.hotels.styx.api.extension.OriginsSnapshot) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with OriginsSnapshot

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

Example 3 with OriginsSnapshot

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)));
}
Also used : ActiveOrigins(com.hotels.styx.api.extension.ActiveOrigins) StubConnectionFactory(com.hotels.styx.client.connectionpool.stubs.StubConnectionFactory) OriginsSnapshot(com.hotels.styx.api.extension.OriginsSnapshot) Test(org.junit.jupiter.api.Test)

Example 4 with OriginsSnapshot

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);
}
Also used : OriginsSnapshot(com.hotels.styx.api.extension.OriginsSnapshot)

Example 5 with OriginsSnapshot

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"));
}
Also used : OriginsSnapshot(com.hotels.styx.api.extension.OriginsSnapshot) Test(org.junit.jupiter.api.Test)

Aggregations

OriginsSnapshot (com.hotels.styx.api.extension.OriginsSnapshot)8 Test (org.junit.jupiter.api.Test)6 Origin (com.hotels.styx.api.extension.Origin)3 EventBus (com.google.common.eventbus.EventBus)2 HttpResponse (com.hotels.styx.api.HttpResponse)2 BackendService (com.hotels.styx.api.extension.service.BackendService)2 MemoryBackedRegistry (com.hotels.styx.infrastructure.MemoryBackedRegistry)2 Id (com.hotels.styx.api.Id)1 ActiveOrigins (com.hotels.styx.api.extension.ActiveOrigins)1 BackendServices (com.hotels.styx.applications.BackendServices)1 BackendServices.newBackendServices (com.hotels.styx.applications.BackendServices.newBackendServices)1 StubConnectionFactory (com.hotels.styx.client.connectionpool.stubs.StubConnectionFactory)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1