Search in sources :

Example 6 with DiscoveryEnabledServer

use of com.netflix.niws.loadbalancer.DiscoveryEnabledServer in project zuul by Netflix.

the class DiscoveryResultTest method sameUnderlyingInstanceInfoEqualsSameResult.

@Test
public void sameUnderlyingInstanceInfoEqualsSameResult() {
    final InstanceInfo instanceInfo = Builder.newBuilder().setAppName("server-equality").setHostName("server-equality").setPort(7777).build();
    final DiscoveryEnabledServer server = new DiscoveryEnabledServer(instanceInfo, false);
    final DiscoveryEnabledServer otherServer = new DiscoveryEnabledServer(instanceInfo, 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).isEqualTo(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 7 with DiscoveryEnabledServer

use of com.netflix.niws.loadbalancer.DiscoveryEnabledServer in project zuul by Netflix.

the class DiscoveryResultTest method serverStatsDifferForDifferentServer.

@Test
public void serverStatsDifferForDifferentServer() {
    final InstanceInfo instanceInfo = Builder.newBuilder().setAppName("serverstats-cache").setHostName("serverstats-cache").setPort(7777).build();
    final InstanceInfo otherInstance = Builder.newBuilder().setAppName("serverstats-cache-2").setHostName("serverstats-cache-2").setPort(7777).build();
    final DiscoveryEnabledServer server = new DiscoveryEnabledServer(instanceInfo, false);
    final DiscoveryEnabledServer serverSecure = new DiscoveryEnabledServer(otherInstance, false);
    final DynamicServerListLoadBalancer<Server> lb = new DynamicServerListLoadBalancer<>(new DefaultClientConfigImpl());
    final DiscoveryResult result = new DiscoveryResult(server, lb.getLoadBalancerStats());
    final DiscoveryResult result1 = new DiscoveryResult(serverSecure, lb.getLoadBalancerStats());
    Truth.assertThat(result.getServerStats()).isNotSameInstanceAs(result1.getServerStats());
}
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 8 with DiscoveryEnabledServer

use of com.netflix.niws.loadbalancer.DiscoveryEnabledServer in project ribbon by Netflix.

the class EurekaDynamicServerListLoadBalancerTest method testShutdownMultiple.

@Test
public void testShutdownMultiple() {
    try {
        eurekaClientMock.registerEventListener(EasyMock.anyObject(EurekaEventListener.class));
        EasyMock.expectLastCall().anyTimes();
        PowerMock.replay(DiscoveryClient.class);
        PowerMock.replay(eurekaClientMock);
        DynamicServerListLoadBalancer<DiscoveryEnabledServer> lb1 = new DynamicServerListLoadBalancer<DiscoveryEnabledServer>(config, new AvailabilityFilteringRule(), new DummyPing(), new DiscoveryEnabledNIWSServerList(vipAddress, eurekaClientProvider), new ZoneAffinityServerListFilter<DiscoveryEnabledServer>(), new EurekaNotificationServerListUpdater(eurekaClientProvider));
        DynamicServerListLoadBalancer<DiscoveryEnabledServer> lb2 = new DynamicServerListLoadBalancer<DiscoveryEnabledServer>(config, new AvailabilityFilteringRule(), new DummyPing(), new DiscoveryEnabledNIWSServerList(vipAddress, eurekaClientProvider), new ZoneAffinityServerListFilter<DiscoveryEnabledServer>(), new EurekaNotificationServerListUpdater(eurekaClientProvider));
        DynamicServerListLoadBalancer<DiscoveryEnabledServer> lb3 = new DynamicServerListLoadBalancer<DiscoveryEnabledServer>(config, new AvailabilityFilteringRule(), new DummyPing(), new DiscoveryEnabledNIWSServerList(vipAddress, eurekaClientProvider), new ZoneAffinityServerListFilter<DiscoveryEnabledServer>(), new EurekaNotificationServerListUpdater(eurekaClientProvider));
        lb3.shutdown();
        lb1.shutdown();
        lb2.shutdown();
    } finally {
        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) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with DiscoveryEnabledServer

use of com.netflix.niws.loadbalancer.DiscoveryEnabledServer in project nutzboot by nutzam.

the class FeignStarter method getLoadBalancer.

public Object getLoadBalancer(String name, FeignInject fc) {
    EurekaClient eurekaClient = ioc.get(EurekaClient.class, "eurekaClient");
    DefaultClientConfigImpl clientConfig = DefaultClientConfigImpl.getClientConfigWithDefaultValues(name);
    ServerList<DiscoveryEnabledServer> list = new DiscoveryEnabledNIWSServerList(name, () -> eurekaClient);
    ServerListFilter<DiscoveryEnabledServer> filter = new ZoneAffinityServerListFilter<DiscoveryEnabledServer>(clientConfig);
    ServerListUpdater updater = new EurekaNotificationServerListUpdater(() -> eurekaClient);
    IRule rule = null;
    switch(getLbRuleString(fc.lbRule())) {
        case "random":
            rule = new RandomRule();
            break;
        case "availability":
        default:
            AvailabilityFilteringRule _rule = new AvailabilityFilteringRule();
            _rule.initWithNiwsConfig(clientConfig);
            rule = _rule;
            break;
    }
    ZoneAwareLoadBalancer<DiscoveryEnabledServer> lb = LoadBalancerBuilder.<DiscoveryEnabledServer>newBuilder().withDynamicServerList(list).withRule(rule).withServerListFilter(filter).withServerListUpdater(updater).withClientConfig(clientConfig).buildDynamicServerListLoadBalancerWithUpdater();
    return LBClient.create(lb, clientConfig);
}
Also used : DiscoveryEnabledNIWSServerList(com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList) DiscoveryEnabledServer(com.netflix.niws.loadbalancer.DiscoveryEnabledServer) ZoneAffinityServerListFilter(com.netflix.loadbalancer.ZoneAffinityServerListFilter) EurekaClient(com.netflix.discovery.EurekaClient) RandomRule(com.netflix.loadbalancer.RandomRule) IRule(com.netflix.loadbalancer.IRule) ServerListUpdater(com.netflix.loadbalancer.ServerListUpdater) EurekaNotificationServerListUpdater(com.netflix.niws.loadbalancer.EurekaNotificationServerListUpdater) EurekaNotificationServerListUpdater(com.netflix.niws.loadbalancer.EurekaNotificationServerListUpdater) AvailabilityFilteringRule(com.netflix.loadbalancer.AvailabilityFilteringRule) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl)

Example 10 with DiscoveryEnabledServer

use of com.netflix.niws.loadbalancer.DiscoveryEnabledServer in project spring-cloud-netflix by spring-cloud.

the class DomainExtractingServerListTests method getDomainExtractingServerList.

protected DomainExtractingServerList getDomainExtractingServerList(DefaultClientConfigImpl config, boolean approximateZoneFromHostname) {
    DiscoveryEnabledServer server = mock(DiscoveryEnabledServer.class);
    @SuppressWarnings("unchecked") ServerList<DiscoveryEnabledServer> originalServerList = mock(ServerList.class);
    InstanceInfo instanceInfo = mock(InstanceInfo.class);
    given(server.getInstanceInfo()).willReturn(instanceInfo);
    given(server.getHost()).willReturn(HOST_NAME);
    given(instanceInfo.getMetadata()).willReturn(this.metadata);
    given(instanceInfo.getHostName()).willReturn(HOST_NAME);
    given(instanceInfo.getIPAddr()).willReturn(IP_ADDR);
    given(instanceInfo.getPort()).willReturn(PORT);
    given(originalServerList.getInitialListOfServers()).willReturn(Arrays.asList(server));
    return new DomainExtractingServerList(originalServerList, config, approximateZoneFromHostname);
}
Also used : DiscoveryEnabledServer(com.netflix.niws.loadbalancer.DiscoveryEnabledServer) InstanceInfo(com.netflix.appinfo.InstanceInfo)

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