本文整理汇总了Java中com.netflix.loadbalancer.RandomRule类的典型用法代码示例。如果您正苦于以下问题:Java RandomRule类的具体用法?Java RandomRule怎么用?Java RandomRule使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RandomRule类属于com.netflix.loadbalancer包,在下文中一共展示了RandomRule类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ruleOverridesToRandom
import com.netflix.loadbalancer.RandomRule; //导入依赖的package包/类
@Test
public void ruleOverridesToRandom() throws Exception {
RandomRule.class.cast(getLoadBalancer("foo").getRule());
RoundRobinRule.class.cast(getLoadBalancer("bar").getRule());
}
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:6,代码来源:RibbonClientPreprocessorOverridesIntegrationTests.java
示例2: createLoadBalancerRule
import com.netflix.loadbalancer.RandomRule; //导入依赖的package包/类
@Override
public IRule createLoadBalancerRule(String ruleName) {
if (RULE_RoundRobin.equals(ruleName)) {
return new RoundRobinRule();
} else if (RULE_Random.equals(ruleName)) {
return new RandomRule();
} else if (RULE_WeightedResponse.equals(ruleName)) {
return new WeightedResponseTimeRule();
} else if (RULE_SessionStickiness.equals(ruleName)) {
return new SessionStickinessRule();
} else {
throw new IllegalStateException("unexpected code to reach here, value is " + ruleName);
}
}
示例3: testRuleName
import com.netflix.loadbalancer.RandomRule; //导入依赖的package包/类
@Test
public void testRuleName() {
System.setProperty("cse.loadbalance.mytest1.strategy.name", "RoundRobin");
System.setProperty("cse.loadbalance.mytest2.strategy.name", "Random");
System.setProperty("cse.loadbalance.mytest3.strategy.name", "WeightedResponse");
System.setProperty("cse.loadbalance.mytest4.strategy.name", "SessionStickiness");
BeansHolder holder = new BeansHolder();
List<ExtensionsFactory> extensionsFactories = new ArrayList<>();
extensionsFactories.add(new RuleClassNameExtentionsFactory());
extensionsFactories.add(new RuleNameExtentionsFactory());
extensionsFactories.add(new DefaultRetryExtensionsFactory());
Deencapsulation.setField(holder, "extentionsFactories", extensionsFactories);
holder.init();
Assert.assertEquals(RoundRobinRule.class.getName(),
ExtensionsManager.createLoadBalancerRule("mytest1").getClass().getName());
Assert.assertEquals(RandomRule.class.getName(),
ExtensionsManager.createLoadBalancerRule("mytest2").getClass().getName());
Assert.assertEquals(WeightedResponseTimeRule.class.getName(),
ExtensionsManager.createLoadBalancerRule("mytest3").getClass().getName());
Assert.assertEquals(SessionStickinessRule.class.getName(),
ExtensionsManager.createLoadBalancerRule("mytest4").getClass().getName());
System.getProperties().remove("cse.loadbalance.mytest1.strategy.name");
System.getProperties().remove("cse.loadbalance.mytest2.strategy.name");
System.getProperties().remove("cse.loadbalance.mytest3.strategy.name");
System.getProperties().remove("cse.loadbalance.mytest4.strategy.name");
}
示例4: testRuleClassName
import com.netflix.loadbalancer.RandomRule; //导入依赖的package包/类
@Test
public void testRuleClassName() {
System.setProperty("cse.loadbalance.mytest1.NFLoadBalancerRuleClassName",
"com.netflix.loadbalancer.RoundRobinRule");
System.setProperty("cse.loadbalance.mytest2.NFLoadBalancerRuleClassName",
"com.netflix.loadbalancer.WeightedResponseTimeRule");
System.setProperty("cse.loadbalance.mytest3.NFLoadBalancerRuleClassName", "com.netflix.loadbalancer.RandomRule");
System.setProperty("cse.loadbalance.mytest4.NFLoadBalancerRuleClassName",
"org.apache.servicecomb.loadbalance.SessionStickinessRule");
BeansHolder holder = new BeansHolder();
List<ExtensionsFactory> extensionsFactories = new ArrayList<>();
extensionsFactories.add(new RuleClassNameExtentionsFactory());
extensionsFactories.add(new RuleNameExtentionsFactory());
extensionsFactories.add(new DefaultRetryExtensionsFactory());
Deencapsulation.setField(holder, "extentionsFactories", extensionsFactories);
holder.init();
Assert.assertEquals(RoundRobinRule.class.getName(),
ExtensionsManager.createLoadBalancerRule("mytest1").getClass().getName());
Assert.assertEquals(WeightedResponseTimeRule.class.getName(),
ExtensionsManager.createLoadBalancerRule("mytest2").getClass().getName());
Assert.assertEquals(RandomRule.class.getName(),
ExtensionsManager.createLoadBalancerRule("mytest3").getClass().getName());
Assert.assertEquals(SessionStickinessRule.class.getName(),
ExtensionsManager.createLoadBalancerRule("mytest4").getClass().getName());
System.getProperties().remove("cse.loadbalance.mytest1.NFLoadBalancerRuleClassName");
System.getProperties().remove("cse.loadbalance.mytest2.NFLoadBalancerRuleClassName");
System.getProperties().remove("cse.loadbalance.mytest3.NFLoadBalancerRuleClassName");
System.getProperties().remove("cse.loadbalance.mytest4.NFLoadBalancerRuleClassName");
Assert.assertEquals(DefaultLoadBalancerRetryHandler.class.getName(),
ExtensionsManager.createRetryHandler("mytest1").getClass().getName());
}
示例5: ribbonRule
import com.netflix.loadbalancer.RandomRule; //导入依赖的package包/类
/**
* 负载均衡策略
* @return
*/
@Bean
public IRule ribbonRule() {
// return new BestAvailableRule(); //选择一个最小的并发请求的server
// return new WeightedResponseTimeRule(); //根据相应时间分配一个weight,相应时间越长,weight越小,被选中的可能性越低。
// return new RetryRule(); //对选定的负载均衡策略机上重试机制。
// return new RoundRobinRule(); //roundRobin方式轮询选择server
return new RandomRule(); //随机选择一个server
// return new ZoneAvoidanceRule(); //复合判断server所在区域的性能和server的可用性选择server
// return new AvailabilityFilteringRule();
}
示例6: ribbonRule
import com.netflix.loadbalancer.RandomRule; //导入依赖的package包/类
@Bean
public IRule ribbonRule() {
// 负载均衡规则,改为随机
return new RandomRule();
}
示例7: ribbonRule
import com.netflix.loadbalancer.RandomRule; //导入依赖的package包/类
@Bean
public IRule ribbonRule() {
return new RandomRule();
}
示例8: getRandomRule
import com.netflix.loadbalancer.RandomRule; //导入依赖的package包/类
private IRule getRandomRule() {
RandomRule randomRule = new RandomRule();
randomRule.setLoadBalancer(this);
return randomRule;
}
示例9: ruleOverridesToRandom
import com.netflix.loadbalancer.RandomRule; //导入依赖的package包/类
@Test
public void ruleOverridesToRandom() throws Exception {
assumeNotTravis();
RandomRule.class.cast(getLoadBalancer("foo2").getRule());
ZoneAvoidanceRule.class.cast(getLoadBalancer("bar").getRule());
}
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:7,代码来源:RibbonClientPreprocessorPropertiesOverridesIntegrationTests.java
示例10: ribbonRule
import com.netflix.loadbalancer.RandomRule; //导入依赖的package包/类
@Bean
public IRule ribbonRule() {
return new RandomRule();
}
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:5,代码来源:RibbonClientPreprocessorOverridesIntegrationTests.java