use of com.netflix.niws.loadbalancer.DiscoveryEnabledServer in project spring-cloud-netflix by spring-cloud.
the class DomainExtractingServer method setZones.
private List<DiscoveryEnabledServer> setZones(List<DiscoveryEnabledServer> servers) {
List<DiscoveryEnabledServer> result = new ArrayList<>();
boolean isSecure = this.ribbon.isSecure(true);
boolean shouldUseIpAddr = this.ribbon.isUseIPAddrForServer();
for (DiscoveryEnabledServer server : servers) {
result.add(new DomainExtractingServer(server, isSecure, shouldUseIpAddr, this.approximateZoneFromHostname));
}
return result;
}
use of com.netflix.niws.loadbalancer.DiscoveryEnabledServer in project zuul by Netflix.
the class DiscoveryResultTest method serverInstancesExposingDiffPortsAreNotEqual.
@Test
public void serverInstancesExposingDiffPortsAreNotEqual() {
final InstanceInfo instanceInfo = Builder.newBuilder().setAppName("server-equality").setHostName("server-equality").setPort(7777).build();
final InstanceInfo otherPort = Builder.newBuilder().setAppName("server-equality").setHostName("server-equality").setPort(9999).build();
final DiscoveryEnabledServer server = new DiscoveryEnabledServer(instanceInfo, false);
final DiscoveryEnabledServer otherServer = new DiscoveryEnabledServer(otherPort, false);
final DynamicServerListLoadBalancer<Server> lb = new DynamicServerListLoadBalancer<>(new DefaultClientConfigImpl());
final DiscoveryResult result = new DiscoveryResult(server, lb.getLoadBalancerStats());
final DiscoveryResult otherResult = new DiscoveryResult(otherServer, lb.getLoadBalancerStats());
Truth.assertThat(result).isNotEqualTo(otherResult);
}
use of com.netflix.niws.loadbalancer.DiscoveryEnabledServer in project zuul by Netflix.
the class DiscoveryResultTest method ipAddrEmptyForIncompleteInstanceInfo.
@Test
public void ipAddrEmptyForIncompleteInstanceInfo() {
final InstanceInfo instanceInfo = Builder.newBuilder().setAppName("ipAddrMissing").setHostName("ipAddrMissing").setPort(7777).build();
final DiscoveryEnabledServer server = new DiscoveryEnabledServer(instanceInfo, false);
final DynamicServerListLoadBalancer<Server> lb = new DynamicServerListLoadBalancer<>(new DefaultClientConfigImpl());
final DiscoveryResult result = new DiscoveryResult(server, lb.getLoadBalancerStats());
Truth.assertThat(result.getIPAddr()).isEqualTo(Optional.empty());
}
use of com.netflix.niws.loadbalancer.DiscoveryEnabledServer in project zuul by Netflix.
the class DynamicServerResolverTest method verifyListenerUpdates.
@Test
public void verifyListenerUpdates() {
class CustomListener implements ResolverListener<DiscoveryResult> {
private List<DiscoveryResult> resultSet = Lists.newArrayList();
@Override
public void onChange(List<DiscoveryResult> changedSet) {
resultSet = changedSet;
}
public List<DiscoveryResult> updatedList() {
return resultSet;
}
}
final CustomListener listener = new CustomListener();
final DynamicServerResolver resolver = new DynamicServerResolver(new DefaultClientConfigImpl(), listener);
final InstanceInfo first = Builder.newBuilder().setAppName("zuul-discovery-1").setHostName("zuul-discovery-1").setIPAddr("100.10.10.1").setPort(443).build();
final InstanceInfo second = Builder.newBuilder().setAppName("zuul-discovery-2").setHostName("zuul-discovery-2").setIPAddr("100.10.10.2").setPort(443).build();
final DiscoveryEnabledServer server1 = new DiscoveryEnabledServer(first, true);
final DiscoveryEnabledServer server2 = new DiscoveryEnabledServer(second, true);
resolver.onUpdate(ImmutableList.of(server1, server2), ImmutableList.of());
Truth.assertThat(listener.updatedList()).containsExactly(new DiscoveryResult(server1), new DiscoveryResult(server2));
}
use of com.netflix.niws.loadbalancer.DiscoveryEnabledServer in project ribbon by Netflix.
the class EurekaDynamicServerListLoadBalancerTest method testLoadBalancerHappyCase.
@Test
public void testLoadBalancerHappyCase() throws Exception {
Assert.assertNotEquals("the two test server list counts should be different", secondServerListSize, initialServerListSize);
DynamicServerListLoadBalancer<DiscoveryEnabledServer> lb = null;
try {
Capture<EurekaEventListener> eventListenerCapture = new Capture<EurekaEventListener>();
eurekaClientMock.registerEventListener(EasyMock.capture(eventListenerCapture));
PowerMock.replay(DiscoveryClient.class);
PowerMock.replay(eurekaClientMock);
// actual testing
// initial creation and loading of the first serverlist
lb = new DynamicServerListLoadBalancer<DiscoveryEnabledServer>(config, new AvailabilityFilteringRule(), new DummyPing(), new DiscoveryEnabledNIWSServerList(vipAddress, eurekaClientProvider), new ZoneAffinityServerListFilter<DiscoveryEnabledServer>(), new EurekaNotificationServerListUpdater(eurekaClientProvider));
Assert.assertEquals(initialServerListSize, lb.getServerCount(false));
// trigger an eureka CacheRefreshEvent
eventListenerCapture.getValue().onEvent(new CacheRefreshedEvent());
Assert.assertTrue(verifyFinalServerListCount(secondServerListSize, lb));
} finally {
if (lb != null) {
lb.shutdown();
PowerMock.verify(eurekaClientMock);
PowerMock.verify(DiscoveryClient.class);
}
}
}
Aggregations