use of com.hotels.styx.api.extension.Origin in project styx by ExpediaGroup.
the class OriginRestrictionLoadBalancingStrategyTest method usesNoOriginsWhenRegularExpressionMatchesNone.
@Test
public void usesNoOriginsWhenRegularExpressionMatchesNone() {
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);
Optional<RemoteHost> chosenOne = strategy.choose(lbPreference(Optional.of("foo")));
assertThat(chosenOne, is(empty()));
verify(mockRandom, never()).nextInt(any(Integer.class));
}
use of com.hotels.styx.api.extension.Origin in project styx by ExpediaGroup.
the class OriginRestrictionLoadBalancingStrategyTest method usesMultipleOriginsMatchingRegularExpression.
@Test
public void usesMultipleOriginsMatchingRegularExpression() {
Random mockRandom = mock(Random.class);
when(mockRandom.nextInt(eq(3))).thenReturn(1);
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("origin-[2-4]")));
verify(mockRandom).nextInt(eq(3));
assertThat(chosenOne.get(), is(origins.get(3)));
}
use of com.hotels.styx.api.extension.Origin in project styx by ExpediaGroup.
the class OriginsInventoryTest method stopsAndRestartsMonitoringModifiedOrigins.
@Test
public void stopsAndRestartsMonitoringModifiedOrigins() {
Origin originV1 = newOriginBuilder("acme01.com", 80).applicationId(GENERIC_APP).id("acme-01").build();
Origin originV2 = newOriginBuilder("acme02.com", 80).applicationId(GENERIC_APP).id("acme-01").build();
inventory.setOrigins(originV1);
verify(monitor).monitor(singleton(originV1));
inventory.setOrigins(originV2);
verify(monitor).stopMonitoring(singleton(originV1));
verify(monitor).monitor(singleton(originV2));
}
use of com.hotels.styx.api.extension.Origin in project styx by ExpediaGroup.
the class OriginsInventoryTest method updatesOriginHostName.
@Test
public void updatesOriginHostName() {
Origin originV1 = newOriginBuilder("acme01.com", 80).applicationId(GENERIC_APP).id("acme-01").build();
Origin originV2 = newOriginBuilder("acme02.com", 80).applicationId(GENERIC_APP).id("acme-01").build();
inventory.setOrigins(originV1);
assertThat(inventory.originCount(ACTIVE), is(1));
verify(monitor).monitor(singleton(originV1));
assertThat(gaugeValue("generic-app", "acme-01"), isValue(1.0));
verify(eventBus).post(any(OriginsSnapshot.class));
inventory.setOrigins(originV2);
assertThat(inventory.originCount(ACTIVE), is(1));
verify(monitor).stopMonitoring(singleton(originV1));
verify(monitor).monitor(singleton(originV2));
assertThat(gaugeValue("generic-app", "acme-01"), isValue(1.0));
verify(eventBus, times(2)).post(any(OriginsSnapshot.class));
}
use of com.hotels.styx.api.extension.Origin in project styx by ExpediaGroup.
the class OriginsInventoryTest method shutsConnectionPoolForRemovedOrigin.
@Test
public void shutsConnectionPoolForRemovedOrigin() {
Origin originV1 = newOriginBuilder("acme01.com", 80).applicationId(GENERIC_APP).id("acme-01").build();
Origin originV2 = newOriginBuilder("acme02.com", 80).applicationId(GENERIC_APP).id("acme-02").build();
ConnectionPool.Factory connectionFactory = mock(ConnectionPool.Factory.class);
ConnectionPool pool1 = mock(ConnectionPool.class);
when(pool1.getOrigin()).thenReturn(originV1);
ConnectionPool pool2 = mock(ConnectionPool.class);
when(pool2.getOrigin()).thenReturn(originV2);
when(connectionFactory.create(eq(originV1))).thenReturn(pool1);
when(connectionFactory.create(eq(originV2))).thenReturn(pool2);
inventory = new OriginsInventory(eventBus, GENERIC_APP, monitor, connectionFactory, hostClientFactory, new CentralisedMetrics(meterRegistry));
inventory.setOrigins(originV1, originV2);
inventory.setOrigins(originV2);
verify(pool1).close();
}
Aggregations