@Override
    public ProviderInfo doSelect(SofaRequest request, List<ProviderInfo> providerInfos) {
        String interfaceId = request.getInterfaceName();
        String method = request.getMethodName();
        String key = interfaceId + "#" + method;
        // 判断是否同样的服务列表
        int hashcode = providerInfos.hashCode();
        Selector selector = selectorCache.get(key);
        // 原来没有
        if (selector == null ||
            // 或者服务列表已经变化
            selector.getHashCode() != hashcode) {
            selector = new Selector(interfaceId, method, providerInfos, hashcode);
            selectorCache.put(key, selector);
        }
        return selector.select(request);
    }
@Test
    public void testWeight() throws Exception {
        WeightConsistentHashLoadBalancer loadBalancer = new WeightConsistentHashLoadBalancer(null);
        SofaRequest request = new SofaRequest();
        request.setInterfaceName(ConsistentHashLoadBalancerTest.class.getName());
        request.setMethod(ConsistentHashLoadBalancerTest.class.getMethod("doSelect"));
        int size = 20;
        int total = 100000;
        List<ProviderInfo> providers = buildDiffWeightProviderList(size);
        Map<Integer, Integer> map = new HashMap(total * 2);
        for (int i = 0; i < total; i++) {
            request.setMethodArgs(new Object[] { "method" + i });
            ProviderInfo provider = loadBalancer.doSelect(request, providers);
            Integer key = provider.getPort();
            if (map.containsKey(key)) {
                int count = map.get(key);
                map.put(key, ++count);
            } else {
                map.put(key, 0);
            }
        }
        Set<Map.Entry<Integer, Integer>> set = map.entrySet();
        Iterator<Map.Entry<Integer, Integer>> iterator = set.iterator();

        while (iterator.hasNext()) {
            Map.Entry<Integer, Integer> entry = iterator.next();
            int port = entry.getKey() - 9000;
            //最大误差不超过10%
            Assert.assertTrue(entry.getValue() > 500 * port * 0.90);
            Assert.assertTrue(entry.getValue() < 500 * port * 1.10);
        }
    }