diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ConfigCenterConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ConfigCenterConfigTest.java index d006c0f90b..6de79d875b 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ConfigCenterConfigTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ConfigCenterConfigTest.java @@ -21,6 +21,7 @@ package org.apache.dubbo.config; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -60,11 +61,11 @@ public class ConfigCenterConfigTest { ConfigCenterConfig config = new ConfigCenterConfig(); config.setNamespace("namespace"); config.setGroup("group"); - config.setAddress("zookeeper://127.0.0.1:2181"); + config.setAddress(ZookeeperRegistryCenterConfig.getConnectionAddress()); config.setHighestPriority(null); config.refresh(); - Assertions.assertEquals("zookeeper://127.0.0.1:2181/ConfigCenterConfig?check=true&" + + Assertions.assertEquals(ZookeeperRegistryCenterConfig.getConnectionAddress()+"/ConfigCenterConfig?check=true&" + "config-file=dubbo.properties&group=group&" + "namespace=namespace&timeout=3000", config.toUrl().toFullString() @@ -74,7 +75,7 @@ public class ConfigCenterConfigTest { @Test public void testOverrideConfig() { - String zkAddr = "zookeeper://127.0.0.1:2181"; + String zkAddr = ZookeeperRegistryCenterConfig.getConnectionAddress(); // sysprops has no id SysProps.setProperty("dubbo.config-center.check", "false"); SysProps.setProperty("dubbo.config-center.address", zkAddr); @@ -116,7 +117,7 @@ public class ConfigCenterConfigTest { try { //No id but has address ConfigCenterConfig configCenter = new ConfigCenterConfig(); - configCenter.setAddress("zookeeper://127.0.0.1:2181"); + configCenter.setAddress(ZookeeperRegistryCenterConfig.getConnectionAddress()); DubboBootstrap.getInstance() .application("demo-app") @@ -277,7 +278,7 @@ public class ConfigCenterConfigTest { @Test public void testAttributes() { ConfigCenterConfig cc = new ConfigCenterConfig(); - cc.setAddress("zookeeper://127.0.0.1:2181"); + cc.setAddress(ZookeeperRegistryCenterConfig.getConnectionAddress()); Map attributes = new LinkedHashMap<>(); ConfigCenterConfig.appendAttributes(attributes, cc); @@ -291,7 +292,7 @@ public class ConfigCenterConfigTest { @Test public void testSetAddress() { - String address = "zookeeper://127.0.0.1:2181"; + String address = ZookeeperRegistryCenterConfig.getConnectionAddress(); ConfigCenterConfig cc = new ConfigCenterConfig(); cc.setUsername("user123"); // set username first cc.setPassword("pass123"); diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java index e3fd8062a5..3a0b747bd8 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java @@ -32,8 +32,6 @@ import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.context.ModuleConfigManager; import org.apache.dubbo.config.provider.impl.DemoServiceImpl; import org.apache.dubbo.registry.client.migration.MigrationInvoker; -import org.apache.dubbo.registrycenter.RegistryCenter; -import org.apache.dubbo.registrycenter.ZookeeperSingleRegistryCenter; import org.apache.dubbo.rpc.Exporter; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.ProxyFactory; @@ -54,7 +52,6 @@ import demo.MultiClassLoaderServiceResult; import javassist.CannotCompileException; import javassist.CtClass; import javassist.NotFoundException; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -127,17 +124,11 @@ public class ReferenceConfigTest { private static String zkUrl1; private static String zkUrl2; private static String registryUrl1; - private static RegistryCenter registryCenter1; - private static RegistryCenter registryCenter2; @BeforeAll public static void beforeAll() { - int zkServerPort1 = NetUtils.getAvailablePort(NetUtils.getRandomPort()); - registryCenter1 = new ZookeeperSingleRegistryCenter(zkServerPort1); - registryCenter1.startup(); - int zkServerPort2 = NetUtils.getAvailablePort(NetUtils.getRandomPort()); - registryCenter2 = new ZookeeperSingleRegistryCenter(zkServerPort2); - registryCenter2.startup(); + int zkServerPort1 = 2181; + int zkServerPort2 = 2182; zkUrl1 = "zookeeper://localhost:" + zkServerPort1; zkUrl2 = "zookeeper://localhost:" + zkServerPort2; registryUrl1 = "registry://localhost:" + zkServerPort1 + "?registry=zookeeper"; @@ -156,12 +147,6 @@ public class ReferenceConfigTest { Mockito.framework().clearInlineMocks(); } - @AfterAll - public static void afterAll() { - registryCenter1.shutdown(); - registryCenter2.shutdown(); - } - /** * Test whether the configuration required for the aggregation service reference meets expectations */ diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/RegistryConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/RegistryConfigTest.java index b895d6daed..10186e1f31 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/RegistryConfigTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/RegistryConfigTest.java @@ -22,6 +22,7 @@ import org.apache.dubbo.common.utils.UrlUtils; import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -202,7 +203,7 @@ public class RegistryConfigTest { public void testEquals() throws Exception { RegistryConfig registry1 = new RegistryConfig(); RegistryConfig registry2 = new RegistryConfig(); - registry1.setAddress("zookeeper://127.0.0.1:2182"); + registry1.setAddress(ZookeeperRegistryCenterConfig.getConnectionAddress2()); registry2.setAddress("zookeeper://127.0.0.1:2183"); Assertions.assertNotEquals(registry1, registry2); } @@ -241,7 +242,7 @@ public class RegistryConfigTest { // process Parameter annotation AbstractConfig.appendParameters(map, registry); // Simulate the check that ZoneAwareClusterInvoker#doInvoke do - URL url = UrlUtils.parseURL("zookeeper://127.0.0.1:2181", map); + URL url = UrlUtils.parseURL(ZookeeperRegistryCenterConfig.getConnectionAddress1(), map); Assertions.assertTrue(url.getParameter(PREFERRED_KEY, false)); } @@ -253,7 +254,7 @@ public class RegistryConfigTest { // Process Parameter annotation AbstractConfig.appendParameters(map, registry); // Simulate the check that ZoneAwareClusterInvoker#doInvoke do - URL url = UrlUtils.parseURL("zookeeper://127.0.0.1:2181", map); + URL url = UrlUtils.parseURL(ZookeeperRegistryCenterConfig.getConnectionAddress1(), map); Assertions.assertFalse(url.getParameter(PREFERRED_KEY, false)); } diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboBootstrapTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboBootstrapTest.java index 2df9558278..c238c0d0b3 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboBootstrapTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboBootstrapTest.java @@ -44,6 +44,7 @@ import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol; import org.apache.curator.test.TestingServer; +import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; @@ -192,7 +193,7 @@ public class DubboBootstrapTest { MonitorConfig monitorConfig = new MonitorConfig(); monitorConfig.setProtocol("registry"); - URL url = ConfigValidationUtils.loadMonitor(getTestInterfaceConfig(monitorConfig), URL.valueOf("zookeeper://127.0.0.1:2181")); + URL url = ConfigValidationUtils.loadMonitor(getTestInterfaceConfig(monitorConfig), URL.valueOf(ZookeeperRegistryCenterConfig.getConnectionAddress())); Assertions.assertEquals("dubbo", url.getProtocol()); Assertions.assertEquals("registry", url.getParameter("protocol")); } @@ -203,14 +204,14 @@ public class DubboBootstrapTest { MonitorConfig monitorConfig = new MonitorConfig(); monitorConfig.setProtocol("service-discovery-registry"); - URL url = ConfigValidationUtils.loadMonitor(getTestInterfaceConfig(monitorConfig), URL.valueOf("zookeeper://127.0.0.1:2181")); + URL url = ConfigValidationUtils.loadMonitor(getTestInterfaceConfig(monitorConfig), URL.valueOf(ZookeeperRegistryCenterConfig.getConnectionAddress())); Assertions.assertEquals("dubbo", url.getProtocol()); Assertions.assertEquals("service-discovery-registry", url.getParameter("protocol")); } @Test public void testLoadUserMonitor_no_monitor() { - URL url = ConfigValidationUtils.loadMonitor(getTestInterfaceConfig(null), URL.valueOf("zookeeper://127.0.0.1:2181")); + URL url = ConfigValidationUtils.loadMonitor(getTestInterfaceConfig(null), URL.valueOf(ZookeeperRegistryCenterConfig.getConnectionAddress())); Assertions.assertNull(url); } @@ -220,7 +221,7 @@ public class DubboBootstrapTest { MonitorConfig monitorConfig = new MonitorConfig(); monitorConfig.setProtocol("user"); - URL url = ConfigValidationUtils.loadMonitor(getTestInterfaceConfig(monitorConfig), URL.valueOf("zookeeper://127.0.0.1:2181")); + URL url = ConfigValidationUtils.loadMonitor(getTestInterfaceConfig(monitorConfig), URL.valueOf(ZookeeperRegistryCenterConfig.getConnectionAddress())); Assertions.assertEquals("user", url.getProtocol()); } @@ -229,7 +230,7 @@ public class DubboBootstrapTest { // dubbo.monitor.address=user://1.2.3.4:5678?k=v MonitorConfig monitorConfig = new MonitorConfig(); monitorConfig.setAddress("user://1.2.3.4:5678?param1=value1"); - URL url = ConfigValidationUtils.loadMonitor(getTestInterfaceConfig(monitorConfig), URL.valueOf("zookeeper://127.0.0.1:2181")); + URL url = ConfigValidationUtils.loadMonitor(getTestInterfaceConfig(monitorConfig), URL.valueOf(ZookeeperRegistryCenterConfig.getConnectionAddress())); Assertions.assertEquals("user", url.getProtocol()); Assertions.assertEquals("1.2.3.4:5678", url.getAddress()); Assertions.assertEquals("value1", url.getParameter("param1")); diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboServiceConsumerBootstrap.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboServiceConsumerBootstrap.java index f493c1637a..ca84218b1e 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboServiceConsumerBootstrap.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboServiceConsumerBootstrap.java @@ -18,6 +18,7 @@ package org.apache.dubbo.config.bootstrap; import org.apache.dubbo.config.MetadataReportConfig; import org.apache.dubbo.config.bootstrap.rest.UserService; +import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig; /** * Dubbo Provider Bootstrap @@ -35,8 +36,8 @@ public class DubboServiceConsumerBootstrap { // .registry(builder -> builder.address("eureka://127.0.0.1:8761?registry-type=service&subscribed-services=dubbo-provider-demo")) // Zookeeper - .registry("zookeeper", builder -> builder.address("zookeeper://127.0.0.1:2181?registry-type=service&subscribed-services=dubbo-provider-demo")) - .metadataReport(new MetadataReportConfig("zookeeper://127.0.0.1:2181")) + .registry("zookeeper", builder -> builder.address(ZookeeperRegistryCenterConfig.getConnectionAddress()+"?registry-type=service&subscribed-services=dubbo-provider-demo")) + .metadataReport(new MetadataReportConfig(ZookeeperRegistryCenterConfig.getConnectionAddress())) // Nacos // .registry("nacos", builder -> builder.address("nacos://127.0.0.1:8848?registry.type=service&subscribed.services=dubbo-provider-demo")) diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboServiceProviderBootstrap.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboServiceProviderBootstrap.java index 35285dd3e3..6ed451124f 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboServiceProviderBootstrap.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboServiceProviderBootstrap.java @@ -23,6 +23,7 @@ import org.apache.dubbo.config.RegistryConfig; import org.apache.dubbo.config.ServiceConfig; import org.apache.dubbo.config.bootstrap.rest.UserService; import org.apache.dubbo.config.bootstrap.rest.UserServiceImpl; +import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig; import java.util.Arrays; @@ -45,11 +46,11 @@ public class DubboServiceProviderBootstrap { RegistryConfig interfaceRegistry = new RegistryConfig(); interfaceRegistry.setId("interfaceRegistry"); - interfaceRegistry.setAddress("zookeeper://127.0.0.1:2181"); + interfaceRegistry.setAddress(ZookeeperRegistryCenterConfig.getConnectionAddress()); RegistryConfig serviceRegistry = new RegistryConfig(); serviceRegistry.setId("serviceRegistry"); - serviceRegistry.setAddress("zookeeper://127.0.0.1:2181?registry-type=service"); + serviceRegistry.setAddress(ZookeeperRegistryCenterConfig.getConnectionAddress()+"?registry-type=service"); ServiceConfig echoService = new ServiceConfig<>(); echoService.setInterface(EchoService.class.getName()); @@ -73,7 +74,7 @@ public class DubboServiceProviderBootstrap { .registries(Arrays.asList(interfaceRegistry, serviceRegistry)) // .registry(RegistryBuilder.newBuilder().address("consul://127.0.0.1:8500?registry.type=service").build()) .protocol(builder -> builder.port(-1).name("dubbo")) - .metadataReport(new MetadataReportConfig("zookeeper://127.0.0.1:2181")) + .metadataReport(new MetadataReportConfig(ZookeeperRegistryCenterConfig.getConnectionAddress())) .service(echoService) .service(userService) .start() diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboServiceProviderMinimumBootstrap.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboServiceProviderMinimumBootstrap.java index b4e3cfaf68..2d705ac09c 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboServiceProviderMinimumBootstrap.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboServiceProviderMinimumBootstrap.java @@ -18,6 +18,7 @@ package org.apache.dubbo.config.bootstrap; import org.apache.dubbo.config.bootstrap.rest.UserService; import org.apache.dubbo.config.bootstrap.rest.UserServiceImpl; +import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig; /** * TODO @@ -27,7 +28,7 @@ public class DubboServiceProviderMinimumBootstrap { public static void main(String[] args) { DubboBootstrap.getInstance() .application("dubbo-provider-demo") - .registry(builder -> builder.address("zookeeper://127.0.0.1:2181?registry-type=service")) + .registry(builder -> builder.address(ZookeeperRegistryCenterConfig.getConnectionAddress()+"?registry-type=service")) // .registry(builder -> builder.address("eureka://127.0.0.1:8761?registry-type=service")) .protocol(builder -> builder.port(-1).name("dubbo")) .service("echo", builder -> builder.interfaceClass(EchoService.class).ref(new EchoServiceImpl())) diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/MultiInstanceTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/MultiInstanceTest.java index b3a98ec5ba..4aacacd47f 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/MultiInstanceTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/MultiInstanceTest.java @@ -34,14 +34,13 @@ import org.apache.dubbo.config.api.DemoService; import org.apache.dubbo.config.api.Greeting; import org.apache.dubbo.config.mock.GreetingLocal2; import org.apache.dubbo.config.provider.impl.DemoServiceImpl; -import org.apache.dubbo.registrycenter.RegistryCenter; -import org.apache.dubbo.registrycenter.ZookeeperSingleRegistryCenter; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.FrameworkModel; import org.apache.dubbo.rpc.model.FrameworkServiceRepository; import org.apache.dubbo.rpc.model.ModuleModel; import org.apache.dubbo.rpc.model.ServiceDescriptor; import org.apache.dubbo.test.check.DubboTestChecker; +import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; @@ -63,8 +62,6 @@ public class MultiInstanceTest { private static final Logger logger = LoggerFactory.getLogger(MultiInstanceTest.class); - private static ZookeeperSingleRegistryCenter registryCenter; - private static RegistryConfig registryConfig; private static DubboTestChecker testChecker; @@ -73,13 +70,7 @@ public class MultiInstanceTest { @BeforeAll public static void beforeAll() { FrameworkModel.destroyAll(); - registryCenter = new ZookeeperSingleRegistryCenter(NetUtils.getAvailablePort()); - registryCenter.startup(); - RegistryCenter.Instance instance = registryCenter.getRegistryCenterInstance().get(0); - registryConfig = new RegistryConfig(String.format("%s://%s:%s", - instance.getType(), - instance.getHostname(), - instance.getPort())); + registryConfig = new RegistryConfig(ZookeeperRegistryCenterConfig.getConnectionAddress1()); // pre-check threads //precheckUnclosedThreads(); @@ -87,7 +78,6 @@ public class MultiInstanceTest { @AfterAll public static void afterAll() throws Exception { - registryCenter.shutdown(); FrameworkModel.destroyAll(); // check threads @@ -321,7 +311,6 @@ public class MultiInstanceTest { DubboBootstrap providerBootstrap1 = null; DubboBootstrap providerBootstrap2 = null; - ZookeeperSingleRegistryCenter registryCenter2 = null; try { @@ -349,13 +338,7 @@ public class MultiInstanceTest { Assertions.assertTrue(stackTraces1.size() > 0, "Get threads of provider app 1 failed"); // start zk server 2 - registryCenter2 = new ZookeeperSingleRegistryCenter(NetUtils.getAvailablePort()); - registryCenter2.startup(); - RegistryCenter.Instance instance = registryCenter2.getRegistryCenterInstance().get(0); - RegistryConfig registryConfig2 = new RegistryConfig(String.format("%s://%s:%s", - instance.getType(), - instance.getHostname(), - instance.getPort())); + RegistryConfig registryConfig2 = new RegistryConfig(ZookeeperRegistryCenterConfig.getConnectionAddress2()); // start provider app 2 use a difference zk server 2 ServiceConfig serviceConfig2 = new ServiceConfig(); @@ -388,7 +371,6 @@ public class MultiInstanceTest { // stop provider app 2 and check threads providerBootstrap2.stop(); // shutdown register center after dubbo application to avoid unregister services blocking - registryCenter2.shutdown(); checkUnclosedThreadsOfApp(stackTraces2, "Found unclosed threads of app 2: ", null); } finally { @@ -398,9 +380,6 @@ public class MultiInstanceTest { if (providerBootstrap2 != null) { providerBootstrap2.stop(); } - if (registryCenter2 != null) { - registryCenter2.shutdown(); - } } } diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/ZookeeperDubboServiceConsumerBootstrap.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/ZookeeperDubboServiceConsumerBootstrap.java index 27f3eb98d4..25093206f5 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/ZookeeperDubboServiceConsumerBootstrap.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/ZookeeperDubboServiceConsumerBootstrap.java @@ -17,6 +17,7 @@ package org.apache.dubbo.config.bootstrap; import org.apache.dubbo.config.bootstrap.rest.UserService; +import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig; import static org.apache.dubbo.common.constants.CommonConstants.COMPOSITE_METADATA_STORAGE_TYPE; import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_TYPE_KEY; @@ -33,7 +34,7 @@ public class ZookeeperDubboServiceConsumerBootstrap { DubboBootstrap bootstrap = DubboBootstrap.getInstance() .application("zookeeper-dubbo-consumer", app -> app.metadata(COMPOSITE_METADATA_STORAGE_TYPE)) - .registry("zookeeper", builder -> builder.address("zookeeper://127.0.0.1:2181") + .registry("zookeeper", builder -> builder.address(ZookeeperRegistryCenterConfig.getConnectionAddress()) .parameter(REGISTRY_TYPE_KEY, SERVICE_REGISTRY_TYPE) .useAsConfigCenter(true) .useAsMetadataCenter(true)) diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/compatible/DubboInterfaceConsumerBootstrap.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/compatible/DubboInterfaceConsumerBootstrap.java index 738a8812f7..d9c9c57287 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/compatible/DubboInterfaceConsumerBootstrap.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/compatible/DubboInterfaceConsumerBootstrap.java @@ -20,6 +20,7 @@ import org.apache.dubbo.config.RegistryConfig; import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.bootstrap.EchoService; import org.apache.dubbo.config.bootstrap.rest.UserService; +import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig; /** * Dubbo Provider Bootstrap @@ -31,7 +32,7 @@ public class DubboInterfaceConsumerBootstrap { public static void main(String[] args) throws Exception { RegistryConfig interfaceRegistry = new RegistryConfig(); interfaceRegistry.setId("interfaceRegistry"); - interfaceRegistry.setAddress("zookeeper://127.0.0.1:2181"); + interfaceRegistry.setAddress(ZookeeperRegistryCenterConfig.getConnectionAddress()); DubboBootstrap bootstrap = DubboBootstrap.getInstance() .application("dubbo-consumer-demo") diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/AbstractRegistryCenterExporterListener.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/AbstractRegistryCenterExporterListener.java similarity index 98% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/AbstractRegistryCenterExporterListener.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/AbstractRegistryCenterExporterListener.java index c23e400ab8..69a3d5e6fd 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/AbstractRegistryCenterExporterListener.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/AbstractRegistryCenterExporterListener.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration; +package org.apache.dubbo.config.integration; import org.apache.dubbo.rpc.Exporter; import org.apache.dubbo.rpc.ExporterListener; diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/AbstractRegistryCenterServiceListener.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/AbstractRegistryCenterServiceListener.java similarity index 97% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/AbstractRegistryCenterServiceListener.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/AbstractRegistryCenterServiceListener.java index 438e228c94..c898c91860 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/AbstractRegistryCenterServiceListener.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/AbstractRegistryCenterServiceListener.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration; +package org.apache.dubbo.config.integration; import org.apache.dubbo.config.ServiceConfig; import org.apache.dubbo.config.ServiceListener; 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/config/integration/Constants.java similarity index 95% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/Constants.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/Constants.java index 6680d31c46..1acd8304a6 100644 --- 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/config/integration/Constants.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration; +package org.apache.dubbo.config.integration; public interface Constants { 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/config/integration/IntegrationTest.java similarity index 95% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/IntegrationTest.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/IntegrationTest.java index 37ba8098df..a185231fb8 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/config/integration/IntegrationTest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration; +package org.apache.dubbo.config.integration; /** * The interface for integration testcases. diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/AbstractStorage.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/AbstractStorage.java similarity index 97% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/AbstractStorage.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/AbstractStorage.java index 7a0b9384d1..f113cde98f 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/AbstractStorage.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/AbstractStorage.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.multiple; +package org.apache.dubbo.config.integration.multiple; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/Storage.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/Storage.java similarity index 97% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/Storage.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/Storage.java index 064289c1f3..cf2d870a06 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/Storage.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/Storage.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.multiple; +package org.apache.dubbo.config.integration.multiple; /** * This interface to store the given type instance in multiple registry center. diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataExporterListener.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataExporterListener.java similarity index 89% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataExporterListener.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataExporterListener.java index 796a5e45c3..1dc3e79929 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataExporterListener.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataExporterListener.java @@ -14,11 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.multiple.exportmetadata; +package org.apache.dubbo.config.integration.multiple.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.config.integration.AbstractRegistryCenterExporterListener; import org.apache.dubbo.metadata.MetadataService; @Activate(group = CommonConstants.PROVIDER, order = 1000) diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataIntegrationTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataIntegrationTest.java similarity index 90% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataIntegrationTest.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataIntegrationTest.java index 958d558530..44684346a0 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataIntegrationTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataIntegrationTest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.multiple.exportmetadata; +package org.apache.dubbo.config.integration.multiple.exportmetadata; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.config.RegistryConfig; @@ -23,13 +23,12 @@ 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.config.integration.IntegrationTest; import org.apache.dubbo.metadata.MetadataService; -import org.apache.dubbo.registrycenter.RegistryCenter; -import org.apache.dubbo.registrycenter.ZookeeperMultipleRegistryCenter; import org.apache.dubbo.rpc.Exporter; import org.apache.dubbo.rpc.ExporterListener; import org.apache.dubbo.rpc.Filter; +import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -77,17 +76,11 @@ public class MultipleRegistryCenterExportMetadataIntegrationTest implements Inte */ private MultipleRegistryCenterExportMetadataExporterListener 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 ZookeeperMultipleRegistryCenter(); - registryCenter.startup(); // initialize service config serviceConfig = new ServiceConfig<>(); serviceConfig.setInterface(MultipleRegistryCenterExportMetadataService.class); @@ -99,13 +92,9 @@ public class MultipleRegistryCenterExportMetadataIntegrationTest implements Inte DubboBootstrap.getInstance() .application(new ApplicationConfig(PROVIDER_APPLICATION_NAME)) .protocol(new ProtocolConfig(PROTOCOL_NAME)) - .service(serviceConfig); - for (RegistryCenter.Instance instance : registryCenter.getRegistryCenterInstance()) { - DubboBootstrap.getInstance().registry(new RegistryConfig(String.format("%s://%s:%s", - instance.getType(), - instance.getHostname(), - instance.getPort()))); - } + .service(serviceConfig) + .registry(new RegistryConfig(ZookeeperRegistryCenterConfig.getConnectionAddress1())) + .registry(new RegistryConfig(ZookeeperRegistryCenterConfig.getConnectionAddress2())); } /** @@ -201,7 +190,5 @@ public class MultipleRegistryCenterExportMetadataIntegrationTest implements Inte 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/multiple/exportmetadata/MultipleRegistryCenterExportMetadataService.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataService.java similarity index 93% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataService.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataService.java index 5cd33e34cb..e6a58fea70 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataService.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataService.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.multiple.exportmetadata; +package org.apache.dubbo.config.integration.multiple.exportmetadata; /** * This interface is used to check if the exported metadata service works well or not in multiple registry center. diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataServiceImpl.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataServiceImpl.java similarity index 94% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataServiceImpl.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataServiceImpl.java index 9836d74744..a6ea4158cf 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataServiceImpl.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataServiceImpl.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.multiple.exportmetadata; +package org.apache.dubbo.config.integration.multiple.exportmetadata; /** * The simple implementation for {@link MultipleRegistryCenterExportMetadataService} diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataServiceListener.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataServiceListener.java similarity index 89% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataServiceListener.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataServiceListener.java index 13605bee08..7a057cd430 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataServiceListener.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataServiceListener.java @@ -14,10 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.multiple.exportmetadata; +package org.apache.dubbo.config.integration.multiple.exportmetadata; import org.apache.dubbo.config.ServiceListener; -import org.apache.dubbo.integration.AbstractRegistryCenterServiceListener; +import org.apache.dubbo.config.integration.AbstractRegistryCenterServiceListener; import org.apache.dubbo.metadata.MetadataService; /** diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderExporterListener.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderExporterListener.java similarity index 89% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderExporterListener.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderExporterListener.java index bf867b17e4..4aba6c9c45 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderExporterListener.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderExporterListener.java @@ -14,11 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.multiple.exportprovider; +package org.apache.dubbo.config.integration.multiple.exportprovider; import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.Activate; -import org.apache.dubbo.integration.AbstractRegistryCenterExporterListener; +import org.apache.dubbo.config.integration.AbstractRegistryCenterExporterListener; @Activate(group = CommonConstants.PROVIDER, order = 1000) public class MultipleRegistryCenterExportProviderExporterListener extends AbstractRegistryCenterExporterListener { diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderFilter.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderFilter.java similarity index 97% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderFilter.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderFilter.java index 045723870c..daf839bc3b 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderFilter.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderFilter.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.multiple.exportprovider; +package org.apache.dubbo.config.integration.multiple.exportprovider; import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.Activate; diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderIntegrationTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderIntegrationTest.java similarity index 92% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderIntegrationTest.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderIntegrationTest.java index 7b80c23ac5..3f9a4c47db 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderIntegrationTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderIntegrationTest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.multiple.exportprovider; +package org.apache.dubbo.config.integration.multiple.exportprovider; import org.apache.dubbo.common.config.configcenter.ConfigItem; import org.apache.dubbo.common.constants.CommonConstants; @@ -26,15 +26,14 @@ import org.apache.dubbo.config.RegistryConfig; import org.apache.dubbo.config.ServiceConfig; import org.apache.dubbo.config.ServiceListener; import org.apache.dubbo.config.bootstrap.DubboBootstrap; -import org.apache.dubbo.integration.IntegrationTest; +import org.apache.dubbo.config.integration.IntegrationTest; import org.apache.dubbo.metadata.ServiceNameMapping; import org.apache.dubbo.metadata.report.MetadataReportInstance; import org.apache.dubbo.registry.integration.RegistryProtocolListener; -import org.apache.dubbo.registrycenter.RegistryCenter; -import org.apache.dubbo.registrycenter.ZookeeperMultipleRegistryCenter; import org.apache.dubbo.rpc.ExporterListener; import org.apache.dubbo.rpc.Filter; import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -75,11 +74,6 @@ public class MultipleRegistryCenterExportProviderIntegrationTest implements Inte */ private ServiceConfig serviceConfig; - /** - * Define a registry center. - */ - private RegistryCenter registryCenter; - /** * Define a {@link RegistryProtocolListener} instance. */ @@ -104,8 +98,6 @@ public class MultipleRegistryCenterExportProviderIntegrationTest implements Inte public void setUp() throws Exception { logger.info(getClass().getSimpleName() + " testcase is beginning..."); DubboBootstrap.reset(); - registryCenter = new ZookeeperMultipleRegistryCenter(); - registryCenter.startup(); // initialize service config serviceConfig = new ServiceConfig<>(); serviceConfig.setInterface(MultipleRegistryCenterExportProviderService.class); @@ -116,14 +108,9 @@ public class MultipleRegistryCenterExportProviderIntegrationTest implements Inte DubboBootstrap.getInstance() .application(new ApplicationConfig(PROVIDER_APPLICATION_NAME)) .protocol(new ProtocolConfig(PROTOCOL_NAME, PROTOCOL_PORT)) - .service(serviceConfig); - for (RegistryCenter.Instance instance : registryCenter.getRegistryCenterInstance()) { - RegistryConfig registryConfig = new RegistryConfig(String.format("%s://%s:%s", - instance.getType(), - instance.getHostname(), - instance.getPort())); - DubboBootstrap.getInstance().registry(registryConfig); - } + .service(serviceConfig) + .registry(new RegistryConfig(ZookeeperRegistryCenterConfig.getConnectionAddress1())) + .registry(new RegistryConfig(ZookeeperRegistryCenterConfig.getConnectionAddress2())); } /** @@ -254,8 +241,6 @@ public class MultipleRegistryCenterExportProviderIntegrationTest implements Inte // The exported service has been unexported Assertions.assertTrue(serviceListener.getExportedServices().isEmpty()); logger.info(getClass().getSimpleName() + " testcase is ending..."); - registryCenter.shutdown(); registryProtocolListener = null; - registryCenter = null; } } diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderRegistryProtocolListener.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderRegistryProtocolListener.java similarity index 97% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderRegistryProtocolListener.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderRegistryProtocolListener.java index b4ca7b3b2d..8b6c87f985 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderRegistryProtocolListener.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderRegistryProtocolListener.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.multiple.exportprovider; +package org.apache.dubbo.config.integration.multiple.exportprovider; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.extension.Activate; diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderService.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderService.java similarity index 93% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderService.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderService.java index a933113e22..070fa6c300 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderService.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderService.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.multiple.exportprovider; +package org.apache.dubbo.config.integration.multiple.exportprovider; /** * This interface is used to check if the exported provider works well or not in multiple registry center. diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderServiceImpl.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderServiceImpl.java similarity index 94% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderServiceImpl.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderServiceImpl.java index 760c16444f..520b14b43d 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderServiceImpl.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderServiceImpl.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.multiple.exportprovider; +package org.apache.dubbo.config.integration.multiple.exportprovider; /** * The implementation of {@link MultipleRegistryCenterExportProviderService} diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderServiceListener.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderServiceListener.java similarity index 89% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderServiceListener.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderServiceListener.java index c8a6576e4d..517c608f30 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderServiceListener.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderServiceListener.java @@ -14,10 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.multiple.exportprovider; +package org.apache.dubbo.config.integration.multiple.exportprovider; import org.apache.dubbo.config.ServiceListener; -import org.apache.dubbo.integration.AbstractRegistryCenterServiceListener; +import org.apache.dubbo.config.integration.AbstractRegistryCenterServiceListener; /** * This implementation of {@link ServiceListener} is to record exported services with injvm protocol in single registry center. diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/injvm/MultipleRegistryCenterInjvmExporterListener.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmExporterListener.java similarity index 89% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/injvm/MultipleRegistryCenterInjvmExporterListener.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmExporterListener.java index 1820a12f28..ead3bb6824 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/injvm/MultipleRegistryCenterInjvmExporterListener.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmExporterListener.java @@ -14,11 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.multiple.injvm; +package org.apache.dubbo.config.integration.multiple.injvm; import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.Activate; -import org.apache.dubbo.integration.AbstractRegistryCenterExporterListener; +import org.apache.dubbo.config.integration.AbstractRegistryCenterExporterListener; @Activate(group = CommonConstants.PROVIDER, order = 1000) public class MultipleRegistryCenterInjvmExporterListener extends AbstractRegistryCenterExporterListener { diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/injvm/MultipleRegistryCenterInjvmFilter.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmFilter.java similarity index 97% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/injvm/MultipleRegistryCenterInjvmFilter.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmFilter.java index 679ff835db..cd2e87dfe5 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/injvm/MultipleRegistryCenterInjvmFilter.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmFilter.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.multiple.injvm; +package org.apache.dubbo.config.integration.multiple.injvm; import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.Activate; diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/injvm/MultipleRegistryCenterInjvmIntegrationTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmIntegrationTest.java similarity index 89% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/injvm/MultipleRegistryCenterInjvmIntegrationTest.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmIntegrationTest.java index 0c7cf66ec5..291f559787 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/injvm/MultipleRegistryCenterInjvmIntegrationTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmIntegrationTest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.multiple.injvm; +package org.apache.dubbo.config.integration.multiple.injvm; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.config.ApplicationConfig; @@ -24,11 +24,10 @@ import org.apache.dubbo.config.RegistryConfig; import org.apache.dubbo.config.ServiceConfig; import org.apache.dubbo.config.ServiceListener; import org.apache.dubbo.config.bootstrap.DubboBootstrap; -import org.apache.dubbo.integration.IntegrationTest; -import org.apache.dubbo.registrycenter.RegistryCenter; -import org.apache.dubbo.registrycenter.ZookeeperMultipleRegistryCenter; +import org.apache.dubbo.config.integration.IntegrationTest; import org.apache.dubbo.rpc.ExporterListener; import org.apache.dubbo.rpc.Filter; +import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -77,18 +76,10 @@ public class MultipleRegistryCenterInjvmIntegrationTest implements IntegrationTe */ private MultipleRegistryCenterInjvmFilter filter; - /** - * Default a registry center. - */ - private RegistryCenter registryCenter; - @BeforeEach public void setUp() throws Exception { logger.info(getClass().getSimpleName() + " testcase is beginning..."); DubboBootstrap.reset(); - //start all zookeeper services only once - registryCenter = new ZookeeperMultipleRegistryCenter(); - registryCenter.startup(); // initialize service config serviceConfig = new ServiceConfig<>(); serviceConfig.setInterface(MultipleRegistryCenterInjvmService.class); @@ -96,17 +87,12 @@ public class MultipleRegistryCenterInjvmIntegrationTest implements IntegrationTe serviceConfig.setAsync(false); serviceConfig.setScope(SCOPE_LOCAL); - // initailize bootstrap - for (RegistryCenter.Instance instance : registryCenter.getRegistryCenterInstance()) { - DubboBootstrap.getInstance().registry(new RegistryConfig(String.format("%s://%s:%s", - instance.getType(), - instance.getHostname(), - instance.getPort()))); - } DubboBootstrap.getInstance() .application(new ApplicationConfig(PROVIDER_APPLICATION_NAME)) .protocol(new ProtocolConfig("injvm")) - .service(serviceConfig); + .service(serviceConfig) + .registry(new RegistryConfig(ZookeeperRegistryCenterConfig.getConnectionAddress1())) + .registry(new RegistryConfig(ZookeeperRegistryCenterConfig.getConnectionAddress2())); } /** @@ -201,8 +187,5 @@ public class MultipleRegistryCenterInjvmIntegrationTest implements IntegrationTe Assertions.assertTrue(serviceListener.getExportedServices().isEmpty()); serviceListener = null; logger.info(getClass().getSimpleName() + " testcase is ending..."); - // destroy registry center - registryCenter.shutdown(); - registryCenter = null; } } diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/injvm/MultipleRegistryCenterInjvmService.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmService.java similarity index 94% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/injvm/MultipleRegistryCenterInjvmService.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmService.java index fba045175f..44cd81645b 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/injvm/MultipleRegistryCenterInjvmService.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmService.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.multiple.injvm; +package org.apache.dubbo.config.integration.multiple.injvm; /** * This interface is used to check if the exported injvm protocol works well or not. */ diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/injvm/MultipleRegistryCenterInjvmServiceImpl.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmServiceImpl.java similarity index 94% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/injvm/MultipleRegistryCenterInjvmServiceImpl.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmServiceImpl.java index 533da89574..7c5a16724e 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/injvm/MultipleRegistryCenterInjvmServiceImpl.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmServiceImpl.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.multiple.injvm; +package org.apache.dubbo.config.integration.multiple.injvm; /** * The simple implementation for {@link MultipleRegistryCenterInjvmService} diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/injvm/MultipleRegistryCenterInjvmServiceListener.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmServiceListener.java similarity index 89% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/injvm/MultipleRegistryCenterInjvmServiceListener.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmServiceListener.java index 766fa18382..c5bfd71204 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/injvm/MultipleRegistryCenterInjvmServiceListener.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmServiceListener.java @@ -14,10 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.multiple.injvm; +package org.apache.dubbo.config.integration.multiple.injvm; import org.apache.dubbo.config.ServiceListener; -import org.apache.dubbo.integration.AbstractRegistryCenterServiceListener; +import org.apache.dubbo.config.integration.AbstractRegistryCenterServiceListener; /** * This implementation of {@link ServiceListener} is to record exported services with injvm protocol in multiple registry center. diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/package-info.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/package-info.java similarity index 95% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/package-info.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/package-info.java index c186c7d68a..314d9de8ca 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/package-info.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/package-info.java @@ -19,4 +19,4 @@ * The one is single registry center, the other is multiple registry centers.

* The purpose of all of testcases in this package is to test for multiple registry center. */ -package org.apache.dubbo.integration.multiple; +package org.apache.dubbo.config.integration.multiple; 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/config/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryIntegrationTest.java similarity index 85% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryIntegrationTest.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryIntegrationTest.java index 2be4305f10..aa61d4a629 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/config/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryIntegrationTest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.multiple.servicediscoveryregistry; +package org.apache.dubbo.config.integration.multiple.servicediscoveryregistry; import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.ExtensionLoader; @@ -24,12 +24,11 @@ import org.apache.dubbo.config.ReferenceConfig; 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.config.integration.IntegrationTest; import org.apache.dubbo.registry.RegistryServiceListener; import org.apache.dubbo.registry.client.metadata.store.InMemoryWritableMetadataService; -import org.apache.dubbo.registrycenter.RegistryCenter; -import org.apache.dubbo.registrycenter.ZookeeperMultipleRegistryCenter; - +import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig; +import org.apache.dubbo.test.check.registrycenter.config.ZookeeperConfig; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -43,7 +42,7 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; -import static org.apache.dubbo.integration.Constants.MULTIPLE_CONFIG_CENTER_SERVICE_DISCOVERY_REGISTRY; +import static org.apache.dubbo.config.integration.Constants.MULTIPLE_CONFIG_CENTER_SERVICE_DISCOVERY_REGISTRY; /** * The testcases are only for checking the process of exporting provider using service-discovery-registry protocol. @@ -71,11 +70,6 @@ public class MultipleRegistryCenterServiceDiscoveryRegistryIntegrationTest imple */ private ServiceConfig serviceConfig; - /** - * Default a registry center. - */ - private RegistryCenter registryCenter; - /** * Define a {@link RegistryServiceListener} instance. */ @@ -95,27 +89,26 @@ public class MultipleRegistryCenterServiceDiscoveryRegistryIntegrationTest imple public void setUp() throws Exception { logger.info(getClass().getSimpleName() + " testcase is beginning..."); DubboBootstrap.reset(); - //start all zookeeper services only once - registryCenter = new ZookeeperMultipleRegistryCenter(); - registryCenter.startup(); // initialize service config serviceConfig = new ServiceConfig<>(); serviceConfig.setInterface(MultipleRegistryCenterServiceDiscoveryRegistryService.class); serviceConfig.setRef(new MultipleRegistryCenterServiceDiscoveryRegistryServiceImpl()); serviceConfig.setAsync(false); - // initialize bootstrap - for (RegistryCenter.Instance instance : registryCenter.getRegistryCenterInstance()) { - RegistryConfig registryConfig = new RegistryConfig(String.format("%s://%s:%s", - instance.getType(), - instance.getHostname(), - instance.getPort())); - Map parameters = new HashMap<>(); - parameters.put("registry.listeners", MULTIPLE_CONFIG_CENTER_SERVICE_DISCOVERY_REGISTRY); - registryConfig.updateParameters(parameters); - DubboBootstrap.getInstance().registry(registryConfig); - ports.add(instance.getPort()); - } + RegistryConfig registryConfig1 = new RegistryConfig(ZookeeperRegistryCenterConfig.getConnectionAddress1()); + Map parameters1 = new HashMap<>(); + parameters1.put("registry.listeners", MULTIPLE_CONFIG_CENTER_SERVICE_DISCOVERY_REGISTRY); + registryConfig1.updateParameters(parameters1); + DubboBootstrap.getInstance().registry(registryConfig1); + ports.add(ZookeeperConfig.DEFAULT_CLIENT_PORT_1); + + RegistryConfig registryConfig2 = new RegistryConfig(ZookeeperRegistryCenterConfig.getConnectionAddress2()); + Map parameters2 = new HashMap<>(); + parameters2.put("registry.listeners", MULTIPLE_CONFIG_CENTER_SERVICE_DISCOVERY_REGISTRY); + registryConfig2.updateParameters(parameters2); + DubboBootstrap.getInstance().registry(registryConfig2); + ports.add(ZookeeperConfig.DEFAULT_CLIENT_PORT_2); + DubboBootstrap.getInstance() .application(new ApplicationConfig(PROVIDER_APPLICATION_NAME)) .protocol(new ProtocolConfig(PROTOCOL_NAME, PROTOCOL_PORT)) @@ -218,8 +211,5 @@ public class MultipleRegistryCenterServiceDiscoveryRegistryIntegrationTest imple registryServiceListener.getStorage().clear(); registryServiceListener = null; logger.info(getClass().getSimpleName() + " testcase is ending..."); - // destroy registry center - registryCenter.shutdown(); - registryCenter = null; } } 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/config/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryRegistryServiceListener.java similarity index 96% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryRegistryServiceListener.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryRegistryServiceListener.java index 00d45f4ea3..519f75a37e 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/config/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryRegistryServiceListener.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.multiple.servicediscoveryregistry; +package org.apache.dubbo.config.integration.multiple.servicediscoveryregistry; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.extension.Activate; @@ -24,7 +24,7 @@ import org.apache.dubbo.registry.RegistryServiceListener; import org.apache.dubbo.registry.client.ServiceDiscoveryRegistry; import org.apache.dubbo.registry.client.metadata.store.InMemoryWritableMetadataService; -import static org.apache.dubbo.integration.Constants.MULTIPLE_CONFIG_CENTER_SERVICE_DISCOVERY_REGISTRY; +import static org.apache.dubbo.config.integration.Constants.MULTIPLE_CONFIG_CENTER_SERVICE_DISCOVERY_REGISTRY; @Activate(value = MULTIPLE_CONFIG_CENTER_SERVICE_DISCOVERY_REGISTRY) diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryService.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryService.java similarity index 93% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryService.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryService.java index 476ccb9d86..f5c66ab7f8 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryService.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryService.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.multiple.servicediscoveryregistry; +package org.apache.dubbo.config.integration.multiple.servicediscoveryregistry; /** * This interface is used to check if the exported service-discovery-registry protocol works well or not. */ diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryServiceImpl.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryServiceImpl.java similarity index 93% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryServiceImpl.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryServiceImpl.java index 104a5139e7..09469df5a7 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryServiceImpl.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryServiceImpl.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.multiple.servicediscoveryregistry; +package org.apache.dubbo.config.integration.multiple.servicediscoveryregistry; /** * The simple implementation for {@link MultipleRegistryCenterServiceDiscoveryRegistryService} */ diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/ServiceDiscoveryRegistryInfoWrapper.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/servicediscoveryregistry/ServiceDiscoveryRegistryInfoWrapper.java similarity index 97% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/ServiceDiscoveryRegistryInfoWrapper.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/servicediscoveryregistry/ServiceDiscoveryRegistryInfoWrapper.java index 583eec9f74..a5f35f849c 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/ServiceDiscoveryRegistryInfoWrapper.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/servicediscoveryregistry/ServiceDiscoveryRegistryInfoWrapper.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.multiple.servicediscoveryregistry; +package org.apache.dubbo.config.integration.multiple.servicediscoveryregistry; import org.apache.dubbo.registry.client.ServiceDiscoveryRegistry; import org.apache.dubbo.registry.client.metadata.store.InMemoryWritableMetadataService; diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/ServiceDiscoveryRegistryStorage.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/servicediscoveryregistry/ServiceDiscoveryRegistryStorage.java similarity index 87% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/ServiceDiscoveryRegistryStorage.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/servicediscoveryregistry/ServiceDiscoveryRegistryStorage.java index ea84beacf5..3a615f6709 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/multiple/servicediscoveryregistry/ServiceDiscoveryRegistryStorage.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/servicediscoveryregistry/ServiceDiscoveryRegistryStorage.java @@ -14,9 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.multiple.servicediscoveryregistry; +package org.apache.dubbo.config.integration.multiple.servicediscoveryregistry; -import org.apache.dubbo.integration.multiple.AbstractStorage; +import org.apache.dubbo.config.integration.multiple.AbstractStorage; /** * The storage to store {@link ServiceDiscoveryRegistryInfoWrapper} instances in multiple registry center. 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/config/integration/single/SingleRegistryCenterDubboProtocolIntegrationTest.java similarity index 95% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/SingleRegistryCenterDubboProtocolIntegrationTest.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/SingleRegistryCenterDubboProtocolIntegrationTest.java index 862a553475..5b4b8ddc24 100644 --- 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/config/integration/single/SingleRegistryCenterDubboProtocolIntegrationTest.java @@ -14,12 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.single; +package org.apache.dubbo.config.integration.single; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.ExtensionLoader; -import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.ProtocolConfig; import org.apache.dubbo.config.ReferenceConfig; @@ -27,7 +26,7 @@ import org.apache.dubbo.config.RegistryConfig; import org.apache.dubbo.config.ServiceConfig; import org.apache.dubbo.config.ServiceListener; import org.apache.dubbo.config.bootstrap.DubboBootstrap; -import org.apache.dubbo.integration.IntegrationTest; +import org.apache.dubbo.config.integration.IntegrationTest; import org.apache.dubbo.metadata.MetadataInfo; import org.apache.dubbo.metadata.WritableMetadataService; import org.apache.dubbo.registry.ListenerRegistryWrapper; @@ -38,10 +37,9 @@ import org.apache.dubbo.registry.client.metadata.store.InMemoryWritableMetadataS import org.apache.dubbo.registry.client.migration.MigrationInvoker; import org.apache.dubbo.registry.support.RegistryManager; import org.apache.dubbo.registry.zookeeper.ZookeeperServiceDiscovery; -import org.apache.dubbo.registrycenter.RegistryCenter; -import org.apache.dubbo.registrycenter.ZookeeperSingleRegistryCenter; import org.apache.dubbo.rpc.cluster.Directory; import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -101,17 +99,10 @@ public class SingleRegistryCenterDubboProtocolIntegrationTest implements Integra */ private SingleRegistryCenterExportedServiceListener singleRegistryCenterExportedServiceListener; - /** - * 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 ServiceConfig serviceConfig = new ServiceConfig<>(); serviceConfig.setInterface(SingleRegistryCenterIntegrationService.class); @@ -122,11 +113,7 @@ public class SingleRegistryCenterDubboProtocolIntegrationTest implements Integra .application(new ApplicationConfig(PROVIDER_APPLICATION_NAME)) .protocol(new ProtocolConfig(PROTOCOL_NAME, PROTOCOL_PORT)) .service(serviceConfig); - RegistryCenter.Instance instance = registryCenter.getRegistryCenterInstance().get(0); - registryConfig = new RegistryConfig(String.format("%s://%s:%s", - instance.getType(), - instance.getHostname(), - instance.getPort())); + registryConfig = new RegistryConfig(ZookeeperRegistryCenterConfig.getConnectionAddress()); DubboBootstrap.getInstance().registry(registryConfig); } @@ -386,8 +373,5 @@ public class SingleRegistryCenterDubboProtocolIntegrationTest implements Integra Assertions.assertTrue(singleRegistryCenterExportedServiceListener.getExportedServices().isEmpty()); singleRegistryCenterExportedServiceListener = null; logger.info(getClass().getSimpleName() + " testcase is ending..."); - // destroy registry center - registryCenter.shutdown(); - registryCenter = null; } } diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/SingleRegistryCenterExportedServiceListener.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/SingleRegistryCenterExportedServiceListener.java similarity index 90% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/SingleRegistryCenterExportedServiceListener.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/SingleRegistryCenterExportedServiceListener.java index 37a733a9f0..631217100b 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/SingleRegistryCenterExportedServiceListener.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/SingleRegistryCenterExportedServiceListener.java @@ -14,10 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.single; +package org.apache.dubbo.config.integration.single; import org.apache.dubbo.config.ServiceListener; -import org.apache.dubbo.integration.AbstractRegistryCenterServiceListener; +import org.apache.dubbo.config.integration.AbstractRegistryCenterServiceListener; /** * This implementation of {@link ServiceListener} is to record exported services in single registry center. diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/SingleRegistryCenterIntegrationService.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/SingleRegistryCenterIntegrationService.java similarity index 94% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/SingleRegistryCenterIntegrationService.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/SingleRegistryCenterIntegrationService.java index 2db63d3ec5..3b83860f4e 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/SingleRegistryCenterIntegrationService.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/SingleRegistryCenterIntegrationService.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.single; +package org.apache.dubbo.config.integration.single; /** * This interface for integration testcases in single registry center. diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/SingleRegistryCenterIntegrationServiceImpl.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/SingleRegistryCenterIntegrationServiceImpl.java similarity index 96% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/SingleRegistryCenterIntegrationServiceImpl.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/SingleRegistryCenterIntegrationServiceImpl.java index 99e5d8a349..eba33040ee 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/SingleRegistryCenterIntegrationServiceImpl.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/SingleRegistryCenterIntegrationServiceImpl.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.single; +package org.apache.dubbo.config.integration.single; import org.slf4j.Logger; import org.slf4j.LoggerFactory; 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/config/integration/single/exportmetadata/SingleRegistryCenterExportMetadataExporterListener.java similarity index 89% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportmetadata/SingleRegistryCenterExportMetadataExporterListener.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportmetadata/SingleRegistryCenterExportMetadataExporterListener.java index 151f5724ea..ad75d9c3e0 100644 --- 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/config/integration/single/exportmetadata/SingleRegistryCenterExportMetadataExporterListener.java @@ -14,11 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.single.exportmetadata; +package org.apache.dubbo.config.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.config.integration.AbstractRegistryCenterExporterListener; import org.apache.dubbo.metadata.MetadataService; @Activate(group = CommonConstants.PROVIDER, order = 1000) 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/config/integration/single/exportmetadata/SingleRegistryCenterExportMetadataIntegrationTest.java similarity index 90% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportmetadata/SingleRegistryCenterExportMetadataIntegrationTest.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportmetadata/SingleRegistryCenterExportMetadataIntegrationTest.java index 0306a5dac8..bfab1a6ef1 100644 --- 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/config/integration/single/exportmetadata/SingleRegistryCenterExportMetadataIntegrationTest.java @@ -14,23 +14,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.single.exportmetadata; +package org.apache.dubbo.config.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.config.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.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -78,17 +76,10 @@ public class SingleRegistryCenterExportMetadataIntegrationTest implements Integr */ 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); @@ -101,11 +92,7 @@ public class SingleRegistryCenterExportMetadataIntegrationTest implements Integr .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())); + RegistryConfig registryConfig = new RegistryConfig(ZookeeperRegistryCenterConfig.getConnectionAddress()); DubboBootstrap.getInstance().registry(registryConfig); } @@ -199,7 +186,5 @@ public class SingleRegistryCenterExportMetadataIntegrationTest implements Integr 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/config/integration/single/exportmetadata/SingleRegistryCenterExportMetadataService.java similarity index 93% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportmetadata/SingleRegistryCenterExportMetadataService.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportmetadata/SingleRegistryCenterExportMetadataService.java index 22f2ab0709..727a58bdb3 100644 --- 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/config/integration/single/exportmetadata/SingleRegistryCenterExportMetadataService.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.single.exportmetadata; +package org.apache.dubbo.config.integration.single.exportmetadata; /** * This interface is used to check if the exported metadata service works well or not. 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/config/integration/single/exportmetadata/SingleRegistryCenterExportMetadataServiceImpl.java similarity index 94% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportmetadata/SingleRegistryCenterExportMetadataServiceImpl.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportmetadata/SingleRegistryCenterExportMetadataServiceImpl.java index 338a09ca37..9bc4d0cf35 100644 --- 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/config/integration/single/exportmetadata/SingleRegistryCenterExportMetadataServiceImpl.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.single.exportmetadata; +package org.apache.dubbo.config.integration.single.exportmetadata; /** * The simple implementation for {@link SingleRegistryCenterExportMetadataService} 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/config/integration/single/exportmetadata/SingleRegistryCenterExportMetadataServiceListener.java similarity index 89% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportmetadata/SingleRegistryCenterExportMetadataServiceListener.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportmetadata/SingleRegistryCenterExportMetadataServiceListener.java index 6008b4d293..42b5d97864 100644 --- 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/config/integration/single/exportmetadata/SingleRegistryCenterExportMetadataServiceListener.java @@ -14,10 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.single.exportmetadata; +package org.apache.dubbo.config.integration.single.exportmetadata; import org.apache.dubbo.config.ServiceListener; -import org.apache.dubbo.integration.AbstractRegistryCenterServiceListener; +import org.apache.dubbo.config.integration.AbstractRegistryCenterServiceListener; import org.apache.dubbo.metadata.MetadataService; /** diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderExporterListener.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderExporterListener.java similarity index 89% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderExporterListener.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderExporterListener.java index 1eca462d5f..3da45677c8 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderExporterListener.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderExporterListener.java @@ -14,11 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.single.exportprovider; +package org.apache.dubbo.config.integration.single.exportprovider; import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.Activate; -import org.apache.dubbo.integration.AbstractRegistryCenterExporterListener; +import org.apache.dubbo.config.integration.AbstractRegistryCenterExporterListener; @Activate(group = CommonConstants.PROVIDER, order = 1000) public class SingleRegistryCenterExportProviderExporterListener extends AbstractRegistryCenterExporterListener { diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderFilter.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderFilter.java similarity index 97% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderFilter.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderFilter.java index 26bbcda57f..caf9963de6 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderFilter.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderFilter.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.single.exportprovider; +package org.apache.dubbo.config.integration.single.exportprovider; import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.Activate; 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/config/integration/single/exportprovider/SingleRegistryCenterExportProviderIntegrationTest.java similarity index 92% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderIntegrationTest.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderIntegrationTest.java index 5a92db8f19..3c9b9cb3cd 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/config/integration/single/exportprovider/SingleRegistryCenterExportProviderIntegrationTest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.single.exportprovider; +package org.apache.dubbo.config.integration.single.exportprovider; import org.apache.dubbo.common.config.configcenter.ConfigItem; import org.apache.dubbo.common.constants.CommonConstants; @@ -26,15 +26,14 @@ import org.apache.dubbo.config.RegistryConfig; import org.apache.dubbo.config.ServiceConfig; import org.apache.dubbo.config.ServiceListener; import org.apache.dubbo.config.bootstrap.DubboBootstrap; -import org.apache.dubbo.integration.IntegrationTest; +import org.apache.dubbo.config.integration.IntegrationTest; import org.apache.dubbo.metadata.ServiceNameMapping; import org.apache.dubbo.metadata.report.MetadataReportInstance; import org.apache.dubbo.registry.integration.RegistryProtocolListener; -import org.apache.dubbo.registrycenter.RegistryCenter; -import org.apache.dubbo.registrycenter.ZookeeperMultipleRegistryCenter; import org.apache.dubbo.rpc.ExporterListener; import org.apache.dubbo.rpc.Filter; import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -47,7 +46,7 @@ import java.util.HashMap; import java.util.Map; import static org.apache.dubbo.common.constants.CommonConstants.REGISTRY_PROTOCOL_LISTENER_KEY; -import static org.apache.dubbo.integration.Constants.SINGLE_CONFIG_CENTER_EXPORT_PROVIDER; +import static org.apache.dubbo.config.integration.Constants.SINGLE_CONFIG_CENTER_EXPORT_PROVIDER; import static org.apache.dubbo.rpc.Constants.SCOPE_LOCAL; /** @@ -76,11 +75,6 @@ public class SingleRegistryCenterExportProviderIntegrationTest implements Integr */ private ServiceConfig serviceConfig; - /** - * Define a registry center. - */ - private RegistryCenter registryCenter; - /** * Define a {@link RegistryProtocolListener} instance. */ @@ -105,8 +99,6 @@ public class SingleRegistryCenterExportProviderIntegrationTest implements Integr public void setUp() throws Exception { logger.info(getClass().getSimpleName() + " testcase is beginning..."); DubboBootstrap.reset(); - registryCenter = new ZookeeperMultipleRegistryCenter(); - registryCenter.startup(); // initialize service config serviceConfig = new ServiceConfig<>(); serviceConfig.setInterface(SingleRegistryCenterExportProviderService.class); @@ -118,12 +110,8 @@ public class SingleRegistryCenterExportProviderIntegrationTest implements Integr .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())); + RegistryConfig registryConfig = new RegistryConfig(ZookeeperRegistryCenterConfig.getConnectionAddress()); Map parameters = new HashMap<>(); parameters.put(REGISTRY_PROTOCOL_LISTENER_KEY, "singleConfigCenterExportProvider"); registryConfig.updateParameters(parameters); @@ -253,8 +241,6 @@ public class SingleRegistryCenterExportProviderIntegrationTest implements Integr // The exported service has been unexported Assertions.assertTrue(serviceListener.getExportedServices().isEmpty()); logger.info(getClass().getSimpleName() + " testcase is ending..."); - registryCenter.shutdown(); registryProtocolListener = null; - registryCenter = null; } } 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/config/integration/single/exportprovider/SingleRegistryCenterExportProviderRegistryProtocolListener.java similarity index 93% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderRegistryProtocolListener.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderRegistryProtocolListener.java index 09b973da1c..c7de521d5b 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/config/integration/single/exportprovider/SingleRegistryCenterExportProviderRegistryProtocolListener.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.single.exportprovider; +package org.apache.dubbo.config.integration.single.exportprovider; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.extension.Activate; @@ -24,7 +24,7 @@ import org.apache.dubbo.registry.integration.RegistryProtocolListener; 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; +import static org.apache.dubbo.config.integration.Constants.SINGLE_CONFIG_CENTER_EXPORT_PROVIDER; /** * The {@link RegistryProtocolListener} for {@link SingleRegistryCenterExportProviderService} diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderService.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderService.java similarity index 93% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderService.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderService.java index 4ea9980782..c23214cf16 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderService.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderService.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.single.exportprovider; +package org.apache.dubbo.config.integration.single.exportprovider; /** * This interface is used to check if the exported provider works well or not. diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderServiceImpl.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderServiceImpl.java similarity index 94% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderServiceImpl.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderServiceImpl.java index 01aad07229..f0fa56d882 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderServiceImpl.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderServiceImpl.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.single.exportprovider; +package org.apache.dubbo.config.integration.single.exportprovider; /** * The implementation of {@link SingleRegistryCenterExportProviderService} diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderServiceListener.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderServiceListener.java similarity index 89% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderServiceListener.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderServiceListener.java index 1eefe4de8c..55ad2ebf3f 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderServiceListener.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderServiceListener.java @@ -14,10 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.single.exportprovider; +package org.apache.dubbo.config.integration.single.exportprovider; import org.apache.dubbo.config.ServiceListener; -import org.apache.dubbo.integration.AbstractRegistryCenterServiceListener; +import org.apache.dubbo.config.integration.AbstractRegistryCenterServiceListener; /** * This implementation of {@link ServiceListener} is to record exported services with injvm protocol in single registry center. diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/injvm/SingleRegistryCenterInjvmExporterListener.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmExporterListener.java similarity index 89% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/injvm/SingleRegistryCenterInjvmExporterListener.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmExporterListener.java index 4edec5fdef..3d9085cfc2 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/injvm/SingleRegistryCenterInjvmExporterListener.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmExporterListener.java @@ -14,11 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.single.injvm; +package org.apache.dubbo.config.integration.single.injvm; import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.Activate; -import org.apache.dubbo.integration.AbstractRegistryCenterExporterListener; +import org.apache.dubbo.config.integration.AbstractRegistryCenterExporterListener; @Activate(group = CommonConstants.PROVIDER, order = 1000) public class SingleRegistryCenterInjvmExporterListener extends AbstractRegistryCenterExporterListener { diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/injvm/SingleRegistryCenterInjvmFilter.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmFilter.java similarity index 97% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/injvm/SingleRegistryCenterInjvmFilter.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmFilter.java index 6580b7e9a0..48b56df8b8 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/injvm/SingleRegistryCenterInjvmFilter.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmFilter.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.single.injvm; +package org.apache.dubbo.config.integration.single.injvm; import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.Activate; diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/injvm/SingleRegistryCenterInjvmIntegrationTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmIntegrationTest.java similarity index 90% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/injvm/SingleRegistryCenterInjvmIntegrationTest.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmIntegrationTest.java index c13fcab02b..4e1bab97f6 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/injvm/SingleRegistryCenterInjvmIntegrationTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmIntegrationTest.java @@ -14,10 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.single.injvm; +package org.apache.dubbo.config.integration.single.injvm; import org.apache.dubbo.common.extension.ExtensionLoader; -import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.ProtocolConfig; import org.apache.dubbo.config.ReferenceConfig; @@ -25,11 +24,10 @@ import org.apache.dubbo.config.RegistryConfig; import org.apache.dubbo.config.ServiceConfig; import org.apache.dubbo.config.ServiceListener; import org.apache.dubbo.config.bootstrap.DubboBootstrap; -import org.apache.dubbo.integration.IntegrationTest; -import org.apache.dubbo.registrycenter.RegistryCenter; -import org.apache.dubbo.registrycenter.ZookeeperSingleRegistryCenter; +import org.apache.dubbo.config.integration.IntegrationTest; import org.apache.dubbo.rpc.ExporterListener; import org.apache.dubbo.rpc.Filter; +import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -77,17 +75,10 @@ public class SingleRegistryCenterInjvmIntegrationTest implements IntegrationTest */ private SingleRegistryCenterInjvmFilter filter; - /** - * 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(SingleRegistryCenterInjvmService.class); @@ -100,11 +91,7 @@ public class SingleRegistryCenterInjvmIntegrationTest implements IntegrationTest .application(new ApplicationConfig(PROVIDER_APPLICATION_NAME)) .protocol(new ProtocolConfig("injvm")) .service(serviceConfig); - RegistryCenter.Instance instance = registryCenter.getRegistryCenterInstance().get(0); - RegistryConfig registryConfig = new RegistryConfig(String.format("%s://%s:%s", - instance.getType(), - instance.getHostname(), - instance.getPort())); + RegistryConfig registryConfig = new RegistryConfig(ZookeeperRegistryCenterConfig.getConnectionAddress()); DubboBootstrap.getInstance().registry(registryConfig); } @@ -199,7 +186,5 @@ public class SingleRegistryCenterInjvmIntegrationTest implements IntegrationTest 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/injvm/SingleRegistryCenterInjvmService.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmService.java similarity index 94% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/injvm/SingleRegistryCenterInjvmService.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmService.java index 916ca69cf2..078338f554 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/injvm/SingleRegistryCenterInjvmService.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmService.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.single.injvm; +package org.apache.dubbo.config.integration.single.injvm; /** * This interface is used to check if the exported injvm protocol works well or not. diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/injvm/SingleRegistryCenterInjvmServiceImpl.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmServiceImpl.java similarity index 95% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/injvm/SingleRegistryCenterInjvmServiceImpl.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmServiceImpl.java index c1f6bda95c..88f82105a5 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/injvm/SingleRegistryCenterInjvmServiceImpl.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmServiceImpl.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.single.injvm; +package org.apache.dubbo.config.integration.single.injvm; /** * The simple implementation for {@link SingleRegistryCenterInjvmService} diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/injvm/SingleRegistryCenterInjvmServiceListener.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmServiceListener.java similarity index 89% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/injvm/SingleRegistryCenterInjvmServiceListener.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmServiceListener.java index b1ff898c9e..b56e1cc21e 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/injvm/SingleRegistryCenterInjvmServiceListener.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmServiceListener.java @@ -14,10 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.integration.single.injvm; +package org.apache.dubbo.config.integration.single.injvm; import org.apache.dubbo.config.ServiceListener; -import org.apache.dubbo.integration.AbstractRegistryCenterServiceListener; +import org.apache.dubbo.config.integration.AbstractRegistryCenterServiceListener; /** * This implementation of {@link ServiceListener} is to record exported services with injvm protocol in single registry center. diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/package-info.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/package-info.java similarity index 95% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/package-info.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/package-info.java index ab1dda23e5..3dccb4fbf7 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/package-info.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/package-info.java @@ -19,4 +19,4 @@ * The one is single registry center, the other is multiple registry centers.

* The purpose of all of testcases in this package is to test for single registry center. */ -package org.apache.dubbo.integration.single; +package org.apache.dubbo.config.integration.single; diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/metadata/MetadataServiceExporterTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/metadata/MetadataServiceExporterTest.java similarity index 93% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/metadata/MetadataServiceExporterTest.java rename to dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/metadata/MetadataServiceExporterTest.java index abf99c1045..da704e4332 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/metadata/MetadataServiceExporterTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/metadata/MetadataServiceExporterTest.java @@ -14,23 +14,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.metadata; +package org.apache.dubbo.config.metadata; import org.apache.dubbo.common.URL; -import org.apache.dubbo.common.utils.NetUtils; 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.api.DemoService; import org.apache.dubbo.config.bootstrap.DubboBootstrap; -import org.apache.dubbo.config.metadata.ConfigurableMetadataServiceExporter; import org.apache.dubbo.config.provider.impl.DemoServiceImpl; -import org.apache.dubbo.registrycenter.RegistryCenter; -import org.apache.dubbo.registrycenter.ZookeeperSingleRegistryCenter; +import org.apache.dubbo.metadata.MetadataService; +import org.apache.dubbo.metadata.MetadataServiceExporter; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.FrameworkModel; - +import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -241,20 +239,12 @@ public class MetadataServiceExporterTest { // assertFalse(exporter.isExported()); // } - private static ZookeeperSingleRegistryCenter registryCenter; private static RegistryConfig registryConfig; @BeforeAll public static void beforeAll() { FrameworkModel.destroyAll(); - registryCenter = new ZookeeperSingleRegistryCenter(NetUtils.getAvailablePort()); - registryCenter.startup(); - RegistryCenter.Instance instance = registryCenter.getRegistryCenterInstance().get(0); - registryConfig = new RegistryConfig(String.format("%s://%s:%s", - instance.getType(), - instance.getHostname(), - instance.getPort())); - + registryConfig = new RegistryConfig(ZookeeperRegistryCenterConfig.getConnectionAddress()); // pre-check threads //precheckUnclosedThreads(); } diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/registrycenter/AbstractRegistryCenter.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/registrycenter/AbstractRegistryCenter.java deleted file mode 100644 index 3ef9e58034..0000000000 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/registrycenter/AbstractRegistryCenter.java +++ /dev/null @@ -1,107 +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.registrycenter; - -import org.apache.curator.test.InstanceSpec; - -import java.io.File; -import java.util.HashMap; -import java.util.Map; - -/** - * The abstraction of {@link RegistryCenter} implements the basic methods. - */ -abstract class AbstractRegistryCenter implements RegistryCenter { - - /** - * The default data directory is null - */ - private static final File DEFAULT_DATA_DIRECTORY = null; - - /** - * The default election port is -1. - */ - private static final int DEFAULT_ELECTION_PORT = -1; - - /** - * The default quorum port is -1. - */ - private static final int DEFAULT_QUORUM_PORT = -1; - - /** - * The default value is true. - */ - private static final boolean DEFAULT_DELETE_DATA_DIRECTORY_ON_CLOSE = true; - - /** - * The default service id is -1. - */ - private static final int DEFAULT_SERVER_ID = -1; - - /** - * The default tick time is 5000 - */ - private static final int DEFAULT_TICK_TIME = 5 * 1000; - - /** - * The default value is -1. - */ - private static final int DEFAULT_MAX_CLIENT_CNXNS = 200; - - /** - * The minimum session timeout. - */ - private static final int DEFAULT_MINIMUM_SESSION_TIMEOUT = DEFAULT_TICK_TIME * 2; - - /** - * The maximum session timeout. - */ - private static final int DEFAULT_MAXIMUM_SESSION_TIMEOUT = 60 * 1000; - - /** - * The default customer properties. - */ - private static final Map DEFAULT_CUSTOM_PROPERTIES = new HashMap<>(2); - - /** - * The default hostname. - */ - private static final String DEFAULT_HOSTNAME = "127.0.0.1"; - - static { - DEFAULT_CUSTOM_PROPERTIES.put("minSessionTimeout", DEFAULT_MINIMUM_SESSION_TIMEOUT); - DEFAULT_CUSTOM_PROPERTIES.put("maxSessionTimeout", DEFAULT_MAXIMUM_SESSION_TIMEOUT); - } - - /** - * Create an {@link InstanceSpec} instance to initialize {@link org.apache.curator.test.TestingServer} - * - * @param port the zookeeper server's port. - */ - protected InstanceSpec createInstanceSpec(int port) { - return new InstanceSpec(DEFAULT_DATA_DIRECTORY, - port, - DEFAULT_ELECTION_PORT, - DEFAULT_QUORUM_PORT, - DEFAULT_DELETE_DATA_DIRECTORY_ON_CLOSE, - DEFAULT_SERVER_ID, - DEFAULT_TICK_TIME, - DEFAULT_MAX_CLIENT_CNXNS, - DEFAULT_CUSTOM_PROPERTIES, - DEFAULT_HOSTNAME); - } -} diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/registrycenter/RegistryCenter.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/registrycenter/RegistryCenter.java deleted file mode 100644 index fd95509b10..0000000000 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/registrycenter/RegistryCenter.java +++ /dev/null @@ -1,70 +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.registrycenter; - -import org.apache.dubbo.rpc.RpcException; - -import java.util.List; - -/** - * The mock registry center. - */ -public interface RegistryCenter { - - /** - * Start the registry center. - * - * @throws RpcException when an exception occurred - */ - void startup() throws RpcException; - - /** - * Returns the registry center instance. - *

This method can be called only after {@link #startup()} is called

- * - * @throws RpcException when an exception occurred - */ - List getRegistryCenterInstance() throws RpcException; - - /** - * Stop the registry center. - * - * @throws RpcException when an exception occurred - */ - void shutdown() throws RpcException; - - /** - * The registry center instance. - */ - interface Instance { - - /** - * Returns the registry center type. - */ - String getType(); - - /** - * Returns the hostname of registry center. - */ - String getHostname(); - - /** - * Returns the port of registry center. - */ - int getPort(); - } -} diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/registrycenter/ZookeeperRegistryCenter.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/registrycenter/ZookeeperRegistryCenter.java deleted file mode 100644 index 2f00cc3cb8..0000000000 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/registrycenter/ZookeeperRegistryCenter.java +++ /dev/null @@ -1,142 +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.registrycenter; - -import org.apache.curator.test.InstanceSpec; -import org.apache.curator.test.TestingServer; -import org.apache.dubbo.common.logger.Logger; -import org.apache.dubbo.common.logger.LoggerFactory; -import org.apache.dubbo.rpc.RpcException; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; - -/** - * The default implementation of registry center can support single and multiple registry center. - *

Each port represents an instance. You can provide multiple ports to build multiple registry center, - * if you want to create multiple registry center - */ -class ZookeeperRegistryCenter extends AbstractRegistryCenter { - - /** - * Initialize the default registry center. - * - * @param ports the registry center's ports. - */ - public ZookeeperRegistryCenter(int... ports) { - this.ports = ports; - this.instanceSpecs = new ArrayList<>(this.ports.length); - this.zookeeperServers = new ArrayList<>(this.ports.length); - } - - private static final Logger logger = LoggerFactory.getLogger(ZookeeperRegistryCenter.class); - - /** - * The type of the registry center. - */ - private static final String DEFAULT_REGISTRY_CENTER_TYPE = "zookeeper"; - - private int[] ports; - - private List instanceSpecs; - - private List zookeeperServers; - - private AtomicBoolean started = new AtomicBoolean(false); - - /** - * {@inheritDoc} - */ - @Override - public void startup() throws RpcException { - try { - if (started.compareAndSet(false, true)) { - logger.info("The ZookeeperRegistryCenter is starting..."); - for (int port : this.ports) { - InstanceSpec instanceSpec = this.createInstanceSpec(port); - this.instanceSpecs.add(instanceSpec); - this.zookeeperServers.add(new TestingServer(instanceSpec, true)); - } - logger.info("The ZookeeperRegistryCenter is started successfully"); - } - } catch (Exception exception) { - started.set(false); - throw new RpcException("Failed to initialize ZookeeperRegistryCenter instance", exception); - } - } - - /** - * {@inheritDoc} - */ - @Override - public List getRegistryCenterInstance() throws RpcException { - this.startup(); - List instances = new ArrayList<>(this.instanceSpecs.size()); - for (InstanceSpec instanceSpec : this.instanceSpecs) { - instances.add(new Instance() { - @Override - public String getType() { - return DEFAULT_REGISTRY_CENTER_TYPE; - } - - @Override - public String getHostname() { - return instanceSpec.getHostname(); - } - - @Override - public int getPort() { - return instanceSpec.getPort(); - } - }); - } - return instances; - } - - /** - * {@inheritDoc} - */ - @Override - public void shutdown() throws RpcException { - logger.info("The ZookeeperRegistryCenter is stopping..."); - List exceptions = new ArrayList<>(this.zookeeperServers.size()); - for (TestingServer testingServer : this.zookeeperServers) { - try { - testingServer.close(); - logger.info(String.format("The zookeeper instance of %s is shutdown successfully", - testingServer.getConnectString())); - } catch (IOException exception) { - RpcException rpcException = new RpcException(String.format("Failed to close zookeeper instance of %s", - testingServer.getConnectString()), - exception); - exceptions.add(rpcException); - logger.error(rpcException); - } - } - this.instanceSpecs.clear(); - this.zookeeperServers.clear(); - if (!exceptions.isEmpty()) { - logger.info("The ZookeeperRegistryCenter failed to close."); - // throw any one of exceptions - throw exceptions.get(0); - } else { - logger.info("The ZookeeperRegistryCenter close successfully."); - } - } -} 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 6aa34fa3bd..2653337ca3 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 @@ -1,8 +1,8 @@ mock=org.apache.dubbo.config.mock.MockServiceListener -exported=org.apache.dubbo.integration.single.SingleRegistryCenterExportedServiceListener -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 -multipleConfigCenterExportMetadata=org.apache.dubbo.integration.multiple.exportmetadata.MultipleRegistryCenterExportMetadataServiceListener -multipleConfigCenterExportProvider=org.apache.dubbo.integration.multiple.exportprovider.MultipleRegistryCenterExportProviderServiceListener +exported=org.apache.dubbo.config.integration.single.SingleRegistryCenterExportedServiceListener +singleConfigCenterInjvm=org.apache.dubbo.config.integration.single.injvm.SingleRegistryCenterInjvmServiceListener +multipleConfigCenterInjvm=org.apache.dubbo.config.integration.multiple.injvm.MultipleRegistryCenterInjvmServiceListener +singleConfigCenterExportProvider=org.apache.dubbo.config.integration.single.exportprovider.SingleRegistryCenterExportProviderServiceListener +singleConfigCenterExportMetadata=org.apache.dubbo.config.integration.single.exportmetadata.SingleRegistryCenterExportMetadataServiceListener +multipleConfigCenterExportMetadata=org.apache.dubbo.config.integration.multiple.exportmetadata.MultipleRegistryCenterExportMetadataServiceListener +multipleConfigCenterExportProvider=org.apache.dubbo.config.integration.multiple.exportprovider.MultipleRegistryCenterExportProviderServiceListener 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 530f279c55..460ffb33f6 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 +1 @@ -multipleConfigCenterServiceDiscoveryRegistry=org.apache.dubbo.integration.multiple.servicediscoveryregistry.MultipleRegistryCenterServiceDiscoveryRegistryRegistryServiceListener +multipleConfigCenterServiceDiscoveryRegistry=org.apache.dubbo.config.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 6ad6a1a66d..11d11d061f 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,2 +1,2 @@ -singleConfigCenterExportProvider=org.apache.dubbo.integration.single.exportprovider.SingleRegistryCenterExportProviderRegistryProtocolListener -multipleConfigCenterExportProvider=org.apache.dubbo.integration.multiple.exportprovider.MultipleRegistryCenterExportProviderRegistryProtocolListener +singleConfigCenterExportProvider=org.apache.dubbo.config.integration.single.exportprovider.SingleRegistryCenterExportProviderRegistryProtocolListener +multipleConfigCenterExportProvider=org.apache.dubbo.config.integration.multiple.exportprovider.MultipleRegistryCenterExportProviderRegistryProtocolListener 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 b76b514569..ad30773e0b 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,7 +1,7 @@ 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 -multipleConfigCenterExportMetadata=org.apache.dubbo.integration.multiple.exportmetadata.MultipleRegistryCenterExportMetadataExporterListener -multipleConfigCenterExportProvider=org.apache.dubbo.integration.multiple.exportprovider.MultipleRegistryCenterExportProviderExporterListener +singleConfigCenterInjvm=org.apache.dubbo.config.integration.single.injvm.SingleRegistryCenterInjvmExporterListener +multipleConfigCenterInjvm=org.apache.dubbo.config.integration.multiple.injvm.MultipleRegistryCenterInjvmExporterListener +singleConfigCenterExportProvider=org.apache.dubbo.config.integration.single.exportprovider.SingleRegistryCenterExportProviderExporterListener +singleConfigCenterExportMetadata=org.apache.dubbo.config.integration.single.exportmetadata.SingleRegistryCenterExportMetadataExporterListener +multipleConfigCenterExportMetadata=org.apache.dubbo.config.integration.multiple.exportmetadata.MultipleRegistryCenterExportMetadataExporterListener +multipleConfigCenterExportProvider=org.apache.dubbo.config.integration.multiple.exportprovider.MultipleRegistryCenterExportProviderExporterListener diff --git a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.rpc.Filter b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.rpc.Filter index 94e6e01801..ca8bdf8ae6 100644 --- a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.rpc.Filter +++ b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/org.apache.dubbo.rpc.Filter @@ -1,5 +1,5 @@ mockfilter=org.apache.dubbo.config.mock.MockFilter -singleConfigCenterInjvm=org.apache.dubbo.integration.single.injvm.SingleRegistryCenterInjvmFilter -multipleConfigCenterInjvm=org.apache.dubbo.integration.multiple.injvm.MultipleRegistryCenterInjvmFilter -singleConfigCenterExportProvider=org.apache.dubbo.integration.single.exportprovider.SingleRegistryCenterExportProviderFilter -multipleConfigCenterExportProvider=org.apache.dubbo.integration.multiple.exportprovider.MultipleRegistryCenterExportProviderFilter +singleConfigCenterInjvm=org.apache.dubbo.config.integration.single.injvm.SingleRegistryCenterInjvmFilter +multipleConfigCenterInjvm=org.apache.dubbo.config.integration.multiple.injvm.MultipleRegistryCenterInjvmFilter +singleConfigCenterExportProvider=org.apache.dubbo.config.integration.single.exportprovider.SingleRegistryCenterExportProviderFilter +multipleConfigCenterExportProvider=org.apache.dubbo.config.integration.multiple.exportprovider.MultipleRegistryCenterExportProviderFilter diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java index ff03bd8566..027e365b0c 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java @@ -43,8 +43,6 @@ import org.apache.dubbo.config.spring.impl.HelloServiceImpl; import org.apache.dubbo.config.spring.impl.NotifyService; import org.apache.dubbo.config.spring.registry.MockRegistry; import org.apache.dubbo.config.spring.registry.MockRegistryFactory; -import org.apache.dubbo.config.spring.registrycenter.RegistryCenter; -import org.apache.dubbo.config.spring.registrycenter.ZookeeperSingleRegistryCenter; import org.apache.dubbo.registry.Registry; import org.apache.dubbo.registry.RegistryService; import org.apache.dubbo.rpc.Exporter; @@ -86,19 +84,6 @@ public class ConfigTest { private static String resourcePath = ConfigTest.class.getPackage().getName().replace('.', '/'); - private static RegistryCenter singleRegistryCenter; - - @BeforeAll - public static void beforeAll() { - singleRegistryCenter = new ZookeeperSingleRegistryCenter(); - singleRegistryCenter.startup(); - } - - @AfterAll - public static void afterAll() { - singleRegistryCenter.shutdown(); - } - @BeforeEach public void setUp() { SysProps.clear(); diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/JavaConfigBeanTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/JavaConfigBeanTest.java index abc20c3ba7..abd2f25b90 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/JavaConfigBeanTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/JavaConfigBeanTest.java @@ -29,14 +29,11 @@ import org.apache.dubbo.config.context.ModuleConfigManager; import org.apache.dubbo.config.spring.api.DemoService; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.apache.dubbo.config.spring.impl.DemoServiceImpl; -import org.apache.dubbo.config.spring.registrycenter.RegistryCenter; -import org.apache.dubbo.config.spring.registrycenter.ZookeeperSingleRegistryCenter; import org.apache.dubbo.rpc.Constants; import org.apache.dubbo.rpc.model.ApplicationModel; -import org.junit.jupiter.api.AfterAll; +import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -50,18 +47,6 @@ public class JavaConfigBeanTest { private static final String MY_PROTOCOL_ID = "myProtocol"; private static final String MY_REGISTRY_ID = "my-registry"; - private static RegistryCenter singleRegistryCenter; - - @BeforeAll - public static void beforeAll() { - singleRegistryCenter = new ZookeeperSingleRegistryCenter(); - singleRegistryCenter.startup(); - } - - @AfterAll - public static void afterAll() { - singleRegistryCenter.shutdown(); - } @BeforeEach public void beforeEach() { @@ -80,7 +65,7 @@ public class JavaConfigBeanTest { SysProps.setProperty("dubbo.application.qos-enable", "false"); SysProps.setProperty("dubbo.protocol.name", "dubbo"); SysProps.setProperty("dubbo.protocol.port", "2346"); - String registryAddress = "zookeeper://127.0.0.1:2181"; + String registryAddress = ZookeeperRegistryCenterConfig.getConnectionAddress(); SysProps.setProperty("dubbo.registry.address", registryAddress); SysProps.setProperty("dubbo.provider.group", "test"); diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/MethodConfigCallbackTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/MethodConfigCallbackTest.java index ce0b78cebd..ccb70c9080 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/MethodConfigCallbackTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/MethodConfigCallbackTest.java @@ -23,8 +23,6 @@ import org.apache.dubbo.config.spring.api.HelloService; import org.apache.dubbo.config.spring.api.MethodCallback; import org.apache.dubbo.config.spring.context.annotation.provider.ProviderConfiguration; import org.apache.dubbo.config.spring.impl.MethodCallbackImpl; -import org.apache.dubbo.config.spring.registrycenter.RegistryCenter; -import org.apache.dubbo.config.spring.registrycenter.ZookeeperSingleRegistryCenter; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -49,25 +47,20 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; }) @TestPropertySource(properties = { "dubbo.protocol.port=-1", - "dubbo.registry.address=zookeeper://127.0.0.1:2181" + "dubbo.registry.address=${zookeeper.connection.address}" }) @EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) public class MethodConfigCallbackTest { - private static RegistryCenter singleRegistryCenter; - @BeforeAll public static void beforeAll() { - singleRegistryCenter = new ZookeeperSingleRegistryCenter(); - singleRegistryCenter.startup(); DubboBootstrap.reset(); } @AfterAll public static void afterAll() { DubboBootstrap.reset(); - singleRegistryCenter.shutdown(); } @Autowired diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/boot/conditional1/XmlReferenceBeanConditionalTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/boot/conditional1/XmlReferenceBeanConditionalTest.java index 17cc50b675..54ed291e62 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/boot/conditional1/XmlReferenceBeanConditionalTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/boot/conditional1/XmlReferenceBeanConditionalTest.java @@ -18,8 +18,6 @@ package org.apache.dubbo.config.spring.boot.conditional1; import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.spring.api.HelloService; -import org.apache.dubbo.config.spring.registrycenter.ZookeeperSingleRegistryCenter; -import org.apache.dubbo.config.spring.registrycenter.RegistryCenter; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -50,19 +48,14 @@ import java.util.Map; //@ComponentScan public class XmlReferenceBeanConditionalTest { - private static RegistryCenter singleRegistryCenter; - @BeforeAll public static void beforeAll(){ - singleRegistryCenter = new ZookeeperSingleRegistryCenter(); - singleRegistryCenter.startup(); DubboBootstrap.reset(); } @AfterAll public static void afterAll(){ DubboBootstrap.reset(); - singleRegistryCenter.shutdown(); } @Autowired diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/boot/conditional2/JavaConfigAnnotationReferenceBeanConditionalTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/boot/conditional2/JavaConfigAnnotationReferenceBeanConditionalTest.java index ba33808f7d..5b4f7bb18a 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/boot/conditional2/JavaConfigAnnotationReferenceBeanConditionalTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/boot/conditional2/JavaConfigAnnotationReferenceBeanConditionalTest.java @@ -22,8 +22,6 @@ import org.apache.dubbo.config.spring.ReferenceBean; import org.apache.dubbo.config.spring.api.HelloService; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.apache.dubbo.config.spring.context.annotation.provider.HelloServiceImpl; -import org.apache.dubbo.config.spring.registrycenter.ZookeeperSingleRegistryCenter; -import org.apache.dubbo.config.spring.registrycenter.RegistryCenter; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -56,19 +54,14 @@ import java.util.Map; @EnableDubbo public class JavaConfigAnnotationReferenceBeanConditionalTest { - private static RegistryCenter singleRegistryCenter; - @BeforeAll public static void beforeAll(){ - singleRegistryCenter = new ZookeeperSingleRegistryCenter(); - singleRegistryCenter.startup(); DubboBootstrap.reset(); } @AfterAll public static void afterAll(){ DubboBootstrap.reset(); - singleRegistryCenter.shutdown(); } @Autowired diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/boot/conditional3/JavaConfigRawReferenceBeanConditionalTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/boot/conditional3/JavaConfigRawReferenceBeanConditionalTest.java index 3e8745538d..014682bcd7 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/boot/conditional3/JavaConfigRawReferenceBeanConditionalTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/boot/conditional3/JavaConfigRawReferenceBeanConditionalTest.java @@ -22,8 +22,6 @@ import org.apache.dubbo.config.spring.api.HelloService; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.apache.dubbo.config.spring.context.annotation.provider.HelloServiceImpl; import org.apache.dubbo.config.spring.reference.ReferenceBeanBuilder; -import org.apache.dubbo.config.spring.registrycenter.ZookeeperSingleRegistryCenter; -import org.apache.dubbo.config.spring.registrycenter.RegistryCenter; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -56,19 +54,14 @@ import java.util.Map; @EnableDubbo public class JavaConfigRawReferenceBeanConditionalTest { - private static RegistryCenter singleRegistryCenter; - @BeforeAll public static void beforeAll(){ - singleRegistryCenter = new ZookeeperSingleRegistryCenter(); - singleRegistryCenter.startup(); DubboBootstrap.reset(); } @AfterAll public static void afterAll(){ DubboBootstrap.reset(); - singleRegistryCenter.shutdown(); } @Autowired diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/boot/conditional4/JavaConfigReferenceBeanConditionalTest4.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/boot/conditional4/JavaConfigReferenceBeanConditionalTest4.java index 9199a3fa36..ce6968a1b2 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/boot/conditional4/JavaConfigReferenceBeanConditionalTest4.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/boot/conditional4/JavaConfigReferenceBeanConditionalTest4.java @@ -22,8 +22,6 @@ import org.apache.dubbo.config.spring.ReferenceBean; import org.apache.dubbo.config.spring.api.HelloService; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.apache.dubbo.config.spring.context.annotation.provider.HelloServiceImpl; -import org.apache.dubbo.config.spring.registrycenter.ZookeeperSingleRegistryCenter; -import org.apache.dubbo.config.spring.registrycenter.RegistryCenter; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -56,19 +54,14 @@ import java.util.Map; @EnableDubbo public class JavaConfigReferenceBeanConditionalTest4 { - private static RegistryCenter singleRegistryCenter; - @BeforeAll public static void beforeAll(){ - singleRegistryCenter = new ZookeeperSingleRegistryCenter(); - singleRegistryCenter.startup(); DubboBootstrap.reset(); } @AfterAll public static void afterAll(){ DubboBootstrap.reset(); - singleRegistryCenter.shutdown(); } @Autowired diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/boot/configprops/SpringBootConfigPropsTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/boot/configprops/SpringBootConfigPropsTest.java index 1d202be4d4..1542a2add0 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/boot/configprops/SpringBootConfigPropsTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/boot/configprops/SpringBootConfigPropsTest.java @@ -30,9 +30,8 @@ import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.context.ConfigManager; import org.apache.dubbo.config.context.ModuleConfigManager; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; -import org.apache.dubbo.config.spring.registrycenter.RegistryCenter; -import org.apache.dubbo.config.spring.registrycenter.ZookeeperMultipleRegistryCenter; import org.apache.dubbo.rpc.model.ModuleModel; +import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -48,51 +47,46 @@ import java.util.List; import static org.apache.dubbo.common.constants.MetricsConstants.PROTOCOL_PROMETHEUS; @SpringBootTest( - properties = { - "dubbo.application.NAME = dubbo-demo-application", - "dubbo.module.name = dubbo-demo-module", - "dubbo.registry.address = zookeeper://192.168.99.100:32770", - "dubbo.protocol.name=dubbo", - "dubbo.protocol.port=20880", - "dubbo.metrics.protocol=prometheus", - "dubbo.metrics.prometheus.exporter.enabled=true", - "dubbo.metrics.prometheus.exporter.enable-http-service-discovery=true", - "dubbo.metrics.prometheus.exporter.http-service-discovery-url=localhost:8080", - "dubbo.metrics.prometheus.exporter.metrics-port=20888", - "dubbo.metrics.prometheus.exporter.metrics-path=/metrics", - "dubbo.metrics.aggregation.enabled=true", - "dubbo.metrics.aggregation.bucket-num=5", - "dubbo.metrics.aggregation.time-window-seconds=120", - "dubbo.monitor.address=zookeeper://127.0.0.1:32770", - "dubbo.Config-center.address=zookeeper://127.0.0.1:2181", - "dubbo.config-Center.group=group1", - "dubbo.metadata-report.address=zookeeper://127.0.0.1:2182", - "dubbo.METADATA-REPORT.username=User", - "dubbo.provider.host=127.0.0.1", - "dubbo.consumer.client=netty" - }, - classes = { - SpringBootConfigPropsTest.class - } + properties = { + "dubbo.application.NAME = dubbo-demo-application", + "dubbo.module.name = dubbo-demo-module", + "dubbo.registry.address = zookeeper://192.168.99.100:32770", + "dubbo.protocol.name=dubbo", + "dubbo.protocol.port=20880", + "dubbo.metrics.protocol=prometheus", + "dubbo.metrics.prometheus.exporter.enabled=true", + "dubbo.metrics.prometheus.exporter.enable-http-service-discovery=true", + "dubbo.metrics.prometheus.exporter.http-service-discovery-url=localhost:8080", + "dubbo.metrics.prometheus.exporter.metrics-port=20888", + "dubbo.metrics.prometheus.exporter.metrics-path=/metrics", + "dubbo.metrics.aggregation.enabled=true", + "dubbo.metrics.aggregation.bucket-num=5", + "dubbo.metrics.aggregation.time-window-seconds=120", + "dubbo.monitor.address=zookeeper://127.0.0.1:32770", + "dubbo.Config-center.address=${zookeeper.connection.address.1}", + "dubbo.config-Center.group=group1", + "dubbo.metadata-report.address=${zookeeper.connection.address.2}", + "dubbo.METADATA-REPORT.username=User", + "dubbo.provider.host=127.0.0.1", + "dubbo.consumer.client=netty" + }, + classes = { + SpringBootConfigPropsTest.class + } ) @Configuration @ComponentScan @EnableDubbo public class SpringBootConfigPropsTest { - private static RegistryCenter multipleRegistryCenter; - @BeforeAll public static void beforeAll() { - multipleRegistryCenter = new ZookeeperMultipleRegistryCenter(); - multipleRegistryCenter.startup(); DubboBootstrap.reset(); } @AfterAll public static void afterAll() { DubboBootstrap.reset(); - multipleRegistryCenter.shutdown(); } @Autowired @@ -135,13 +129,13 @@ public class SpringBootConfigPropsTest { Collection configCenters = configManager.getConfigCenters(); Assertions.assertEquals(1, configCenters.size()); ConfigCenterConfig centerConfig = configCenters.iterator().next(); - Assertions.assertEquals("zookeeper://127.0.0.1:2181", centerConfig.getAddress()); + Assertions.assertEquals(ZookeeperRegistryCenterConfig.getConnectionAddress1(), centerConfig.getAddress()); Assertions.assertEquals("group1", centerConfig.getGroup()); Collection metadataConfigs = configManager.getMetadataConfigs(); Assertions.assertEquals(1, metadataConfigs.size()); MetadataReportConfig reportConfig = metadataConfigs.iterator().next(); - Assertions.assertEquals("zookeeper://127.0.0.1:2182", reportConfig.getAddress()); + Assertions.assertEquals(ZookeeperRegistryCenterConfig.getConnectionAddress2(), reportConfig.getAddress()); Assertions.assertEquals("User", reportConfig.getUsername()); // module configs diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/boot/configprops/SpringBootMultipleConfigPropsTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/boot/configprops/SpringBootMultipleConfigPropsTest.java index d5eb21b4a8..27151e6962 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/boot/configprops/SpringBootMultipleConfigPropsTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/boot/configprops/SpringBootMultipleConfigPropsTest.java @@ -30,10 +30,8 @@ import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.context.ConfigManager; import org.apache.dubbo.config.context.ModuleConfigManager; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; -import org.apache.dubbo.config.spring.registrycenter.RegistryCenter; -import org.apache.dubbo.config.spring.registrycenter.ZookeeperMultipleRegistryCenter; import org.apache.dubbo.rpc.model.ModuleModel; - +import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -65,9 +63,9 @@ import static org.apache.dubbo.common.constants.MetricsConstants.PROTOCOL_PROMET "dubbo.metricses.my-metrics.aggregation.bucket-num=5", "dubbo.metricses.my-metrics.aggregation.time-window-seconds=120", "dubbo.monitors.my-monitor.address=zookeeper://127.0.0.1:32770", - "dubbo.config-centers.my-configcenter.address=zookeeper://127.0.0.1:2181", + "dubbo.config-centers.my-configcenter.address=${zookeeper.connection.address.1}", "dubbo.config-centers.my-configcenter.group=group1", - "dubbo.metadata-reports.my-metadata.address=zookeeper://127.0.0.1:2182", + "dubbo.metadata-reports.my-metadata.address=${zookeeper.connection.address.2}", "dubbo.metadata-reports.my-metadata.username=User", "dubbo.providers.my-provider.host=127.0.0.1", "dubbo.consumers.my-consumer.client=netty" @@ -81,19 +79,14 @@ import static org.apache.dubbo.common.constants.MetricsConstants.PROTOCOL_PROMET @EnableDubbo public class SpringBootMultipleConfigPropsTest { - private static RegistryCenter multipleRegistryCenter; - @BeforeAll public static void beforeAll() { - multipleRegistryCenter = new ZookeeperMultipleRegistryCenter(); - multipleRegistryCenter.startup(); DubboBootstrap.reset(); } @AfterAll public static void afterAll() { DubboBootstrap.reset(); - multipleRegistryCenter.shutdown(); } @Autowired @@ -137,13 +130,13 @@ public class SpringBootMultipleConfigPropsTest { Collection configCenters = configManager.getConfigCenters(); Assertions.assertEquals(1, configCenters.size()); ConfigCenterConfig centerConfig = configCenters.iterator().next(); - Assertions.assertEquals("zookeeper://127.0.0.1:2181", centerConfig.getAddress()); + Assertions.assertEquals(ZookeeperRegistryCenterConfig.getConnectionAddress1(), centerConfig.getAddress()); Assertions.assertEquals("group1", centerConfig.getGroup()); Collection metadataConfigs = configManager.getMetadataConfigs(); Assertions.assertEquals(1, metadataConfigs.size()); MetadataReportConfig reportConfig = metadataConfigs.iterator().next(); - Assertions.assertEquals("zookeeper://127.0.0.1:2182", reportConfig.getAddress()); + Assertions.assertEquals(ZookeeperRegistryCenterConfig.getConnectionAddress2(), reportConfig.getAddress()); Assertions.assertEquals("User", reportConfig.getUsername()); // module configs diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/boot/importxml/SpringBootImportDubboXmlTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/boot/importxml/SpringBootImportDubboXmlTest.java index 0efc4e937b..bd7ffea3b0 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/boot/importxml/SpringBootImportDubboXmlTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/boot/importxml/SpringBootImportDubboXmlTest.java @@ -18,8 +18,6 @@ package org.apache.dubbo.config.spring.boot.importxml; import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.spring.api.HelloService; -import org.apache.dubbo.config.spring.registrycenter.ZookeeperSingleRegistryCenter; -import org.apache.dubbo.config.spring.registrycenter.RegistryCenter; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -44,19 +42,14 @@ import org.springframework.context.annotation.ImportResource; @ImportResource("classpath:/org/apache/dubbo/config/spring/boot/importxml/consumer/dubbo-consumer.xml") public class SpringBootImportDubboXmlTest { - private static RegistryCenter singleRegistryCenter; - @BeforeAll public static void beforeAll(){ - singleRegistryCenter = new ZookeeperSingleRegistryCenter(); - singleRegistryCenter.startup(); DubboBootstrap.reset(); } @AfterAll public static void afterAll(){ DubboBootstrap.reset(); - singleRegistryCenter.shutdown(); } @Autowired diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/DubboConfigConfigurationTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/DubboConfigConfigurationTest.java index 3898b3e42b..e745f511a0 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/DubboConfigConfigurationTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/DubboConfigConfigurationTest.java @@ -22,8 +22,6 @@ import org.apache.dubbo.config.ProtocolConfig; import org.apache.dubbo.config.RegistryConfig; import org.apache.dubbo.config.bootstrap.DubboBootstrap; -import org.apache.dubbo.config.spring.registrycenter.ZookeeperSingleRegistryCenter; -import org.apache.dubbo.config.spring.registrycenter.RegistryCenter; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -83,20 +81,14 @@ public class DubboConfigConfigurationTest { @Test public void testMultiple() { - RegistryCenter singleRegistryCenter = new ZookeeperSingleRegistryCenter(); - singleRegistryCenter.startup(); - try{ - context.register(DubboConfigConfiguration.Multiple.class); - context.refresh(); + context.register(DubboConfigConfiguration.Multiple.class); + context.refresh(); - RegistryConfig registry1 = context.getBean("registry1", RegistryConfig.class); - Assertions.assertEquals(2181, registry1.getPort()); + RegistryConfig registry1 = context.getBean("registry1", RegistryConfig.class); + Assertions.assertEquals(2181, registry1.getPort()); - RegistryConfig registry2 = context.getBean("registry2", RegistryConfig.class); - Assertions.assertEquals(2182, registry2.getPort()); - }finally { - singleRegistryCenter.shutdown(); - } + RegistryConfig registry2 = context.getBean("registry2", RegistryConfig.class); + Assertions.assertEquals(2182, registry2.getPort()); } } diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/EnableDubboConfigTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/EnableDubboConfigTest.java index 4c309df641..122a713a9e 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/EnableDubboConfigTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/EnableDubboConfigTest.java @@ -25,8 +25,6 @@ import org.apache.dubbo.config.ProviderConfig; import org.apache.dubbo.config.RegistryConfig; import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.context.ConfigManager; -import org.apache.dubbo.config.spring.registrycenter.RegistryCenter; -import org.apache.dubbo.config.spring.registrycenter.ZookeeperMultipleRegistryCenter; import org.apache.dubbo.rpc.model.ApplicationModel; import org.junit.jupiter.api.AfterEach; @@ -48,19 +46,14 @@ import static org.junit.jupiter.api.Assertions.assertFalse; */ public class EnableDubboConfigTest { - private RegistryCenter multipleRegistryCenter; - @BeforeEach public void setUp() { - multipleRegistryCenter = new ZookeeperMultipleRegistryCenter(); - multipleRegistryCenter.startup(); DubboBootstrap.reset(); } @AfterEach public void tearDown() { DubboBootstrap.reset(); - multipleRegistryCenter.shutdown(); } //@Test diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/customize/DubboSpringInitCustomizerTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/customize/DubboSpringInitCustomizerTest.java index 1b5a0f944e..c5e6cfba7c 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/customize/DubboSpringInitCustomizerTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/customize/DubboSpringInitCustomizerTest.java @@ -20,12 +20,11 @@ import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.spring.SysProps; import org.apache.dubbo.config.spring.api.HelloService; import org.apache.dubbo.config.spring.context.DubboSpringInitCustomizerHolder; -import org.apache.dubbo.config.spring.registrycenter.RegistryCenter; -import org.apache.dubbo.config.spring.registrycenter.ZookeeperSingleRegistryCenter; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.FrameworkModel; import org.apache.dubbo.rpc.model.ModuleModel; import org.apache.dubbo.rpc.model.ServiceDescriptor; +import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -34,22 +33,16 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; public class DubboSpringInitCustomizerTest { - private static RegistryCenter singleRegistryCenter; - @BeforeAll public static void beforeAll() { DubboBootstrap.reset(); - singleRegistryCenter = new ZookeeperSingleRegistryCenter(); - singleRegistryCenter.startup(); - RegistryCenter.Instance registryCenterInstance = singleRegistryCenter.getRegistryCenterInstance().get(0); - SysProps.setProperty("dubbo.registry.address", registryCenterInstance.toURL()); + SysProps.setProperty("dubbo.registry.address", ZookeeperRegistryCenterConfig.getConnectionAddress()); } @AfterAll public static void afterAll() { DubboBootstrap.reset(); - singleRegistryCenter.shutdown(); SysProps.clear(); } diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/issues/issue6000/Issue6000Test.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/issues/issue6000/Issue6000Test.java index d05517040a..c652a4c4b2 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/issues/issue6000/Issue6000Test.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/issues/issue6000/Issue6000Test.java @@ -19,8 +19,6 @@ package org.apache.dubbo.config.spring.issues.issue6000; import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.apache.dubbo.config.spring.issues.issue6000.adubbo.HelloDubbo; -import org.apache.dubbo.config.spring.registrycenter.ZookeeperSingleRegistryCenter; -import org.apache.dubbo.config.spring.registrycenter.RegistryCenter; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.AfterAll; @@ -40,19 +38,14 @@ import org.springframework.context.annotation.PropertySource; @PropertySource("classpath:/META-INF/issues/issue6000/config.properties") public class Issue6000Test { - private static RegistryCenter singleRegistryCenter; - @BeforeAll public static void beforeAll() { - singleRegistryCenter = new ZookeeperSingleRegistryCenter(); - singleRegistryCenter.startup(); DubboBootstrap.reset(); } @AfterAll public static void afterAll() { DubboBootstrap.reset(); - singleRegistryCenter.shutdown(); } @Test diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/issues/issue6252/Issue6252Test.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/issues/issue6252/Issue6252Test.java index b7609e4df8..8d9e8155ec 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/issues/issue6252/Issue6252Test.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/issues/issue6252/Issue6252Test.java @@ -18,10 +18,8 @@ package org.apache.dubbo.config.spring.issues.issue6252; import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.bootstrap.DubboBootstrap; -import org.apache.dubbo.config.spring.registrycenter.RegistryCenter; import org.apache.dubbo.config.spring.api.DemoService; import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfig; -import org.apache.dubbo.config.spring.registrycenter.ZookeeperMultipleRegistryCenter; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -39,19 +37,14 @@ import org.springframework.context.annotation.PropertySource; @PropertySource("classpath:/META-INF/issues/issue6252/config.properties") public class Issue6252Test { - private static RegistryCenter multipleRegistryCenter; - @BeforeAll public static void beforeAll() { - multipleRegistryCenter = new ZookeeperMultipleRegistryCenter(); - multipleRegistryCenter.startup(); DubboBootstrap.reset(); } @AfterAll public static void afterAll() { DubboBootstrap.reset(); - multipleRegistryCenter.shutdown(); } @DubboReference diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/issues/issue7003/Issue7003Test.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/issues/issue7003/Issue7003Test.java index 0da499e36a..a31fbee1b7 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/issues/issue7003/Issue7003Test.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/issues/issue7003/Issue7003Test.java @@ -22,8 +22,6 @@ import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.spring.ReferenceBean; import org.apache.dubbo.config.spring.api.HelloService; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; -import org.apache.dubbo.config.spring.registrycenter.RegistryCenter; -import org.apache.dubbo.config.spring.registrycenter.ZookeeperSingleRegistryCenter; import org.apache.dubbo.rpc.model.ApplicationModel; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; @@ -49,19 +47,14 @@ import java.util.Map; @PropertySource("classpath:/META-INF/issues/issue7003/config.properties") public class Issue7003Test { - private static RegistryCenter singleRegistryCenter; - @BeforeAll public static void beforeAll() { - singleRegistryCenter = new ZookeeperSingleRegistryCenter(); - singleRegistryCenter.startup(); DubboBootstrap.reset(); } @AfterAll public static void afterAll() { DubboBootstrap.reset(); - singleRegistryCenter.shutdown(); } @Test diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/issues/issue9172/MultipleConsumerAndProviderTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/issues/issue9172/MultipleConsumerAndProviderTest.java index 91b86da023..654ba9c5a0 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/issues/issue9172/MultipleConsumerAndProviderTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/issues/issue9172/MultipleConsumerAndProviderTest.java @@ -25,12 +25,9 @@ import org.apache.dubbo.config.spring.api.HelloService; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.apache.dubbo.config.spring.impl.DemoServiceImpl; import org.apache.dubbo.config.spring.impl.HelloServiceImpl; -import org.apache.dubbo.config.spring.registrycenter.ZookeeperMultipleRegistryCenter; import org.apache.dubbo.config.spring.util.DubboBeanUtils; import org.apache.dubbo.rpc.model.ModuleModel; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; @@ -41,21 +38,6 @@ import org.springframework.context.annotation.PropertySource; */ public class MultipleConsumerAndProviderTest { - private static ZookeeperMultipleRegistryCenter registryCenter; - - @BeforeAll - public static void setUp() { - registryCenter = new ZookeeperMultipleRegistryCenter(); - registryCenter.startup(); - } - - @AfterAll - public static void tearDown() { - if (registryCenter != null) { - registryCenter.shutdown(); - } - } - @Test public void test() { diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer/PropertyConfigurerTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer/PropertyConfigurerTest.java index 571c8cddc3..4191be8ca7 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer/PropertyConfigurerTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer/PropertyConfigurerTest.java @@ -19,8 +19,6 @@ package org.apache.dubbo.config.spring.propertyconfigurer.consumer; import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.spring.api.HelloService; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; -import org.apache.dubbo.config.spring.registrycenter.RegistryCenter; -import org.apache.dubbo.config.spring.registrycenter.ZookeeperSingleRegistryCenter; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -34,19 +32,14 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; public class PropertyConfigurerTest { - private static RegistryCenter singleRegistryCenter; - @BeforeAll public static void beforeAll() { - singleRegistryCenter = new ZookeeperSingleRegistryCenter(); - singleRegistryCenter.startup(); DubboBootstrap.reset(); } @AfterAll public static void afterAll() { DubboBootstrap.reset(); - singleRegistryCenter.shutdown(); } @Test diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer/app.properties b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer/app.properties index fcda447cfa..5d67384816 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer/app.properties +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer/app.properties @@ -1,4 +1,4 @@ -dubbo.registry.address=zookeeper://127.0.0.1:2181?registry-type=service +dubbo.registry.address=${zookeeper.connection.address}?registry-type=service biz.group=greeting biz.group2=group2 dubbo.call-timeout=2000 diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer/dubbo-consumer.xml b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer/dubbo-consumer.xml index 8b25aa1516..d00f3b2e29 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer/dubbo-consumer.xml +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer/dubbo-consumer.xml @@ -30,7 +30,7 @@ - + diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer2/PropertySourcesConfigurerTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer2/PropertySourcesConfigurerTest.java index 06a2df4056..a75d319f55 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer2/PropertySourcesConfigurerTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer2/PropertySourcesConfigurerTest.java @@ -20,8 +20,6 @@ import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.spring.api.HelloService; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.apache.dubbo.config.spring.propertyconfigurer.consumer.DemoBeanFactoryPostProcessor; -import org.apache.dubbo.config.spring.registrycenter.RegistryCenter; -import org.apache.dubbo.config.spring.registrycenter.ZookeeperSingleRegistryCenter; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -35,19 +33,14 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; public class PropertySourcesConfigurerTest { - private static RegistryCenter singleRegistryCenter; - @BeforeAll public static void beforeAll() { - singleRegistryCenter = new ZookeeperSingleRegistryCenter(); - singleRegistryCenter.startup(); DubboBootstrap.reset(); } @AfterAll public static void afterAll() { DubboBootstrap.reset(); - singleRegistryCenter.shutdown(); } @Test diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer2/app.properties b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer2/app.properties index fcda447cfa..5d67384816 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer2/app.properties +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer2/app.properties @@ -1,4 +1,4 @@ -dubbo.registry.address=zookeeper://127.0.0.1:2181?registry-type=service +dubbo.registry.address=${zookeeper.connection.address}?registry-type=service biz.group=greeting biz.group2=group2 dubbo.call-timeout=2000 diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer2/dubbo-consumer.xml b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer2/dubbo-consumer.xml index fe30acb29d..60487164f0 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer2/dubbo-consumer.xml +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer2/dubbo-consumer.xml @@ -30,7 +30,7 @@ - + diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer3/PropertySourcesInJavaConfigTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer3/PropertySourcesInJavaConfigTest.java index 163b466f05..f209fdd7c8 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer3/PropertySourcesInJavaConfigTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer3/PropertySourcesInJavaConfigTest.java @@ -20,12 +20,8 @@ import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.spring.api.HelloService; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.apache.dubbo.config.spring.propertyconfigurer.consumer.DemoBeanFactoryPostProcessor; -import org.apache.dubbo.config.spring.registrycenter.RegistryCenter; -import org.apache.dubbo.config.spring.registrycenter.ZookeeperSingleRegistryCenter; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -45,18 +41,6 @@ public class PropertySourcesInJavaConfigTest { private static final String SCAN_PACKAGE_NAME = "org.apache.dubbo.config.spring.propertyconfigurer.consumer3.notexist"; private static final String PACKAGE_PATH = "/org/apache/dubbo/config/spring/propertyconfigurer/consumer3"; private static final String PROVIDER_CONFIG_PATH = "org/apache/dubbo/config/spring/propertyconfigurer/provider/dubbo-provider.xml"; - private static RegistryCenter singleRegistryCenter; - - @BeforeAll - public static void beforeAll() { - singleRegistryCenter = new ZookeeperSingleRegistryCenter(); - singleRegistryCenter.startup(); - } - - @AfterAll - public static void afterAll() { - singleRegistryCenter.shutdown(); - } @BeforeEach public void setUp() throws Exception { diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer3/app.properties b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer3/app.properties index fcda447cfa..5d67384816 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer3/app.properties +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer3/app.properties @@ -1,4 +1,4 @@ -dubbo.registry.address=zookeeper://127.0.0.1:2181?registry-type=service +dubbo.registry.address=${zookeeper.connection.address}?registry-type=service biz.group=greeting biz.group2=group2 dubbo.call-timeout=2000 diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer3/dubbo-consumer.xml b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer3/dubbo-consumer.xml index c5233e7ede..4a5d49203b 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer3/dubbo-consumer.xml +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer3/dubbo-consumer.xml @@ -24,7 +24,7 @@ - + diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/provider/app.properties b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/provider/app.properties index 56d423ab85..a7e4b1ebdf 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/provider/app.properties +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/provider/app.properties @@ -1,6 +1,6 @@ dubbo.application.name=demo-provider -dubbo.registry.address=zookeeper://127.0.0.1:2181?registry-type=service -dubbo.config-center.address=zookeeper://127.0.0.1:2181 -dubbo.metadata-report.address=zookeeper://127.0.0.1:2181 +dubbo.registry.address=${zookeeper.connection.address}?registry-type=service +dubbo.config-center.address=${zookeeper.connection.address} +dubbo.metadata-report.address=${zookeeper.connection.address} biz.group=greeting biz.group2=group2 diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/DubboConfigBeanInitializerTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/DubboConfigBeanInitializerTest.java index 63bdde2227..a056711106 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/DubboConfigBeanInitializerTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/DubboConfigBeanInitializerTest.java @@ -22,8 +22,6 @@ import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.spring.api.HelloService; import org.apache.dubbo.config.spring.context.DubboConfigBeanInitializer; import org.apache.dubbo.config.spring.context.annotation.provider.ProviderConfiguration; -import org.apache.dubbo.config.spring.registrycenter.RegistryCenter; -import org.apache.dubbo.config.spring.registrycenter.ZookeeperSingleRegistryCenter; import org.apache.dubbo.config.spring.util.DubboBeanUtils; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; @@ -55,23 +53,19 @@ import java.util.List; }) @TestPropertySource(properties = { "dubbo.protocol.port=-1", - "dubbo.registry.address=zookeeper://127.0.0.1:2181" + "dubbo.registry.address=${zookeeper.connection.address}" }) @EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) public class DubboConfigBeanInitializerTest { - private static RegistryCenter singleRegistryCenter; @BeforeAll public static void beforeAll() { - singleRegistryCenter = new ZookeeperSingleRegistryCenter(); - singleRegistryCenter.startup(); DubboBootstrap.reset(); } @AfterAll public static void afterAll() { - singleRegistryCenter.shutdown(); DubboBootstrap.reset(); } diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/ReferenceKeyTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/ReferenceKeyTest.java index 79e1e5a3e7..398ac4e204 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/ReferenceKeyTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/ReferenceKeyTest.java @@ -25,13 +25,9 @@ import org.apache.dubbo.config.spring.api.DemoService; import org.apache.dubbo.config.spring.api.HelloService; import org.apache.dubbo.config.spring.impl.DemoServiceImpl; import org.apache.dubbo.config.spring.impl.HelloServiceImpl; -import org.apache.dubbo.config.spring.registrycenter.RegistryCenter; -import org.apache.dubbo.config.spring.registrycenter.ZookeeperSingleRegistryCenter; import com.alibaba.spring.util.AnnotationUtils; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -50,20 +46,6 @@ import java.util.Map; public class ReferenceKeyTest { - private static RegistryCenter singleRegistryCenter; - - @BeforeAll - public static void beforeAll() { - singleRegistryCenter = new ZookeeperSingleRegistryCenter(); - singleRegistryCenter.startup(); - } - - @AfterAll - public static void afterAll() { - singleRegistryCenter.shutdown(); - } - - @BeforeEach protected void setUp() { DubboBootstrap.reset(); diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/javaconfig/JavaConfigReferenceBeanTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/javaconfig/JavaConfigReferenceBeanTest.java index a4ec239667..494fdc336e 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/javaconfig/JavaConfigReferenceBeanTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/javaconfig/JavaConfigReferenceBeanTest.java @@ -27,8 +27,6 @@ import org.apache.dubbo.config.spring.api.HelloService; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.apache.dubbo.config.spring.impl.HelloServiceImpl; import org.apache.dubbo.config.spring.reference.ReferenceBeanBuilder; -import org.apache.dubbo.config.spring.registrycenter.RegistryCenter; -import org.apache.dubbo.config.spring.registrycenter.ZookeeperMultipleRegistryCenter; import org.apache.dubbo.rpc.service.GenericException; import org.apache.dubbo.rpc.service.GenericService; import org.junit.jupiter.api.AfterAll; @@ -53,23 +51,6 @@ import java.util.Map; public class JavaConfigReferenceBeanTest { - private static RegistryCenter multipleRegistryCenter; - - @BeforeAll - public static void beforeAll() { - multipleRegistryCenter = new ZookeeperMultipleRegistryCenter(); - multipleRegistryCenter.startup(); - } - - @AfterAll - public static void afterAll() throws Exception { - multipleRegistryCenter.shutdown(); - multipleRegistryCenter = null; - - //Thread.sleep(10000); - //dumpHeap("/Users/gongdewei/work/dump/dubbo/", true); - } - public static void dumpHeap(String dirpath, boolean live) throws Exception { java.lang.management.RuntimeMXBean runtime = diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/javaconfig/consumer.properties b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/javaconfig/consumer.properties index f2f6ea5703..0782ed8552 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/javaconfig/consumer.properties +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/javaconfig/consumer.properties @@ -1,7 +1,7 @@ dubbo.application.name=consumer-app dubbo.protocol.name=dubbo dubbo.protocol.port=-1 -dubbo.registry.address=zookeeper://127.0.0.1:2181 +dubbo.registry.address=${zookeeper.connection.address} dubbo.reference.org.apache.dubbo.config.spring.api.DemoService.init=false #dubbo.reference.org.apache.dubbo.config.spring.api.HelloService.init=false #dubbo.consumer.init=false diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/localcall/LocalCallTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/localcall/LocalCallTest.java index 25fee33fea..8283a973e2 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/localcall/LocalCallTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/localcall/LocalCallTest.java @@ -18,15 +18,12 @@ package org.apache.dubbo.config.spring.reference.localcall; import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.spring.api.HelloService; -import org.apache.dubbo.config.spring.registrycenter.ZookeeperSingleRegistryCenter; -import org.apache.dubbo.config.spring.registrycenter.RegistryCenter; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -39,19 +36,14 @@ import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER @DirtiesContext(classMode = AFTER_EACH_TEST_METHOD) public class LocalCallTest { - private static RegistryCenter singleRegistryCenter; - @BeforeAll public static void beforeAll() { - singleRegistryCenter = new ZookeeperSingleRegistryCenter(); - singleRegistryCenter.startup(); DubboBootstrap.reset(); } @AfterAll public static void afterAll() { DubboBootstrap.reset(); - singleRegistryCenter.shutdown(); } @Autowired diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/localcall/LocalCallTest2.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/localcall/LocalCallTest2.java index 5eb1a98606..a443519ee6 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/localcall/LocalCallTest2.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/localcall/LocalCallTest2.java @@ -19,8 +19,6 @@ package org.apache.dubbo.config.spring.reference.localcall; import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.spring.api.HelloService; -import org.apache.dubbo.config.spring.registrycenter.ZookeeperSingleRegistryCenter; -import org.apache.dubbo.config.spring.registrycenter.RegistryCenter; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -39,19 +37,14 @@ import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER @DirtiesContext(classMode = AFTER_EACH_TEST_METHOD) public class LocalCallTest2 { - private static RegistryCenter singleRegistryCenter; - @BeforeAll public static void setUp() { - singleRegistryCenter = new ZookeeperSingleRegistryCenter(); - singleRegistryCenter.startup(); DubboBootstrap.reset(); } @AfterAll public static void tearDown() { DubboBootstrap.reset(); - singleRegistryCenter.shutdown(); } @DubboReference diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/localcall/local-call-provider.xml b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/localcall/local-call-provider.xml index 0f7c0b512c..dc811f6a4d 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/localcall/local-call-provider.xml +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/localcall/local-call-provider.xml @@ -25,7 +25,7 @@ - + diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/localcallam/LocalCallMultipleReferenceAnnotationsTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/localcallam/LocalCallMultipleReferenceAnnotationsTest.java index 2da37326f0..763251a7fa 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/localcallam/LocalCallMultipleReferenceAnnotationsTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/localcallam/LocalCallMultipleReferenceAnnotationsTest.java @@ -22,10 +22,7 @@ import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.spring.ReferenceBean; import org.apache.dubbo.config.spring.api.HelloService; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; -import org.apache.dubbo.config.spring.registrycenter.RegistryCenter; -import org.apache.dubbo.config.spring.registrycenter.ZookeeperSingleRegistryCenter; import org.apache.dubbo.rpc.RpcContext; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -49,18 +46,9 @@ import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER @DirtiesContext(classMode = AFTER_EACH_TEST_METHOD) public class LocalCallMultipleReferenceAnnotationsTest { - private static RegistryCenter registryCenter; - @BeforeAll public static void setUp() { DubboBootstrap.reset(); - registryCenter = new ZookeeperSingleRegistryCenter(); - registryCenter.startup(); - } - - @AfterAll - public static void tearDown() { - registryCenter.shutdown(); } @Autowired diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/localcallam/local-call-config.properties b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/localcallam/local-call-config.properties index 7f19a27557..be75cda3dc 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/localcallam/local-call-config.properties +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/localcallam/local-call-config.properties @@ -1,6 +1,6 @@ dubbo.application.name=local-call-demo dubbo.protocol.name=dubbo dubbo.protocol.port=-1 -dubbo.registry.address=zookeeper://127.0.0.1:2181 +dubbo.registry.address=${zookeeper.connection.address} biz.group=demo biz.version=2.0.0 diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/registrycenter/AbstractRegistryCenter.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/registrycenter/AbstractRegistryCenter.java deleted file mode 100644 index d373234bd3..0000000000 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/registrycenter/AbstractRegistryCenter.java +++ /dev/null @@ -1,107 +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.config.spring.registrycenter; - -import org.apache.curator.test.InstanceSpec; - -import java.io.File; -import java.util.HashMap; -import java.util.Map; - -/** - * The abstraction of {@link RegistryCenter} implements the basic methods. - */ -abstract class AbstractRegistryCenter implements RegistryCenter { - - /** - * The default data directory is null - */ - private static final File DEFAULT_DATA_DIRECTORY = null; - - /** - * The default election port is -1. - */ - private static final int DEFAULT_ELECTION_PORT = -1; - - /** - * The default quorum port is -1. - */ - private static final int DEFAULT_QUORUM_PORT = -1; - - /** - * The default value is true. - */ - private static final boolean DEFAULT_DELETE_DATA_DIRECTORY_ON_CLOSE = true; - - /** - * The default service id is -1. - */ - private static final int DEFAULT_SERVER_ID = -1; - - /** - * The default tick time is 5000 - */ - private static final int DEFAULT_TICK_TIME = 5 * 1000; - - /** - * The default value is 200. - */ - private static final int DEFAULT_MAX_CLIENT_CNXNS = 200; - - /** - * The minimum session timeout. - */ - private static final int DEFAULT_MINIMUM_SESSION_TIMEOUT = DEFAULT_TICK_TIME * 2; - - /** - * The maximum session timeout. - */ - private static final int DEFAULT_MAXIMUM_SESSION_TIMEOUT = 600 * 1000; - - /** - * The default customer properties. - */ - private static final Map DEFAULT_CUSTOM_PROPERTIES = new HashMap<>(2); - - /** - * The default hostname. - */ - private static final String DEFAULT_HOSTNAME = "127.0.0.1"; - - static { - DEFAULT_CUSTOM_PROPERTIES.put("minSessionTimeout", DEFAULT_MINIMUM_SESSION_TIMEOUT); - DEFAULT_CUSTOM_PROPERTIES.put("maxSessionTimeout", DEFAULT_MAXIMUM_SESSION_TIMEOUT); - } - - /** - * Create an {@link InstanceSpec} instance to initialize {@link org.apache.curator.test.TestingServer} - * - * @param port the zookeeper server's port. - */ - protected InstanceSpec createInstanceSpec(int port) { - return new InstanceSpec(DEFAULT_DATA_DIRECTORY, - port, - DEFAULT_ELECTION_PORT, - DEFAULT_QUORUM_PORT, - DEFAULT_DELETE_DATA_DIRECTORY_ON_CLOSE, - DEFAULT_SERVER_ID, - DEFAULT_TICK_TIME, - DEFAULT_MAX_CLIENT_CNXNS, - DEFAULT_CUSTOM_PROPERTIES, - DEFAULT_HOSTNAME); - } -} diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/registrycenter/RegistryCenter.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/registrycenter/RegistryCenter.java deleted file mode 100644 index 0b8dd5b605..0000000000 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/registrycenter/RegistryCenter.java +++ /dev/null @@ -1,75 +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.config.spring.registrycenter; - -import org.apache.dubbo.rpc.RpcException; - -import java.util.List; - -/** - * The mock registry center. - */ -public interface RegistryCenter { - - /** - * Start the registry center. - * - * @throws RpcException when an exception occurred - */ - void startup() throws RpcException; - - /** - * Returns the registry center instance. - *

This method can be called only after {@link #startup()} is called

- * - * @throws RpcException when an exception occurred - */ - List getRegistryCenterInstance() throws RpcException; - - /** - * Stop the registry center. - * - * @throws RpcException when an exception occurred - */ - void shutdown() throws RpcException; - - /** - * The registry center instance. - */ - interface Instance { - - /** - * Returns the registry center type. - */ - String getType(); - - /** - * Returns the hostname of registry center. - */ - String getHostname(); - - /** - * Returns the port of registry center. - */ - int getPort(); - - /** - * Return registry center url, such as: zookeeper://127.0.0.1:2181 - */ - String toURL(); - } -} diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/registrycenter/ZookeeperMultipleRegistryCenter.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/registrycenter/ZookeeperMultipleRegistryCenter.java deleted file mode 100644 index ff6f3c7ac6..0000000000 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/registrycenter/ZookeeperMultipleRegistryCenter.java +++ /dev/null @@ -1,43 +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.config.spring.registrycenter; - -/** - * The default zookeeper multiple registry center. - */ -public class ZookeeperMultipleRegistryCenter extends ZookeeperRegistryCenter { - - /** - * Initialize {@link ZookeeperMultipleRegistryCenter} instance. - * - * @param port1 the zookeeper server's port. - * @param port2 the zookeeper server's port. - */ - public ZookeeperMultipleRegistryCenter(int port1, int port2) { - super(port1, port2); - } - - /** - * Initialize {@link ZookeeperMultipleRegistryCenter} instance. - */ - public ZookeeperMultipleRegistryCenter() { - this(DEFAULT_PORT1, DEFAULT_PORT2); - } - - private static final int DEFAULT_PORT1 = 2181; - private static final int DEFAULT_PORT2 = 2182; -} diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/registrycenter/ZookeeperRegistryCenter.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/registrycenter/ZookeeperRegistryCenter.java deleted file mode 100644 index 0dd47a8a12..0000000000 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/registrycenter/ZookeeperRegistryCenter.java +++ /dev/null @@ -1,147 +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.config.spring.registrycenter; - -import org.apache.curator.test.InstanceSpec; -import org.apache.curator.test.TestingServer; -import org.apache.dubbo.common.logger.Logger; -import org.apache.dubbo.common.logger.LoggerFactory; -import org.apache.dubbo.rpc.RpcException; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; - -/** - * The default implementation of registry center can support single and multiple registry center. - *

Each port represents an instance. You can provide multiple ports to build multiple registry center, - * if you want to create multiple registry center - */ -class ZookeeperRegistryCenter extends AbstractRegistryCenter { - - /** - * Initialize the default registry center. - * - * @param ports the registry center's ports. - */ - public ZookeeperRegistryCenter(int... ports) { - this.ports = ports; - this.instanceSpecs = new ArrayList<>(this.ports.length); - this.zookeeperServers = new ArrayList<>(this.ports.length); - } - - private static final Logger logger = LoggerFactory.getLogger(ZookeeperRegistryCenter.class); - - /** - * The type of the registry center. - */ - private static final String DEFAULT_REGISTRY_CENTER_TYPE = "zookeeper"; - - private int[] ports; - - private List instanceSpecs; - - private List zookeeperServers; - - private AtomicBoolean started = new AtomicBoolean(false); - - /** - * {@inheritDoc} - */ - @Override - public void startup() throws RpcException { - try { - if (started.compareAndSet(false, true)) { - logger.info("The ZookeeperRegistryCenter is starting..."); - for (int port : this.ports) { - InstanceSpec instanceSpec = this.createInstanceSpec(port); - this.instanceSpecs.add(instanceSpec); - this.zookeeperServers.add(new TestingServer(instanceSpec, true)); - } - logger.info("The ZookeeperRegistryCenter is started successfully"); - } - } catch (Exception exception) { - started.set(false); - throw new RpcException("Failed to initialize ZookeeperRegistryCenter instance", exception); - } - } - - /** - * {@inheritDoc} - */ - @Override - public List getRegistryCenterInstance() throws RpcException { - this.startup(); - List instances = new ArrayList<>(this.instanceSpecs.size()); - for (InstanceSpec instanceSpec : this.instanceSpecs) { - instances.add(new Instance() { - @Override - public String getType() { - return DEFAULT_REGISTRY_CENTER_TYPE; - } - - @Override - public String getHostname() { - return instanceSpec.getHostname(); - } - - @Override - public int getPort() { - return instanceSpec.getPort(); - } - - @Override - public String toURL() { - return String.format("%s://%s:%d", getType(), getHostname(), getPort()); - } - }); - } - return instances; - } - - /** - * {@inheritDoc} - */ - @Override - public void shutdown() throws RpcException { - logger.info("The ZookeeperRegistryCenter is stopping..."); - List exceptions = new ArrayList<>(this.zookeeperServers.size()); - for (TestingServer testingServer : this.zookeeperServers) { - try { - testingServer.close(); - logger.info(String.format("The zookeeper instance of %s is shutdown successfully", - testingServer.getConnectString())); - } catch (IOException exception) { - RpcException rpcException = new RpcException(String.format("Failed to close zookeeper instance of %s", - testingServer.getConnectString()), - exception); - exceptions.add(rpcException); - logger.error(rpcException); - } - } - this.instanceSpecs.clear(); - this.zookeeperServers.clear(); - if (!exceptions.isEmpty()) { - logger.info("The ZookeeperRegistryCenter failed to close."); - // throw any one of exceptions - throw exceptions.get(0); - } else { - logger.info("The ZookeeperRegistryCenter close successfully."); - } - } -} 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 ae213a7aa6..79d0afef24 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 @@ -21,8 +21,6 @@ import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.context.ModuleConfigManager; import org.apache.dubbo.config.spring.ServiceBean; import org.apache.dubbo.config.spring.api.DemoService; -import org.apache.dubbo.config.spring.registrycenter.RegistryCenter; -import org.apache.dubbo.config.spring.registrycenter.ZookeeperSingleRegistryCenter; import org.apache.dubbo.rpc.service.GenericService; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; @@ -45,19 +43,14 @@ import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER @ImportResource(locations = "classpath:/META-INF/spring/dubbo-generic-consumer.xml") public class GenericServiceTest { - private static RegistryCenter singleRegistryCenter; - @BeforeAll public static void beforeAll() { - singleRegistryCenter = new ZookeeperSingleRegistryCenter(); - singleRegistryCenter.startup(); DubboBootstrap.reset(); } @AfterAll public static void afterAll() { DubboBootstrap.reset(); - singleRegistryCenter.shutdown(); } @Autowired diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/schema/GenericServiceWithoutInterfaceTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/schema/GenericServiceWithoutInterfaceTest.java index 672c4b90b1..ff0861d997 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/schema/GenericServiceWithoutInterfaceTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/schema/GenericServiceWithoutInterfaceTest.java @@ -19,8 +19,6 @@ package org.apache.dubbo.config.spring.schema; import org.apache.dubbo.common.utils.ClassUtils; import org.apache.dubbo.config.ReferenceConfigBase; import org.apache.dubbo.config.bootstrap.DubboBootstrap; -import org.apache.dubbo.config.spring.registrycenter.RegistryCenter; -import org.apache.dubbo.config.spring.registrycenter.ZookeeperSingleRegistryCenter; import org.apache.dubbo.rpc.service.GenericService; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; @@ -42,19 +40,14 @@ import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER @ImportResource(locations = "classpath:/META-INF/spring/dubbo-generic-consumer-without-interface.xml") public class GenericServiceWithoutInterfaceTest { - private static RegistryCenter singleRegistryCenter; - @BeforeAll public static void beforeAll() { - singleRegistryCenter = new ZookeeperSingleRegistryCenter(); - singleRegistryCenter.startup(); DubboBootstrap.reset(); } @AfterAll public static void afterAll() { DubboBootstrap.reset(); - singleRegistryCenter.shutdown(); } @Autowired diff --git a/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/issues/issue6000/config.properties b/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/issues/issue6000/config.properties index 519de97a12..b415cc459f 100644 --- a/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/issues/issue6000/config.properties +++ b/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/issues/issue6000/config.properties @@ -1,4 +1,4 @@ dubbo.application.name=demo-6000 dubbo.protocol.name=dubbo dubbo.protocol.port=-1 -dubbo.registry.address=zookeeper://127.0.0.1:2181 +dubbo.registry.address=${zookeeper.connection.address} diff --git a/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/issues/issue6252/config.properties b/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/issues/issue6252/config.properties index 5d0ff91aeb..b98da3cf84 100644 --- a/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/issues/issue6252/config.properties +++ b/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/issues/issue6252/config.properties @@ -4,12 +4,12 @@ dubbo.protocol.name=dubbo dubbo.protocol.port=-1 dubbo.scan.basePackages=com.example.demo dubbo.consumer.check=false -dubbo.registries.z214.address=zookeeper://127.0.0.1:2181 +dubbo.registries.z214.address=${zookeeper.connection.address.1} dubbo.registries.z214.timeout=20000 dubbo.registries.z214.subscribe=false dubbo.registries.z214.useAsConfigCenter=false dubbo.registries.z214.useAsMetadataCenter=false -dubbo.registries.z205.address=zookeeper://127.0.0.1:2182 +dubbo.registries.z205.address=${zookeeper.connection.address.2} dubbo.registries.z205.timeout=20000 dubbo.registries.z205.useAsConfigCenter=false dubbo.registries.z205.useAsMetadataCenter=false diff --git a/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/issues/issue7003/config.properties b/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/issues/issue7003/config.properties index 35885f63c1..6620808df7 100644 --- a/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/issues/issue7003/config.properties +++ b/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/issues/issue7003/config.properties @@ -1,4 +1,4 @@ dubbo.application.name=demo-app dubbo.protocol.name=dubbo dubbo.protocol.port=-1 -dubbo.registry.address=zookeeper://127.0.0.1:2181 +dubbo.registry.address=${zookeeper.connection.address} diff --git a/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/service-introspection/zookeeper-dubbb-consumer.properties b/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/service-introspection/zookeeper-dubbb-consumer.properties index 89e59a4846..ecdc96aa01 100644 --- a/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/service-introspection/zookeeper-dubbb-consumer.properties +++ b/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/service-introspection/zookeeper-dubbb-consumer.properties @@ -2,7 +2,7 @@ dubbo.application.name = zookeeper-dubbo-spring-consumer -dubbo.registry.address = zookeeper://127.0.0.1:2181?registry-type=service +dubbo.registry.address = ${zookeeper.connection.address}?registry-type=service dubbo.registry.useAsConfigCenter = true dubbo.registry.useAsMetadataCenter = true diff --git a/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/service-introspection/zookeeper-dubbb-provider.properties b/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/service-introspection/zookeeper-dubbb-provider.properties index d81a529124..2eb414aba9 100644 --- a/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/service-introspection/zookeeper-dubbb-provider.properties +++ b/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/service-introspection/zookeeper-dubbb-provider.properties @@ -2,7 +2,7 @@ dubbo.application.name = zookeeper-dubbo-spring-provider-1 -dubbo.registry.address = zookeeper://127.0.0.1:2181?registry-type=service +dubbo.registry.address = ${zookeeper.connection.address}?registry-type=service dubbo.registry.useAsConfigCenter = true dubbo.registry.useAsMetadataCenter = true diff --git a/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/service-introspection/zookeeper-dubbo-consumer.xml b/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/service-introspection/zookeeper-dubbo-consumer.xml index 92305f5ff4..89ef0a5528 100644 --- a/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/service-introspection/zookeeper-dubbo-consumer.xml +++ b/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/service-introspection/zookeeper-dubbo-consumer.xml @@ -25,10 +25,10 @@ - - \ No newline at end of file + diff --git a/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/spring/dubbo-generic-consumer-without-interface.xml b/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/spring/dubbo-generic-consumer-without-interface.xml index 002f8f69e7..3078126c41 100644 --- a/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/spring/dubbo-generic-consumer-without-interface.xml +++ b/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/spring/dubbo-generic-consumer-without-interface.xml @@ -25,7 +25,7 @@ - + diff --git a/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/spring/dubbo-generic-consumer.xml b/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/spring/dubbo-generic-consumer.xml index e426e22a7c..1bf81f0670 100644 --- a/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/spring/dubbo-generic-consumer.xml +++ b/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/spring/dubbo-generic-consumer.xml @@ -25,7 +25,7 @@ - + diff --git a/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-consumer/src/main/resources/spring/dubbo-consumer.properties b/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-consumer/src/main/resources/spring/dubbo-consumer.properties index 151fc038a0..46ff34d078 100644 --- a/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-consumer/src/main/resources/spring/dubbo-consumer.properties +++ b/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-consumer/src/main/resources/spring/dubbo-consumer.properties @@ -18,5 +18,5 @@ # dubbo.application.name=dubbo-demo-annotation-consumer -dubbo.registry.address=zookeeper://127.0.0.1:2181 +dubbo.registry.address=${zookeeper.connection.address} dubbo.protocol.port=-1 diff --git a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/src/main/resources/spring/dubbo-consumer.xml b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/src/main/resources/spring/dubbo-consumer.xml index a89803c1ed..374060bf6e 100644 --- a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/src/main/resources/spring/dubbo-consumer.xml +++ b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/src/main/resources/spring/dubbo-consumer.xml @@ -24,9 +24,9 @@ - + - + diff --git a/dubbo-test/dubbo-test-check/pom.xml b/dubbo-test/dubbo-test-check/pom.xml index 4cb1b10985..d7bbd6a56d 100644 --- a/dubbo-test/dubbo-test-check/pom.xml +++ b/dubbo-test/dubbo-test-check/pom.xml @@ -32,6 +32,12 @@ 8 8 true + 5.1.0 + 3.6.0 + 5.1.0 + 1.20 + 1.6.2 + 1.3 @@ -42,11 +48,49 @@ org.junit.platform junit-platform-launcher - 1.6.2 + ${junit.platform.launcher.version} org.apache.commons commons-lang3 + + org.apache.curator + curator-test + ${curator.test.version} + compile + + + com.google.guava + guava + + + org.apache.zookeeper + zookeeper + + + + + org.apache.zookeeper + zookeeper + ${zookeeper.version} + + + org.apache.curator + curator-framework + ${curator5.version} + + + + org.apache.commons + commons-compress + ${commons.compress.version} + compile + + + org.apache.commons + commons-exec + ${commons.exec.version} + diff --git a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/AbstractRegistryCenterTestExecutionListener.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/AbstractRegistryCenterTestExecutionListener.java new file mode 100644 index 0000000000..45bab8f392 --- /dev/null +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/AbstractRegistryCenterTestExecutionListener.java @@ -0,0 +1,93 @@ +/* + * 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.test.check; + +import org.junit.platform.engine.TestSource; +import org.junit.platform.engine.support.descriptor.ClassSource; +import org.junit.platform.launcher.TestExecutionListener; +import org.junit.platform.launcher.TestIdentifier; +import org.junit.platform.launcher.TestPlan; +import java.util.HashSet; +import java.util.Set; + +/** + * The abstract implementation provides the basic methods.

+ * {@link #needRegistryCenter(TestPlan)}: checks if current {@link TestPlan} need registry center. + */ +public abstract class AbstractRegistryCenterTestExecutionListener implements TestExecutionListener { + + /** + * The JVM arguments to set if it can use embedded zookeeper, the default value is {@code true}. + */ + private static final String CONFIG_ENABLE_EMBEDDED_ZOOKEEPER = "enableEmbeddedZookeeper"; + + /** + * The registry center should start + * if we want to run the test cases in the given package. + */ + private static final Set PACKAGE_NAME = new HashSet<>(); + + /** + * Use embedded zookeeper or not. + */ + private static boolean enableEmbeddedZookeeper; + + static { + // dubbo-config module + PACKAGE_NAME.add("org.apache.dubbo.config"); + // dubbo-test module + PACKAGE_NAME.add("org.apache.dubbo.test"); + enableEmbeddedZookeeper = Boolean.valueOf(System.getProperty(CONFIG_ENABLE_EMBEDDED_ZOOKEEPER, "true")); + } + + /** + * Checks if current {@link TestPlan} need registry center. + */ + public boolean needRegistryCenter(TestPlan testPlan) { + return testPlan.getRoots().stream() + .flatMap(testIdentifier -> testPlan.getChildren(testIdentifier).stream()) + .filter(testIdentifier -> testIdentifier.getSource().isPresent()) + .filter(testIdentifier -> supportEmbeddedZookeeper(testIdentifier)) + .count() > 0; + } + + /** + * Checks if current {@link TestIdentifier} need registry center. + */ + public boolean needRegistryCenter(TestIdentifier testIdentifier) { + return supportEmbeddedZookeeper(testIdentifier); + } + + /** + * Checks if the current {@link TestIdentifier} need embedded zookeeper. + */ + private boolean supportEmbeddedZookeeper(TestIdentifier testIdentifier) { + if (!enableEmbeddedZookeeper) { + return false; + } + TestSource testSource = testIdentifier.getSource().orElse(null); + if (testSource instanceof ClassSource) { + String packageName = ((ClassSource) testSource).getJavaClass().getPackage().getName(); + for (String pkgName : PACKAGE_NAME) { + if (packageName.contains(pkgName)) { + return true; + } + } + } + return false; + } +} diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/registrycenter/ZookeeperSingleRegistryCenter.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/RegistryCenterFinished.java similarity index 53% rename from dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/registrycenter/ZookeeperSingleRegistryCenter.java rename to dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/RegistryCenterFinished.java index ffc0ec3989..28253fa7f5 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/registrycenter/ZookeeperSingleRegistryCenter.java +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/RegistryCenterFinished.java @@ -14,31 +14,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.config.spring.registrycenter; +package org.apache.dubbo.test.check; + +import org.apache.dubbo.test.check.registrycenter.GlobalRegistryCenter; +import org.junit.platform.launcher.TestPlan; /** - * The default zookeeper single registry center. + * The entrance to terminate the mocked registry center. */ -public class ZookeeperSingleRegistryCenter extends ZookeeperRegistryCenter { +public class RegistryCenterFinished extends AbstractRegistryCenterTestExecutionListener { - /** - * Initialize {@link ZookeeperSingleRegistryCenter} instance. - */ - public ZookeeperSingleRegistryCenter() { - this(DEFAULT_PORT); + @Override + public void testPlanExecutionFinished(TestPlan testPlan) { + super.testPlanExecutionFinished(testPlan); + try { + if(needRegistryCenter(testPlan)){ + GlobalRegistryCenter.shutdown(); + } + } catch (Throwable cause) { + throw new IllegalStateException("Failed to terminate zookeeper instance in unit test",cause); + } } - /** - * Initialize {@link RegistryCenter} instance. - * - * @param port the zookeeper server's port. - */ - public ZookeeperSingleRegistryCenter(int port) { - super(port); - } - - /** - * The zookeeper server's default port. - */ - private static final int DEFAULT_PORT = 2181; } diff --git a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/RegistryCenterStarted.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/RegistryCenterStarted.java new file mode 100644 index 0000000000..e45b16196f --- /dev/null +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/RegistryCenterStarted.java @@ -0,0 +1,50 @@ +/* + * 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.test.check; + +import org.apache.dubbo.test.check.registrycenter.GlobalRegistryCenter; +import org.junit.platform.engine.TestExecutionResult; +import org.junit.platform.launcher.TestIdentifier; +import org.junit.platform.launcher.TestPlan; + +/** + * The entrance to start the mocked registry center. + */ +public class RegistryCenterStarted extends AbstractRegistryCenterTestExecutionListener { + + @Override + public void testPlanExecutionStarted(TestPlan testPlan) { + try { + if (needRegistryCenter(testPlan)) { + GlobalRegistryCenter.startup(); + } + } catch (Throwable cause) { + throw new IllegalStateException("Failed to start zookeeper instance in unit test", cause); + } + } + + @Override + public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) { + try { + if (needRegistryCenter(testIdentifier)) { + GlobalRegistryCenter.reset(); + } + } catch (Throwable cause) { + // ignore the exception + } + } +} diff --git a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/exception/DubboTestException.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/exception/DubboTestException.java new file mode 100644 index 0000000000..6c3f1062a6 --- /dev/null +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/exception/DubboTestException.java @@ -0,0 +1,43 @@ +/* + * 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.test.check.exception; +/** + * Define a specified exception when test. + */ +public class DubboTestException extends RuntimeException { + + /** + * Constructs a new {@link DubboTestException} with the specified detail message. + * + * @param message the detail message. The detail message is saved for later retrieval by the {@link #getMessage()} method. + */ + public DubboTestException(String message) { + super(message); + } + + /** + * Constructs a new {@link DubboTestException} with the specified detail message and cause. + * + * @param message the detail message. The detail message is saved for later retrieval by the {@link #getMessage()} method. + * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). + * (A null value is permitted, and indicates that the cause is nonexistent or unknown.) + */ + public DubboTestException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/Config.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/Config.java new file mode 100644 index 0000000000..0cda9b5684 --- /dev/null +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/Config.java @@ -0,0 +1,67 @@ +/* + * 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.test.check.registrycenter; + +/** + * Define the config to obtain the + */ +public interface Config { + + /** + * Returns the default connection address in single registry center. + */ + default String getConnectionAddress(){ + return getConnectionAddress1(); + } + + /** + * Returns the first connection address in multiple registry center. + */ + String getConnectionAddress1(); + + /** + * Returns the second connection address in multiple registry center. + */ + String getConnectionAddress2(); + + /** + * Returns the default connection address key in single registry center. + *

How to use

+ *
+     * System.getProperty({@link #getConnectionAddressKey()})
+     * 
+ */ + String getConnectionAddressKey(); + + /** + * Returns the first connection address key in multiple registry center. + *

How to use

+ *
+     * System.getProperty({@link #getConnectionAddressKey1()})
+     * 
+ */ + String getConnectionAddressKey1(); + + /** + * Returns the second connection address key in multiple registry center. + *

How to use

+ *
+     * System.getProperty({@link #getConnectionAddressKey2()})
+     * 
+ */ + String getConnectionAddressKey2(); +} diff --git a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/Context.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/Context.java new file mode 100644 index 0000000000..76b15fcdbb --- /dev/null +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/Context.java @@ -0,0 +1,23 @@ +/* + * 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.test.check.registrycenter; + +/** + * The global context to store all initialized variables. + */ +public interface Context { +} diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/registrycenter/ZookeeperMultipleRegistryCenter.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/GlobalRegistryCenter.java similarity index 52% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/registrycenter/ZookeeperMultipleRegistryCenter.java rename to dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/GlobalRegistryCenter.java index 254d794cf4..9fadc1e909 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/registrycenter/ZookeeperMultipleRegistryCenter.java +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/GlobalRegistryCenter.java @@ -14,32 +14,42 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.registrycenter; - -import org.apache.dubbo.common.utils.NetUtils; +package org.apache.dubbo.test.check.registrycenter; /** - * The default zookeeper multiple registry center. + * The global registry center. */ -public class ZookeeperMultipleRegistryCenter extends ZookeeperRegistryCenter { +public class GlobalRegistryCenter { /** - * Initialize {@link ZookeeperMultipleRegistryCenter} instance. + * The default static registry center instance. + */ + private static final RegistryCenter INSTANCE = new ZookeeperRegistryCenter(); + + /** + * Start the registry center. * - * @param port1 the zookeeper server's port. - * @param port2 the zookeeper server's port. + * @throws Exception when an exception occurred */ - public ZookeeperMultipleRegistryCenter(int port1, int port2) { - super(port1, port2); + public static void startup() throws Exception { + INSTANCE.startup(); } /** - * Initialize {@link ZookeeperMultipleRegistryCenter} instance. + * Reset the registry center. + * + * @throws Exception when an exception occurred */ - public ZookeeperMultipleRegistryCenter() { - this(NetUtils.getAvailablePort(), NetUtils.getAvailablePort()); + public static void reset() throws Exception { + INSTANCE.reset(); } - private static final int DEFAULT_PORT1 = 2181; - private static final int DEFAULT_PORT2 = 2182; + /** + * Stop the registry center. + * + * @throws Exception when an exception occurred + */ + public static void shutdown() throws Exception { + INSTANCE.shutdown(); + } } diff --git a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/Initializer.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/Initializer.java new file mode 100644 index 0000000000..7315565269 --- /dev/null +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/Initializer.java @@ -0,0 +1,32 @@ +/* + * 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.test.check.registrycenter; + +import org.apache.dubbo.test.check.exception.DubboTestException; + +/** + * The purpose of this class is to do initialization when we build {@link RegistryCenter}. + */ +public interface Initializer { + + /** + * Initialize the global context. + * @param context the global context to be initialized. + * @throws DubboTestException when any exception occurred. + */ + void initialize(Context context) throws DubboTestException; +} diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/registrycenter/ZookeeperSingleRegistryCenter.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/Processor.java similarity index 57% rename from dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/registrycenter/ZookeeperSingleRegistryCenter.java rename to dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/Processor.java index 04e8f85f65..3df6c6ad09 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/registrycenter/ZookeeperSingleRegistryCenter.java +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/Processor.java @@ -14,31 +14,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.registrycenter; +package org.apache.dubbo.test.check.registrycenter; + +import org.apache.dubbo.test.check.exception.DubboTestException; /** - * The default zookeeper single registry center. + * Define the processor to execute {@link Process} with the {@link org.apache.dubbo.test.check.registrycenter.Initializer.Context} */ -public class ZookeeperSingleRegistryCenter extends ZookeeperRegistryCenter { +public interface Processor { /** - * Initialize {@link ZookeeperSingleRegistryCenter} instance. - */ - public ZookeeperSingleRegistryCenter() { - this(DEFAULT_PORT); - } - - /** - * Initialize {@link RegistryCenter} instance. + * Process the command with the global context. * - * @param port the zookeeper server's port. + * @param context the global context. + * @throws DubboTestException when any exception occurred. */ - public ZookeeperSingleRegistryCenter(int port) { - super(port); - } - - /** - * The zookeeper server's default port. - */ - private static final int DEFAULT_PORT = 2181; + void process(Context context) throws DubboTestException; } diff --git a/dubbo-test/dubbo-test-common/src/main/java/org/apache/dubbo/test/common/registrycenter/ZookeeperSingleRegistryCenter.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/RegistryCenter.java similarity index 58% rename from dubbo-test/dubbo-test-common/src/main/java/org/apache/dubbo/test/common/registrycenter/ZookeeperSingleRegistryCenter.java rename to dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/RegistryCenter.java index 9f0e0100a3..e28f65ee5a 100644 --- a/dubbo-test/dubbo-test-common/src/main/java/org/apache/dubbo/test/common/registrycenter/ZookeeperSingleRegistryCenter.java +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/RegistryCenter.java @@ -14,31 +14,32 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.test.common.registrycenter; +package org.apache.dubbo.test.check.registrycenter; + +import org.apache.dubbo.test.check.exception.DubboTestException; /** - * The default zookeeper single registry center. + * The registry center. */ -public class ZookeeperSingleRegistryCenter extends ZookeeperRegistryCenter { +public interface RegistryCenter { /** - * Initialize {@link ZookeeperSingleRegistryCenter} instance. - */ - public ZookeeperSingleRegistryCenter() { - this(DEFAULT_PORT); - } - - /** - * Initialize {@link RegistryCenter} instance. + * Start the registry center. * - * @param port the zookeeper server's port. + * @throws DubboTestException when an exception occurred */ - public ZookeeperSingleRegistryCenter(int port) { - super(port); - } + void startup() throws DubboTestException; /** - * The zookeeper server's default port. + * Reset the registry center after ut exited. + * @throws DubboTestException when an exception occurred */ - private static final int DEFAULT_PORT = 2181; + void reset() throws DubboTestException; + + /** + * Stop the registry center. + * + * @throws DubboTestException when an exception occurred + */ + void shutdown() throws DubboTestException; } diff --git a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/ZookeeperRegistryCenter.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/ZookeeperRegistryCenter.java new file mode 100644 index 0000000000..144b7d3509 --- /dev/null +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/ZookeeperRegistryCenter.java @@ -0,0 +1,186 @@ +/* + * 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.test.check.registrycenter; + +import org.apache.dubbo.test.check.exception.DubboTestException; +import org.apache.dubbo.test.check.registrycenter.context.ZookeeperContext; +import org.apache.dubbo.test.check.registrycenter.context.ZookeeperWindowsContext; +import org.apache.dubbo.test.check.registrycenter.initializer.ConfigZookeeperInitializer; +import org.apache.dubbo.test.check.registrycenter.initializer.DownloadZookeeperInitializer; +import org.apache.dubbo.test.check.registrycenter.initializer.UnpackZookeeperInitializer; +import org.apache.dubbo.test.check.registrycenter.initializer.ZookeeperInitializer; +import org.apache.dubbo.test.check.registrycenter.processor.StartZookeeperUnixProcessor; +import org.apache.dubbo.test.check.registrycenter.processor.StartZookeeperWindowsProcessor; +import org.apache.dubbo.test.check.registrycenter.processor.ResetZookeeperProcessor; +import org.apache.dubbo.test.check.registrycenter.processor.StopZookeeperUnixProcessor; +import org.apache.dubbo.test.check.registrycenter.processor.StopZookeeperWindowsProcessor; + +import java.util.List; +import java.util.ArrayList; +import java.util.Objects; +import java.util.Map; +import java.util.HashMap; +import java.util.concurrent.atomic.AtomicBoolean; + +/** + * Build the registry center with embedded zookeeper, which is run by a new process. + */ +class ZookeeperRegistryCenter implements RegistryCenter { + + public ZookeeperRegistryCenter() { + this.initializers = new ArrayList<>(); + this.initializers.add(new DownloadZookeeperInitializer()); + this.initializers.add(new UnpackZookeeperInitializer()); + this.initializers.add(new ConfigZookeeperInitializer()); + // start processor + this.put(OS.Unix, Command.Start, new StartZookeeperUnixProcessor()); + this.put(OS.Windows, Command.Start, new StartZookeeperWindowsProcessor()); + + // reset processor + Processor resetProcessor = new ResetZookeeperProcessor(); + this.put(OS.Unix, Command.Reset, resetProcessor); + this.put(OS.Windows, Command.Reset, resetProcessor); + + // stop processor + this.put(OS.Unix, Command.Stop, new StopZookeeperUnixProcessor()); + this.put(OS.Windows, Command.Stop, new StopZookeeperWindowsProcessor()); + + // initialize the global context + if (OS.Unix.equals(os)) { + this.context = new ZookeeperContext(); + } else { + this.context = new ZookeeperWindowsContext(); + } + } + + /** + * The OS type. + */ + private static OS os = getOS(); + + /** + * All of {@link ZookeeperInitializer} instances. + */ + private List initializers; + + /** + * The global context of zookeeper. + */ + private ZookeeperContext context; + + /** + * To store all processor instances. + */ + private Map> processors = new HashMap<>(); + + /** + * The {@link #INITIALIZED} for flagging the {@link #startup()} method is called or not. + */ + private final AtomicBoolean INITIALIZED = new AtomicBoolean(false); + + /** + * Returns the Operating System. + */ + private static OS getOS() { + String osName = System.getProperty("os.name").toLowerCase(); + OS os = OS.Unix; + if (osName.contains("windows")) { + os = OS.Windows; + } + return os; + } + + /** + * Store all initialized processor instances. + * + * @param os the {@link OS} type. + * @param command the {@link Command} to execute. + * @param processor the {@link Processor} to run. + */ + private void put(OS os, Command command, Processor processor) { + Map commandProcessorMap = this.processors.get(os); + if (commandProcessorMap == null) { + commandProcessorMap = new HashMap<>(); + this.processors.put(os, commandProcessorMap); + } + commandProcessorMap.put(command, processor); + } + + /** + * Gets the {@link Processor} with the given {@link OS} type and {@link Command}. + * + * @param os the {@link OS} type. + * @param command the {@link Command} to execute. + * @return the {@link Processor} to run. + */ + private Processor get(OS os, Command command) { + Map commandProcessorMap = this.processors.get(os); + Objects.requireNonNull(commandProcessorMap, "The command with the OS cannot be null"); + Processor processor = commandProcessorMap.get(command); + Objects.requireNonNull(processor, "The processor cannot be null"); + return processor; + } + + /** + * {@inheritDoc} + */ + @Override + public void startup() throws DubboTestException { + if (!this.INITIALIZED.get()) { + if (!this.INITIALIZED.compareAndSet(false, true)) { + return; + } + for (Initializer initializer : this.initializers) { + initializer.initialize(this.context); + } + } + this.get(os, Command.Start).process(this.context); + } + + /** + * {@inheritDoc} + */ + @Override + public void reset() throws DubboTestException { + this.get(os, Command.Reset).process(this.context); + } + + /** + * {@inheritDoc} + */ + @Override + public void shutdown() throws DubboTestException { + this.get(os, Command.Stop).process(this.context); + } + + /** + * The type of OS. + */ + enum OS { + Windows, + Unix + } + + /** + * The commands to support the zookeeper. + */ + enum Command { + Start, + Reset, + Stop + } +} diff --git a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/config/ZookeeperConfig.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/config/ZookeeperConfig.java new file mode 100644 index 0000000000..9b601aebb5 --- /dev/null +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/config/ZookeeperConfig.java @@ -0,0 +1,175 @@ +/* + * 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.test.check.registrycenter.config; + +import org.apache.dubbo.test.check.registrycenter.Config; + +/** + * The zookeeper config in registry center. + */ +public class ZookeeperConfig implements Config { + + /** + * The system properties config key with zookeeper port. + */ + private static final String ZOOKEEPER_PORT_KEY = "zookeeper.port"; + + /** + * The system properties config key with first zookeeper port. + */ + private static final String ZOOKEEPER_PORT_1_KEY = "zookeeper.port.1"; + + /** + * The system properties config key with second zookeeper port. + */ + private static final String ZOOKEEPER_PORT_2_KEY = "zookeeper.port.2"; + + /** + * The system properties config key with zookeeper connection address. + */ + private static final String ZOOKEEPER_CONNECTION_ADDRESS_KEY = "zookeeper.connection.address"; + + /** + * The system properties config key with first zookeeper connection address. + */ + private static final String ZOOKEEPER_CONNECTION_ADDRESS_1_KEY = "zookeeper.connection.address.1"; + + /** + * The system properties config key with second zookeeper connection address. + */ + private static final String ZOOKEEPER_CONNECTION_ADDRESS_2_KEY = "zookeeper.connection.address.2"; + + /** + * The default first client port of zookeeper. + */ + public static final int DEFAULT_CLIENT_PORT_1 = 2181; + + /** + * The default second client port of zookeeper. + */ + public static final int DEFAULT_CLIENT_PORT_2 = 2182; + + /** + * The default client ports of zookeeper. + */ + private static final int[] CLIENT_PORTS = new int[2]; + + /** + * The default admin server ports of zookeeper. + */ + private static final int[] DEFAULT_ADMIN_SERVER_PORTS = new int[]{8081, 8082}; + + /** + * The default version of zookeeper. + */ + private static final String DEFAULT_ZOOKEEPER_VERSION = "3.6.0"; + + /** + * The format for zookeeper connection address. + */ + private static final String CONNECTION_ADDRESS_FORMAT = "zookeeper://127.0.0.1:%d"; + + // initialize the client ports of zookeeper. + static { + // There are two client ports + + // The priority of the one is that get it from system properties config + // with the key of {@link #ZOOKEEPER_PORT_1_KEY} first, and then {@link #ZOOKEEPER_PORT_KEY}, + // finally use {@link #DEFAULT_CLIENT_PORT_1} as default port + + // The priority of the other is that get it from system properties config with the key of {@link #ZOOKEEPER_PORT_2_KEY} first, + // and then use {@link #DEFAULT_CLIENT_PORT_2} as default port + + int port1 = DEFAULT_CLIENT_PORT_1; + int port2 = DEFAULT_CLIENT_PORT_2; + String portConfig1 = System.getProperty(ZOOKEEPER_PORT_1_KEY, System.getProperty(ZOOKEEPER_PORT_KEY)); + if (portConfig1 != null) { + try { + port1 = Integer.parseInt(portConfig1); + } catch (NumberFormatException e) { + port1 = DEFAULT_CLIENT_PORT_1; + } + } + + String portConfig2 = System.getProperty(ZOOKEEPER_PORT_2_KEY); + if (portConfig2 != null) { + try { + port2 = Integer.parseInt(portConfig2); + } catch (NumberFormatException e) { + port2 = DEFAULT_CLIENT_PORT_2; + } + } + + if (port1 == port2) { + throw new IllegalArgumentException(String.format("The client ports %d and %d of zookeeper cannot be same!", port1, port2)); + } + + CLIENT_PORTS[0] = port1; + CLIENT_PORTS[1] = port2; + + // set system properties config + System.setProperty(ZOOKEEPER_CONNECTION_ADDRESS_KEY, String.format(CONNECTION_ADDRESS_FORMAT, CLIENT_PORTS[0])); + System.setProperty(ZOOKEEPER_CONNECTION_ADDRESS_1_KEY, String.format(CONNECTION_ADDRESS_FORMAT, CLIENT_PORTS[0])); + System.setProperty(ZOOKEEPER_CONNECTION_ADDRESS_2_KEY, String.format(CONNECTION_ADDRESS_FORMAT, CLIENT_PORTS[1])); + } + + @Override + public String getConnectionAddress1() { + return String.format(CONNECTION_ADDRESS_FORMAT, CLIENT_PORTS[0]); + } + + @Override + public String getConnectionAddress2() { + return String.format(CONNECTION_ADDRESS_FORMAT, CLIENT_PORTS[1]); + } + + @Override + public String getConnectionAddressKey() { + return ZOOKEEPER_CONNECTION_ADDRESS_KEY; + } + + @Override + public String getConnectionAddressKey1() { + return ZOOKEEPER_CONNECTION_ADDRESS_1_KEY; + } + + @Override + public String getConnectionAddressKey2() { + return ZOOKEEPER_CONNECTION_ADDRESS_2_KEY; + } + + /** + * Returns the zookeeper's version. + */ + public String getVersion() { + return DEFAULT_ZOOKEEPER_VERSION; + } + + /** + * Returns the client ports of zookeeper. + */ + public int[] getClientPorts() { + return CLIENT_PORTS; + } + + /** + * Returns the admin server ports of zookeeper. + */ + public int[] getAdminServerPorts() { + return DEFAULT_ADMIN_SERVER_PORTS; + } +} diff --git a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/config/ZookeeperRegistryCenterConfig.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/config/ZookeeperRegistryCenterConfig.java new file mode 100644 index 0000000000..86080835f1 --- /dev/null +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/config/ZookeeperRegistryCenterConfig.java @@ -0,0 +1,84 @@ +/* + * 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.test.check.registrycenter.config; + +import org.apache.dubbo.test.check.registrycenter.Config; + +/** + * Define the zookeeper global config for registry center. + */ +public class ZookeeperRegistryCenterConfig { + + /** + * Define the {@link Config} instance. + */ + private static final Config CONFIG = new ZookeeperConfig(); + + /** + * Returns the connection address in single registry center. + */ + public static String getConnectionAddress() { + return CONFIG.getConnectionAddress(); + } + + /** + * Returns the first connection address in multiple registry centers. + */ + public static String getConnectionAddress1() { + return CONFIG.getConnectionAddress1(); + } + + /** + * Returns the second connection address in multiple registry centers. + */ + public static String getConnectionAddress2() { + return CONFIG.getConnectionAddress2(); + } + + /** + * Returns the default connection address key in single registry center. + *

How to use

+ *
+     * System.getProperty({@link ZookeeperRegistryCenterConfig#getConnectionAddressKey()})
+     * 
+ */ + public static String getConnectionAddressKey() { + return CONFIG.getConnectionAddressKey(); + } + + /** + * Returns the first connection address key in multiple registry center. + *

How to use

+ *
+     * System.getProperty({@link ZookeeperRegistryCenterConfig#getConnectionAddressKey1()})
+     * 
+ */ + public static String getConnectionAddressKey1() { + return CONFIG.getConnectionAddressKey1(); + } + + /** + * Returns the second connection address key in multiple registry center. + *

How to use

+ *
+     * System.getProperty({@link ZookeeperRegistryCenterConfig#getConnectionAddressKey2()})
+     * 
+ */ + public static String getConnectionAddressKey2() { + return CONFIG.getConnectionAddressKey2(); + } +} diff --git a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/context/ZookeeperContext.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/context/ZookeeperContext.java new file mode 100644 index 0000000000..9fd6ab520e --- /dev/null +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/context/ZookeeperContext.java @@ -0,0 +1,73 @@ +/* + * 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.test.check.registrycenter.context; + +import org.apache.dubbo.test.check.registrycenter.Context; +import org.apache.dubbo.test.check.registrycenter.config.ZookeeperConfig; + +import java.nio.file.Path; + +/** + * The global context for zookeeper. + */ +public class ZookeeperContext implements Context { + + /** + * The config of zookeeper. + */ + private ZookeeperConfig config = new ZookeeperConfig(); + + /** + * The the source file path of downloaded zookeeper binary archive. + */ + private Path sourceFile; + + /** + * Sets the source file path of downloaded zookeeper binary archive. + */ + public void setSourceFile(Path sourceFile) { + this.sourceFile = sourceFile; + } + + /** + * Returns the source file path of downloaded zookeeper binary archive. + */ + public Path getSourceFile() { + return this.sourceFile; + } + + /** + * Returns the zookeeper's version. + */ + public String getVersion() { + return config.getVersion(); + } + + /** + * Returns the client ports of zookeeper. + */ + public int[] getClientPorts() { + return config.getClientPorts(); + } + + /** + * Returns the admin server ports of zookeeper. + */ + public int[] getAdminServerPorts() { + return config.getAdminServerPorts(); + } +} diff --git a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/context/ZookeeperWindowsContext.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/context/ZookeeperWindowsContext.java new file mode 100644 index 0000000000..ffbe0a8ee1 --- /dev/null +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/context/ZookeeperWindowsContext.java @@ -0,0 +1,110 @@ +/* + * 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.test.check.registrycenter.context; + +import org.apache.commons.exec.ExecuteWatchdog; +import org.apache.dubbo.common.threadlocal.NamedInternalThreadFactory; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.SynchronousQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +/** + * The global context for zookeeper on Windows OS. + */ +public class ZookeeperWindowsContext extends ZookeeperContext { + + /** + * The default executor service to manage the lifecycle of zookeeper. + */ + private final ExecutorService DEFAULT_EXECUTOR_SERVICE = new ThreadPoolExecutor(2, 2, 0, TimeUnit.MILLISECONDS, + new SynchronousQueue<>(), + new NamedInternalThreadFactory("mocked-zookeeper", true), new ThreadPoolExecutor.AbortPolicy()); + + /** + * Define the default {@link ExecuteWatchdog} for terminating all registered zookeeper processes. + */ + private final ExecuteWatchdog WATCHDOG = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT); + + /** + * The map to store the pair of clientPort and PID. + */ + private Map processIds = new HashMap<>(); + + /** + * Register the process id of zookeeper. + * + * @param clientPort the client port of zookeeper. + * @param pid the process id of zookeeper instance. + */ + public void register(int clientPort, int pid) { + this.processIds.put(clientPort, pid); + } + + /** + * Returns the pid of zookeeper instance with the given client port. + * + * @param clientPort the client port of zookeeper instance. + * @return the pid of zookeeper instance. + */ + public Integer getPid(int clientPort) { + return this.processIds.get(clientPort); + } + + /** + * Remove the registered pid with the given client port. + * @param clientPort the client port of zookeeper instance. + */ + public void removePid(int clientPort){ + this.processIds.remove(clientPort); + } + + /** + * Returns the default executor service to manage the lifecycle of zookeeper. + */ + public ExecutorService getExecutorService() { + return DEFAULT_EXECUTOR_SERVICE; + } + + /** + * Returns the {@link ExecuteWatchdog}. + */ + public ExecuteWatchdog getWatchdog() { + return WATCHDOG; + } + + /** + * Destroy all registered resources. + */ + public void destroy() { + this.processIds.clear(); + this.WATCHDOG.destroyProcess(); + try { + DEFAULT_EXECUTOR_SERVICE.shutdownNow(); + } catch (SecurityException | NullPointerException ex) { + return; + } + try { + DEFAULT_EXECUTOR_SERVICE.awaitTermination(5, TimeUnit.SECONDS); + } catch (InterruptedException ex) { + Thread.currentThread().interrupt(); + } + } +} diff --git a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/initializer/ConfigZookeeperInitializer.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/initializer/ConfigZookeeperInitializer.java new file mode 100644 index 0000000000..6ca780611b --- /dev/null +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/initializer/ConfigZookeeperInitializer.java @@ -0,0 +1,119 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.test.check.registrycenter.initializer; + +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.test.check.exception.DubboTestException; +import org.apache.dubbo.test.check.registrycenter.context.ZookeeperContext; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Properties; + +/** + * Update the config file of zookeeper. + */ +public class ConfigZookeeperInitializer extends ZookeeperInitializer { + + private static final Logger logger = LoggerFactory.getLogger(ConfigZookeeperInitializer.class); + + /** + * Update the config file with the given client port and admin server port. + * + * @param clientPort the client port + * @param adminServerPort the admin server port + * @throws DubboTestException when an exception occurred + */ + private void updateConfig(ZookeeperContext context, int clientPort, int adminServerPort) throws DubboTestException { + Path zookeeperConf = Paths.get(context.getSourceFile().getParent().toString(), + String.valueOf(clientPort), + String.format("apache-zookeeper-%s-bin", context.getVersion()), + "conf"); + File zooSample = Paths.get(zookeeperConf.toString(), "zoo_sample.cfg").toFile(); + + Properties properties = new Properties(); + try { + properties.load(new FileInputStream(zooSample)); + properties.setProperty("clientPort", String.valueOf(clientPort)); + properties.setProperty("admin.serverPort", String.valueOf(adminServerPort)); + Path dataDir = Paths.get(zookeeperConf.getParent().toString(), "data"); + if (!Files.exists(dataDir)) { + try { + logger.info("It is creating the data directory..."); + Files.createDirectories(dataDir); + } catch (IOException e) { + throw new RuntimeException(String.format("Failed to create the data directory to save zookeeper binary file, file path:%s", context.getSourceFile()), e); + } + } + properties.setProperty("dataDir", dataDir.toString()); + FileOutputStream oFile = null; + try { + oFile = new FileOutputStream(Paths.get(zookeeperConf.toString(), "zoo.cfg").toFile()); + properties.store(oFile, ""); + } finally { + try { + oFile.close(); + } catch (IOException e) { + throw new DubboTestException("Failed to close file", e); + } + } + } catch (IOException e) { + throw new DubboTestException(String.format("Failed to update %s file", zooSample.toString()), e); + } + + File log4j = Paths.get(zookeeperConf.toString(), "log4j.properties").toFile(); + try { + properties.load(new FileInputStream(log4j)); + Path logDir = Paths.get(zookeeperConf.getParent().toString(), "logs"); + if (!Files.exists(logDir)) { + try { + logger.info("It is creating the log directory..."); + Files.createDirectories(logDir); + } catch (IOException e) { + throw new RuntimeException(String.format("Failed to create the log directory to save zookeeper binary file, file path:%s", context.getSourceFile()), e); + } + } + properties.setProperty("zookeeper.log.dir", logDir.toString()); + FileOutputStream oFile = null; + try { + oFile = new FileOutputStream(Paths.get(zookeeperConf.toString(), "log4j.properties").toFile()); + properties.store(oFile, ""); + } finally { + try { + oFile.close(); + } catch (IOException e) { + throw new DubboTestException("Failed to close file", e); + } + } + } catch (IOException e) { + throw new DubboTestException(String.format("Failed to update %s file", zooSample.toString()), e); + } + } + + @Override + protected void doInitialize(ZookeeperContext context) throws DubboTestException { + for (int i = 0; i < context.getClientPorts().length; i++) { + this.updateConfig(context, context.getClientPorts()[i], context.getAdminServerPorts()[i]); + } + } +} diff --git a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/initializer/DownloadZookeeperInitializer.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/initializer/DownloadZookeeperInitializer.java new file mode 100644 index 0000000000..653c23a625 --- /dev/null +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/initializer/DownloadZookeeperInitializer.java @@ -0,0 +1,92 @@ +/* + * 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.test.check.registrycenter.initializer; + +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.test.check.exception.DubboTestException; +import org.apache.dubbo.test.check.registrycenter.context.ZookeeperContext; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; + +/** + * Download zookeeper binary archive. + */ +public class DownloadZookeeperInitializer extends ZookeeperInitializer { + + private static final Logger logger = LoggerFactory.getLogger(DownloadZookeeperInitializer.class); + + /** + * The zookeeper binary file name format. + */ + private static final String ZOOKEEPER_FILE_NAME_FORMAT = "apache-zookeeper-%s-bin.tar.gz"; + + /** + * The url format for zookeeper binary file. + */ + private static final String ZOOKEEPER_BINARY_URL_FORMAT = "https://archive.apache.org/dist/zookeeper/zookeeper-%s/" + ZOOKEEPER_FILE_NAME_FORMAT; + + /** + * The temporary directory name + */ + private static final String TEMPORARY_DIRECTORY_NAME = "dubbo-mocked-zookeeper"; + + @Override + protected void doInitialize(ZookeeperContext context) throws DubboTestException { + String zookeeperFileName = String.format(ZOOKEEPER_FILE_NAME_FORMAT, context.getVersion()); + try { + context.setSourceFile(Paths.get(Files.createTempDirectory("").getParent().toString(), + TEMPORARY_DIRECTORY_NAME, + zookeeperFileName)); + } catch (IOException e) { + throw new RuntimeException(String.format("Cannot create the temporary directory, related directory:%s/%s", + TEMPORARY_DIRECTORY_NAME, zookeeperFileName), e); + } + // check if the zookeeper binary file exists + if (context.getSourceFile() != null && context.getSourceFile().toFile().isFile()) { + return; + } + // create the temporary directory path. + if (!Files.exists(context.getSourceFile())) { + try { + Files.createDirectories(context.getSourceFile()); + } catch (IOException e) { + throw new RuntimeException(String.format("Failed to create the temporary directory to save zookeeper binary file, file path:%s", context.getSourceFile()), e); + } + } + // download zookeeper binary file + String zookeeperBinaryUrl = String.format(ZOOKEEPER_BINARY_URL_FORMAT, context.getVersion(), context.getVersion()); + try { + logger.info("It is beginning to download the zookeeper binary archive, it will take several minutes..."); + URL zookeeperBinaryURL = new URL(zookeeperBinaryUrl); + InputStream inputStream = zookeeperBinaryURL.openStream(); + Files.copy(inputStream, context.getSourceFile(), StandardCopyOption.REPLACE_EXISTING); + } catch (Exception e) { + throw new RuntimeException(String.format("Download zookeeper binary archive failed, download url:%s, file path:%s", + zookeeperBinaryUrl, context.getSourceFile()), e); + } + // check if the zookeeper binary file exists again. + if (context.getSourceFile() == null || !context.getSourceFile().toFile().isFile()) { + throw new IllegalArgumentException(String.format("The zookeeper binary archive file doesn't exist, file path:%s", context.getSourceFile())); + } + } +} diff --git a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/initializer/UnpackZookeeperInitializer.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/initializer/UnpackZookeeperInitializer.java new file mode 100644 index 0000000000..622cf9a89e --- /dev/null +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/initializer/UnpackZookeeperInitializer.java @@ -0,0 +1,97 @@ +/* + * 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.test.check.registrycenter.initializer; + +import org.apache.commons.compress.archivers.tar.TarArchiveEntry; +import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; +import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; +import org.apache.commons.compress.utils.IOUtils; +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.test.check.exception.DubboTestException; +import org.apache.dubbo.test.check.registrycenter.context.ZookeeperContext; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; + +/** + * Unpack the downloaded zookeeper binary archive. + */ +public class UnpackZookeeperInitializer extends ZookeeperInitializer { + + private static final Logger logger = LoggerFactory.getLogger(UnpackZookeeperInitializer.class); + + /** + * Unpack the zookeeper binary file. + * + * @param context the global context of zookeeper. + * @param clientPort the client port + * @throws DubboTestException when an exception occurred + */ + private void unpack(ZookeeperContext context, int clientPort) throws DubboTestException { + File sourceFile = context.getSourceFile().toFile(); + Path targetPath = Paths.get(context.getSourceFile().getParent().toString(), + String.valueOf(clientPort)); + // check if it's unpacked. + if (targetPath.toFile() != null && targetPath.toFile().isDirectory()) { + logger.info(String.format("The file has been unpacked, target path:%s", targetPath.toString())); + return; + } + try (FileInputStream fileInputStream = new FileInputStream(sourceFile); + GzipCompressorInputStream gzipCompressorInputStream = new GzipCompressorInputStream(fileInputStream); + TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(gzipCompressorInputStream, "UTF-8")) { + File targetFile = targetPath.toFile(); + TarArchiveEntry entry; + while ((entry = tarArchiveInputStream.getNextTarEntry()) != null) { + if (entry.isDirectory()) { + continue; + } + File curFile = new File(targetFile, entry.getName()); + File parent = curFile.getParentFile(); + if (!parent.exists()) { + parent.mkdirs(); + } + try (FileOutputStream outputStream = new FileOutputStream(curFile)) { + IOUtils.copy(tarArchiveInputStream, outputStream); + } + } + } catch (IOException e) { + throw new DubboTestException(String.format("Failed to unpack the zookeeper binary file"), e); + } + } + + @Override + protected void doInitialize(ZookeeperContext context) throws DubboTestException { + for (int clientPort : context.getClientPorts()) { + this.unpack(context, clientPort); + // update file permission + Path zookeeperBin = Paths.get(context.getSourceFile().getParent().toString(), + String.valueOf(clientPort), + String.format("apache-zookeeper-%s-bin", context.getVersion()), + "bin"); + for (File file : zookeeperBin.toFile().listFiles()) { + file.setExecutable(true, false); + file.setReadable(true, false); + file.setWritable(false, false); + } + } + } +} diff --git a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/initializer/ZookeeperInitializer.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/initializer/ZookeeperInitializer.java new file mode 100644 index 0000000000..c67fc8febb --- /dev/null +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/initializer/ZookeeperInitializer.java @@ -0,0 +1,51 @@ +/* + * 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.test.check.registrycenter.initializer; + +import org.apache.dubbo.test.check.exception.DubboTestException; +import org.apache.dubbo.test.check.registrycenter.Context; +import org.apache.dubbo.test.check.registrycenter.Initializer; +import org.apache.dubbo.test.check.registrycenter.context.ZookeeperContext; + +import java.util.concurrent.atomic.AtomicBoolean; + +/** + * The implementation of {@link Initializer} to initialize zookeeper. + */ +public abstract class ZookeeperInitializer implements Initializer { + + /** + * The {@link #INITIALIZED} for checking the {@link #initialize(Context)} method is called or not. + */ + private final AtomicBoolean INITIALIZED = new AtomicBoolean(false); + + @Override + public void initialize(Context context) throws DubboTestException { + if (!this.INITIALIZED.compareAndSet(false, true)) { + return; + } + this.doInitialize((ZookeeperContext) context); + } + + /** + * Initialize the global context for zookeeper. + * + * @param context the global context for zookeeper. + * @throws DubboTestException when any exception occurred. + */ + protected abstract void doInitialize(ZookeeperContext context) throws DubboTestException; +} diff --git a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/FindPidWindowsProcessor.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/FindPidWindowsProcessor.java new file mode 100644 index 0000000000..a6200dd44a --- /dev/null +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/FindPidWindowsProcessor.java @@ -0,0 +1,119 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.test.check.registrycenter.processor; + +import org.apache.commons.exec.CommandLine; +import org.apache.commons.exec.DefaultExecutor; +import org.apache.commons.exec.Executor; +import org.apache.commons.exec.PumpStreamHandler; +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.test.check.exception.DubboTestException; +import org.apache.dubbo.test.check.registrycenter.context.ZookeeperWindowsContext; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + + +/** + * Create a {@link org.apache.dubbo.test.check.registrycenter.Processor} to find pid on Windows OS. + */ +public class FindPidWindowsProcessor extends ZookeeperWindowsProcessor { + + private static final Logger logger = LoggerFactory.getLogger(FindPidWindowsProcessor.class); + + @Override + protected void doProcess(ZookeeperWindowsContext context) throws DubboTestException { + for (int clientPort : context.getClientPorts()) { + this.findPid(context, clientPort); + } + } + + /** + * Find the pid of zookeeper instance. + * + * @param context the global context. + * @param clientPort the client port of zookeeper instance. + */ + private void findPid(ZookeeperWindowsContext context, int clientPort) { + logger.info(String.format("Find the pid of the zookeeper with port %d", clientPort)); + Executor executor = new DefaultExecutor(); + executor.setExitValues(null); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ByteArrayOutputStream ins = new ByteArrayOutputStream(); + ByteArrayInputStream in = new ByteArrayInputStream(ins.toByteArray()); + executor.setStreamHandler(new PumpStreamHandler(out, null, in)); + CommandLine cmdLine = new CommandLine("cmd.exe"); + cmdLine.addArgument("/c"); + cmdLine.addArgument("netstat -ano | findstr " + clientPort); + try { + executor.execute(cmdLine); + String result = out.toString(); + logger.info(String.format("Find result: %s", result)); + if (StringUtils.isNotEmpty(result)) { + String[] values = result.split("\\r\\n"); + // values sample: + // Protocol Local address Foreign address Status PID + // TCP 127.0.0.1:2182 127.0.0.1:56672 ESTABLISHED 4020 + // TCP 127.0.0.1:56672 127.0.0.1:2182 ESTABLISHED 1980 + // TCP 127.0.0.1:56692 127.0.0.1:2182 ESTABLISHED 1980 + // TCP 127.0.0.1:56723 127.0.0.1:2182 ESTABLISHED 1980 + // TCP [::]:2182 [::]:0 LISTENING 4020 + if (values != null && values.length > 0) { + for (int i = 0; i < values.length; i++) { + List segments = Arrays.stream(values[i].trim().split(" ")) + .filter(str -> !"".equals(str)) + .collect(Collectors.toList()); + // segments sample: + // TCP + // 127.0.0.1:2182 + // 127.0.0.1:56672 + // ESTABLISHED + // 4020 + if (segments != null && segments.size() == 5) { + if (this.check(segments.get(1), clientPort)) { + int pid = Integer.valueOf(segments.get(segments.size() - 1).trim()); + context.register(clientPort, pid); + return; + } + } + } + } + } + } catch (IOException e) { + throw new DubboTestException(String.format("Failed to find the PID of zookeeper with port %d", clientPort), e); + } + } + + /** + * Checks if segment is valid ip and port pair. + * + * @param segment the segment to check + * @param clientPort the client port of zookeeper instance + * @return {@code true} if segment is valid pair of ip and port, otherwise {@code false} + */ + private boolean check(String segment, int clientPort) { + return ("[::]:" + clientPort).equalsIgnoreCase(segment) + || ("0.0.0.0:" + clientPort).equalsIgnoreCase(segment) + || ("127.0.0.1:" + clientPort).equalsIgnoreCase(segment); + } +} diff --git a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/KillProcessWindowsProcessor.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/KillProcessWindowsProcessor.java new file mode 100644 index 0000000000..d38d8a8784 --- /dev/null +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/KillProcessWindowsProcessor.java @@ -0,0 +1,61 @@ +/* + * 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.test.check.registrycenter.processor; + +import org.apache.commons.exec.CommandLine; +import org.apache.commons.exec.DefaultExecutor; +import org.apache.commons.exec.Executor; +import org.apache.commons.exec.PumpStreamHandler; +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.test.check.exception.DubboTestException; +import org.apache.dubbo.test.check.registrycenter.context.ZookeeperWindowsContext; + +import java.io.IOException; + +/** + * Create a {@link org.apache.dubbo.test.check.registrycenter.Processor} to kill pid on Windows OS. + */ +public class KillProcessWindowsProcessor extends ZookeeperWindowsProcessor { + + private static final Logger logger = LoggerFactory.getLogger(KillProcessWindowsProcessor.class); + + @Override + protected void doProcess(ZookeeperWindowsContext context) throws DubboTestException { + for (int clientPort : context.getClientPorts()) { + Integer pid = context.getPid(clientPort); + if (pid == null) { + logger.info("There is no PID of zookeeper instance with the port " + clientPort); + continue; + } + logger.info(String.format("Kill the pid %d of the zookeeper with port %d", pid, clientPort)); + Executor executor = new DefaultExecutor(); + executor.setExitValues(null); + executor.setStreamHandler(new PumpStreamHandler(null, null, null)); + CommandLine cmdLine = new CommandLine("cmd.exe"); + cmdLine.addArgument("/c"); + cmdLine.addArgument("taskkill /PID " + pid + " -t -f"); + try { + executor.execute(cmdLine); + // clear pid + context.removePid(clientPort); + } catch (IOException e) { + throw new DubboTestException(String.format("Failed to kill the pid %d of zookeeper with port %d", pid, clientPort), e); + } + } + } +} diff --git a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/ResetZookeeperProcessor.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/ResetZookeeperProcessor.java new file mode 100644 index 0000000000..8ce3ee0cac --- /dev/null +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/ResetZookeeperProcessor.java @@ -0,0 +1,55 @@ +/* + * 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.test.check.registrycenter.processor; + +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.CuratorFrameworkFactory; +import org.apache.curator.retry.RetryNTimes; +import org.apache.dubbo.test.check.exception.DubboTestException; +import org.apache.dubbo.test.check.registrycenter.Context; +import org.apache.dubbo.test.check.registrycenter.Processor; +import org.apache.dubbo.test.check.registrycenter.context.ZookeeperContext; + +import java.util.concurrent.TimeUnit; + +/** + * Create {@link Process} to reset zookeeper. + */ +public class ResetZookeeperProcessor implements Processor { + + @Override + public void process(Context context) throws DubboTestException { + ZookeeperContext zookeeperContext = (ZookeeperContext)context; + for (int clientPort : zookeeperContext.getClientPorts()) { + CuratorFramework client; + try { + CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder() + .connectString("127.0.0.1:" + clientPort) + .retryPolicy(new RetryNTimes(1, 1000)); + client = builder.build(); + client.start(); + boolean connected = client.blockUntilConnected(1000, TimeUnit.MILLISECONDS); + if (!connected) { + throw new IllegalStateException("zookeeper not connected"); + } + client.delete().deletingChildrenIfNeeded().forPath("/dubbo"); + } catch (Exception e) { + throw new DubboTestException(e.getMessage(), e); + } + } + } +} diff --git a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/StartZookeeperUnixProcessor.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/StartZookeeperUnixProcessor.java new file mode 100644 index 0000000000..b2688da519 --- /dev/null +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/StartZookeeperUnixProcessor.java @@ -0,0 +1,64 @@ +/* + * 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.test.check.registrycenter.processor; + +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.test.check.exception.DubboTestException; +import org.apache.dubbo.test.check.registrycenter.context.ZookeeperContext; + +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Pattern; + +/** + * Create {@link Process} to start zookeeper on Unix OS. + */ +public class StartZookeeperUnixProcessor extends ZookeeperUnixProcessor { + + private static final Logger logger = LoggerFactory.getLogger(StartZookeeperUnixProcessor.class); + + @Override + protected Process doProcess(ZookeeperContext context, int clientPort) throws DubboTestException { + logger.info(String.format("The zookeeper-%d is starting...", clientPort)); + List commands = new ArrayList<>(); + Path zookeeperBin = Paths.get(context.getSourceFile().getParent().toString(), + String.valueOf(clientPort), + String.format("apache-zookeeper-%s-bin", context.getVersion()), + "bin"); + commands.add(Paths.get(zookeeperBin.toString(), "zkServer.sh") + .toAbsolutePath().toString()); + commands.add("start"); + commands.add(Paths.get(zookeeperBin.getParent().toString(), + "conf", + "zoo.cfg").toAbsolutePath().toString()); + try { + return new ProcessBuilder().directory(zookeeperBin.getParent().toFile()) + .command(commands).inheritIO().redirectOutput(ProcessBuilder.Redirect.PIPE).start(); + } catch (IOException e) { + throw new DubboTestException(String.format("Failed to start zookeeper-%d", clientPort), e); + } + } + + @Override + protected Pattern getPattern() { + return Pattern.compile(".*STARTED.*"); + } +} diff --git a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/StartZookeeperWindowsProcessor.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/StartZookeeperWindowsProcessor.java new file mode 100644 index 0000000000..673d6fc1d8 --- /dev/null +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/StartZookeeperWindowsProcessor.java @@ -0,0 +1,81 @@ +/* + * 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.test.check.registrycenter.processor; + +import org.apache.commons.exec.Executor; +import org.apache.commons.exec.DefaultExecutor; +import org.apache.commons.exec.CommandLine; +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.test.check.exception.DubboTestException; +import org.apache.dubbo.test.check.registrycenter.Processor; +import org.apache.dubbo.test.check.registrycenter.context.ZookeeperWindowsContext; + +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.concurrent.TimeUnit; + +/** + * Create {@link Process} to start zookeeper on Windows OS. + */ +public class StartZookeeperWindowsProcessor extends ZookeeperWindowsProcessor { + + private static final Logger logger = LoggerFactory.getLogger(StartZookeeperWindowsProcessor.class); + + /** + * The {@link Processor} to find the pid of zookeeper instance. + */ + private final Processor findPidProcessor = new FindPidWindowsProcessor(); + + /** + * The {@link Processor} to kill the pid of zookeeper instance. + */ + private final Processor killPidProcessor = new KillProcessWindowsProcessor(); + + @Override + protected void doProcess(ZookeeperWindowsContext context) throws DubboTestException { + // find pid and save into global context. + this.findPidProcessor.process(context); + // kill pid of zookeeper instance if exists + this.killPidProcessor.process(context); + for (int clientPort : context.getClientPorts()) { + logger.info(String.format("The zookeeper-%d is starting...", clientPort)); + Path zookeeperBin = Paths.get(context.getSourceFile().getParent().toString(), + String.valueOf(clientPort), + String.format("apache-zookeeper-%s-bin", context.getVersion()), + "bin"); + Executor executor = new DefaultExecutor(); + executor.setExitValues(null); + executor.setWatchdog(context.getWatchdog()); + CommandLine cmdLine = new CommandLine("cmd.exe"); + cmdLine.addArgument("/c"); + cmdLine.addArgument(Paths.get(zookeeperBin.toString(), "zkServer.cmd") + .toAbsolutePath().toString()); + context.getExecutorService().submit(() -> executor.execute(cmdLine)); + } + try { + // TODO: Help me to optimize the ugly sleep. + // sleep to wait all of zookeeper instances are started successfully. + // The best way is to check the output log with the specified keywords, + // however, there maybe keep waiting for check when any exception occurred, + // because the output stream will be blocked to wait for continuous data without any break + TimeUnit.SECONDS.sleep(3); + } catch (InterruptedException e) { + // ignored + } + } +} diff --git a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/StopZookeeperUnixProcessor.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/StopZookeeperUnixProcessor.java new file mode 100644 index 0000000000..7748d02882 --- /dev/null +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/StopZookeeperUnixProcessor.java @@ -0,0 +1,61 @@ +/* + * 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.test.check.registrycenter.processor; + +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.test.check.exception.DubboTestException; +import org.apache.dubbo.test.check.registrycenter.context.ZookeeperContext; + +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Pattern; + +/** + * Create {@link Process} to stop zookeeper on Unix OS. + */ +public class StopZookeeperUnixProcessor extends ZookeeperUnixProcessor { + + private static final Logger logger = LoggerFactory.getLogger(StopZookeeperUnixProcessor.class); + + @Override + protected Process doProcess(ZookeeperContext context, int clientPort) throws DubboTestException { + logger.info(String.format("The zookeeper-%d is stopping...", clientPort)); + List commands = new ArrayList<>(); + Path zookeeperBin = Paths.get(context.getSourceFile().getParent().toString(), + String.valueOf(clientPort), + String.format("apache-zookeeper-%s-bin", context.getVersion()), + "bin"); + commands.add(Paths.get(zookeeperBin.toString(), "zkServer.sh") + .toAbsolutePath().toString()); + commands.add("stop"); + try { + return new ProcessBuilder().directory(zookeeperBin.getParent().toFile()) + .command(commands).inheritIO().redirectOutput(ProcessBuilder.Redirect.PIPE).start(); + } catch (IOException e) { + throw new DubboTestException(String.format("Failed to stop zookeeper-%d", clientPort), e); + } + } + + @Override + protected Pattern getPattern() { + return Pattern.compile(".*STOPPED.*"); + } +} diff --git a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/StopZookeeperWindowsProcessor.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/StopZookeeperWindowsProcessor.java new file mode 100644 index 0000000000..a671e682e7 --- /dev/null +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/StopZookeeperWindowsProcessor.java @@ -0,0 +1,52 @@ +/* + * 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.test.check.registrycenter.processor; + +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.test.check.exception.DubboTestException; +import org.apache.dubbo.test.check.registrycenter.Processor; +import org.apache.dubbo.test.check.registrycenter.context.ZookeeperWindowsContext; + +/** + * Create {@link Process} to stop zookeeper on Windows OS. + */ +public class StopZookeeperWindowsProcessor extends ZookeeperWindowsProcessor { + + private static final Logger logger = LoggerFactory.getLogger(StopZookeeperWindowsProcessor.class); + + /** + * The {@link Processor} to find the pid of zookeeper instance. + */ + private final Processor findPidProcessor = new FindPidWindowsProcessor(); + + /** + * The {@link Processor} to kill the pid of zookeeper instance. + */ + private final Processor killPidProcessor = new KillProcessWindowsProcessor(); + + @Override + protected void doProcess(ZookeeperWindowsContext context) throws DubboTestException { + logger.info("All of zookeeper instances are stopping..."); + // find pid and save into global context. + this.findPidProcessor.process(context); + // kill pid of zookeeper instance if exists + this.killPidProcessor.process(context); + // destroy all resources + context.destroy(); + } +} diff --git a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/ZookeeperUnixProcessor.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/ZookeeperUnixProcessor.java new file mode 100644 index 0000000000..38786db86d --- /dev/null +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/ZookeeperUnixProcessor.java @@ -0,0 +1,100 @@ +/* + * 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.test.check.registrycenter.processor; + +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.test.check.exception.DubboTestException; +import org.apache.dubbo.test.check.registrycenter.Context; +import org.apache.dubbo.test.check.registrycenter.Processor; +import org.apache.dubbo.test.check.registrycenter.context.ZookeeperContext; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.regex.Pattern; + +/** + * The abstract implementation of {@link Processor} is to provide some common methods on Unix OS. + */ +public abstract class ZookeeperUnixProcessor implements Processor { + + private static final Logger logger = LoggerFactory.getLogger(ZookeeperUnixProcessor.class); + + @Override + public void process(Context context) throws DubboTestException { + ZookeeperContext zookeeperContext = (ZookeeperContext) context; + for (int clientPort : zookeeperContext.getClientPorts()) { + Process process = this.doProcess(zookeeperContext, clientPort); + this.logErrorStream(process.getErrorStream()); + this.awaitProcessReady(process.getInputStream()); + } + } + + /** + * Prints the error log after run {@link Process}. + * + * @param errorStream the error stream. + */ + private void logErrorStream(final InputStream errorStream) { + try (final BufferedReader reader = new BufferedReader(new InputStreamReader(errorStream))) { + String line; + while ((line = reader.readLine()) != null) { + logger.error(line); + } + } catch (IOException e) { + /* eat quietly */ + } + } + + /** + * Wait until the server is started successfully. + * + * @param inputStream the log after run {@link Process}. + * @throws DubboTestException if cannot match the given pattern. + */ + private void awaitProcessReady(final InputStream inputStream) throws DubboTestException { + final StringBuilder log = new StringBuilder(); + try (final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { + String line; + while ((line = reader.readLine()) != null) { + if (this.getPattern().matcher(line).matches()) + return; + log.append('\n').append(line); + } + } catch (IOException e) { + throw new DubboTestException("Failed to read the log after executed process.", e); + } + throw new DubboTestException("Ready pattern not found in log, log: " + log); + } + + /** + * Use {@link Process} to handle the command. + * + * @param context the global zookeeper context. + * @param clientPort the client port of zookeeper. + * @return the instance of {@link Process}. + * @throws DubboTestException when any exception occurred. + */ + protected abstract Process doProcess(ZookeeperContext context, int clientPort) throws DubboTestException; + + /** + * Gets the pattern to check the server is ready or not. + */ + protected abstract Pattern getPattern(); +} diff --git a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/ZookeeperWindowsProcessor.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/ZookeeperWindowsProcessor.java new file mode 100644 index 0000000000..d364bd63ac --- /dev/null +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/ZookeeperWindowsProcessor.java @@ -0,0 +1,41 @@ +/* + * 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.test.check.registrycenter.processor; + +import org.apache.dubbo.test.check.exception.DubboTestException; +import org.apache.dubbo.test.check.registrycenter.Context; +import org.apache.dubbo.test.check.registrycenter.Processor; +import org.apache.dubbo.test.check.registrycenter.context.ZookeeperWindowsContext; +/** + * The abstract implementation of {@link Processor} is to provide some common methods on Windows OS. + */ +public abstract class ZookeeperWindowsProcessor implements Processor { + + @Override + public void process(Context context) throws DubboTestException { + ZookeeperWindowsContext zookeeperWindowsContext = (ZookeeperWindowsContext) context; + this.doProcess(zookeeperWindowsContext); + } + + /** + * Use {@link Process} to handle the command. + * + * @param context the global zookeeper context. + * @throws DubboTestException when any exception occurred. + */ + protected abstract void doProcess(ZookeeperWindowsContext context) throws DubboTestException; +} diff --git a/dubbo-test/dubbo-test-check/src/main/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener b/dubbo-test/dubbo-test-check/src/main/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener index 0b6e457b5b..1eb8e5b91f 100644 --- a/dubbo-test/dubbo-test-check/src/main/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener +++ b/dubbo-test/dubbo-test-check/src/main/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener @@ -1 +1,5 @@ +# DubboRegistryCenterStarted should be the first one because of the startup of zookeeper +org.apache.dubbo.test.check.RegistryCenterStarted org.apache.dubbo.test.check.DubboTestChecker +# DubboRegistryCenterFinished should be the last one because of the shutdown of zookeeper +org.apache.dubbo.test.check.RegistryCenterFinished diff --git a/dubbo-test/dubbo-test-common/src/main/java/org/apache/dubbo/test/common/EmbeddedZooKeeper.java b/dubbo-test/dubbo-test-common/src/main/java/org/apache/dubbo/test/common/EmbeddedZooKeeper.java deleted file mode 100644 index c96f06f2a1..0000000000 --- a/dubbo-test/dubbo-test-common/src/main/java/org/apache/dubbo/test/common/EmbeddedZooKeeper.java +++ /dev/null @@ -1,248 +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.test.common; - -import org.apache.dubbo.common.utils.NetUtils; -import org.apache.zookeeper.server.ServerConfig; -import org.apache.zookeeper.server.ZooKeeperServerMain; -import org.apache.zookeeper.server.quorum.QuorumPeerConfig; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; -import java.lang.reflect.Method; -import java.util.Properties; -import java.util.UUID; - -/** - * from: https://github.com/spring-projects/spring-xd/blob/v1.3.1.RELEASE/spring-xd-dirt/src/main/java/org/springframework/xd/dirt/zookeeper/ZooKeeperUtils.java - *

- * Helper class to start an embedded instance of standalone (non clustered) ZooKeeper. - *

- * NOTE: at least an external standalone server (if not an ensemble) are recommended, even for - * {@link org.springframework.xd.dirt.server.singlenode.SingleNodeApplication} - * - * @author Patrick Peralta - * @author Mark Fisher - * @author David Turanski - * @deprecated - * @see org.apache.dubbo.test.common.registrycenter.ZookeeperSingleRegistryCenter - * @see org.apache.dubbo.test.common.registrycenter.ZookeeperMultipleRegistryCenter - */ -@Deprecated -public class EmbeddedZooKeeper { - - /** - * Logger. - */ - private static final Logger logger = LoggerFactory.getLogger(EmbeddedZooKeeper.class); - - /** - * ZooKeeper client port. This will be determined dynamically upon startup. - */ - private final int clientPort; - - /** - * Whether to auto-start. Default is true. - */ - private boolean autoStartup = true; - - /** - * Lifecycle phase. Default is 0. - */ - private int phase = 0; - - /** - * Thread for running the ZooKeeper server. - */ - private volatile Thread zkServerThread; - - /** - * ZooKeeper server. - */ - private volatile ZooKeeperServerMain zkServer; - - /** - * {@link ErrorHandler} to be invoked if an Exception is thrown from the ZooKeeper server thread. - */ - private ErrorHandler errorHandler; - - private boolean daemon = true; - - /** - * Construct an EmbeddedZooKeeper with a random port. - */ - public EmbeddedZooKeeper() { - // clientPort = SocketUtils.findAvailableTcpPort(); - clientPort = NetUtils.getAvailablePort(); - } - - /** - * Construct an EmbeddedZooKeeper with the provided port. - * - * @param clientPort port for ZooKeeper server to bind to - */ - public EmbeddedZooKeeper(int clientPort, boolean daemon) { - this.clientPort = clientPort; - this.daemon = daemon; - } - - /** - * Returns the port that clients should use to connect to this embedded server. - * - * @return dynamically determined client port - */ - public int getClientPort() { - return this.clientPort; - } - - /** - * Specify whether to start automatically. Default is true. - * - * @param autoStartup whether to start automatically - */ - public void setAutoStartup(boolean autoStartup) { - this.autoStartup = autoStartup; - } - - /** - * {@inheritDoc} - */ - public boolean isAutoStartup() { - return this.autoStartup; - } - - /** - * Specify the lifecycle phase for the embedded server. - * - * @param phase the lifecycle phase - */ - public void setPhase(int phase) { - this.phase = phase; - } - - /** - * {@inheritDoc} - */ - public int getPhase() { - return this.phase; - } - - /** - * {@inheritDoc} - */ - public boolean isRunning() { - return (zkServerThread != null); - } - - /** - * Start the ZooKeeper server in a background thread. - *

- * Register an error handler via {@link #setErrorHandler} in order to handle - * any exceptions thrown during startup or execution. - */ - public synchronized void start() { - if (zkServerThread == null) { - zkServerThread = new Thread(new ServerRunnable(), "ZooKeeper Server Starter"); - zkServerThread.setDaemon(daemon); - zkServerThread.start(); - } - } - - /** - * Shutdown the ZooKeeper server. - */ - public synchronized void stop() { - if (zkServerThread != null) { - // The shutdown method is protected...thus this hack to invoke it. - // This will log an exception on shutdown; see - // https://issues.apache.org/jira/browse/ZOOKEEPER-1873 for details. - try { - Method shutdown = ZooKeeperServerMain.class.getDeclaredMethod("shutdown"); - shutdown.setAccessible(true); - shutdown.invoke(zkServer); - } catch (Exception e) { - throw new RuntimeException(e); - } - - // It is expected that the thread will exit after - // the server is shutdown; this will block until - // the shutdown is complete. - try { - zkServerThread.join(5000); - zkServerThread = null; - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - logger.warn("Interrupted while waiting for embedded ZooKeeper to exit"); - // abandoning zk thread - zkServerThread = null; - } - } - } - - /** - * Stop the server if running and invoke the callback when complete. - */ - public void stop(Runnable callback) { - stop(); - callback.run(); - } - - /** - * Provide an {@link ErrorHandler} to be invoked if an Exception is thrown from the ZooKeeper server thread. If none - * is provided, only error-level logging will occur. - * - * @param errorHandler the {@link ErrorHandler} to be invoked - */ - public void setErrorHandler(ErrorHandler errorHandler) { - this.errorHandler = errorHandler; - } - - /** - * Runnable implementation that starts the ZooKeeper server. - */ - private class ServerRunnable implements Runnable { - - @Override - public void run() { - try { - Properties properties = new Properties(); - File file = new File(System.getProperty("java.io.tmpdir") - + File.separator + UUID.randomUUID()); - file.deleteOnExit(); - properties.setProperty("dataDir", file.getAbsolutePath()); - properties.setProperty("clientPort", String.valueOf(clientPort)); - - QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig(); - quorumPeerConfig.parseProperties(properties); - - zkServer = new ZooKeeperServerMain(); - ServerConfig configuration = new ServerConfig(); - configuration.readFrom(quorumPeerConfig); - - zkServer.runFromConfig(configuration); - } catch (Exception e) { - if (errorHandler != null) { - errorHandler.handleError(e); - } else { - logger.error("Exception running embedded ZooKeeper", e); - } - } - } - } - -} diff --git a/dubbo-test/dubbo-test-common/src/main/java/org/apache/dubbo/test/common/ZooKeeperServer.java b/dubbo-test/dubbo-test-common/src/main/java/org/apache/dubbo/test/common/ZooKeeperServer.java deleted file mode 100644 index 846c2acc7b..0000000000 --- a/dubbo-test/dubbo-test-common/src/main/java/org/apache/dubbo/test/common/ZooKeeperServer.java +++ /dev/null @@ -1,57 +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.test.common; - -/** - * Using this class as registry center is not very well because of time-consuming. - *

The alternative is to use {@link org.apache.dubbo.test.common.registrycenter.ZookeeperSingleRegistryCenter}

or - * {@link org.apache.dubbo.test.common.registrycenter.ZookeeperMultipleRegistryCenter} - * @deprecated - * @see org.apache.dubbo.test.common.registrycenter.ZookeeperSingleRegistryCenter - * @see org.apache.dubbo.test.common.registrycenter.ZookeeperMultipleRegistryCenter - */ -@Deprecated -public class ZooKeeperServer { - - private static EmbeddedZooKeeper zookeeper1; - private static EmbeddedZooKeeper zookeeper2; - - public static void start() { - if (zookeeper1 == null) { - zookeeper1 = new EmbeddedZooKeeper(2181, true); - zookeeper1.start(); - } - if (zookeeper2 == null) { - zookeeper2 = new EmbeddedZooKeeper(2182, true); - zookeeper2.start(); - } - } - - public static void stop() { - try { - if (zookeeper1 != null) { - zookeeper1.stop(); - } - if (zookeeper2 != null) { - zookeeper2.stop(); - } - } finally { - zookeeper1 = null; - zookeeper2 = null; - } - } -} diff --git a/dubbo-test/dubbo-test-common/src/main/java/org/apache/dubbo/test/common/registrycenter/AbstractRegistryCenter.java b/dubbo-test/dubbo-test-common/src/main/java/org/apache/dubbo/test/common/registrycenter/AbstractRegistryCenter.java deleted file mode 100644 index cbf637ac86..0000000000 --- a/dubbo-test/dubbo-test-common/src/main/java/org/apache/dubbo/test/common/registrycenter/AbstractRegistryCenter.java +++ /dev/null @@ -1,107 +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.test.common.registrycenter; - -import org.apache.curator.test.InstanceSpec; - -import java.io.File; -import java.util.HashMap; -import java.util.Map; - -/** - * The abstraction of {@link RegistryCenter} implements the basic methods. - */ -abstract class AbstractRegistryCenter implements RegistryCenter { - - /** - * The default data directory is null - */ - private static final File DEFAULT_DATA_DIRECTORY = null; - - /** - * The default election port is -1. - */ - private static final int DEFAULT_ELECTION_PORT = -1; - - /** - * The default quorum port is -1. - */ - private static final int DEFAULT_QUORUM_PORT = -1; - - /** - * The default value is true. - */ - private static final boolean DEFAULT_DELETE_DATA_DIRECTORY_ON_CLOSE = true; - - /** - * The default service id is -1. - */ - private static final int DEFAULT_SERVER_ID = -1; - - /** - * The default tick time is 5000 - */ - private static final int DEFAULT_TICK_TIME = 5 * 1000; - - /** - * The default value is 60. - */ - private static final int DEFAULT_MAX_CLIENT_CNXNS = 200; - - /** - * The minimum session timeout. - */ - private static final int DEFAULT_MINIMUM_SESSION_TIMEOUT = DEFAULT_TICK_TIME * 2; - - /** - * The maximum session timeout. - */ - private static final int DEFAULT_MAXIMUM_SESSION_TIMEOUT = 60 * 1000; - - /** - * The default customer properties. - */ - private static final Map DEFAULT_CUSTOM_PROPERTIES = new HashMap<>(2); - - /** - * The default hostname. - */ - private static final String DEFAULT_HOSTNAME = "127.0.0.1"; - - static { - DEFAULT_CUSTOM_PROPERTIES.put("minSessionTimeout", DEFAULT_MINIMUM_SESSION_TIMEOUT); - DEFAULT_CUSTOM_PROPERTIES.put("maxSessionTimeout", DEFAULT_MAXIMUM_SESSION_TIMEOUT); - } - - /** - * Create an {@link InstanceSpec} instance to initialize {@link org.apache.curator.test.TestingServer} - * - * @param port the zookeeper server's port. - */ - protected InstanceSpec createInstanceSpec(int port) { - return new InstanceSpec(DEFAULT_DATA_DIRECTORY, - port, - DEFAULT_ELECTION_PORT, - DEFAULT_QUORUM_PORT, - DEFAULT_DELETE_DATA_DIRECTORY_ON_CLOSE, - DEFAULT_SERVER_ID, - DEFAULT_TICK_TIME, - DEFAULT_MAX_CLIENT_CNXNS, - DEFAULT_CUSTOM_PROPERTIES, - DEFAULT_HOSTNAME); - } -} diff --git a/dubbo-test/dubbo-test-common/src/main/java/org/apache/dubbo/test/common/registrycenter/RegistryCenter.java b/dubbo-test/dubbo-test-common/src/main/java/org/apache/dubbo/test/common/registrycenter/RegistryCenter.java deleted file mode 100644 index 8e9c569b55..0000000000 --- a/dubbo-test/dubbo-test-common/src/main/java/org/apache/dubbo/test/common/registrycenter/RegistryCenter.java +++ /dev/null @@ -1,70 +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.test.common.registrycenter; - -import org.apache.dubbo.rpc.RpcException; - -import java.util.List; - -/** - * The mock registry center. - */ -public interface RegistryCenter { - - /** - * Start the registry center. - * - * @throws RpcException when an exception occurred - */ - void startup() throws RpcException; - - /** - * Returns the registry center instance. - *

This method can be called only after {@link #startup()} is called

- * - * @throws RpcException when an exception occurred - */ - List getRegistryCenterInstance() throws RpcException; - - /** - * Stop the registry center. - * - * @throws RpcException when an exception occurred - */ - void shutdown() throws RpcException; - - /** - * The registry center instance. - */ - interface Instance { - - /** - * Returns the registry center type. - */ - String getType(); - - /** - * Returns the hostname of registry center. - */ - String getHostname(); - - /** - * Returns the port of registry center. - */ - int getPort(); - } -} diff --git a/dubbo-test/dubbo-test-common/src/main/java/org/apache/dubbo/test/common/registrycenter/ZookeeperMultipleRegistryCenter.java b/dubbo-test/dubbo-test-common/src/main/java/org/apache/dubbo/test/common/registrycenter/ZookeeperMultipleRegistryCenter.java deleted file mode 100644 index 761558ad4e..0000000000 --- a/dubbo-test/dubbo-test-common/src/main/java/org/apache/dubbo/test/common/registrycenter/ZookeeperMultipleRegistryCenter.java +++ /dev/null @@ -1,43 +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.test.common.registrycenter; - -/** - * The default zookeeper multiple registry center. - */ -public class ZookeeperMultipleRegistryCenter extends ZookeeperRegistryCenter { - - /** - * Initialize {@link ZookeeperMultipleRegistryCenter} instance. - * - * @param port1 the zookeeper server's port. - * @param port2 the zookeeper server's port. - */ - public ZookeeperMultipleRegistryCenter(int port1, int port2) { - super(port1, port2); - } - - /** - * Initialize {@link ZookeeperMultipleRegistryCenter} instance. - */ - public ZookeeperMultipleRegistryCenter() { - this(DEFAULT_PORT1, DEFAULT_PORT2); - } - - private static final int DEFAULT_PORT1 = 2181; - private static final int DEFAULT_PORT2 = 2182; -} diff --git a/dubbo-test/dubbo-test-common/src/main/java/org/apache/dubbo/test/common/registrycenter/ZookeeperRegistryCenter.java b/dubbo-test/dubbo-test-common/src/main/java/org/apache/dubbo/test/common/registrycenter/ZookeeperRegistryCenter.java deleted file mode 100644 index 4b2e3b66b5..0000000000 --- a/dubbo-test/dubbo-test-common/src/main/java/org/apache/dubbo/test/common/registrycenter/ZookeeperRegistryCenter.java +++ /dev/null @@ -1,142 +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.test.common.registrycenter; - -import org.apache.curator.test.InstanceSpec; -import org.apache.curator.test.TestingServer; -import org.apache.dubbo.common.logger.Logger; -import org.apache.dubbo.common.logger.LoggerFactory; -import org.apache.dubbo.rpc.RpcException; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; - -/** - * The default implementation of registry center can support single and multiple registry center. - *

Each port represents an instance. You can provide multiple ports to build multiple registry center, - * if you want to create multiple registry center - */ -class ZookeeperRegistryCenter extends AbstractRegistryCenter { - - /** - * Initialize the default registry center. - * - * @param ports the registry center's ports. - */ - public ZookeeperRegistryCenter(int... ports) { - this.ports = ports; - this.instanceSpecs = new ArrayList<>(this.ports.length); - this.zookeeperServers = new ArrayList<>(this.ports.length); - } - - private static final Logger logger = LoggerFactory.getLogger(ZookeeperRegistryCenter.class); - - /** - * The type of the registry center. - */ - private static final String DEFAULT_REGISTRY_CENTER_TYPE = "zookeeper"; - - private int[] ports; - - private List instanceSpecs; - - private List zookeeperServers; - - private AtomicBoolean started = new AtomicBoolean(false); - - /** - * {@inheritDoc} - */ - @Override - public void startup() throws RpcException { - try { - if (started.compareAndSet(false, true)) { - logger.info("The ZookeeperRegistryCenter is starting..."); - for (int port : this.ports) { - InstanceSpec instanceSpec = this.createInstanceSpec(port); - this.instanceSpecs.add(instanceSpec); - this.zookeeperServers.add(new TestingServer(instanceSpec, true)); - } - logger.info("The ZookeeperRegistryCenter is started successfully"); - } - } catch (Exception exception) { - started.set(false); - throw new RpcException("Failed to initialize ZookeeperRegistryCenter instance", exception); - } - } - - /** - * {@inheritDoc} - */ - @Override - public List getRegistryCenterInstance() throws RpcException { - this.startup(); - List instances = new ArrayList<>(this.instanceSpecs.size()); - for (InstanceSpec instanceSpec : this.instanceSpecs) { - instances.add(new Instance() { - @Override - public String getType() { - return DEFAULT_REGISTRY_CENTER_TYPE; - } - - @Override - public String getHostname() { - return instanceSpec.getHostname(); - } - - @Override - public int getPort() { - return instanceSpec.getPort(); - } - }); - } - return instances; - } - - /** - * {@inheritDoc} - */ - @Override - public void shutdown() throws RpcException { - logger.info("The ZookeeperRegistryCenter is stopping..."); - List exceptions = new ArrayList<>(this.zookeeperServers.size()); - for (TestingServer testingServer : this.zookeeperServers) { - try { - testingServer.close(); - logger.info(String.format("The zookeeper instance of %s is shutdown successfully", - testingServer.getConnectString())); - } catch (IOException exception) { - RpcException rpcException = new RpcException(String.format("Failed to close zookeeper instance of %s", - testingServer.getConnectString()), - exception); - exceptions.add(rpcException); - logger.error(rpcException); - } - } - this.instanceSpecs.clear(); - this.zookeeperServers.clear(); - if (!exceptions.isEmpty()) { - logger.info("The ZookeeperRegistryCenter failed to close."); - // throw any one of exceptions - throw exceptions.get(0); - } else { - logger.info("The ZookeeperRegistryCenter close successfully."); - } - } -} diff --git a/dubbo-test/dubbo-test-spring/src/main/java/org/apache/dubbo/test/spring/SpringAnnotationBeanTest.java b/dubbo-test/dubbo-test-spring/src/main/java/org/apache/dubbo/test/spring/SpringAnnotationBeanTest.java index 61376ce0ce..7b3d28e793 100644 --- a/dubbo-test/dubbo-test-spring/src/main/java/org/apache/dubbo/test/spring/SpringAnnotationBeanTest.java +++ b/dubbo-test/dubbo-test-spring/src/main/java/org/apache/dubbo/test/spring/SpringAnnotationBeanTest.java @@ -20,8 +20,6 @@ import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.apache.dubbo.test.common.api.DemoService; -import org.apache.dubbo.test.common.registrycenter.RegistryCenter; -import org.apache.dubbo.test.common.registrycenter.ZookeeperSingleRegistryCenter; import org.apache.dubbo.test.spring.context.MockSpringInitCustomizer; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; @@ -34,19 +32,14 @@ import org.springframework.context.annotation.PropertySource; public class SpringAnnotationBeanTest { - private static RegistryCenter registryCenter; - @BeforeAll public static void beforeAll() { - registryCenter = new ZookeeperSingleRegistryCenter(); - registryCenter.startup(); DubboBootstrap.reset(); } @AfterAll public static void afterAll(){ DubboBootstrap.reset(); - registryCenter.shutdown(); } @Test diff --git a/dubbo-test/dubbo-test-spring/src/main/java/org/apache/dubbo/test/spring/SpringJavaConfigBeanTest.java b/dubbo-test/dubbo-test-spring/src/main/java/org/apache/dubbo/test/spring/SpringJavaConfigBeanTest.java index 31239f9622..8c4cce734a 100644 --- a/dubbo-test/dubbo-test-spring/src/main/java/org/apache/dubbo/test/spring/SpringJavaConfigBeanTest.java +++ b/dubbo-test/dubbo-test-spring/src/main/java/org/apache/dubbo/test/spring/SpringJavaConfigBeanTest.java @@ -30,11 +30,10 @@ import org.apache.dubbo.config.spring.ReferenceBean; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.apache.dubbo.rpc.Constants; import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig; import org.apache.dubbo.test.common.SysProps; import org.apache.dubbo.test.common.api.DemoService; import org.apache.dubbo.test.common.impl.DemoServiceImpl; -import org.apache.dubbo.test.common.registrycenter.RegistryCenter; -import org.apache.dubbo.test.common.registrycenter.ZookeeperSingleRegistryCenter; import org.apache.dubbo.test.spring.context.MockSpringInitCustomizer; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; @@ -54,19 +53,14 @@ public class SpringJavaConfigBeanTest { private static final String MY_PROTOCOL_ID = "myProtocol"; private static final String MY_REGISTRY_ID = "my-registry"; - private static RegistryCenter registryCenter; - @BeforeAll public static void beforeAll() { - registryCenter = new ZookeeperSingleRegistryCenter(); - registryCenter.startup(); DubboBootstrap.reset(); } @AfterAll public static void afterAll(){ DubboBootstrap.reset(); - registryCenter.shutdown(); } @BeforeEach @@ -86,7 +80,7 @@ public class SpringJavaConfigBeanTest { SysProps.setProperty("dubbo.application.qos-enable", "false"); SysProps.setProperty("dubbo.protocol.name", "dubbo"); SysProps.setProperty("dubbo.protocol.port", "2346"); - String registryAddress = "zookeeper://127.0.0.1:2181"; + String registryAddress = ZookeeperRegistryCenterConfig.getConnectionAddress(); SysProps.setProperty("dubbo.registry.address", registryAddress); SysProps.setProperty("dubbo.provider.group", "test"); diff --git a/dubbo-test/dubbo-test-spring/src/main/java/org/apache/dubbo/test/spring/SpringXmlConfigTest.java b/dubbo-test/dubbo-test-spring/src/main/java/org/apache/dubbo/test/spring/SpringXmlConfigTest.java index 7d7eba1644..5530de71a6 100644 --- a/dubbo-test/dubbo-test-spring/src/main/java/org/apache/dubbo/test/spring/SpringXmlConfigTest.java +++ b/dubbo-test/dubbo-test-spring/src/main/java/org/apache/dubbo/test/spring/SpringXmlConfigTest.java @@ -21,8 +21,6 @@ import org.apache.dubbo.test.common.SysProps; import org.apache.dubbo.test.common.api.DemoService; import org.apache.dubbo.test.common.api.GreetingService; import org.apache.dubbo.test.common.api.RestDemoService; -import org.apache.dubbo.test.common.registrycenter.RegistryCenter; -import org.apache.dubbo.test.common.registrycenter.ZookeeperSingleRegistryCenter; import org.apache.dubbo.test.spring.context.MockSpringInitCustomizer; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; @@ -34,19 +32,14 @@ import static org.apache.dubbo.common.constants.CommonConstants.SHUTDOWN_WAIT_KE public class SpringXmlConfigTest { - private static RegistryCenter registryCenter; - @BeforeAll public static void beforeAll() { - registryCenter = new ZookeeperSingleRegistryCenter(); - registryCenter.startup(); DubboBootstrap.reset(); } @AfterAll public static void afterAll(){ DubboBootstrap.reset(); - registryCenter.shutdown(); } @Test diff --git a/dubbo-test/dubbo-test-spring/src/main/resources/demo-app.properties b/dubbo-test/dubbo-test-spring/src/main/resources/demo-app.properties index f5bfdffb1e..d486b16532 100644 --- a/dubbo-test/dubbo-test-spring/src/main/resources/demo-app.properties +++ b/dubbo-test/dubbo-test-spring/src/main/resources/demo-app.properties @@ -1,11 +1,11 @@ dubbo.application.name=demo-app -dubbo.registry.address=zookeeper://127.0.0.1:2181?registry-type=service +dubbo.registry.address=${zookeeper.connection.address}?registry-type=service -dubbo.config-center.address=zookeeper://127.0.0.1:2181 +dubbo.config-center.address=${zookeeper.connection.address} -dubbo.metadata-report.address=zookeeper://127.0.0.1:2181 +dubbo.metadata-report.address=${zookeeper.connection.address} dubbo.protocols.dubbo.port=-1 diff --git a/dubbo-test/dubbo-test-spring/src/main/resources/spring/dubbo-demo.xml b/dubbo-test/dubbo-test-spring/src/main/resources/spring/dubbo-demo.xml index 05392dabb5..e44a9530d5 100644 --- a/dubbo-test/dubbo-test-spring/src/main/resources/spring/dubbo-demo.xml +++ b/dubbo-test/dubbo-test-spring/src/main/resources/spring/dubbo-demo.xml @@ -23,9 +23,9 @@ - - - + + +