protected int getWeight(Invoker<?> invoker, Invocation invocation) {
        int weight;
        URL url = invoker.getUrl();
        if (invoker instanceof ClusterInvoker) {
            url = ((ClusterInvoker<?>) invoker).getRegistryUrl();
        }

        // Multiple registry scenario, load balance among multiple registries.
        if (REGISTRY_SERVICE_REFERENCE_PATH.equals(url.getServiceInterface())) {
            weight = url.getParameter(WEIGHT_KEY, DEFAULT_WEIGHT);
        } else {
            weight = url.getMethodParameter(RpcUtils.getMethodName(invocation), WEIGHT_KEY, DEFAULT_WEIGHT);
            if (weight > 0) {
                long timestamp = invoker.getUrl().getParameter(TIMESTAMP_KEY, 0L);
                if (timestamp > 0L) {
                    long uptime = System.currentTimeMillis() - timestamp;
                    if (uptime < 0) {
                        return 1;
                    }
                    int warmup = invoker.getUrl().getParameter(WARMUP_KEY, DEFAULT_WARMUP);
                    if (uptime > 0 && uptime < warmup) {
                        weight = calculateWarmupWeight((int) uptime, warmup, weight);
                    }
                }
            }
        }
        return Math.max(weight, 0);
    }
@Test
    void testGetRegistryWeight() {
        RpcInvocation invocation = new RpcInvocation();
        invocation.setMethodName("say");

        Invoker invoker1 = mock(Invoker.class, Mockito.withSettings().stubOnly());
        URL url1 = new ServiceConfigURL("", "", 0, "DemoService", new HashMap<>());
        given(invoker1.getUrl()).willReturn(url1);

        ClusterInvoker invoker2 =
                mock(ClusterInvoker.class, Mockito.withSettings().stubOnly());
        URL url2 = new ServiceConfigURL("", "", 0, "org.apache.dubbo.registry.RegistryService", new HashMap<>());
        url2 = url2.addParameter(WEIGHT_KEY, 20);
        URL registryUrl2 =
                new ServiceConfigURL("", "", 0, "org.apache.dubbo.registry.RegistryService", new HashMap<>());
        registryUrl2 = registryUrl2.addParameter(WEIGHT_KEY, 30);
        given(invoker2.getUrl()).willReturn(url2);
        given(invoker2.getRegistryUrl()).willReturn(registryUrl2);

        Assertions.assertEquals(100, balance.getWeight(invoker1, invocation));
        Assertions.assertEquals(30, balance.getWeight(invoker2, invocation));
    }