当前位置: 首页>>代码示例>>Java>>正文


Java ClientFactory.getNamedLoadBalancer方法代码示例

本文整理汇总了Java中com.netflix.client.ClientFactory.getNamedLoadBalancer方法的典型用法代码示例。如果您正苦于以下问题:Java ClientFactory.getNamedLoadBalancer方法的具体用法?Java ClientFactory.getNamedLoadBalancer怎么用?Java ClientFactory.getNamedLoadBalancer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.netflix.client.ClientFactory的用法示例。


在下文中一共展示了ClientFactory.getNamedLoadBalancer方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testPrimeConnectionsLargePool

import com.netflix.client.ClientFactory; //导入方法依赖的package包/类
@Test
public void testPrimeConnectionsLargePool() throws Exception {
	Configuration config = ConfigurationManager.getConfigInstance();
	config.setProperty("PrimeConnectionsTest2.ribbon.NFLoadBalancerClassName", 
			com.netflix.loadbalancer.DynamicServerListLoadBalancer.class.getName());
	config.setProperty("PrimeConnectionsTest2.ribbon.NIWSServerListClassName", LargeFixedServerList.class.getName());
	config.setProperty("PrimeConnectionsTest2.ribbon.EnablePrimeConnections", "true");
	DynamicServerListLoadBalancer<Server> lb = (DynamicServerListLoadBalancer<Server>) ClientFactory.getNamedLoadBalancer("PrimeConnectionsTest2");
	PrimeConnectionEndStats stats = lb.getPrimeConnections().getEndStats();
	assertEquals(stats.success, LARGE_FIXED_SERVER_LIST_SIZE);
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:12,代码来源:PrimeConnectionsTest.java

示例2: testZoneExclusivity

import com.netflix.client.ClientFactory; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })    
@Test
public void testZoneExclusivity() throws Exception {
    ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest2.ribbon.DeploymentContextBasedVipAddresses", "l10nservicegeneral.cloud.netflix.net:7001");
    ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest2.ribbon.NFLoadBalancerClassName", DynamicServerListLoadBalancer.class.getName());
    ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest2.ribbon.EnableZoneExclusivity", "true");
    ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest2.ribbon.NIWSServerListClassName", DiscoveryEnabledNIWSServerList.class.getName());
    DynamicServerListLoadBalancer lb = (DynamicServerListLoadBalancer) ClientFactory.getNamedLoadBalancer("DefaultNIWSServerListFilterTest2");
    ZoneAffinityServerListFilter filter = (ZoneAffinityServerListFilter) lb.getFilter();
    LoadBalancerStats loadBalancerStats = lb.getLoadBalancerStats();
    List<DiscoveryEnabledServer> servers = new ArrayList<DiscoveryEnabledServer>();        
    servers.add(createServer(1, "a"));
    servers.add(createServer(2, "a"));
    servers.add(createServer(3, "a"));
    servers.add(createServer(4, "a"));
    servers.add(createServer(1, "b"));
    servers.add(createServer(2, "b"));
    servers.add(createServer(3, "b"));
    servers.add(createServer(1, "c"));
    servers.add(createServer(2, "c"));
    servers.add(createServer(3, "c"));
    servers.add(createServer(4, "c"));
    servers.add(createServer(5, "c"));
    List<DiscoveryEnabledServer> filtered = filter.getFilteredListOfServers(servers);
    List<DiscoveryEnabledServer> expected = new ArrayList<DiscoveryEnabledServer>();
    expected.add(createServer(1, "c"));
    expected.add(createServer(2, "c"));
    expected.add(createServer(3, "c"));
    expected.add(createServer(4, "c"));
    expected.add(createServer(5, "c"));
    assertEquals(expected, filtered);
    lb.setServersList(filtered);        
    for (int i = 1; i <= 4; i++) {            
        loadBalancerStats.incrementActiveRequestsCount(createServer(i, "c"));
    }
    filtered = filter.getFilteredListOfServers(servers);
    assertEquals(expected, filtered);
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:39,代码来源:DefaultNIWSServerListFilterTest.java

示例3: testPrimeConnectionsSmallPool

import com.netflix.client.ClientFactory; //导入方法依赖的package包/类
@Test
public void testPrimeConnectionsSmallPool() throws Exception {
	Configuration config = ConfigurationManager.getConfigInstance();
	config.setProperty("PrimeConnectionsTest1.ribbon.NFLoadBalancerClassName", 
			com.netflix.loadbalancer.DynamicServerListLoadBalancer.class.getName());
	config.setProperty("PrimeConnectionsTest1.ribbon.NIWSServerListClassName", SmallFixedServerList.class.getName());
	config.setProperty("PrimeConnectionsTest1.ribbon.EnablePrimeConnections", "true");
	DynamicServerListLoadBalancer<Server> lb = (DynamicServerListLoadBalancer<Server>) ClientFactory.getNamedLoadBalancer("PrimeConnectionsTest1");
	PrimeConnectionEndStats stats = lb.getPrimeConnections().getEndStats();
	assertEquals(stats.success, SMALL_FIXED_SERVER_LIST_SIZE);
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:12,代码来源:PrimeConnectionsTest.java

示例4: init

import com.netflix.client.ClientFactory; //导入方法依赖的package包/类
@BeforeClass
public static void init() {
	Configuration config = ConfigurationManager.getConfigInstance();
	config.setProperty("ServerListLoabBalancerTest.ribbon.NFLoadBalancerClassName", 
			com.netflix.loadbalancer.DynamicServerListLoadBalancer.class.getName());
	config.setProperty("ServerListLoabBalancerTest.ribbon.NIWSServerListClassName", FixedServerList.class.getName());
	lb = (DynamicServerListLoadBalancer<Server>) ClientFactory.getNamedLoadBalancer("ServerListLoabBalancerTest");
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:9,代码来源:ServerListLoabBalancerTest.java

示例5: create

import com.netflix.client.ClientFactory; //导入方法依赖的package包/类
@Override
public LBClient create(String clientName) {
  IClientConfig config = ClientFactory.getNamedConfig(clientName, DisableAutoRetriesByDefaultClientConfig.class);
  ILoadBalancer lb = ClientFactory.getNamedLoadBalancer(clientName);
  return LBClient.create(lb, config);
}
 
开发者ID:wenwu315,项目名称:XXXX,代码行数:7,代码来源:LBClientFactory.java

示例6: testZoneAffinityEnabled

import com.netflix.client.ClientFactory; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testZoneAffinityEnabled() throws Exception {
    ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest1.ribbon.DeploymentContextBasedVipAddresses", "l10nservicegeneral.cloud.netflix.net:7001");
    ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest1.ribbon.NFLoadBalancerClassName", DynamicServerListLoadBalancer.class.getName());
    ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest1.ribbon.NIWSServerListClassName", DiscoveryEnabledNIWSServerList.class.getName());

    ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest1.ribbon.EnableZoneAffinity", "true");
    DynamicServerListLoadBalancer lb = (DynamicServerListLoadBalancer) ClientFactory.getNamedLoadBalancer("DefaultNIWSServerListFilterTest1");
    assertTrue(lb.getRule() instanceof AvailabilityFilteringRule);
    ZoneAffinityServerListFilter filter = (ZoneAffinityServerListFilter) lb.getFilter();
    LoadBalancerStats loadBalancerStats = lb.getLoadBalancerStats();
    List<DiscoveryEnabledServer> servers = new ArrayList<DiscoveryEnabledServer>();        
    servers.add(createServer(1, "a"));
    servers.add(createServer(2, "a"));
    servers.add(createServer(3, "a"));
    servers.add(createServer(4, "a"));
    servers.add(createServer(1, "b"));
    servers.add(createServer(2, "b"));
    servers.add(createServer(3, "b"));
    servers.add(createServer(1, "c"));
    servers.add(createServer(2, "c"));
    servers.add(createServer(3, "c"));
    servers.add(createServer(4, "c"));
    servers.add(createServer(5, "c"));
    List<DiscoveryEnabledServer> filtered = filter.getFilteredListOfServers(servers);
    List<DiscoveryEnabledServer> expected = new ArrayList<DiscoveryEnabledServer>();
    expected.add(createServer(1, "c"));
    expected.add(createServer(2, "c"));
    expected.add(createServer(3, "c"));
    expected.add(createServer(4, "c"));
    expected.add(createServer(5, "c"));
    assertEquals(expected, filtered);
    lb.setServersList(filtered);        
    for (int i = 1; i <= 4; i++) {            
        loadBalancerStats.incrementActiveRequestsCount(createServer(i, "c"));
    }
    filtered = filter.getFilteredListOfServers(servers);
    assertEquals(servers, filtered);

}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:42,代码来源:DefaultNIWSServerListFilterTest.java

示例7: testZoneAffinityOverride

import com.netflix.client.ClientFactory; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testZoneAffinityOverride() throws Exception {
    ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest3.ribbon.DeploymentContextBasedVipAddresses", "l10nservicegeneral.cloud.netflix.net:7001");
    ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest3.ribbon.NFLoadBalancerClassName", DynamicServerListLoadBalancer.class.getName());
    ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest3.ribbon.EnableZoneAffinity", "true");
    ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest3.ribbon.NIWSServerListClassName", DiscoveryEnabledNIWSServerList.class.getName());
    ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest3.ribbon.zoneAffinity.minAvailableServers", "3");
    DynamicServerListLoadBalancer lb = (DynamicServerListLoadBalancer) ClientFactory.getNamedLoadBalancer("DefaultNIWSServerListFilterTest3");
    ZoneAffinityServerListFilter filter = (ZoneAffinityServerListFilter) lb.getFilter();
    LoadBalancerStats loadBalancerStats = lb.getLoadBalancerStats();
    List<DiscoveryEnabledServer> servers = new ArrayList<DiscoveryEnabledServer>();        
    servers.add(createServer(1, "a"));
    servers.add(createServer(2, "a"));
    servers.add(createServer(3, "a"));
    servers.add(createServer(4, "a"));
    servers.add(createServer(1, "b"));
    servers.add(createServer(2, "b"));
    servers.add(createServer(3, "b"));
    servers.add(createServer(1, "c"));
    servers.add(createServer(2, "c"));
    List<DiscoveryEnabledServer> filtered = filter.getFilteredListOfServers(servers);
    List<DiscoveryEnabledServer> expected = new ArrayList<DiscoveryEnabledServer>();
    /*
    expected.add(createServer(1, "c"));
    expected.add(createServer(2, "c"));
    expected.add(createServer(3, "c"));
    expected.add(createServer(4, "c"));
    expected.add(createServer(5, "c")); */
    // less than 3 servers in zone c, will not honor zone affinity
    assertEquals(servers, filtered);
    lb.setServersList(filtered);        
    servers.add(createServer(3, "c"));
    filtered = filter.getFilteredListOfServers(servers);
    expected.add(createServer(1, "c"));
    expected.add(createServer(2, "c"));
    expected.add(createServer(3, "c"));
    filtered = filter.getFilteredListOfServers(servers);
    // now we have enough servers in C
    assertEquals(expected, filtered);

    // make one server black out
    for (int i = 1; i <= 3; i++) {            
        loadBalancerStats.incrementSuccessiveConnectionFailureCount(createServer(1, "c"));
    }
    filtered = filter.getFilteredListOfServers(servers);
    assertEquals(servers, filtered);
    // new server added in zone c, zone c should now have enough servers
    servers.add(createServer(4, "c"));
    filtered = filter.getFilteredListOfServers(servers);
    expected.add(createServer(4, "c"));
    assertEquals(expected, filtered);
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:54,代码来源:DefaultNIWSServerListFilterTest.java

示例8: testWithLoadBalancer

import com.netflix.client.ClientFactory; //导入方法依赖的package包/类
@Test
public void testWithLoadBalancer() {
    DynamicServerListLoadBalancer<Server> lb = (DynamicServerListLoadBalancer<Server>) 
            ClientFactory.getNamedLoadBalancer("SubsetFilerTest");        
    MockServerList serverList = (MockServerList) lb.getServerListImpl();
    Object[][] serverStats = { 
            {"server0", 0, 0},
            {"server1", 0, 0},
            {"server2", 0, 0},
            {"server3", 0, 0},
            {"server4", 0, 0},
            {"server5", 0, 0},
            {"server6", 0, 0},
            {"server7", 0, 0},
            {"server8", 0, 0},
            {"server9", 0, 0}
    };
    LoadBalancerStats stats = lb.getLoadBalancerStats();
    List<Server> list = getServersAndStats(stats, serverStats);
    serverList.setServerList(list);
    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    lb.updateListOfServers();
    List<Server> filtered = lb.getAllServers();
    // first filtering, should get 5 servers 
    assertEquals(filtered.size(), 5);
    
    Server s1 = filtered.get(0);        
    Server s2 = filtered.get(1);
    Server s3 = filtered.get(2);
    Server s4 = filtered.get(3);
    Server s5 = filtered.get(4);

    // failure count > threshold
    DummyServerStats stats1 = (DummyServerStats) stats.getSingleServerStat(s1);
    stats1.setConnectionFailureCount(3);
    
    // active requests count > threshold
    DummyServerStats stats2 = (DummyServerStats) stats.getSingleServerStat(s2);
    stats2.setActiveRequestsCount(3);

    // will be forced eliminated after sorting 
    DummyServerStats stats3 = (DummyServerStats) stats.getSingleServerStat(s3);
    stats3.setActiveRequestsCount(2);

    // will be forced eliminated after sorting
    DummyServerStats stats4 = (DummyServerStats) stats.getSingleServerStat(s4);
    stats4.setConnectionFailureCount(1);

    // filter again, this time some servers will be eliminated
    serverList.setServerList(list);
    lb.updateListOfServers();
    filtered = lb.getAllServers();
    
    assertEquals(5, filtered.size());
    assertTrue(!filtered.contains(s1));
    assertTrue(!filtered.contains(s2));
    assertTrue(filtered.contains(s3));
    assertTrue(!filtered.contains(s4));
    assertTrue(filtered.contains(s5));
    
    // Not enough healthy servers, just get whatever is available
    serverList.setServerList(Lists.newArrayList(filtered));
    lb.updateListOfServers();
    List<Server> lastFiltered = lb.getAllServers();
    assertEquals(5, lastFiltered.size());

}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:73,代码来源:SubsetFilterTest.java

示例9: testConstruction

import com.netflix.client.ClientFactory; //导入方法依赖的package包/类
@Test
public void testConstruction() {
    ConfigurationManager.getConfigInstance().setProperty("mylb.ribbon.NFLoadBalancerRuleClassName", RandomRule.class.getName());
    ZoneAwareLoadBalancer lb = (ZoneAwareLoadBalancer) ClientFactory.getNamedLoadBalancer("mylb");
    assertTrue(lb.getLoadBalancer("myzone").getRule() instanceof RandomRule);
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:7,代码来源:ZoneAwareLoadBalancerTest.java

示例10: testActiveConnectionsLimit

import com.netflix.client.ClientFactory; //导入方法依赖的package包/类
@Test
public void testActiveConnectionsLimit() {
    ConfigurationManager.getConfigInstance().clearProperty("niws.loadbalancer.serverStats.activeRequestsCount.effectiveWindowSeconds");
    ConfigurationManager.getConfigInstance().setProperty("testlb.ribbon.ActiveConnectionsLimit", 1);

	ZoneAwareLoadBalancer balancer = (ZoneAwareLoadBalancer) ClientFactory.getNamedLoadBalancer("testlb");
    LoadBalancerStats loadBalancerStats = balancer.getLoadBalancerStats();
    assertNotNull(loadBalancerStats);
    List<Server> servers = new ArrayList<Server>();        
    servers.add(createServer(1, "a"));
    servers.add(createServer(2, "a"));
    servers.add(createServer(3, "a"));
    servers.add(createServer(4, "a"));
    servers.add(createServer(5, "a"));
    servers.add(createServer(6, "a"));
    servers.add(createServer(1, "b"));
    servers.add(createServer(2, "b"));
    servers.add(createServer(3, "b"));
    servers.add(createServer(4, "b"));
    servers.add(createServer(5, "b"));
    servers.add(createServer(6, "b"));
    servers.add(createServer(7, "b"));
    servers.add(createServer(8, "b"));
    balancer.setServersList(servers);
    balancer.setUpServerList(servers);
    // cause both zone a and b outage 
    Server server = servers.get(0);
    loadBalancerStats.getSingleServerStat(server).incrementActiveRequestsCount();
    server = servers.get(8);
    loadBalancerStats.getSingleServerStat(server).incrementActiveRequestsCount();
    
    server = servers.get(servers.size() - 1);
    for (int j = 0; j < 3; j++) {
        loadBalancerStats.getSingleServerStat(server).incrementSuccessiveConnectionFailureCount();
    }

    Set<Server> expected = new HashSet<Server>();
    expected.add(createServer(2, "a"));
    expected.add(createServer(3, "a"));
    expected.add(createServer(4, "a"));
    expected.add(createServer(5, "a"));
    expected.add(createServer(6, "a"));
    expected.add(createServer(1, "b"));
    expected.add(createServer(2, "b"));
    expected.add(createServer(4, "b"));
    expected.add(createServer(5, "b"));
    expected.add(createServer(6, "b"));
    expected.add(createServer(7, "b"));
    AvailabilityFilteringRule rule = (AvailabilityFilteringRule) balancer.getRule();
    assertEquals(expected.size(), rule.getAvailableServersCount());
    AvailabilityFilteringRule rule1 = (AvailabilityFilteringRule) balancer.getLoadBalancer("us-east-1a").getRule();
    assertEquals(5, rule1.getAvailableServersCount());
    AvailabilityFilteringRule rule2 = (AvailabilityFilteringRule) balancer.getLoadBalancer("us-east-1b").getRule();
    assertEquals(6, rule2.getAvailableServersCount());
    
    Set<Server> result = new HashSet<Server>();
    for (int i = 0; i < 100; i++) {            
        result.add(balancer.chooseServer(null));
    }
    assertEquals(expected, result);
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:62,代码来源:ZoneAwareLoadBalancerTest.java


注:本文中的com.netflix.client.ClientFactory.getNamedLoadBalancer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。