use of com.hotels.styx.api.extension.Origin in project styx by ExpediaGroup.
the class BackendServicesTest method derivesApplicationIdsOnOriginsWhenUsingYamlConstructor.
@Test
public void derivesApplicationIdsOnOriginsWhenUsingYamlConstructor() {
BackendService before = BackendService.newBackendServiceBuilder().id("generic_app").origins(newOriginBuilder("localhost", 8080).id("origin1").build()).build();
BackendServices backendServices = new BackendServices(singletonList(before));
Origin origin = first(backendServices.first().origins());
assertThat(origin.applicationId(), is(id("generic_app")));
}
use of com.hotels.styx.api.extension.Origin 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.Origin in project styx by ExpediaGroup.
the class OriginRestrictionLoadBalancingStrategyTest method setUp.
@BeforeEach
public void setUp() {
delegate = mock(LoadBalancer.class);
when(delegate.choose(any(LoadBalancer.Preferences.class))).thenReturn(Optional.of(origins.get(0)));
strategy = new OriginRestrictionLoadBalancingStrategy(new ActiveOrigins() {
@Override
public Iterable<RemoteHost> snapshot() {
return origins;
}
@Override
public String getApplicationId() {
return null;
}
@Override
public List<Origin> origins() {
return null;
}
}, delegate);
log = new LoggingTestSupport(OriginRestrictionLoadBalancingStrategy.class);
}
use of com.hotels.styx.api.extension.Origin in project styx by ExpediaGroup.
the class OriginRestrictionLoadBalancingStrategyTest method logsInvalidPatterns.
@Test
public void logsInvalidPatterns() {
Random mockRandom = mock(Random.class);
strategy = new OriginRestrictionLoadBalancingStrategy(new ActiveOrigins() {
@Override
public Iterable<RemoteHost> snapshot() {
return origins;
}
@Override
public String getApplicationId() {
return null;
}
@Override
public List<Origin> origins() {
return null;
}
}, delegate, mockRandom);
strategy.choose(lbPreference(Optional.of("*-01")));
assertThat(log.lastMessage(), is(loggingEvent(ERROR, "Invalid origin restriction cookie value=.*, Cause=Dangling meta character .*")));
}
use of com.hotels.styx.api.extension.Origin in project styx by ExpediaGroup.
the class OriginRestrictionLoadBalancingStrategyTest method usesAllOriginsWhenRegularExpressionMatchesAll.
@Test
public void usesAllOriginsWhenRegularExpressionMatchesAll() {
Random mockRandom = mock(Random.class);
when(mockRandom.nextInt(any(Integer.class))).thenReturn(3);
strategy = new OriginRestrictionLoadBalancingStrategy(new ActiveOrigins() {
@Override
public Iterable<RemoteHost> snapshot() {
return origins;
}
@Override
public String getApplicationId() {
return null;
}
@Override
public List<Origin> origins() {
return null;
}
}, delegate, mockRandom);
Optional<RemoteHost> chosenOne = strategy.choose(lbPreference(Optional.of(".*")));
assertThat(chosenOne.get(), isOneOf(origins.get(3)));
verify(mockRandom).nextInt(eq(7));
}
Aggregations