Search in sources :

Example 16 with DiscoveryEnabledServer

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;
}
Also used : DiscoveryEnabledServer(com.netflix.niws.loadbalancer.DiscoveryEnabledServer) ArrayList(java.util.ArrayList)

Example 17 with DiscoveryEnabledServer

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);
}
Also used : DiscoveryEnabledServer(com.netflix.niws.loadbalancer.DiscoveryEnabledServer) Server(com.netflix.loadbalancer.Server) DynamicServerListLoadBalancer(com.netflix.loadbalancer.DynamicServerListLoadBalancer) DiscoveryEnabledServer(com.netflix.niws.loadbalancer.DiscoveryEnabledServer) InstanceInfo(com.netflix.appinfo.InstanceInfo) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl) Test(org.junit.Test)

Example 18 with DiscoveryEnabledServer

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());
}
Also used : DiscoveryEnabledServer(com.netflix.niws.loadbalancer.DiscoveryEnabledServer) Server(com.netflix.loadbalancer.Server) DynamicServerListLoadBalancer(com.netflix.loadbalancer.DynamicServerListLoadBalancer) DiscoveryEnabledServer(com.netflix.niws.loadbalancer.DiscoveryEnabledServer) InstanceInfo(com.netflix.appinfo.InstanceInfo) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl) Test(org.junit.Test)

Example 19 with DiscoveryEnabledServer

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));
}
Also used : DiscoveryEnabledServer(com.netflix.niws.loadbalancer.DiscoveryEnabledServer) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ResolverListener(com.netflix.zuul.resolver.ResolverListener) InstanceInfo(com.netflix.appinfo.InstanceInfo) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl) Test(org.junit.Test)

Example 20 with DiscoveryEnabledServer

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);
        }
    }
}
Also used : DiscoveryEnabledNIWSServerList(com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList) DiscoveryEnabledServer(com.netflix.niws.loadbalancer.DiscoveryEnabledServer) EurekaEventListener(com.netflix.discovery.EurekaEventListener) EurekaNotificationServerListUpdater(com.netflix.niws.loadbalancer.EurekaNotificationServerListUpdater) Capture(org.easymock.Capture) CacheRefreshedEvent(com.netflix.discovery.CacheRefreshedEvent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

DiscoveryEnabledServer (com.netflix.niws.loadbalancer.DiscoveryEnabledServer)20 Test (org.junit.Test)15 DefaultClientConfigImpl (com.netflix.client.config.DefaultClientConfigImpl)13 InstanceInfo (com.netflix.appinfo.InstanceInfo)10 Server (com.netflix.loadbalancer.Server)8 DynamicServerListLoadBalancer (com.netflix.loadbalancer.DynamicServerListLoadBalancer)7 DiscoveryEnabledNIWSServerList (com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList)3 EurekaNotificationServerListUpdater (com.netflix.niws.loadbalancer.EurekaNotificationServerListUpdater)3 EurekaEventListener (com.netflix.discovery.EurekaEventListener)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 ImmutableList (com.google.common.collect.ImmutableList)1 CacheRefreshedEvent (com.netflix.discovery.CacheRefreshedEvent)1 EurekaClient (com.netflix.discovery.EurekaClient)1 AvailabilityFilteringRule (com.netflix.loadbalancer.AvailabilityFilteringRule)1 ILoadBalancer (com.netflix.loadbalancer.ILoadBalancer)1 IRule (com.netflix.loadbalancer.IRule)1 RandomRule (com.netflix.loadbalancer.RandomRule)1 ServerListUpdater (com.netflix.loadbalancer.ServerListUpdater)1 ZoneAffinityServerListFilter (com.netflix.loadbalancer.ZoneAffinityServerListFilter)1 ZoneAwareLoadBalancer (com.netflix.loadbalancer.ZoneAwareLoadBalancer)1