This is an automated email from the ASF dual-hosted git repository.
liujun 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 6689f4e Add testcase for checking exported metadata service in single
registry center (#8583)
6689f4e is described below
commit 6689f4e85eaafe6f2873b07923d8f6fcf20ba7a4
Author: Xiong, Pin <[email protected]>
AuthorDate: Wed Aug 25 02:18:42 2021 -0500
Add testcase for checking exported metadata service in single registry
center (#8583)
---
...gistryCenterExportMetadataExporterListener.java | 34 ++++
...egistryCenterExportMetadataIntegrationTest.java | 205 +++++++++++++++++++++
.../SingleRegistryCenterExportMetadataService.java | 28 +++
...gleRegistryCenterExportMetadataServiceImpl.java | 31 ++++
...egistryCenterExportMetadataServiceListener.java | 35 ++++
.../org.apache.dubbo.config.ServiceListener | 1 +
.../services/org.apache.dubbo.rpc.ExporterListener | 1 +
.../config/spring/schema/GenericServiceTest.java | 7 +-
8 files changed, 340 insertions(+), 2 deletions(-)
diff --git
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportmetadata/SingleRegistryCenterExportMetadataExporterListener.java
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportmetadata/SingleRegistryCenterExportMetadataExporterListener.java
new file mode 100644
index 0000000..151f572
--- /dev/null
+++
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportmetadata/SingleRegistryCenterExportMetadataExporterListener.java
@@ -0,0 +1,34 @@
+/*
+ * 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.single.exportmetadata;
+
+import org.apache.dubbo.common.constants.CommonConstants;
+import org.apache.dubbo.common.extension.Activate;
+import org.apache.dubbo.integration.AbstractRegistryCenterExporterListener;
+import org.apache.dubbo.metadata.MetadataService;
+
+@Activate(group = CommonConstants.PROVIDER, order = 1000)
+public class SingleRegistryCenterExportMetadataExporterListener extends
AbstractRegistryCenterExporterListener {
+
+ /**
+ * Returns the interface of exported service.
+ */
+ @Override
+ protected Class<?> getInterface() {
+ return MetadataService.class;
+ }
+}
diff --git
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportmetadata/SingleRegistryCenterExportMetadataIntegrationTest.java
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportmetadata/SingleRegistryCenterExportMetadataIntegrationTest.java
new file mode 100644
index 0000000..0306a5d
--- /dev/null
+++
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportmetadata/SingleRegistryCenterExportMetadataIntegrationTest.java
@@ -0,0 +1,205 @@
+/*
+ * 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.single.exportmetadata;
+
+import org.apache.dubbo.common.extension.ExtensionLoader;
+import org.apache.dubbo.common.utils.NetUtils;
+import org.apache.dubbo.config.RegistryConfig;
+import org.apache.dubbo.config.ServiceConfig;
+import org.apache.dubbo.config.ApplicationConfig;
+import org.apache.dubbo.config.ProtocolConfig;
+import org.apache.dubbo.config.ServiceListener;
+import org.apache.dubbo.config.bootstrap.DubboBootstrap;
+import org.apache.dubbo.integration.IntegrationTest;
+import org.apache.dubbo.metadata.MetadataService;
+import org.apache.dubbo.registrycenter.RegistryCenter;
+import org.apache.dubbo.registrycenter.ZookeeperSingleRegistryCenter;
+import org.apache.dubbo.rpc.Exporter;
+import org.apache.dubbo.rpc.ExporterListener;
+import org.apache.dubbo.rpc.Filter;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+
+import static org.apache.dubbo.rpc.Constants.SCOPE_LOCAL;
+
+/**
+ * The testcases are only for checking the process of exporting metadata
service.
+ */
+public class SingleRegistryCenterExportMetadataIntegrationTest implements
IntegrationTest {
+
+ private static final Logger logger =
LoggerFactory.getLogger(SingleRegistryCenterExportMetadataIntegrationTest.class);
+
+ /**
+ * Define the provider application name.
+ */
+ private static String PROVIDER_APPLICATION_NAME =
"single-registry-center-export-metadata";
+
+ /**
+ * The name for getting the specified instance, which is loaded using SPI.
+ */
+ private static String SPI_NAME = "singleConfigCenterExportMetadata";
+
+ /**
+ * Define the protocol's name.
+ */
+ private static String PROTOCOL_NAME = "injvm";
+ /**
+ * Define the {@link ServiceConfig} instance.
+ */
+ private ServiceConfig<SingleRegistryCenterExportMetadataService>
serviceConfig;
+
+ /**
+ * The listener to record exported services
+ */
+ private SingleRegistryCenterExportMetadataServiceListener serviceListener;
+
+ /**
+ * The listener to record exported exporters.
+ */
+ private SingleRegistryCenterExportMetadataExporterListener
exporterListener;
+
+ /**
+ * Define a registry center.
+ */
+ private RegistryCenter registryCenter;
+
+ @BeforeEach
+ public void setUp() throws Exception {
+ logger.info(getClass().getSimpleName() + " testcase is beginning...");
+ DubboBootstrap.reset();
+ registryCenter = new
ZookeeperSingleRegistryCenter(NetUtils.getAvailablePort());
+ registryCenter.startup();
+ // initialize service config
+ serviceConfig = new ServiceConfig<>();
+
serviceConfig.setInterface(SingleRegistryCenterExportMetadataService.class);
+ serviceConfig.setRef(new
SingleRegistryCenterExportMetadataServiceImpl());
+ serviceConfig.setAsync(false);
+ serviceConfig.setScope(SCOPE_LOCAL);
+
+ // initailize bootstrap
+ DubboBootstrap.getInstance()
+ .application(new ApplicationConfig(PROVIDER_APPLICATION_NAME))
+ .protocol(new ProtocolConfig(PROTOCOL_NAME))
+ .service(serviceConfig);
+ RegistryCenter.Instance instance =
registryCenter.getRegistryCenterInstance().get(0);
+ RegistryConfig registryConfig = new
RegistryConfig(String.format("%s://%s:%s",
+ instance.getType(),
+ instance.getHostname(),
+ instance.getPort()));
+ DubboBootstrap.getInstance().registry(registryConfig);
+ }
+
+ /**
+ * Define {@link ServiceListener}, {@link ExporterListener} and {@link
Filter} for helping check.
+ * <p>Use SPI to load them before exporting.
+ * <p>After that, there are some checkpoints need to verify as follow:
+ * <ul>
+ * <li>There is nothing in ServiceListener or not</li>
+ * <li>There is nothing in ExporterListener or not</li>
+ * <li>ServiceConfig is exported or not</li>
+ * </ul>
+ */
+ private void beforeExport() {
+ // ---------------initialize--------------- //
+ serviceListener = (SingleRegistryCenterExportMetadataServiceListener)
ExtensionLoader.getExtensionLoader(ServiceListener.class).getExtension(SPI_NAME);
+ exporterListener =
(SingleRegistryCenterExportMetadataExporterListener)
ExtensionLoader.getExtensionLoader(ExporterListener.class).getExtension(SPI_NAME);
+
+ // ---------------checkpoints--------------- //
+ // There is nothing in ServiceListener
+ Assertions.assertTrue(serviceListener.getExportedServices().isEmpty());
+ // There is nothing in ExporterListener
+
Assertions.assertTrue(exporterListener.getExportedExporters().isEmpty());
+ // ServiceConfig isn't exported
+ Assertions.assertFalse(serviceConfig.isExported());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Test
+ @Override
+ public void integrate() {
+ beforeExport();
+ DubboBootstrap.getInstance().start();
+ afterExport();
+ }
+
+ /**
+ * There are some checkpoints need to check after exported as follow:
+ * <ul>
+ * <li>The metadata service is only one or not</li>
+ * <li>The exported service is MetadataService or not</li>
+ * <li>The MetadataService is exported or not</li>
+ * <li>The exported exporters are right or not</li>
+ * </ul>
+ */
+ private void afterExport() {
+ // The metadata service is only one
+ Assertions.assertEquals(serviceListener.getExportedServices().size(),
1);
+ // The exported service is MetadataService
+
Assertions.assertEquals(serviceListener.getExportedServices().get(0).getInterfaceClass(),
+ MetadataService.class);
+ // The MetadataService is exported
+
Assertions.assertTrue(serviceListener.getExportedServices().get(0).isExported());
+ // There are two exported exporters
+ // 1. Metadata Service exporter with dubbo protocol
+ // 2. SingleRegistryCenterExportMetadataService exporter with Injvm
protocol
+
Assertions.assertEquals(exporterListener.getExportedExporters().size(), 2);
+ // Obtain SingleRegistryCenterExportMetadataService exporter with
Injvm protocol
+ Exporter<?> injvmExporter = (Exporter<?>)
exporterListener.getExportedExporters()
+ .stream()
+ .filter(
+ exporter ->
PROTOCOL_NAME.equalsIgnoreCase(exporter.getInvoker().getUrl().getProtocol())
+ )
+ .findFirst()
+ .get();
+ // Obtain Metadata Service exporter with dubbo protocol
+ Exporter<?> metadataExporter = (Exporter<?>)
exporterListener.getExportedExporters()
+ .stream()
+ .filter(
+ exporter ->
!PROTOCOL_NAME.equalsIgnoreCase(exporter.getInvoker().getUrl().getProtocol())
+ )
+ .filter(
+ exporter ->
exporter.getInvoker().getInterface().equals(MetadataService.class)
+ )
+ .findFirst()
+ .get();
+ // Make sure injvmExporter is not null
+ Assertions.assertNotNull(injvmExporter);
+ // Make sure metadataExporter is not null
+ Assertions.assertNotNull(metadataExporter);
+ }
+
+ @AfterEach
+ public void tearDown() throws IOException {
+ DubboBootstrap.reset();
+ PROVIDER_APPLICATION_NAME = null;
+ serviceConfig = null;
+ // The exported service has been unexported
+ Assertions.assertTrue(serviceListener.getExportedServices().isEmpty());
+ serviceListener = null;
+ logger.info(getClass().getSimpleName() + " testcase is ending...");
+ registryCenter.shutdown();
+ registryCenter = null;
+ }
+}
diff --git
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportmetadata/SingleRegistryCenterExportMetadataService.java
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportmetadata/SingleRegistryCenterExportMetadataService.java
new file mode 100644
index 0000000..22f2ab0
--- /dev/null
+++
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportmetadata/SingleRegistryCenterExportMetadataService.java
@@ -0,0 +1,28 @@
+/*
+ * 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.single.exportmetadata;
+
+/**
+ * This interface is used to check if the exported metadata service works well
or not.
+ */
+public interface SingleRegistryCenterExportMetadataService {
+
+ /**
+ * The simple method for testing.
+ */
+ String hello(String name);
+}
diff --git
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportmetadata/SingleRegistryCenterExportMetadataServiceImpl.java
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportmetadata/SingleRegistryCenterExportMetadataServiceImpl.java
new file mode 100644
index 0000000..338a09c
--- /dev/null
+++
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportmetadata/SingleRegistryCenterExportMetadataServiceImpl.java
@@ -0,0 +1,31 @@
+/*
+ * 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.single.exportmetadata;
+
+/**
+ * The simple implementation for {@link
SingleRegistryCenterExportMetadataService}
+ */
+public class SingleRegistryCenterExportMetadataServiceImpl implements
SingleRegistryCenterExportMetadataService {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String hello(String name) {
+ return "Hello " + name;
+ }
+}
diff --git
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportmetadata/SingleRegistryCenterExportMetadataServiceListener.java
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportmetadata/SingleRegistryCenterExportMetadataServiceListener.java
new file mode 100644
index 0000000..6008b4d
--- /dev/null
+++
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportmetadata/SingleRegistryCenterExportMetadataServiceListener.java
@@ -0,0 +1,35 @@
+/*
+ * 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.single.exportmetadata;
+
+import org.apache.dubbo.config.ServiceListener;
+import org.apache.dubbo.integration.AbstractRegistryCenterServiceListener;
+import org.apache.dubbo.metadata.MetadataService;
+
+/**
+ * This implementation of {@link ServiceListener} is to record exported
metadata services in single registry center.
+ */
+public class SingleRegistryCenterExportMetadataServiceListener extends
AbstractRegistryCenterServiceListener {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Class<?> getInterface() {
+ return MetadataService.class;
+ }
+}
diff --git
a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.config.ServiceListener
b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.config.ServiceListener
index fadb1c2..eb41d2a 100644
---
a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.config.ServiceListener
+++
b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.config.ServiceListener
@@ -3,3 +3,4 @@
exported=org.apache.dubbo.integration.single.SingleRegistryCenterExportedService
singleConfigCenterInjvm=org.apache.dubbo.integration.single.injvm.SingleRegistryCenterInjvmServiceListener
multipleConfigCenterInjvm=org.apache.dubbo.integration.multiple.injvm.MultipleRegistryCenterInjvmServiceListener
singleConfigCenterExportProvider=org.apache.dubbo.integration.single.exportprovider.SingleRegistryCenterExportProviderServiceListener
+singleConfigCenterExportMetadata=org.apache.dubbo.integration.single.exportmetadata.SingleRegistryCenterExportMetadataServiceListener
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 b9231ee..4f4bb35 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
@@ -19,3 +19,4 @@
mockexporterlistener=org.apache.dubbo.config.mock.MockExporterListener
singleConfigCenterInjvm=org.apache.dubbo.integration.single.injvm.SingleRegistryCenterInjvmExporterListener
multipleConfigCenterInjvm=org.apache.dubbo.integration.multiple.injvm.MultipleRegistryCenterInjvmExporterListener
singleConfigCenterExportProvider=org.apache.dubbo.integration.single.exportprovider.SingleRegistryCenterExportProviderExporterListener
+singleConfigCenterExportMetadata=org.apache.dubbo.integration.single.exportmetadata.SingleRegistryCenterExportMetadataExporterListener
diff --git
a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/schema/GenericServiceTest.java
b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/schema/GenericServiceTest.java
index 0e48137..57c0b83 100644
---
a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/schema/GenericServiceTest.java
+++
b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/schema/GenericServiceTest.java
@@ -26,7 +26,11 @@ import org.apache.dubbo.config.spring.api.DemoService;
import
org.apache.dubbo.config.spring.registrycenter.ZookeeperSingleRegistryCenter;
import org.apache.dubbo.config.spring.registrycenter.RegistryCenter;
import org.apache.dubbo.rpc.service.GenericService;
-import org.junit.jupiter.api.*;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -55,7 +59,6 @@ public class GenericServiceTest {
@AfterAll
public static void afterAll() {
- DubboBootstrap.reset();
singleRegistryCenter.shutdown();
}