You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/10/27 09:08:36 UTC
[dubbo] branch 3.0 updated: [3.0] code review
ServiceCheckUtils.isRegistered should be check all registries (#9133)
This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.0 by this push:
new e05cd6b [3.0] code review ServiceCheckUtils.isRegistered should be check all registries (#9133)
e05cd6b is described below
commit e05cd6bee3ae0185061e021d108bca6ba4f03f2b
Author: Wang Chengming <63...@qq.com>
AuthorDate: Wed Oct 27 17:08:26 2021 +0800
[3.0] code review ServiceCheckUtils.isRegistered should be check all registries (#9133)
* on branch 3.0, ServiceCheckUtils.isRegistered should be check all registries
* on branch 3.0, ServiceCheckUtils.isRegistered should be check all registries
* add ServiceCheckUtils test
---
.../dubbo/qos/command/util/ServiceCheckUtils.java | 9 ++--
.../java/org/apache/dubbo/qos/DemoService.java | 22 ++++++++
.../java/org/apache/dubbo/qos/DemoServiceImpl.java | 25 +++++++++
.../qos/command/util/ServiceCheckUtilsTest.java | 63 ++++++++++++++++++++++
4 files changed, 113 insertions(+), 6 deletions(-)
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/util/ServiceCheckUtils.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/util/ServiceCheckUtils.java
index a466e85..68ef1b7 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/util/ServiceCheckUtils.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/util/ServiceCheckUtils.java
@@ -31,12 +31,9 @@ import java.util.Map;
public class ServiceCheckUtils {
public static boolean isRegistered(ProviderModel providerModel) {
- // TODO, only check the status of one registry and no protocol now.
- RegistryManager registryManager = providerModel.getModuleModel().getApplicationModel().getBeanFactory().getBean(RegistryManager.class);
- Collection<Registry> registries = registryManager.getRegistries();
- if (CollectionUtils.isNotEmpty(registries)) {
- AbstractRegistry abstractRegistry = (AbstractRegistry) registries.iterator().next();
- if (abstractRegistry.getRegistered().stream().anyMatch(url -> url.getServiceKey().equals(providerModel.getServiceKey()))) {
+ // check all registries status
+ for (ProviderModel.RegisterStatedURL registerStatedURL : providerModel.getStatedUrl()) {
+ if (registerStatedURL.isRegistered()) {
return true;
}
}
diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/DemoService.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/DemoService.java
new file mode 100644
index 0000000..f133f7a
--- /dev/null
+++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/DemoService.java
@@ -0,0 +1,22 @@
+/*
+ * 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.qos;
+
+public interface DemoService {
+
+ String echo(String str);
+}
diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/DemoServiceImpl.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/DemoServiceImpl.java
new file mode 100644
index 0000000..02585e1
--- /dev/null
+++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/DemoServiceImpl.java
@@ -0,0 +1,25 @@
+/*
+ * 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.qos;
+
+public class DemoServiceImpl implements DemoService {
+
+ @Override
+ public String echo(String str) {
+ return "hello world";
+ }
+}
diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/util/ServiceCheckUtilsTest.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/util/ServiceCheckUtilsTest.java
new file mode 100644
index 0000000..54e0e75
--- /dev/null
+++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/util/ServiceCheckUtilsTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.qos.command.util;
+
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.utils.NetUtils;
+import org.apache.dubbo.qos.DemoService;
+import org.apache.dubbo.qos.DemoServiceImpl;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+import org.apache.dubbo.rpc.model.ModuleServiceRepository;
+import org.apache.dubbo.rpc.model.ProviderModel;
+import org.apache.dubbo.rpc.model.ServiceDescriptor;
+import org.apache.dubbo.rpc.model.ServiceMetadata;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+/**
+ * Test for ServiceCheckUtils
+ */
+public class ServiceCheckUtilsTest {
+
+ private final ModuleServiceRepository repository = ApplicationModel.defaultModel().getDefaultModule().getServiceRepository();
+
+ @Test
+ public void testIsRegistered() {
+ DemoService demoServiceImpl = new DemoServiceImpl();
+
+ int availablePort = NetUtils.getAvailablePort();
+
+ URL url = URL.valueOf("tri://127.0.0.1:" + availablePort + "/" + DemoService.class.getName());
+
+ ServiceDescriptor serviceDescriptor = repository.registerService(DemoService.class);
+
+ ProviderModel providerModel = new ProviderModel(
+ url.getServiceKey(),
+ demoServiceImpl,
+ serviceDescriptor,
+ null,
+ new ServiceMetadata());
+ repository.registerProvider(providerModel);
+
+ boolean registered = ServiceCheckUtils.isRegistered(providerModel);
+ assertFalse(registered);
+ }
+
+}