@Override
    public List<URL> build(ServiceInstance serviceInstance) {
        Map<String, String> paramsMap = getMetadataServiceURLsParams(serviceInstance);

        String serviceName = serviceInstance.getServiceName();

        String host = serviceInstance.getHost();

        URL url;
        if (paramsMap.isEmpty()) {
            // ServiceInstance Metadata is empty. Happened when registry not support metadata write.
            url = generateUrlWithoutMetadata(serviceName, host, serviceInstance.getPort());
        } else {
            url = generateWithMetadata(serviceName, host, paramsMap);
        }

        url = url.setScopeModel(serviceInstance.getApplicationModel().getInternalModule());

        return Collections.singletonList(url);
    }
@Test
    void testBuild() {
        ExtensionLoader<MetadataServiceURLBuilder> loader =
                ApplicationModel.defaultModel().getExtensionLoader(MetadataServiceURLBuilder.class);
        MetadataServiceURLBuilder builder = loader.getExtension(StandardMetadataServiceURLBuilder.NAME);

        // test generateUrlWithoutMetadata
        List<URL> urls =
                builder.build(new DefaultServiceInstance("test", "127.0.0.1", 8080, ApplicationModel.defaultModel()));
        assertEquals(1, urls.size());
        URL url = urls.get(0);
        assertEquals("dubbo", url.getProtocol());
        assertEquals("127.0.0.1", url.getHost());
        assertEquals(7001, url.getPort());
        assertEquals(MetadataService.class.getName(), url.getServiceInterface());
        assertEquals("test", url.getGroup());
        assertEquals("consumer", url.getSide());
        assertEquals("1.0.0", url.getVersion());
        //        assertEquals(url.getParameters().get("getAndListenInstanceMetadata.1.callback"), "true");
        assertEquals("false", url.getParameters().get("reconnect"));
        assertEquals("5000", url.getParameters().get("timeout"));
        assertEquals(ApplicationModel.defaultModel(), url.getApplicationModel());

        // test generateWithMetadata
        urls = builder.build(serviceInstance);
        assertEquals(1, urls.size());
        url = urls.get(0);
        assertEquals("rest", url.getProtocol());
        assertEquals("127.0.0.1", url.getHost());
        assertEquals(20880, url.getPort());
        assertEquals(MetadataService.class.getName(), url.getServiceInterface());
        assertEquals("test", url.getGroup());
        assertEquals("consumer", url.getSide());
        assertEquals("1.0.0", url.getVersion());
        assertEquals("dubbo-provider-demo", url.getApplication());
        assertEquals("5000", url.getParameters().get("timeout"));
    }