use of com.weibo.api.motan.rpc.Referer in project motan by weibocom.
the class ActiveWeightLoadBalanceTest method allAvailableCluster.
private void allAvailableCluster(int refererSize) {
ActiveWeightLoadBalance balance = createBalance(refererSize, 0);
Referer referer = balance.select(null);
Assert.assertNotNull(referer);
if (refererSize <= ActiveWeightLoadBalance.MAX_REFERER_COUNT) {
Assert.assertEquals(referer.activeRefererCount(), lowActive);
} else {
Assert.assertTrue(refererSize - ActiveWeightLoadBalance.MAX_REFERER_COUNT + 1 >= referer.activeRefererCount());
}
List<Referer> referersHolder = new ArrayList<Referer>();
balance.selectToHolder(null, referersHolder);
if (refererSize <= ActiveWeightLoadBalance.MAX_REFERER_COUNT) {
Assert.assertEquals(referersHolder.size(), refererSize);
check(referersHolder);
} else {
Assert.assertEquals(referersHolder.size(), ActiveWeightLoadBalance.MAX_REFERER_COUNT);
check(referersHolder);
}
}
use of com.weibo.api.motan.rpc.Referer in project motan by weibocom.
the class ActiveWeightLoadBalanceTest method main.
public static void main(String[] args) {
List<MockReferer> referers = new ArrayList<MockReferer>();
for (int i = 0; i < 20; i++) {
MockReferer referer = new MockReferer();
referer.active = 1 + i;
referers.add(referer);
}
for (int j = 0; j < 20; j++) {
List<Referer> copy = new ArrayList<Referer>(referers);
Collections.shuffle(copy);
String buffer = "[";
for (Referer referer : copy) {
buffer += referer.activeRefererCount() + ",";
}
Collections.sort(copy, new ActiveWeightLoadBalance.LowActivePriorityComparator());
int prefix = -1;
for (Referer aCopy : copy) {
if (aCopy.activeRefererCount() <= prefix) {
throw new RuntimeException("bug bug bug");
}
prefix = aCopy.activeRefererCount();
}
}
}
use of com.weibo.api.motan.rpc.Referer in project motan by weibocom.
the class ConfigurableWeightLoadBalanceTest method testDoSelect.
@Test
public void testDoSelect() {
int[] groupWeight = new int[] { 2, 3, 5 };
Map<String, AtomicInteger> counter = generate(3, groupWeight, new int[] { 3, 4, 5 });
for (int j = 0; j < 100; j++) {
int size = 100;
for (int i = 0; i < size; i++) {
Referer referer = balance.doSelect(new DefaultRequest());
String group = referer.getServiceUrl().getGroup();
counter.get(group).incrementAndGet();
}
for (String key : counter.keySet()) {
float total = size * (j + 1);
float ratio = counter.get(key).get() * 10 / total;
int weight = groupWeight[Integer.parseInt(key.substring("group".length()))];
// 权重误差不超过阈值。
Assert.assertTrue(Math.abs(weight - ratio) < 2);
}
}
}
use of com.weibo.api.motan.rpc.Referer in project motan by weibocom.
the class RandomLoadBalanceTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
randomLoadBalance.onRefresh(referers);
mockery.checking(new Expectations() {
{
int i = 0;
for (Referer<IHello> ref : referers) {
boolean rs = i++ >= falseCount;
atLeast(0).of(ref).isAvailable();
will(returnValue(rs));
}
}
});
}
Aggregations