From bcf8167aa305aca36ed3ed08801c8a6d5ce5dcc3 Mon Sep 17 00:00:00 2001 From: crazyhzm Date: Thu, 26 Aug 2021 11:22:41 +0800 Subject: [PATCH 1/2] change test spi scope --- ...rviceDiscoveryRegistryIntegrationTest.java | 12 ++++++--- ...coveryRegistryRegistryServiceListener.java | 26 +++++++++---------- ...ryCenterExportProviderIntegrationTest.java | 8 +++++- ...xportProviderRegistryProtocolListener.java | 2 +- ...g.apache.dubbo.common.status.StatusChecker | 19 +------------- ....apache.dubbo.common.threadpool.ThreadPool | 19 +------------- ...che.dubbo.registry.RegistryServiceListener | 17 ------------ ...istry.integration.RegistryProtocolListener | 17 ------------ .../org.apache.dubbo.remoting.Dispatcher | 19 +------------- .../org.apache.dubbo.remoting.Transporter | 19 +------------- ...g.apache.dubbo.remoting.exchange.Exchanger | 19 +------------- ...apache.dubbo.remoting.telnet.TelnetHandler | 16 ------------ .../org.apache.dubbo.rpc.ExporterListener | 17 ------------ 13 files changed, 35 insertions(+), 175 deletions(-) diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryIntegrationTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryIntegrationTest.java index cb078d14a6c..af9e6117c8b 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryIntegrationTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryIntegrationTest.java @@ -37,7 +37,9 @@ import org.slf4j.LoggerFactory; import java.io.IOException; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Set; /** @@ -104,12 +106,16 @@ public void setUp() throws Exception { serviceConfig.setRef(new MultipleRegistryCenterServiceDiscoveryRegistryServiceImpl()); serviceConfig.setAsync(false); - // initailize bootstrap + // initialize bootstrap for (RegistryCenter.Instance instance : registryCenter.getRegistryCenterInstance()) { - DubboBootstrap.getInstance().registry(new RegistryConfig(String.format("%s://%s:%s", + RegistryConfig registryConfig = new RegistryConfig(String.format("%s://%s:%s", instance.getType(), instance.getHostname(), - instance.getPort()))); + instance.getPort())); + Map parameters = new HashMap<>(); + parameters.put("registry.listeners", "multipleConfigCenterServiceDiscoveryRegistry"); + registryConfig.updateParameters(parameters); + DubboBootstrap.getInstance().registry(registryConfig); ports.add(instance.getPort()); } DubboBootstrap.getInstance() diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryRegistryServiceListener.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryRegistryServiceListener.java index a1dd4d7f55b..c138e47a768 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryRegistryServiceListener.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryRegistryServiceListener.java @@ -25,7 +25,7 @@ import org.apache.dubbo.registry.client.ServiceDiscoveryRegistry; import org.apache.dubbo.registry.client.metadata.store.InMemoryWritableMetadataService; -@Activate +@Activate(value = "multipleConfigCenterServiceDiscoveryRegistry") public class MultipleRegistryCenterServiceDiscoveryRegistryRegistryServiceListener implements RegistryServiceListener { private ServiceDiscoveryRegistryStorage storage = new ServiceDiscoveryRegistryStorage(); @@ -33,7 +33,7 @@ public class MultipleRegistryCenterServiceDiscoveryRegistryRegistryServiceListen /** * Create an {@link ServiceDiscoveryRegistryInfoWrapper} instance. */ - private ServiceDiscoveryRegistryInfoWrapper createServiceDiscoveryRegistryInfoWrapper(ServiceDiscoveryRegistry serviceDiscoveryRegistry){ + private ServiceDiscoveryRegistryInfoWrapper createServiceDiscoveryRegistryInfoWrapper(ServiceDiscoveryRegistry serviceDiscoveryRegistry) { String host = serviceDiscoveryRegistry.getUrl().getHost(); int port = serviceDiscoveryRegistry.getUrl().getPort(); ServiceDiscoveryRegistryInfoWrapper serviceDiscoveryRegistryInfoWrapper = new ServiceDiscoveryRegistryInfoWrapper(); @@ -48,7 +48,7 @@ private ServiceDiscoveryRegistryInfoWrapper createServiceDiscoveryRegistryInfoWr /** * Checks if the registry is checked application */ - private boolean isCheckedApplication(Registry registry){ + private boolean isCheckedApplication(Registry registry) { return registry.getUrl().getParameter(CommonConstants.APPLICATION_KEY) .equals(MultipleRegistryCenterServiceDiscoveryRegistryIntegrationTest .PROVIDER_APPLICATION_NAME); @@ -56,13 +56,13 @@ private boolean isCheckedApplication(Registry registry){ public void onRegister(URL url, Registry registry) { if (registry instanceof ServiceDiscoveryRegistry && isCheckedApplication(registry)) { - ServiceDiscoveryRegistry serviceDiscoveryRegistry = (ServiceDiscoveryRegistry)registry; + ServiceDiscoveryRegistry serviceDiscoveryRegistry = (ServiceDiscoveryRegistry) registry; String host = serviceDiscoveryRegistry.getUrl().getHost(); int port = serviceDiscoveryRegistry.getUrl().getPort(); - if (!storage.contains(host,port)){ - storage.put(host,port,createServiceDiscoveryRegistryInfoWrapper(serviceDiscoveryRegistry)); + if (!storage.contains(host, port)) { + storage.put(host, port, createServiceDiscoveryRegistryInfoWrapper(serviceDiscoveryRegistry)); } - storage.get(host,port).setRegistered(true); + storage.get(host, port).setRegistered(true); } } @@ -70,19 +70,19 @@ public void onUnregister(URL url, Registry registry) { if (registry instanceof ServiceDiscoveryRegistry && isCheckedApplication(registry)) { String host = registry.getUrl().getHost(); int port = registry.getUrl().getPort(); - storage.get(host,port).setRegistered(false); + storage.get(host, port).setRegistered(false); } } public void onSubscribe(URL url, Registry registry) { if (registry instanceof ServiceDiscoveryRegistry && isCheckedApplication(registry)) { - ServiceDiscoveryRegistry serviceDiscoveryRegistry = (ServiceDiscoveryRegistry)registry; + ServiceDiscoveryRegistry serviceDiscoveryRegistry = (ServiceDiscoveryRegistry) registry; String host = serviceDiscoveryRegistry.getUrl().getHost(); int port = serviceDiscoveryRegistry.getUrl().getPort(); - if (!storage.contains(host,port)){ - storage.put(host,port,createServiceDiscoveryRegistryInfoWrapper(serviceDiscoveryRegistry)); + if (!storage.contains(host, port)) { + storage.put(host, port, createServiceDiscoveryRegistryInfoWrapper(serviceDiscoveryRegistry)); } - storage.get(host,port).setSubscribed(true); + storage.get(host, port).setSubscribed(true); } } @@ -90,7 +90,7 @@ public void onUnsubscribe(URL url, Registry registry) { if (registry instanceof ServiceDiscoveryRegistry && isCheckedApplication(registry)) { String host = registry.getUrl().getHost(); int port = registry.getUrl().getPort(); - storage.get(host,port).setSubscribed(false); + storage.get(host, port).setSubscribed(false); } } diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderIntegrationTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderIntegrationTest.java index 1afdb06f926..eb0d4ebd821 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderIntegrationTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderIntegrationTest.java @@ -39,6 +39,8 @@ import org.slf4j.LoggerFactory; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; import static org.apache.dubbo.rpc.Constants.SCOPE_LOCAL; @@ -110,16 +112,20 @@ public void setUp() throws Exception { serviceConfig.setRef(new SingleRegistryCenterExportProviderServiceImpl()); serviceConfig.setAsync(false); - // initailize bootstrap + // initialize bootstrap DubboBootstrap.getInstance() .application(new ApplicationConfig(PROVIDER_APPLICATION_NAME)) .protocol(new ProtocolConfig(PROTOCOL_NAME, PROTOCOL_PORT)) .service(serviceConfig); RegistryCenter.Instance instance = registryCenter.getRegistryCenterInstance().get(0); + RegistryConfig registryConfig = new RegistryConfig(String.format("%s://%s:%s", instance.getType(), instance.getHostname(), instance.getPort())); + Map parameters = new HashMap<>(); + parameters.put("registry.protocol.listener", "singleConfigCenterExportProvider"); + registryConfig.updateParameters(parameters); DubboBootstrap.getInstance().registry(registryConfig); } diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderRegistryProtocolListener.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderRegistryProtocolListener.java index bf8f3a35844..f69b702a686 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderRegistryProtocolListener.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderRegistryProtocolListener.java @@ -27,7 +27,7 @@ /** * The {@link RegistryProtocolListener} for {@link SingleRegistryCenterExportProviderService} */ -@Activate(order = 100) +@Activate(order = 100, value = "singleConfigCenterExportProvider") public class SingleRegistryCenterExportProviderRegistryProtocolListener implements RegistryProtocolListener { private boolean exported = false; diff --git a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.common.status.StatusChecker b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.common.status.StatusChecker index d7d3b446008..21022b30243 100644 --- a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.common.status.StatusChecker +++ b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.common.status.StatusChecker @@ -1,18 +1 @@ -# -# 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. -# - -mockstatuschecker=org.apache.dubbo.config.mock.MockStatusChecker \ No newline at end of file +mockstatuschecker=org.apache.dubbo.config.mock.MockStatusChecker diff --git a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.common.threadpool.ThreadPool b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.common.threadpool.ThreadPool index f4f5d34d323..ffbae903569 100644 --- a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.common.threadpool.ThreadPool +++ b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.common.threadpool.ThreadPool @@ -1,18 +1 @@ -# -# 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. -# - -mockthreadpool=org.apache.dubbo.config.mock.MockThreadPool \ No newline at end of file +mockthreadpool=org.apache.dubbo.config.mock.MockThreadPool diff --git a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.registry.RegistryServiceListener b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.registry.RegistryServiceListener index 4caa712154e..530f279c556 100644 --- a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.registry.RegistryServiceListener +++ b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.registry.RegistryServiceListener @@ -1,18 +1 @@ -# -# 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. -# - multipleConfigCenterServiceDiscoveryRegistry=org.apache.dubbo.integration.multiple.servicediscoveryregistry.MultipleRegistryCenterServiceDiscoveryRegistryRegistryServiceListener diff --git a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.registry.integration.RegistryProtocolListener b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.registry.integration.RegistryProtocolListener index 244d907d7ad..0b1907467c8 100644 --- a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.registry.integration.RegistryProtocolListener +++ b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.registry.integration.RegistryProtocolListener @@ -1,18 +1 @@ -# -# 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. -# - singleConfigCenterExportProvider=org.apache.dubbo.integration.single.exportprovider.SingleRegistryCenterExportProviderRegistryProtocolListener diff --git a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.remoting.Dispatcher b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.remoting.Dispatcher index febb4f8e2af..6bfd10364b5 100644 --- a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.remoting.Dispatcher +++ b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.remoting.Dispatcher @@ -1,18 +1 @@ -# -# 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. -# - -mockdispatcher=org.apache.dubbo.config.mock.MockDispatcher \ No newline at end of file +mockdispatcher=org.apache.dubbo.config.mock.MockDispatcher diff --git a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.remoting.Transporter b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.remoting.Transporter index ef9ec51063f..6478b7c3203 100644 --- a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.remoting.Transporter +++ b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.remoting.Transporter @@ -1,18 +1 @@ -# -# 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. -# - -mocktransporter=org.apache.dubbo.config.mock.MockTransporter \ No newline at end of file +mocktransporter=org.apache.dubbo.config.mock.MockTransporter diff --git a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.remoting.exchange.Exchanger b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.remoting.exchange.Exchanger index f8d3c3b9e5c..176d5497b40 100644 --- a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.remoting.exchange.Exchanger +++ b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.remoting.exchange.Exchanger @@ -1,18 +1 @@ -# -# 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. -# - -mockexchanger=org.apache.dubbo.config.mock.MockExchanger \ No newline at end of file +mockexchanger=org.apache.dubbo.config.mock.MockExchanger diff --git a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.remoting.telnet.TelnetHandler b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.remoting.telnet.TelnetHandler index 76dfd94078b..9d9b8968edb 100644 --- a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.remoting.telnet.TelnetHandler +++ b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.remoting.telnet.TelnetHandler @@ -1,18 +1,2 @@ -# -# 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. -# mocktelnethandler=org.apache.dubbo.config.mock.MockTelnetHandler diff --git a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.rpc.ExporterListener b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.rpc.ExporterListener index b9231ee8983..db2b0aa14cf 100644 --- a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.rpc.ExporterListener +++ b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.rpc.ExporterListener @@ -1,20 +1,3 @@ -# -# 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. -# - mockexporterlistener=org.apache.dubbo.config.mock.MockExporterListener singleConfigCenterInjvm=org.apache.dubbo.integration.single.injvm.SingleRegistryCenterInjvmExporterListener multipleConfigCenterInjvm=org.apache.dubbo.integration.multiple.injvm.MultipleRegistryCenterInjvmExporterListener From db31574184233fe84b3ca2c8ae4ea9180320da50 Mon Sep 17 00:00:00 2001 From: crazyhzm Date: Fri, 27 Aug 2021 15:49:04 +0800 Subject: [PATCH 2/2] change test spi scope --- .../apache/dubbo/integration/Constants.java | 24 +++++++++++++++++++ ...rviceDiscoveryRegistryIntegrationTest.java | 11 ++++----- ...coveryRegistryRegistryServiceListener.java | 5 +++- ...ryCenterExportProviderIntegrationTest.java | 14 ++++------- ...xportProviderRegistryProtocolListener.java | 4 +++- 5 files changed, 40 insertions(+), 18 deletions(-) create mode 100644 dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/Constants.java diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/Constants.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/Constants.java new file mode 100644 index 00000000000..6680d31c468 --- /dev/null +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/Constants.java @@ -0,0 +1,24 @@ +/* + * 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.integration; + +public interface Constants { + + String MULTIPLE_CONFIG_CENTER_SERVICE_DISCOVERY_REGISTRY = "multipleConfigCenterServiceDiscoveryRegistry"; + + String SINGLE_CONFIG_CENTER_EXPORT_PROVIDER = "singleConfigCenterExportProvider"; +} diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryIntegrationTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryIntegrationTest.java index af9e6117c8b..acb4aa0d407 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryIntegrationTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryIntegrationTest.java @@ -42,6 +42,8 @@ import java.util.Map; import java.util.Set; +import static org.apache.dubbo.integration.Constants.MULTIPLE_CONFIG_CENTER_SERVICE_DISCOVERY_REGISTRY; + /** * The testcases are only for checking the process of exporting provider using service-discovery-registry protocol. */ @@ -54,11 +56,6 @@ public class MultipleRegistryCenterServiceDiscoveryRegistryIntegrationTest imple */ public static String PROVIDER_APPLICATION_NAME = "multiple-registry-center-provider-for-service-discovery-registry-protocol"; - /** - * The name for getting the specified instance, which is loaded using SPI. - */ - private static String SPI_NAME = "multipleConfigCenterServiceDiscoveryRegistry"; - /** * Define the protocol's name. */ @@ -113,7 +110,7 @@ public void setUp() throws Exception { instance.getHostname(), instance.getPort())); Map parameters = new HashMap<>(); - parameters.put("registry.listeners", "multipleConfigCenterServiceDiscoveryRegistry"); + parameters.put("registry.listeners", MULTIPLE_CONFIG_CENTER_SERVICE_DISCOVERY_REGISTRY); registryConfig.updateParameters(parameters); DubboBootstrap.getInstance().registry(registryConfig); ports.add(instance.getPort()); @@ -124,7 +121,7 @@ public void setUp() throws Exception { .service(serviceConfig); // ---------------initialize--------------- // registryServiceListener = (MultipleRegistryCenterServiceDiscoveryRegistryRegistryServiceListener) ExtensionLoader - .getExtensionLoader(RegistryServiceListener.class).getExtension(SPI_NAME); + .getExtensionLoader(RegistryServiceListener.class).getExtension(MULTIPLE_CONFIG_CENTER_SERVICE_DISCOVERY_REGISTRY); // RegistryServiceListener is not null Assertions.assertNotNull(registryServiceListener); registryServiceListener.getStorage().clear(); diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryRegistryServiceListener.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryRegistryServiceListener.java index c138e47a768..127adcf58b6 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryRegistryServiceListener.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryRegistryServiceListener.java @@ -25,7 +25,10 @@ import org.apache.dubbo.registry.client.ServiceDiscoveryRegistry; import org.apache.dubbo.registry.client.metadata.store.InMemoryWritableMetadataService; -@Activate(value = "multipleConfigCenterServiceDiscoveryRegistry") +import static org.apache.dubbo.integration.Constants.MULTIPLE_CONFIG_CENTER_SERVICE_DISCOVERY_REGISTRY; + + +@Activate(value = MULTIPLE_CONFIG_CENTER_SERVICE_DISCOVERY_REGISTRY) public class MultipleRegistryCenterServiceDiscoveryRegistryRegistryServiceListener implements RegistryServiceListener { private ServiceDiscoveryRegistryStorage storage = new ServiceDiscoveryRegistryStorage(); diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderIntegrationTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderIntegrationTest.java index eb0d4ebd821..e0c2e040389 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderIntegrationTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderIntegrationTest.java @@ -42,6 +42,7 @@ import java.util.HashMap; import java.util.Map; +import static org.apache.dubbo.integration.Constants.SINGLE_CONFIG_CENTER_EXPORT_PROVIDER; import static org.apache.dubbo.rpc.Constants.SCOPE_LOCAL; /** @@ -56,11 +57,6 @@ public class SingleRegistryCenterExportProviderIntegrationTest implements Integr */ private static String PROVIDER_APPLICATION_NAME = "single-registry-center-for-export-provider"; - /** - * The name for getting the specified instance, which is loaded using SPI. - */ - private static String SPI_NAME = "singleConfigCenterExportProvider"; - /** * Define the protocol's name. */ @@ -141,16 +137,16 @@ public void setUp() throws Exception { private void beforeExport() { registryProtocolListener = (SingleRegistryCenterExportProviderRegistryProtocolListener) ExtensionLoader .getExtensionLoader(RegistryProtocolListener.class) - .getExtension(SPI_NAME); + .getExtension(SINGLE_CONFIG_CENTER_EXPORT_PROVIDER); exporterListener = (SingleRegistryCenterExportProviderExporterListener) ExtensionLoader .getExtensionLoader(ExporterListener.class) - .getExtension(SPI_NAME); + .getExtension(SINGLE_CONFIG_CENTER_EXPORT_PROVIDER); filter = (SingleRegistryCenterExportProviderFilter) ExtensionLoader .getExtensionLoader(Filter.class) - .getExtension(SPI_NAME); + .getExtension(SINGLE_CONFIG_CENTER_EXPORT_PROVIDER); serviceListener = (SingleRegistryCenterExportProviderServiceListener) ExtensionLoader .getExtensionLoader(ServiceListener.class) - .getExtension(SPI_NAME); + .getExtension(SINGLE_CONFIG_CENTER_EXPORT_PROVIDER); // ---------------checkpoints--------------- // // ServiceConfig isn't exported Assertions.assertFalse(serviceConfig.isExported()); diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderRegistryProtocolListener.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderRegistryProtocolListener.java index f69b702a686..09b973da1ce 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderRegistryProtocolListener.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderRegistryProtocolListener.java @@ -24,10 +24,12 @@ import org.apache.dubbo.rpc.Exporter; import org.apache.dubbo.rpc.cluster.ClusterInvoker; +import static org.apache.dubbo.integration.Constants.SINGLE_CONFIG_CENTER_EXPORT_PROVIDER; + /** * The {@link RegistryProtocolListener} for {@link SingleRegistryCenterExportProviderService} */ -@Activate(order = 100, value = "singleConfigCenterExportProvider") +@Activate(order = 100, value = SINGLE_CONFIG_CENTER_EXPORT_PROVIDER) public class SingleRegistryCenterExportProviderRegistryProtocolListener implements RegistryProtocolListener { private boolean exported = false;