private String buildServiceKey(Invoker<?> invoker, Invocation invocation) {
        URL url = invoker.getUrl();
        StringBuilder sb = new StringBuilder(128);
        sb.append(url.getAddress()).append(":").append(invocation.getProtocolServiceKey());
        return sb.toString();
    }
@Test
    @Order(1)
    void testSelectByAdaptive() {
        int sumInvoker1 = 0;
        int sumInvoker2 = 0;
        int sumInvoker5 = 0;
        int loop = 10000;

        scopeModel = ApplicationModel.defaultModel();
        AdaptiveLoadBalance lb = new AdaptiveLoadBalance(scopeModel);

        lb.select(weightInvokersSR, null, weightTestInvocation);

        for (int i = 0; i < loop; i++) {
            Invoker selected = lb.select(weightInvokersSR, null, weightTestInvocation);

            Map<String, String> metricsMap = new HashMap<>();
            String idKey = buildServiceKey(selected);

            if (selected.getUrl().getProtocol().equals("test1")) {
                sumInvoker1++;
                metricsMap.put("rt", "10");
                metricsMap.put("load", "10");
                metricsMap.put("curTime", String.valueOf(System.currentTimeMillis() - 10));
                getAdaptiveMetricsInstance().addConsumerSuccess(idKey);
            }

            if (selected.getUrl().getProtocol().equals("test2")) {
                sumInvoker2++;
                metricsMap.put("rt", "100");
                metricsMap.put("load", "40");
                metricsMap.put("curTime", String.valueOf(System.currentTimeMillis() - 100));
                getAdaptiveMetricsInstance().addConsumerSuccess(idKey);
            }

            if (selected.getUrl().getProtocol().equals("test5")) {
                metricsMap.put("rt", "5000");
                metricsMap.put("load", "400"); // 400%
                metricsMap.put("curTime", String.valueOf(System.currentTimeMillis() - 5000));

                getAdaptiveMetricsInstance().addErrorReq(idKey);
                sumInvoker5++;
            }
            getAdaptiveMetricsInstance().setProviderMetrics(idKey, metricsMap);
        }
        Map<Invoker<LoadBalanceBaseTest>, Integer> weightMap = weightInvokersSR.stream()
                .collect(Collectors.toMap(
                        Function.identity(), e -> Integer.valueOf(e.getUrl().getParameter("weight"))));
        Integer totalWeight = weightMap.values().stream().reduce(0, Integer::sum);
        // max deviation = expectWeightValue * 2
        int expectWeightValue = loop / totalWeight;
        int maxDeviation = expectWeightValue * 2;
        double beta = 0.5;
        // this EMA is an approximate value
        double ewma1 = beta * 50 + (1 - beta) * 10;
        double ewma2 = beta * 50 + (1 - beta) * 100;
        double ewma5 = beta * 50 + (1 - beta) * 5000;

        AtomicInteger weight1 = new AtomicInteger();
        AtomicInteger weight2 = new AtomicInteger();
        AtomicInteger weight5 = new AtomicInteger();
        weightMap.forEach((k, v) -> {
            if (k.getUrl().getProtocol().equals("test1")) {
                weight1.set(v);
            } else if (k.getUrl().getProtocol().equals("test2")) {
                weight2.set(v);
            } else if (k.getUrl().getProtocol().equals("test5")) {
                weight5.set(v);
            }
        });

        Assertions.assertEquals(sumInvoker1 + sumInvoker2 + sumInvoker5, loop, "select failed!");
        Assertions.assertTrue(
                Math.abs(sumInvoker1 / (weightMap.get(weightInvoker1) * ewma1) - expectWeightValue) < maxDeviation,
                "select failed!");
        Assertions.assertTrue(
                Math.abs(sumInvoker2 / (weightMap.get(weightInvoker2) * ewma2) - expectWeightValue) < maxDeviation,
                "select failed!");
        Assertions.assertTrue(
                Math.abs(sumInvoker5 / (weightMap.get(weightInvoker5) * ewma5) - expectWeightValue) < maxDeviation,
                "select failed!");
    }