use of com.weibo.api.motan.mock.MockReferer in project motan by weibocom.
the class ConfigurableWeightLoadBalanceTest method generate.
private Map<String, AtomicInteger> generate(int groupNum, int[] groupWeight, int[] groupSize) {
StringBuilder sb = new StringBuilder();
List<Referer<IHello>> list = new ArrayList<Referer<IHello>>();
Map<String, AtomicInteger> counterMap = new HashMap<String, AtomicInteger>();
for (int i = 0; i < groupNum; i++) {
// build weight
sb.append("group").append(i).append(":").append(groupWeight[i]).append(",");
// build counter
counterMap.put("group" + i, new AtomicInteger(0));
// build param map
Map<String, String> param = new HashMap<String, String>();
param.put("group", "group" + i);
// build referers
for (int j = 0; j < groupSize[i]; j++) {
list.add(new MockReferer<IHello>(new URL("motan", "localhost", i * 100 + j, "com.weibo.Hello", param)));
}
}
balance = new ConfigurableWeightLoadBalance();
balance.setWeightString(sb.substring(0, sb.length() - 1));
balance.onRefresh(list);
return counterMap;
}
use of com.weibo.api.motan.mock.MockReferer in project motan by weibocom.
the class ActiveWeightLoadBalanceTest method createBalance.
private ActiveWeightLoadBalance createBalance(int refererSize, int unAvailableSize) {
List<MockReferer> referers = new ArrayList<MockReferer>();
for (int i = 0; i < refererSize; i++) {
MockReferer referer = new MockReferer();
referer.active = lowActive + i;
referers.add(referer);
}
Collections.shuffle(referers);
for (int i = 0; i < unAvailableSize; i++) {
referers.get(i).available = false;
}
ActiveWeightLoadBalance balance = new ActiveWeightLoadBalance();
balance.onRefresh(referers);
return balance;
}
use of com.weibo.api.motan.mock.MockReferer 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();
}
}
}
Aggregations