Search in sources :

Example 1 with MockReferer

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Referer(com.weibo.api.motan.rpc.Referer) MockReferer(com.weibo.api.motan.mock.MockReferer) URL(com.weibo.api.motan.rpc.URL) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IHello(com.weibo.api.motan.protocol.example.IHello)

Example 2 with MockReferer

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;
}
Also used : ArrayList(java.util.ArrayList) MockReferer(com.weibo.api.motan.mock.MockReferer)

Example 3 with MockReferer

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();
        }
    }
}
Also used : ArrayList(java.util.ArrayList) MockReferer(com.weibo.api.motan.mock.MockReferer) Referer(com.weibo.api.motan.rpc.Referer) MockReferer(com.weibo.api.motan.mock.MockReferer)

Aggregations

MockReferer (com.weibo.api.motan.mock.MockReferer)3 ArrayList (java.util.ArrayList)3 Referer (com.weibo.api.motan.rpc.Referer)2 IHello (com.weibo.api.motan.protocol.example.IHello)1 URL (com.weibo.api.motan.rpc.URL)1 HashMap (java.util.HashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1