@Test
    public void doSelect() throws Exception {
        WeightRoundRobinLoadBalancer loadBalancer = new WeightRoundRobinLoadBalancer(null);

        Map<Integer, Integer> cnt = new HashMap<Integer, Integer>();
        int size = 20;
        int total = 19000; // too slow
        SofaRequest request = new SofaRequest();
        {
            for (int i = 0; i < size; i++) {
                cnt.put(9000 + i, 0);
            }
            List<ProviderInfo> providers = buildSameWeightProviderList(size);
            long start = System.currentTimeMillis();
            for (int i = 0; i < total; i++) {
                ProviderInfo provider = loadBalancer.doSelect(request, providers);
                int port = provider.getPort();
                cnt.put(port, cnt.get(port) + 1);
            }
            long end = System.currentTimeMillis();
            LOGGER.info("elapsed" + (end - start) + "ms");
            LOGGER.info("avg " + (end - start) * 1000 * 1000 / total + "ns");

            int avg = total / size;
            for (int i = 0; i < size; i++) {
                Assert.assertTrue(avg == cnt.get(9000 + i));
            }
        }

        {
            for (int i = 0; i < size; i++) {
                cnt.put(9000 + i, 0);
            }
            List<ProviderInfo> providers = buildDiffWeightProviderList(size);
            long start = System.currentTimeMillis();
            for (int i = 0; i < total; i++) {
                ProviderInfo provider = loadBalancer.doSelect(request, providers);
                int port = provider.getPort();
                cnt.put(port, cnt.get(port) + 1);
            }
            long end = System.currentTimeMillis();
            LOGGER.info("elapsed" + (end - start) + "ms");
            LOGGER.info("avg " + (end - start) * 1000 * 1000 / total + "ns");

            Assert.assertTrue(cnt.get(9000) == 0);
            int count = 0;
            int sum = 0;
            for (int i = 0; i < size; i++) {
                count += i;
                sum += cnt.get(9000 + i);
            }
            Assert.assertTrue(sum == total);

            int per = total / count;
            for (int i = 1; i < size; i++) {
                Assert.assertTrue(per * i == cnt.get(9000 + i));
            }
        }
    }
@author <a href="mailto:zhanggeng.zg@antfin.com">GengZhang</a>
core-impl/client/src/test/java/com/alipay/sofa/rpc/client/lb/WeightRoundRobinLoadBalancerTest.java