AlbumenJ commented on code in PR #13137:
URL: https://github.com/apache/dubbo/pull/13137#discussion_r1357980292


##########
dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/event/listener/ServiceInstancesChangedListener.java:
##########
@@ -159,7 +159,7 @@ private synchronized void 
doOnEvent(ServiceInstancesChangedEvent event) {
                 .filter(Objects::nonNull)
                 .filter(m -> revision.equals(m.getRevision()))
                 .findFirst()
-                .orElseGet(() -> serviceDiscovery.getRemoteMetadata(revision, 
subInstances));
+                .orElseGet(() -> getRemoteMetadata(revision, subInstances));

Review Comment:
   Why change this line?



##########
dubbo-registry/dubbo-registry-multiple/src/test/java/org/apache/dubbo/registry/multiple/MultipleServiceDiscoveryTest.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.registry.multiple;
+
+import com.google.common.collect.Sets;
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.utils.Assert;
+import org.apache.dubbo.common.utils.CollectionUtils;
+import org.apache.dubbo.common.utils.JsonUtils;
+import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.config.ApplicationConfig;
+import org.apache.dubbo.metadata.MetadataInfo;
+import org.apache.dubbo.registry.client.DefaultServiceInstance;
+import org.apache.dubbo.registry.client.ServiceDiscovery;
+import org.apache.dubbo.registry.client.ServiceInstance;
+import org.apache.dubbo.registry.client.event.ServiceInstancesChangedEvent;
+import 
org.apache.dubbo.registry.client.event.listener.ServiceInstancesChangedListener;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.dubbo.common.constants.CommonConstants.REVISION_KEY;
+import static 
org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.EXPORTED_SERVICES_REVISION_PROPERTY_NAME;
+
+/**
+ * MultipleServiceDiscoveryTest
+ */
+public class MultipleServiceDiscoveryTest {
+
+    private static String zookeeperConnectionAddress1, 
zookeeperConnectionAddress2;
+
+    @Test
+    public void testOnEvent() {
+        try {
+            String metadata_111 = 
"{\"app\":\"app1\",\"revision\":\"111\",\"services\":{"
+                + 
"\"org.apache.dubbo.demo.DemoService:dubbo\":{\"name\":\"org.apache.dubbo.demo.DemoService\",\"protocol\":\"dubbo\",\"path\":\"org.apache.dubbo.demo.DemoService\",\"params\":{\"side\":\"provider\",\"release\":\"\",\"methods\":\"sayHello,sayHelloAsync\",\"deprecated\":\"false\",\"dubbo\":\"2.0.2\",\"pid\":\"72723\",\"interface\":\"org.apache.dubbo.demo.DemoService\",\"service-name-mapping\":\"true\",\"timeout\":\"3000\",\"generic\":\"false\",\"metadata-type\":\"remote\",\"delay\":\"5000\",\"application\":\"app1\",\"dynamic\":\"true\",\"REGISTRY_CLUSTER\":\"registry1\",\"anyhost\":\"true\",\"timestamp\":\"1625800233446\"}}"
+                + "}}";
+            MetadataInfo metadataInfo = JsonUtils.toJavaObject(metadata_111, 
MetadataInfo.class);
+            ApplicationModel applicationModel = 
ApplicationModel.defaultModel();
+            applicationModel.getApplicationConfigManager().setApplication(new 
ApplicationConfig("app2"));
+            zookeeperConnectionAddress1 = 
"multiple://127.0.0.1:2181?reference-registry=127.0.0.1:2181?enableEmptyProtection=false&child.a1=zookeeper://127.0.0.1:2181";
+            List<Object> urlsSameRevision = new ArrayList<>();
+            urlsSameRevision.add("127.0.0.1:20880?revision=111");
+            urlsSameRevision.add("127.0.0.2:20880?revision=111");
+            urlsSameRevision.add("127.0.0.3:20880?revision=111");
+            URL url = URL.valueOf(zookeeperConnectionAddress1);
+            url.setScopeModel(applicationModel);
+            MultipleServiceDiscovery multipleServiceDiscovery = new 
MultipleServiceDiscovery(url);
+            Class<MultipleServiceDiscovery> multipleServiceDiscoveryClass = 
MultipleServiceDiscovery.class;
+            Field serviceDiscoveries = 
multipleServiceDiscoveryClass.getDeclaredField("serviceDiscoveries");
+            serviceDiscoveries.setAccessible(true);
+            ServiceDiscovery serviceDiscoveryMock = 
Mockito.mock(ServiceDiscovery.class);
+            
Mockito.when(serviceDiscoveryMock.getRemoteMetadata(Mockito.anyString(), 
Mockito.anyList())).thenReturn(metadataInfo);
+            serviceDiscoveries.set(multipleServiceDiscovery, 
Collections.singletonMap("child.a1", serviceDiscoveryMock));
+            MultipleServiceDiscovery.MultiServiceInstancesChangedListener 
listener = (MultipleServiceDiscovery.MultiServiceInstancesChangedListener) 
multipleServiceDiscovery.createListener(Sets.newHashSet("app1"));
+            
multipleServiceDiscovery.addServiceInstancesChangedListener(listener);
+            MultipleServiceDiscovery.SingleServiceInstancesChangedListener 
singleServiceInstancesChangedListener = 
listener.getAndComputeIfAbsent("child.a1", (a1) -> null);
+            Assert.notNull(singleServiceInstancesChangedListener, "监听器不能为空");

Review Comment:
   Translate into english pls



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org
For additional commands, e-mail: notifications-h...@dubbo.apache.org

Reply via email to