Search in sources :

Example 1 with DiscoveryEnabledServer

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

the class DomainExtractingServerListTests method testDomainExtractingServerDontApproximateZone.

@Test
public void testDomainExtractingServerDontApproximateZone() {
    DomainExtractingServerList serverList = getDomainExtractingServerList(new DefaultClientConfigImpl(), false);
    List<DiscoveryEnabledServer> servers = serverList.getInitialListOfServers();
    assertNotNull("servers was null", servers);
    assertEquals("servers was not size 1", 1, servers.size());
    DomainExtractingServer des = assertDomainExtractingServer(servers, null);
    assertEquals("hostPort was wrong", HOST_NAME + ":" + PORT, des.getHostPort());
}
Also used : DiscoveryEnabledServer(com.netflix.niws.loadbalancer.DiscoveryEnabledServer) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl) Test(org.junit.Test)

Example 2 with DiscoveryEnabledServer

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

the class EurekaRibbonClientConfigurationTests method basicConfigurationCreatedForLoadBalancer.

@Test
@Ignore
public void basicConfigurationCreatedForLoadBalancer() {
    EurekaClientConfigBean client = new EurekaClientConfigBean();
    EurekaInstanceConfigBean configBean = getEurekaInstanceConfigBean();
    client.getAvailabilityZones().put(client.getRegion(), "foo");
    SpringClientFactory clientFactory = new SpringClientFactory();
    EurekaRibbonClientConfiguration clientPreprocessor = new EurekaRibbonClientConfiguration(client, "service", configBean, false);
    clientPreprocessor.preprocess();
    ILoadBalancer balancer = clientFactory.getLoadBalancer("service");
    assertNotNull(balancer);
    @SuppressWarnings("unchecked") ZoneAwareLoadBalancer<DiscoveryEnabledServer> aware = (ZoneAwareLoadBalancer<DiscoveryEnabledServer>) balancer;
    assertTrue(aware.getServerListImpl() instanceof DomainExtractingServerList);
    assertEquals("foo", ConfigurationManager.getDeploymentContext().getValue(ContextKey.zone));
}
Also used : EurekaInstanceConfigBean(org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean) SpringClientFactory(org.springframework.cloud.netflix.ribbon.SpringClientFactory) ILoadBalancer(com.netflix.loadbalancer.ILoadBalancer) DiscoveryEnabledServer(com.netflix.niws.loadbalancer.DiscoveryEnabledServer) ZoneAwareLoadBalancer(com.netflix.loadbalancer.ZoneAwareLoadBalancer) EurekaClientConfigBean(org.springframework.cloud.netflix.eureka.EurekaClientConfigBean) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with DiscoveryEnabledServer

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

the class DiscoveryResultTest method serverStatsCacheForSameServer.

@Test
public void serverStatsCacheForSameServer() {
    final InstanceInfo instanceInfo = Builder.newBuilder().setAppName("serverstats-cache").setHostName("serverstats-cache").setPort(7777).build();
    final DiscoveryEnabledServer server = new DiscoveryEnabledServer(instanceInfo, false);
    final DiscoveryEnabledServer serverSecure = new DiscoveryEnabledServer(instanceInfo, true);
    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()).isSameInstanceAs(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 4 with DiscoveryEnabledServer

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

the class DiscoveryResultTest method securePortMustCheckInstanceInfo.

@Test
public void securePortMustCheckInstanceInfo() {
    final InstanceInfo instanceInfo = Builder.newBuilder().setAppName("secure-port").setHostName("secure-port").setPort(7777).enablePort(PortType.SECURE, false).build();
    final InstanceInfo secureEnabled = Builder.newBuilder().setAppName("secure-port").setHostName("secure-port").setPort(7777).enablePort(PortType.SECURE, true).build();
    final DiscoveryEnabledServer server = new DiscoveryEnabledServer(instanceInfo, true);
    final DiscoveryEnabledServer secureServer = new DiscoveryEnabledServer(secureEnabled, true);
    final DynamicServerListLoadBalancer<Server> lb = new DynamicServerListLoadBalancer<>(new DefaultClientConfigImpl());
    final DiscoveryResult result = new DiscoveryResult(server, lb.getLoadBalancerStats());
    final DiscoveryResult secure = new DiscoveryResult(secureServer, lb.getLoadBalancerStats());
    Truth.assertThat(result.isSecurePortEnabled()).isFalse();
    Truth.assertThat(secure.isSecurePortEnabled()).isTrue();
}
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 5 with DiscoveryEnabledServer

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

the class DiscoveryResultTest method ipAddrV4FromInstanceInfo.

@Test
public void ipAddrV4FromInstanceInfo() {
    final String ipAddr = "100.1.0.1";
    final InstanceInfo instanceInfo = Builder.newBuilder().setAppName("ipAddrv4").setHostName("ipAddrv4").setIPAddr(ipAddr).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.of(ipAddr));
}
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)

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