use of com.hotels.styx.api.extension.RemoteHost in project styx by ExpediaGroup.
the class OriginRestrictionLoadBalancingStrategyTest method usesAllOriginsWhenCookieIsAbsent.
@Test
public void usesAllOriginsWhenCookieIsAbsent() {
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(empty()));
assertThat(chosenOne.get(), is(origins.get(0)));
verify(mockRandom, never()).nextInt(any(Integer.class));
verify(delegate).choose(any(LoadBalancer.Preferences.class));
}
use of com.hotels.styx.api.extension.RemoteHost in project styx by ExpediaGroup.
the class OriginRestrictionLoadBalancingStrategyTest method randomlyChoosesOneOfTheOriginsWithInvalidPreferences.
@Test
public void randomlyChoosesOneOfTheOriginsWithInvalidPreferences() {
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("*-01")));
// Chooses one from *all (= 7)* origins:
verify(mockRandom).nextInt(eq(7));
assertThat(chosenOne.get().id(), is(id("origin-3")));
}
use of com.hotels.styx.api.extension.RemoteHost in project styx by ExpediaGroup.
the class OriginRestrictionLoadBalancingStrategyTest method usesSingleOriginMatchingRegularExpression.
@Test
public void usesSingleOriginMatchingRegularExpression() {
Random mockRandom = mock(Random.class);
when(mockRandom.nextInt(eq(1))).thenReturn(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, mockRandom);
Optional<RemoteHost> chosenOne = strategy.choose(lbPreference(Optional.of("origin-1")));
assertThat(chosenOne.get(), is(origins.get(1)));
}
use of com.hotels.styx.api.extension.RemoteHost 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.RemoteHost 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)));
}
Aggregations