Search in sources :

Example 11 with DiscoveryEnabledServer

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

the class DomainExtractingServerListTests method testDomainExtractingServer.

@Test
public void testDomainExtractingServer() {
    DomainExtractingServerList serverList = getDomainExtractingServerList(new DefaultClientConfigImpl(), true);
    List<DiscoveryEnabledServer> servers = serverList.getInitialListOfServers();
    assertNotNull("servers was null", servers);
    assertEquals("servers was not size 1", 1, servers.size());
    DomainExtractingServer des = assertDomainExtractingServer(servers, ZONE);
    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 12 with DiscoveryEnabledServer

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

the class DomainExtractingServerListTests method testDomainExtractingServerUseIpAddress.

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

Example 13 with DiscoveryEnabledServer

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

the class DomainExtractingServerListTests method assertDomainExtractingServer.

protected DomainExtractingServer assertDomainExtractingServer(List<DiscoveryEnabledServer> servers, String zone) {
    Server actualServer = servers.get(0);
    assertTrue("server was not a DomainExtractingServer", actualServer instanceof DomainExtractingServer);
    DomainExtractingServer des = DomainExtractingServer.class.cast(actualServer);
    assertEquals("zone was wrong", zone, des.getZone());
    assertEquals("instanceId was wrong", HOST_NAME + ":" + INSTANCE_ID, des.getId());
    return des;
}
Also used : DiscoveryEnabledServer(com.netflix.niws.loadbalancer.DiscoveryEnabledServer) Server(com.netflix.loadbalancer.Server)

Example 14 with DiscoveryEnabledServer

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

the class DomainExtractingServerListTests method testZoneInMetaData.

@Test
public void testZoneInMetaData() {
    this.metadata = new HashMap<String, String>();
    this.metadata.put("zone", "us-west-1");
    this.metadata.put("instanceId", INSTANCE_ID);
    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, "us-west-1");
    assertEquals("Zone was wrong", "us-west-1", des.getZone());
}
Also used : DiscoveryEnabledServer(com.netflix.niws.loadbalancer.DiscoveryEnabledServer) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl) Test(org.junit.Test)

Example 15 with DiscoveryEnabledServer

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

the class DomainExtractingServer method extractId.

private String extractId(Server server) {
    if (server instanceof DiscoveryEnabledServer) {
        DiscoveryEnabledServer enabled = (DiscoveryEnabledServer) server;
        InstanceInfo instance = enabled.getInstanceInfo();
        if (instance.getMetadata().containsKey("instanceId")) {
            return instance.getHostName() + ":" + instance.getMetadata().get("instanceId");
        }
    }
    return super.getId();
}
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