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 d46f331 test: Design integration testcase of the whole process for
provider service exposure (#8296)
d46f331 is described below
commit d46f33132b80d01efd00509b2e5064271e4c0964
Author: Xiong, Pin <[email protected]>
AuthorDate: Thu Jul 15 06:06:26 2021 -0500
test: Design integration testcase of the whole process for provider service
exposure (#8296)
1. Refactor the previous design for integration testcase
2. Support single and multiple registry center
3. Optimize the zookeeper server instance and make sure there is only one
instance
---
.../dubbo/integration/AbstractIntegrationTest.java | 81 -------
.../apache/dubbo/integration/IntegrationTest.java | 10 -
.../AbstractRegistryProtocolTest.java | 106 ---------
.../RegistryProtocol4DubboTest.java | 48 ----
.../AbstractServiceDiscoveryRegistryTest.java | 143 ------------
.../ServiceDiscoveryRegistry4DubboTest.java | 49 ----
...ServiceDiscoveryRegistryIntegrationService.java | 36 ---
.../servicediscoveryregistry/package-info.java | 22 --
...RegistryCenterDubboProtocolIntegrationTest.java | 258 +++++++++++++++++++++
.../SingleRegistryCenterIntegrationService.java} | 6 +-
...ingleRegistryCenterIntegrationServiceImpl.java} | 9 +-
.../single/SingleZooKeeperServer.java} | 23 +-
.../{registryprotocol => single}/package-info.java | 7 +-
13 files changed, 288 insertions(+), 510 deletions(-)
diff --git
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/AbstractIntegrationTest.java
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/AbstractIntegrationTest.java
deleted file mode 100644
index 1e69d7b..0000000
---
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/AbstractIntegrationTest.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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;
-
-import org.apache.dubbo.ZooKeeperServerTesting;
-import org.apache.dubbo.config.bootstrap.DubboBootstrap;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-/**
- * This abstraction class will implement some methods as base.
- * @param <T> the type of subclass of {@link IntegrationService}.
- */
-public abstract class AbstractIntegrationTest<T> implements IntegrationTest {
-
- private static final Logger logger =
LoggerFactory.getLogger(AbstractIntegrationTest.class);
-
- /**
- * Start global config only once.
- */
- @BeforeAll
- public static void beforeAll() {
- //start zookeeper only once
- ZooKeeperServerTesting.start();
- }
-
- @BeforeEach
- public void before() {
- logger.info(getClass().getSimpleName()+ " testcase is beginning...");
- DubboBootstrap.reset();
- this.initialize();
- }
-
- @Test
- @Override
- public void integrate() {
- this.process();
- }
-
- /**
- * This abstract method should be implement by all subclass.
- *
- */
- public abstract void process();
-
- @AfterEach
- public void after() {
- this.destroy();
- DubboBootstrap.reset();
- logger.info(getClass().getSimpleName()+ " testcase is ending...");
- }
-
- /**
- * Destroy all global resources.
- */
- @AfterAll
- public static void afterAll() {
- // destroy zookeeper only once
- ZooKeeperServerTesting.shutdown();
- }
-}
diff --git
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/IntegrationTest.java
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/IntegrationTest.java
index 7debda8..37ba809 100644
---
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/IntegrationTest.java
+++
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/IntegrationTest.java
@@ -22,17 +22,7 @@ package org.apache.dubbo.integration;
public interface IntegrationTest {
/**
- * Initialize all needed resources.
- */
- void initialize();
-
- /**
* Run the integration testcases.
*/
void integrate();
-
- /**
- * Release all resources.
- */
- void destroy();
}
diff --git
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/registryprotocol/AbstractRegistryProtocolTest.java
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/registryprotocol/AbstractRegistryProtocolTest.java
deleted file mode 100644
index b4b3256..0000000
---
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/registryprotocol/AbstractRegistryProtocolTest.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * 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.registryprotocol;
-
-import org.apache.dubbo.ZooKeeperServerTesting;
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.config.ApplicationConfig;
-import org.apache.dubbo.config.ProtocolConfig;
-import org.apache.dubbo.config.RegistryConfig;
-import org.apache.dubbo.config.ServiceConfig;
-import org.apache.dubbo.config.bootstrap.DubboBootstrap;
-import org.apache.dubbo.integration.AbstractIntegrationTest;
-import org.apache.dubbo.integration.IntegrationService;
-import org.junit.jupiter.api.Assertions;
-
-/**
- * <pre>The purpose of this testcase is to check if there exists problems
between {@link org.apache.dubbo.config.ServiceConfig} and {@link
org.apache.dubbo.registry.integration.RegistryProtocol} using {@code zookeeper}
protocol.</pre>
- */
-public abstract class AbstractRegistryProtocolTest extends
AbstractIntegrationTest<RegistryProtocolIntegrationService> {
-
- private ServiceConfig<RegistryProtocolIntegrationService> serviceConfig;
-
- @Override
- public void initialize() {
- // initialize ServiceConfig
- this.serviceConfig = new ServiceConfig<>();
- this.serviceConfig.setInterface(IntegrationService.class);
- this.serviceConfig.setRef(new RegistryProtocolIntegrationService());
- this.serviceConfig.setAsync(false);
-
- DubboBootstrap.getInstance()
- .application(new ApplicationConfig(this.getApplicationName()))
- .registry(new RegistryConfig("zookeeper://127.0.0.1:" +
ZooKeeperServerTesting.getPort()))
- .protocol(new ProtocolConfig(this.getProtocolName(),
this.getProtocolPort()))
- .service(this.serviceConfig);
- }
-
- @Override
- public void process() {
- this.beforeExport();
- // export provider
- DubboBootstrap.getInstance().start();
- this.afterExport();
- }
-
- /**
- * before export
- */
- private void beforeExport() {
- // assert the service hasn't been exported
- Assertions.assertFalse(this.serviceConfig.isExported());
- // assert there is no exported url
- Assertions.assertEquals(this.serviceConfig.getExportedUrls().size(),
0);
- }
-
- /**
- * after export
- */
- private void afterExport() {
- // check the service has been exported
- Assertions.assertTrue(this.serviceConfig.isExported());
- // check there is exported url
- Assertions.assertEquals(this.serviceConfig.getExportedUrls().size(),
1);
- URL exportedUrl = this.serviceConfig.getExportedUrls().get(0);
- // check the protocol
- Assertions.assertEquals(exportedUrl.getProtocol(),
this.getProtocolName());
- // check the application name
- Assertions.assertEquals(exportedUrl.getApplication(),
this.getApplicationName());
- // check the service port
- Assertions.assertEquals(exportedUrl.getPort(), this.getProtocolPort());
- }
-
- @Override
- public void destroy() {
- this.serviceConfig = null;
- }
-
- /**
- * Returns the protocol's name.
- */
- protected abstract String getProtocolName();
-
- /**
- * Returns the application name.
- */
- protected abstract String getApplicationName();
-
- /**
- * Returns the protocol's port.
- */
- protected abstract int getProtocolPort();
-}
diff --git
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/registryprotocol/RegistryProtocol4DubboTest.java
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/registryprotocol/RegistryProtocol4DubboTest.java
deleted file mode 100644
index 8056886..0000000
---
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/registryprotocol/RegistryProtocol4DubboTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.registryprotocol;
-
-/**
- * <pre>The purpose of this testcase is to check
- * if there exists problems between {@link
org.apache.dubbo.config.ServiceConfig} and {@link
org.apache.dubbo.registry.integration.RegistryProtocol} using dubbo
protocol.</pre>
- */
-public class RegistryProtocol4DubboTest extends AbstractRegistryProtocolTest {
-
- /**
- * Returns the protocol name.
- */
- @Override
- protected String getProtocolName() {
- return "dubbo";
- }
-
- /**
- * Returns the application name.
- */
- @Override
- protected String getApplicationName() {
- return "integration-registry-protocol-dubbo";
- }
-
- /**
- * Returns the protocol's port.
- */
- @Override
- protected int getProtocolPort() {
- return 20880;
- }
-}
diff --git
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/servicediscoveryregistry/AbstractServiceDiscoveryRegistryTest.java
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/servicediscoveryregistry/AbstractServiceDiscoveryRegistryTest.java
deleted file mode 100644
index c8ecaf3..0000000
---
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/servicediscoveryregistry/AbstractServiceDiscoveryRegistryTest.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * 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.servicediscoveryregistry;
-
-import org.apache.dubbo.ZooKeeperServerTesting;
-import org.apache.dubbo.config.ApplicationConfig;
-import org.apache.dubbo.config.ProtocolConfig;
-import org.apache.dubbo.config.RegistryConfig;
-import org.apache.dubbo.config.ServiceConfig;
-import org.apache.dubbo.config.bootstrap.DubboBootstrap;
-import org.apache.dubbo.integration.AbstractIntegrationTest;
-import org.apache.dubbo.integration.IntegrationService;
-import org.apache.dubbo.registry.Registry;
-import org.apache.dubbo.registry.client.ServiceDiscoveryRegistry;
-import org.apache.dubbo.registry.support.AbstractRegistryFactory;
-import org.apache.dubbo.registry.zookeeper.ZookeeperServiceDiscovery;
-import org.junit.jupiter.api.Assertions;
-
-import java.lang.reflect.Field;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * The purpose of is to check if there exists problem
- * between {@link org.apache.dubbo.registry.integration.RegistryProtocol} and
- * {@link org.apache.dubbo.registry.client.ServiceDiscoveryRegistry}
- * using zookeeper as registry center.
- */
-public abstract class AbstractServiceDiscoveryRegistryTest extends
AbstractIntegrationTest<ServiceDiscoveryRegistryIntegrationService> {
-
- private ServiceConfig<ServiceDiscoveryRegistryIntegrationService>
serviceConfig;
-
- @Override
- public void initialize() {
- // initialize ServiceConfig
- this.serviceConfig = new ServiceConfig<>();
- this.serviceConfig.setInterface(IntegrationService.class);
- this.serviceConfig.setRef(new
ServiceDiscoveryRegistryIntegrationService());
- this.serviceConfig.setAsync(false);
-
- DubboBootstrap.getInstance()
- .application(new ApplicationConfig(this.getApplicationName()))
- .registry(new RegistryConfig("zookeeper://127.0.0.1:" +
ZooKeeperServerTesting.getPort()))
- .protocol(new ProtocolConfig(this.getProtocolName(),
this.getProtocolPort()))
- .service(this.serviceConfig);
- }
-
- @Override
- public void process() {
- this.beforeExport();
- // export provider
- DubboBootstrap.getInstance().start();
- this.afterExport();
- }
-
- /**
- * before export
- */
- private void beforeExport() {
- // assert the service hasn't been exported
- Assertions.assertFalse(this.serviceConfig.isExported());
- // assert there is no exported url
- Assertions.assertEquals(this.serviceConfig.getExportedUrls().size(),
0);
- }
-
- /**
- * after export
- */
- private void afterExport() {
- // obtain ServiceDiscoveryRegistry instance
- ServiceDiscoveryRegistry serviceDiscoveryRegistry =
this.getServiceDiscoveryRegistry();
- serviceDiscoveryRegistry.getServiceDiscovery();
- // check service discovery protocol
- Assertions.assertTrue(serviceDiscoveryRegistry.getServiceDiscovery()
instanceof ZookeeperServiceDiscovery);
- // convert to ZookeeperServiceDiscovery instance
- ZookeeperServiceDiscovery zookeeperServiceDiscovery
=(ZookeeperServiceDiscovery) serviceDiscoveryRegistry.getServiceDiscovery();
- // zookeeperServiceDiscovery can't destroy
- Assertions.assertFalse(zookeeperServiceDiscovery.isDestroy());
- // Gets registered service by ZookeeperServiceDiscovery
- Set<String> services = zookeeperServiceDiscovery.getServices();
- // check service exists
- Assertions.assertTrue(!services.isEmpty());
- Assertions.assertTrue(services.contains(this.getApplicationName()));
- }
-
- /**
- * Returns {@link ServiceDiscoveryRegistry} instance.
- * <p>
- * FIXME It's not a good way to obtain {@link ServiceDiscoveryRegistry}
using Reflection.
- */
- private ServiceDiscoveryRegistry getServiceDiscoveryRegistry(){
- ServiceDiscoveryRegistry serviceDiscoveryRegistry = null;
- try {
- // get AbstractRegistryFactory.REGISTRIES
- Field field =
AbstractRegistryFactory.class.getDeclaredField("REGISTRIES");
- field.setAccessible(true);
- Map<String, Registry> REGISTRIES = (Map<String,
Registry>)field.get(AbstractRegistryFactory.class);
- for(Registry registry:REGISTRIES.values()){
- if(registry instanceof ServiceDiscoveryRegistry){
- serviceDiscoveryRegistry =
(ServiceDiscoveryRegistry)registry;
- break;
- }
- }
- } catch (IllegalAccessException | NoSuchFieldException e) {
- // ignore
- }
- return serviceDiscoveryRegistry;
- }
-
- @Override
- public void destroy() {
- this.serviceConfig = null;
- }
-
- /**
- * Returns the protocol's name.
- */
- protected abstract String getProtocolName();
-
- /**
- * Returns the application name.
- */
- protected abstract String getApplicationName();
-
- /**
- * Returns the protocol's port.
- */
- protected abstract int getProtocolPort();
-}
diff --git
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/servicediscoveryregistry/ServiceDiscoveryRegistry4DubboTest.java
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/servicediscoveryregistry/ServiceDiscoveryRegistry4DubboTest.java
deleted file mode 100644
index b3da14f..0000000
---
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/servicediscoveryregistry/ServiceDiscoveryRegistry4DubboTest.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.servicediscoveryregistry;
-
-/**
- * Checks if there exists problems between
- * {@link org.apache.dubbo.registry.integration.RegistryProtocol} and
- * {@link org.apache.dubbo.registry.client.ServiceDiscoveryRegistry}
- * using dubbo protocol.
- */
-public class ServiceDiscoveryRegistry4DubboTest extends
AbstractServiceDiscoveryRegistryTest{
- /**
- * Returns the protocol's name.
- */
- @Override
- protected String getProtocolName() {
- return "dubbo";
- }
-
- /**
- * Returns the application name.
- */
- @Override
- protected String getApplicationName() {
- return "integration-service-discovery-registry-dubbo";
- }
-
- /**
- * Returns the protocol's port.
- */
- @Override
- protected int getProtocolPort() {
- return 20880;
- }
-}
diff --git
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/servicediscoveryregistry/ServiceDiscoveryRegistryIntegrationService.java
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/servicediscoveryregistry/ServiceDiscoveryRegistryIntegrationService.java
deleted file mode 100644
index a60e861..0000000
---
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/servicediscoveryregistry/ServiceDiscoveryRegistryIntegrationService.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.servicediscoveryregistry;
-
-import org.apache.dubbo.integration.IntegrationService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * The implementation for {@link IntegrationService}
- */
-public class ServiceDiscoveryRegistryIntegrationService implements
IntegrationService {
-
- private static final Logger logger =
LoggerFactory.getLogger(ServiceDiscoveryRegistryIntegrationService.class);
-
- @Override
- public String hello(String name) {
- String value = "Hello " + name;
- logger.info(value);
- return value;
- }
-}
diff --git
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/servicediscoveryregistry/package-info.java
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/servicediscoveryregistry/package-info.java
deleted file mode 100644
index f85c294..0000000
---
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/servicediscoveryregistry/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * 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.
- */
-/**
- * The purpose of this package is to define integration testcases for checking
- * <p>if there exists problems between {@link
org.apache.dubbo.registry.integration.RegistryProtocol}
- * and {@link org.apache.dubbo.registry.client.ServiceDiscoveryRegistry}.</p>
- */
-package org.apache.dubbo.integration.servicediscoveryregistry;
diff --git
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/SingleRegistryCenterDubboProtocolIntegrationTest.java
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/SingleRegistryCenterDubboProtocolIntegrationTest.java
new file mode 100644
index 0000000..602d34d
--- /dev/null
+++
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/SingleRegistryCenterDubboProtocolIntegrationTest.java
@@ -0,0 +1,258 @@
+/*
+ * 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;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.constants.CommonConstants;
+import org.apache.dubbo.config.ApplicationConfig;
+import org.apache.dubbo.config.ProtocolConfig;
+import org.apache.dubbo.config.RegistryConfig;
+import org.apache.dubbo.config.ServiceConfig;
+import org.apache.dubbo.config.bootstrap.DubboBootstrap;
+import org.apache.dubbo.integration.IntegrationTest;
+import org.apache.dubbo.metadata.MetadataInfo;
+import org.apache.dubbo.metadata.WritableMetadataService;
+import org.apache.dubbo.registry.Registry;
+import org.apache.dubbo.registry.client.ServiceDiscoveryRegistry;
+import
org.apache.dubbo.registry.client.metadata.store.InMemoryWritableMetadataService;
+import org.apache.dubbo.registry.support.AbstractRegistryFactory;
+import org.apache.dubbo.registry.zookeeper.ZookeeperServiceDiscovery;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.util.Map;
+import java.util.Set;
+
+
+/**
+ * This abstraction class will implement some methods as base for single
registry center.
+ */
+public class SingleRegistryCenterDubboProtocolIntegrationTest implements
IntegrationTest {
+
+ private static final Logger logger =
LoggerFactory.getLogger(SingleRegistryCenterDubboProtocolIntegrationTest.class);
+ /**
+ * Define the application name.
+ */
+ private static String APPLICATION_NAME =
"single-registry-center-integration-testcase-for-dubbo-protocol";
+ /**
+ * Define the protocol's name.
+ */
+ private static String PROTOCOL_NAME = CommonConstants.DUBBO;
+ /**
+ * Define the protocol's port.
+ */
+ private static int PROTOCOL_PORT = 20800;
+
+ /**
+ * Define the {@link ServiceConfig} instance.
+ */
+ private ServiceConfig<SingleRegistryCenterIntegrationServiceImpl>
serviceConfig;
+
+ @BeforeEach
+ public void setUp() throws Exception {
+ logger.info(getClass().getSimpleName() + " testcase is beginning...");
+ DubboBootstrap.reset();
+ //start zookeeper only once
+ logger.info(SingleZooKeeperServer.getZookeeperServerName() + " is
beginning to start...");
+ SingleZooKeeperServer.start();
+ logger.info(SingleZooKeeperServer.getZookeeperServerName() + " has
started.");
+ // initialize ServiceConfig
+ serviceConfig = new ServiceConfig<>();
+
serviceConfig.setInterface(SingleRegistryCenterIntegrationService.class);
+ serviceConfig.setRef(new SingleRegistryCenterIntegrationServiceImpl());
+ serviceConfig.setAsync(false);
+
+ DubboBootstrap.getInstance()
+ .application(new ApplicationConfig(APPLICATION_NAME))
+ .registry(new RegistryConfig("zookeeper://127.0.0.1:" +
SingleZooKeeperServer.getPort()))
+ .protocol(new ProtocolConfig(PROTOCOL_NAME, PROTOCOL_PORT))
+ .service(serviceConfig);
+ }
+
+ @Test
+ @Override
+ public void integrate() {
+ this.beforeExport();
+ // export provider
+ DubboBootstrap.getInstance().start();
+ this.afterExport();
+ }
+
+ /**
+ * There are some checkpoints needed to check as follow :
+ * <li>ZookeeperServer's status</li>
+ * <li>ServiceConfig is exported or not</li>
+ * <li>ServiceConfig's exportedUrl has values or not</li>
+ * <li>DubboBootstrap is initialized or not</li>
+ * <li>DubboBootstrap is started or not</li>
+ * <li>DubboBootstrap is shutdown or not</li>
+ */
+ private void beforeExport() {
+ // ZookeeperServer's status
+ Assertions.assertTrue(SingleZooKeeperServer.isRunning());
+ // ServiceConfig is exported or not
+ Assertions.assertFalse(serviceConfig.isExported());
+ // ServiceConfig's exportedUrl has values or not
+ Assertions.assertEquals(serviceConfig.getExportedUrls().size(), 0);
+ // DubboBootstrap is initialized or not
+ Assertions.assertFalse(DubboBootstrap.getInstance().isInitialized());
+ // DubboBootstrap is started or not
+ Assertions.assertFalse(DubboBootstrap.getInstance().isStarted());
+ // DubboBootstrap is shutdown or not
+ Assertions.assertFalse(DubboBootstrap.getInstance().isShutdown());
+ }
+
+ /**
+ * There are some checkpoints needed to check as follow :
+ * <li>DubboBootstrap is initialized or not</li>
+ * <li>DubboBootstrap is started or not</li>
+ * <li>DubboBootstrap is shutdown or not</li>
+ * <li>Service has been exported or not</li>
+ * <li>There is exported urls or not</li>
+ * <li>Protocol name is right or not</li>
+ * <li>Protocol port is right or not</li>
+ * <li>ServiceDiscoveryRegistry's protocol is right or not</li>
+ * <li>ServiceDiscoveryRegistry is destroy or not</li>
+ * <li>Registered service in registry center is right or not</li>
+ * <li>Exported url is right or not in InMemoryWritableMetadataService</li>
+ * <li>MetadataInfo exists or not in InMemoryWritableMetadataService</li>
+ * <li>MetadataInfo has reported or not</li>
+ * <li>MetadataInfo has reported or not has service or not</li>
+ * <li>MetadataInfo's application name is right or not</li>
+ * <li>MetadataInfo's service exists or not</li>
+ * <li>The name of MetadataInfo's service is right or not</li>
+ * <li>The group of MetadataInfo's service is right or not</li>
+ * <li>The version of MetadataInfo's service is right or not</li>
+ * <li>The protocol of MetadataInfo's service is right or not</li>
+ * <li>The serviceKey of MetadataInfo's service is right or not</li>
+ * <li>The matchKey of MetadataInfo's service is right or not</li>
+ */
+ private void afterExport() {
+ // DubboBootstrap is initialized or not
+ Assertions.assertTrue(DubboBootstrap.getInstance().isInitialized());
+ // DubboBootstrap is started or not
+ Assertions.assertTrue(DubboBootstrap.getInstance().isStarted());
+ // DubboBootstrap is shutdown or not
+ Assertions.assertFalse(DubboBootstrap.getInstance().isShutdown());
+ // Service has been exported or not
+ Assertions.assertTrue(this.serviceConfig.isExported());
+ // There is exported urls or not
+ Assertions.assertEquals(this.serviceConfig.getExportedUrls().size(),
1);
+ URL exportedUrl = this.serviceConfig.getExportedUrls().get(0);
+ // Protocol name is right or not
+ Assertions.assertEquals(exportedUrl.getProtocol(), PROTOCOL_NAME);
+ // Protocol port is right or not
+ Assertions.assertEquals(exportedUrl.getPort(), PROTOCOL_PORT);
+ // Application name is right or not
+ Assertions.assertEquals(exportedUrl.getApplication(),
APPLICATION_NAME);
+
+ // obtain ServiceDiscoveryRegistry instance
+ ServiceDiscoveryRegistry serviceDiscoveryRegistry =
this.getServiceDiscoveryRegistry();
+ // ServiceDiscoveryRegistry instance cannot be null
+ Assertions.assertNotNull(serviceDiscoveryRegistry);
+ // ServiceDiscoveryRegistry's protocol is right or not
+ Assertions.assertTrue(serviceDiscoveryRegistry.getServiceDiscovery()
instanceof ZookeeperServiceDiscovery);
+ // Convert to ZookeeperServiceDiscovery instance
+ ZookeeperServiceDiscovery zookeeperServiceDiscovery =
(ZookeeperServiceDiscovery) serviceDiscoveryRegistry.getServiceDiscovery();
+ // ServiceDiscoveryRegistry is destroy or not
+ Assertions.assertFalse(zookeeperServiceDiscovery.isDestroy());
+ // Gets registered service by ZookeeperServiceDiscovery
+ Set<String> services = zookeeperServiceDiscovery.getServices();
+ // check service exists
+ Assertions.assertTrue(!services.isEmpty());
+ // Registered service in registry center is right or not
+ Assertions.assertTrue(services.contains(APPLICATION_NAME));
+
+ // obtain InMemoryWritableMetadataService instance
+ InMemoryWritableMetadataService inMemoryWritableMetadataService =
(InMemoryWritableMetadataService) WritableMetadataService.getDefaultExtension();
+ // Exported url is right or not in InMemoryWritableMetadataService
+
Assertions.assertEquals(inMemoryWritableMetadataService.getExportedURLs().size(),
1);
+ // MetadataInfo exists or not in InMemoryWritableMetadataService
+
Assertions.assertFalse(inMemoryWritableMetadataService.getMetadataInfos().values().isEmpty());
+ // get MetadataInfo
+ MetadataInfo metadataInfo =
inMemoryWritableMetadataService.getMetadataInfos().get("default");
+ // MetadataInfo exists or not in InMemoryWritableMetadataService
+ Assertions.assertNotNull(metadataInfo);
+ // MetadataInfo has reported or not
+ Assertions.assertTrue(metadataInfo.hasReported());
+ // MetadataInfo has reported or not has service or not
+ Assertions.assertFalse(metadataInfo.getServices().isEmpty());
+ // MetadataInfo has reported or not has service or not
+ Assertions.assertEquals(metadataInfo.getServices().size(), 1);
+ // obtain the service's key
+ String key = SingleRegistryCenterIntegrationService.class.getName() +
":" + PROTOCOL_NAME;
+ MetadataInfo.ServiceInfo serviceInfo =
metadataInfo.getServices().get(key);
+ // MetadataInfo's service exists or not
+ Assertions.assertNotNull(serviceInfo);
+ // The name of MetadataInfo's service is right or not
+
Assertions.assertEquals(serviceInfo.getName(),SingleRegistryCenterIntegrationService.class.getName());
+ // The group of MetadataInfo's service is right or not
+ Assertions.assertNull(serviceInfo.getGroup());
+ // The version of MetadataInfo's service is right or not
+ Assertions.assertNull(serviceInfo.getVersion());
+ // The protocol of MetadataInfo's service is right or not
+ Assertions.assertEquals(serviceInfo.getProtocol(),PROTOCOL_NAME);
+ // The serviceKey of MetadataInfo's service is right or not
+
Assertions.assertEquals(serviceInfo.getServiceKey(),SingleRegistryCenterIntegrationService.class.getName());
+ // The matchKey of MetadataInfo's service is right or not
+ Assertions.assertEquals(serviceInfo.getMatchKey(),key);
+ }
+
+ /**
+ * Returns {@link ServiceDiscoveryRegistry} instance.
+ * <p>
+ * FIXME It's not a good way to obtain {@link ServiceDiscoveryRegistry}
using Reflection.
+ */
+ private ServiceDiscoveryRegistry getServiceDiscoveryRegistry() {
+ ServiceDiscoveryRegistry serviceDiscoveryRegistry = null;
+ try {
+ // get AbstractRegistryFactory.REGISTRIES
+ Field field =
AbstractRegistryFactory.class.getDeclaredField("REGISTRIES");
+ field.setAccessible(true);
+ Map<String, Registry> REGISTRIES = (Map<String, Registry>)
field.get(AbstractRegistryFactory.class);
+ for (Registry registry : REGISTRIES.values()) {
+ if (registry instanceof ServiceDiscoveryRegistry) {
+ serviceDiscoveryRegistry = (ServiceDiscoveryRegistry)
registry;
+ break;
+ }
+ }
+ } catch (IllegalAccessException | NoSuchFieldException e) {
+ // ignore
+ }
+ return serviceDiscoveryRegistry;
+ }
+
+ @AfterEach
+ public void tearDown() throws IOException {
+ DubboBootstrap.reset();
+ APPLICATION_NAME = null;
+ PROTOCOL_NAME = null;
+ PROTOCOL_PORT = 0;
+ serviceConfig = null;
+ logger.info(getClass().getSimpleName() + " testcase is ending...");
+ // destroy zookeeper only once
+ logger.info(SingleZooKeeperServer.getZookeeperServerName() + " is
beginning to shutdown...");
+ SingleZooKeeperServer.shutdown();
+ logger.info(SingleZooKeeperServer.getZookeeperServerName() + " has
shutdown.");
+ }
+}
diff --git
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/IntegrationService.java
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/SingleRegistryCenterIntegrationService.java
similarity index 82%
rename from
dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/IntegrationService.java
rename to
dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/SingleRegistryCenterIntegrationService.java
index 3ae3242..2db63d3 100644
---
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/IntegrationService.java
+++
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/SingleRegistryCenterIntegrationService.java
@@ -14,12 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.dubbo.integration;
+package org.apache.dubbo.integration.single;
/**
- * This interface for integration testcases.
+ * This interface for integration testcases in single registry center.
*/
-public interface IntegrationService {
+public interface SingleRegistryCenterIntegrationService {
String hello(String name);
}
diff --git
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/registryprotocol/RegistryProtocolIntegrationService.java
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/SingleRegistryCenterIntegrationServiceImpl.java
similarity index 79%
rename from
dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/registryprotocol/RegistryProtocolIntegrationService.java
rename to
dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/SingleRegistryCenterIntegrationServiceImpl.java
index 2878642..99e5d8a 100644
---
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/registryprotocol/RegistryProtocolIntegrationService.java
+++
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/SingleRegistryCenterIntegrationServiceImpl.java
@@ -14,18 +14,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.dubbo.integration.registryprotocol;
+package org.apache.dubbo.integration.single;
-import org.apache.dubbo.integration.IntegrationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * The implementation for {@link IntegrationService}
+ * The implementation for {@link SingleRegistryCenterIntegrationService}
*/
-public class RegistryProtocolIntegrationService implements IntegrationService {
+public class SingleRegistryCenterIntegrationServiceImpl implements
SingleRegistryCenterIntegrationService {
- private static final Logger logger =
LoggerFactory.getLogger(RegistryProtocolIntegrationService.class);
+ private static final Logger logger =
LoggerFactory.getLogger(SingleRegistryCenterIntegrationServiceImpl.class);
@Override
public String hello(String name) {
diff --git
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/ZooKeeperServerTesting.java
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/SingleZooKeeperServer.java
similarity index 92%
rename from
dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/ZooKeeperServerTesting.java
rename to
dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/SingleZooKeeperServer.java
index a4e9e4c..c27fdda 100644
---
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/ZooKeeperServerTesting.java
+++
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/SingleZooKeeperServer.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.dubbo;
+package org.apache.dubbo.integration.single;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.zookeeper.server.ServerConfig;
@@ -30,14 +30,15 @@ import java.util.UUID;
/**
* The zookeeper server is just for testing.
+ * Also there is only one static instance, which can be created.
* <p>
* Note: It can only be used if the following conditions are satisfied
* <p>1. Integration testcase instead of unit testcase
* <p>2. You can use only one zookeeper instance per Package, because the
zookeeper is a static global instance.
*/
-public class ZooKeeperServerTesting {
+public class SingleZooKeeperServer {
- private static final Logger logger =
LoggerFactory.getLogger(ZooKeeperServerTesting.class);
+ private static final Logger logger =
LoggerFactory.getLogger(SingleZooKeeperServer.class);
/**
* Define a static zookeeper instance.
@@ -62,6 +63,20 @@ public class ZooKeeperServerTesting {
}
/**
+ * Checks if the zookeeper server is running.
+ */
+ public static boolean isRunning(){
+ return INSTANCE.isRunning();
+ }
+
+ /**
+ * Returns the zookeeper server's name.
+ */
+ public static String getZookeeperServerName(){
+ return "single-zookeeper-server-for-test";
+ }
+
+ /**
* Shutdown the zookeeper instance.
*/
public static void shutdown() {
@@ -147,7 +162,7 @@ public class ZooKeeperServerTesting {
} catch (Exception e) {
logger.error("Exception running embedded ZooKeeper",
e);
}
- }, "zookeeper-server-for-test");
+ }, getZookeeperServerName());
zkServerThread.setDaemon(true);
zkServerThread.start();
}
diff --git
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/registryprotocol/package-info.java
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/package-info.java
similarity index 73%
rename from
dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/registryprotocol/package-info.java
rename to
dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/package-info.java
index f7aad2e..ab1dda2 100644
---
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/registryprotocol/package-info.java
+++
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/package-info.java
@@ -15,7 +15,8 @@
* limitations under the License.
*/
/**
- * The purpose of this package is to define integration testcases for checking
- * <p>if there exists problems between {@link
org.apache.dubbo.config.ServiceConfig} and {@link
org.apache.dubbo.registry.integration.RegistryProtocol}.</p>
+ * There are two scenario in integration testcases.<p>
+ * The one is single registry center, the other is multiple registry
centers.<p>
+ * The purpose of all of testcases in this package is to test for single
registry center.
*/
-package org.apache.dubbo.integration.registryprotocol;
+package org.apache.dubbo.integration.single;