diff --git a/.artifacts b/.artifacts index 69d057be080..5818a24e9ad 100644 --- a/.artifacts +++ b/.artifacts @@ -38,7 +38,6 @@ dubbo-core-spi dubbo-dependencies dubbo-dependencies-all dubbo-dependencies-bom -dubbo-dependencies-zookeeper dubbo-dependencies-zookeeper-curator5 dubbo-distribution dubbo-filter-cache @@ -78,8 +77,6 @@ dubbo-remoting-api dubbo-remoting-http12 dubbo-remoting-netty dubbo-remoting-netty4 -dubbo-remoting-zookeeper-api -dubbo-remoting-zookeeper dubbo-remoting-zookeeper-curator5 dubbo-rpc dubbo-rpc-api diff --git a/dubbo-compatible/pom.xml b/dubbo-compatible/pom.xml index f6948de37a0..5d0891978fb 100644 --- a/dubbo-compatible/pom.xml +++ b/dubbo-compatible/pom.xml @@ -45,7 +45,7 @@ org.apache.dubbo - dubbo-remoting-zookeeper + dubbo-remoting-zookeeper-curator5 ${project.parent.version} diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting/zookeeper/ZookeeperTransporter.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting/zookeeper/ZookeeperTransporter.java deleted file mode 100644 index 25cabd64ce1..00000000000 --- a/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting/zookeeper/ZookeeperTransporter.java +++ /dev/null @@ -1,20 +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 com.alibaba.dubbo.remoting.zookeeper; - -@Deprecated -public interface ZookeeperTransporter extends org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter {} diff --git a/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDataListener.java b/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDataListener.java index 5ec5a3cd574..508b9430a87 100644 --- a/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDataListener.java +++ b/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDataListener.java @@ -22,8 +22,8 @@ import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.metrics.config.event.ConfigCenterEvent; import org.apache.dubbo.metrics.event.MetricsEventBus; -import org.apache.dubbo.remoting.zookeeper.DataListener; -import org.apache.dubbo.remoting.zookeeper.EventType; +import org.apache.dubbo.remoting.zookeeper.curator5.DataListener; +import org.apache.dubbo.remoting.zookeeper.curator5.EventType; import org.apache.dubbo.rpc.model.ApplicationModel; import java.util.Set; diff --git a/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfiguration.java b/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfiguration.java index f29671f0c64..1dee56fb636 100644 --- a/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfiguration.java +++ b/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfiguration.java @@ -23,8 +23,8 @@ import org.apache.dubbo.common.threadpool.support.AbortPolicyWithReport; import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.NamedThreadFactory; -import org.apache.dubbo.remoting.zookeeper.ZookeeperClient; -import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter; +import org.apache.dubbo.remoting.zookeeper.curator5.ZookeeperClient; +import org.apache.dubbo.remoting.zookeeper.curator5.ZookeeperClientManager; import org.apache.dubbo.rpc.model.ApplicationModel; import java.util.Collection; @@ -51,7 +51,7 @@ public class ZookeeperDynamicConfiguration extends TreePathDynamicConfiguration private final ApplicationModel applicationModel; ZookeeperDynamicConfiguration( - URL url, ZookeeperTransporter zookeeperTransporter, ApplicationModel applicationModel) { + URL url, ZookeeperClientManager zookeeperClientManager, ApplicationModel applicationModel) { super(url); this.cacheListener = new CacheListener(); @@ -67,7 +67,7 @@ public class ZookeeperDynamicConfiguration extends TreePathDynamicConfiguration new NamedThreadFactory(threadName, true), new AbortPolicyWithReport(threadName, url)); - zkClient = zookeeperTransporter.connect(url); + zkClient = zookeeperClientManager.connect(url); boolean isConnected = zkClient.isConnected(); if (!isConnected) { diff --git a/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfigurationFactory.java b/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfigurationFactory.java index 1ab74973799..542d0c48d27 100644 --- a/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfigurationFactory.java +++ b/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfigurationFactory.java @@ -19,22 +19,22 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.common.config.configcenter.AbstractDynamicConfigurationFactory; import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; -import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter; +import org.apache.dubbo.remoting.zookeeper.curator5.ZookeeperClientManager; import org.apache.dubbo.rpc.model.ApplicationModel; public class ZookeeperDynamicConfigurationFactory extends AbstractDynamicConfigurationFactory { - private final ZookeeperTransporter zookeeperTransporter; + private final ZookeeperClientManager zookeeperClientManager; private final ApplicationModel applicationModel; public ZookeeperDynamicConfigurationFactory(ApplicationModel applicationModel) { this.applicationModel = applicationModel; - this.zookeeperTransporter = ZookeeperTransporter.getExtension(applicationModel); + this.zookeeperClientManager = ZookeeperClientManager.getInstance(applicationModel); } @Override protected DynamicConfiguration createDynamicConfiguration(URL url) { - return new ZookeeperDynamicConfiguration(url, zookeeperTransporter, applicationModel); + return new ZookeeperDynamicConfiguration(url, zookeeperClientManager, applicationModel); } } diff --git a/dubbo-dependencies/dubbo-dependencies-zookeeper/pom.xml b/dubbo-dependencies/dubbo-dependencies-zookeeper/pom.xml deleted file mode 100644 index c077c86ac2e..00000000000 --- a/dubbo-dependencies/dubbo-dependencies-zookeeper/pom.xml +++ /dev/null @@ -1,212 +0,0 @@ - - - - 4.0.0 - - - org.apache - apache - 31 - - - - org.apache.dubbo - dubbo-dependencies-zookeeper - ${revision} - pom - - - 3.3.0-beta.3-SNAPSHOT - 1.6.0 - 1.7.36 - 4.3.0 - 3.4.14 - 2.43.0 - check - 1.0.0 - 2.38.0 - - - - - org.apache.curator - curator-x-discovery - ${curator_version} - - - org.apache.zookeeper - zookeeper - - - org.slf4j - slf4j-api - - - com.google.guava - listenablefuture - - - - - org.apache.zookeeper - zookeeper - ${zookeeper_version} - - - org.slf4j - slf4j-log4j12 - - - log4j - log4j - - - com.github.spotbugs - spotbugs-annotations - - - org.apache.yetus - audience-annotations - - - jline - jline - - - io.netty - * - - - org.slf4j - slf4j-api - - - - - org.slf4j - slf4j-api - ${slf4j_version} - - - - - - - org.codehaus.mojo - flatten-maven-plugin - ${maven_flatten_version} - - true - oss - - - - flatten - - flatten - - process-resources - - - flatten.clean - - clean - - clean - - - - - - - - - release - - - - org.apache.maven.plugins - maven-gpg-plugin - - - - sign - - verify - - - - - - - - java11+ - - [11,) - - - - - - com.diffplug.spotless - spotless-maven-plugin - ${spotless-maven-plugin.version} - - - - ${palantirJavaFormat.version} - - - - dubbo-importorder.txt - - - checkstyle-header.txt - - - - - false - true - - - - true - - - - - com.alibaba - dubbo-shared-resources - ${dubbo-shared-resources.version} - - - - - - ${spotless.action} - - process-sources - - - - - - - - diff --git a/dubbo-dependencies/pom.xml b/dubbo-dependencies/pom.xml index 585c25fc95c..afc7ab7ab44 100644 --- a/dubbo-dependencies/pom.xml +++ b/dubbo-dependencies/pom.xml @@ -27,7 +27,6 @@ dubbo-dependencies pom - dubbo-dependencies-zookeeper dubbo-dependencies-zookeeper-curator5 diff --git a/dubbo-distribution/dubbo-all-shaded/pom.xml b/dubbo-distribution/dubbo-all-shaded/pom.xml index a27f148cef6..f9207588e36 100644 --- a/dubbo-distribution/dubbo-all-shaded/pom.xml +++ b/dubbo-distribution/dubbo-all-shaded/pom.xml @@ -326,13 +326,6 @@ compile true - - org.apache.dubbo - dubbo-remoting-zookeeper - ${project.version} - compile - true - org.apache.dubbo dubbo-remoting-zookeeper-curator5 @@ -495,7 +488,6 @@ org.apache.dubbo:dubbo-remoting-http org.apache.dubbo:dubbo-remoting-netty4 org.apache.dubbo:dubbo-remoting-netty - org.apache.dubbo:dubbo-remoting-zookeeper org.apache.dubbo:dubbo-remoting-zookeeper-curator5 org.apache.dubbo:dubbo-rpc-api org.apache.dubbo:dubbo-rpc-dubbo @@ -733,9 +725,6 @@ META-INF/dubbo/internal/org.apache.dubbo.remoting.telnet.TelnetHandler - - META-INF/dubbo/internal/org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter - META-INF/dubbo/internal/org.apache.dubbo.rpc.ExporterListener diff --git a/dubbo-distribution/dubbo-all/pom.xml b/dubbo-distribution/dubbo-all/pom.xml index efe16c5cbf4..dceb0307b12 100644 --- a/dubbo-distribution/dubbo-all/pom.xml +++ b/dubbo-distribution/dubbo-all/pom.xml @@ -357,20 +357,6 @@ compile true - - org.apache.dubbo - dubbo-remoting-zookeeper-api - ${project.version} - compile - true - - - org.apache.dubbo - dubbo-remoting-zookeeper - ${project.version} - compile - true - org.apache.dubbo dubbo-remoting-zookeeper-curator5 @@ -534,8 +520,6 @@ org.apache.dubbo:dubbo-remoting-http12 org.apache.dubbo:dubbo-remoting-netty4 org.apache.dubbo:dubbo-remoting-netty - org.apache.dubbo:dubbo-remoting-zookeeper-api - org.apache.dubbo:dubbo-remoting-zookeeper org.apache.dubbo:dubbo-remoting-zookeeper-curator5 org.apache.dubbo:dubbo-rpc-api org.apache.dubbo:dubbo-rpc-dubbo @@ -772,9 +756,6 @@ META-INF/dubbo/internal/org.apache.dubbo.remoting.telnet.TelnetHandler - - META-INF/dubbo/internal/org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter - META-INF/dubbo/internal/org.apache.dubbo.rpc.ExporterListener diff --git a/dubbo-distribution/dubbo-bom/pom.xml b/dubbo-distribution/dubbo-bom/pom.xml index 7e535f3421d..80335d6743b 100644 --- a/dubbo-distribution/dubbo-bom/pom.xml +++ b/dubbo-distribution/dubbo-bom/pom.xml @@ -410,16 +410,6 @@ dubbo-remoting-netty4 ${project.version} - - org.apache.dubbo - dubbo-remoting-zookeeper-api - ${project.version} - - - org.apache.dubbo - dubbo-remoting-zookeeper - ${project.version} - org.apache.dubbo dubbo-remoting-zookeeper-curator5 diff --git a/dubbo-distribution/dubbo-core-spi/pom.xml b/dubbo-distribution/dubbo-core-spi/pom.xml index cdcd0bc429b..c9661590f2d 100644 --- a/dubbo-distribution/dubbo-core-spi/pom.xml +++ b/dubbo-distribution/dubbo-core-spi/pom.xml @@ -357,9 +357,6 @@ META-INF/dubbo/internal/org.apache.dubbo.remoting.telnet.TelnetHandler - - META-INF/dubbo/internal/org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter - META-INF/dubbo/internal/org.apache.dubbo.rpc.ExporterListener diff --git a/dubbo-metadata/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport.java b/dubbo-metadata/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport.java index ce01bf0d7c8..205138cf472 100644 --- a/dubbo-metadata/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport.java +++ b/dubbo-metadata/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport.java @@ -32,10 +32,10 @@ import org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier; import org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier; import org.apache.dubbo.metadata.report.support.AbstractMetadataReport; -import org.apache.dubbo.remoting.zookeeper.DataListener; -import org.apache.dubbo.remoting.zookeeper.EventType; -import org.apache.dubbo.remoting.zookeeper.ZookeeperClient; -import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter; +import org.apache.dubbo.remoting.zookeeper.curator5.DataListener; +import org.apache.dubbo.remoting.zookeeper.curator5.EventType; +import org.apache.dubbo.remoting.zookeeper.curator5.ZookeeperClient; +import org.apache.dubbo.remoting.zookeeper.curator5.ZookeeperClientManager; import java.util.ArrayList; import java.util.Collections; @@ -67,7 +67,7 @@ public class ZookeeperMetadataReport extends AbstractMetadataReport { private ConcurrentMap casListenerMap = new ConcurrentHashMap<>(); - public ZookeeperMetadataReport(URL url, ZookeeperTransporter zookeeperTransporter) { + public ZookeeperMetadataReport(URL url, ZookeeperClientManager zookeeperClientManager) { super(url); if (url.isAnyHost()) { throw new IllegalStateException("registry address == null"); @@ -77,7 +77,7 @@ public ZookeeperMetadataReport(URL url, ZookeeperTransporter zookeeperTransporte group = PATH_SEPARATOR + group; } this.root = group; - zkClient = zookeeperTransporter.connect(url); + zkClient = zookeeperClientManager.connect(url); } protected String toRootDir() { diff --git a/dubbo-metadata/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportFactory.java b/dubbo-metadata/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportFactory.java index 42270d863e3..568eacf6d43 100644 --- a/dubbo-metadata/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportFactory.java +++ b/dubbo-metadata/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportFactory.java @@ -20,7 +20,7 @@ import org.apache.dubbo.common.extension.DisableInject; import org.apache.dubbo.metadata.report.MetadataReport; import org.apache.dubbo.metadata.report.support.AbstractMetadataReportFactory; -import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter; +import org.apache.dubbo.remoting.zookeeper.curator5.ZookeeperClientManager; import org.apache.dubbo.rpc.model.ApplicationModel; /** @@ -28,22 +28,19 @@ */ public class ZookeeperMetadataReportFactory extends AbstractMetadataReportFactory { - private ZookeeperTransporter zookeeperTransporter; - - private ApplicationModel applicationModel; + private ZookeeperClientManager zookeeperClientManager; public ZookeeperMetadataReportFactory(ApplicationModel applicationModel) { - this.applicationModel = applicationModel; - this.zookeeperTransporter = ZookeeperTransporter.getExtension(applicationModel); + this.zookeeperClientManager = ZookeeperClientManager.getInstance(applicationModel); } @DisableInject - public void setZookeeperTransporter(ZookeeperTransporter zookeeperTransporter) { - this.zookeeperTransporter = zookeeperTransporter; + public void setZookeeperTransporter(ZookeeperClientManager zookeeperClientManager) { + this.zookeeperClientManager = zookeeperClientManager; } @Override public MetadataReport createMetadataReport(URL url) { - return new ZookeeperMetadataReport(url, zookeeperTransporter); + return new ZookeeperMetadataReport(url, zookeeperClientManager); } } diff --git a/dubbo-registry/dubbo-registry-multiple/src/test/java/org/apache/dubbo/registry/multiple/MultipleRegistry2S2RTest.java b/dubbo-registry/dubbo-registry-multiple/src/test/java/org/apache/dubbo/registry/multiple/MultipleRegistry2S2RTest.java index cb83155ff7d..7a258f7ff5b 100644 --- a/dubbo-registry/dubbo-registry-multiple/src/test/java/org/apache/dubbo/registry/multiple/MultipleRegistry2S2RTest.java +++ b/dubbo-registry/dubbo-registry-multiple/src/test/java/org/apache/dubbo/registry/multiple/MultipleRegistry2S2RTest.java @@ -20,8 +20,8 @@ import org.apache.dubbo.registry.NotifyListener; import org.apache.dubbo.registry.Registry; import org.apache.dubbo.registry.zookeeper.ZookeeperRegistry; -import org.apache.dubbo.remoting.zookeeper.ZookeeperClient; import org.apache.dubbo.remoting.zookeeper.curator5.Curator5ZookeeperClient; +import org.apache.dubbo.remoting.zookeeper.curator5.ZookeeperClient; import java.util.ArrayList; import java.util.List; diff --git a/dubbo-registry/dubbo-registry-zookeeper/pom.xml b/dubbo-registry/dubbo-registry-zookeeper/pom.xml index f4ccf4f23a5..f9228eb8786 100644 --- a/dubbo-registry/dubbo-registry-zookeeper/pom.xml +++ b/dubbo-registry/dubbo-registry-zookeeper/pom.xml @@ -41,6 +41,7 @@ dubbo-remoting-zookeeper-curator5 ${project.parent.version} + org.apache.curator curator-x-discovery diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java index 4052df8d262..7ac6e69d5b5 100644 --- a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java +++ b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java @@ -26,10 +26,10 @@ import org.apache.dubbo.registry.NotifyListener; import org.apache.dubbo.registry.support.CacheableFailbackRegistry; import org.apache.dubbo.remoting.Constants; -import org.apache.dubbo.remoting.zookeeper.ChildListener; -import org.apache.dubbo.remoting.zookeeper.StateListener; -import org.apache.dubbo.remoting.zookeeper.ZookeeperClient; -import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter; +import org.apache.dubbo.remoting.zookeeper.curator5.ChildListener; +import org.apache.dubbo.remoting.zookeeper.curator5.StateListener; +import org.apache.dubbo.remoting.zookeeper.curator5.ZookeeperClient; +import org.apache.dubbo.remoting.zookeeper.curator5.ZookeeperClientManager; import org.apache.dubbo.rpc.RpcException; import java.util.ArrayList; @@ -72,7 +72,7 @@ public class ZookeeperRegistry extends CacheableFailbackRegistry { private ZookeeperClient zkClient; - public ZookeeperRegistry(URL url, ZookeeperTransporter zookeeperTransporter) { + public ZookeeperRegistry(URL url, ZookeeperClientManager zookeeperClientManager) { super(url); if (url.isAnyHost()) { @@ -85,7 +85,7 @@ public ZookeeperRegistry(URL url, ZookeeperTransporter zookeeperTransporter) { } this.root = group; - this.zkClient = zookeeperTransporter.connect(url); + this.zkClient = zookeeperClientManager.connect(url); this.zkClient.addStateListener((state) -> { if (state == StateListener.RECONNECTED) { diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistryFactory.java b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistryFactory.java index ec4ce4ac342..c830c557a3e 100644 --- a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistryFactory.java +++ b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistryFactory.java @@ -20,7 +20,7 @@ import org.apache.dubbo.common.extension.DisableInject; import org.apache.dubbo.registry.Registry; import org.apache.dubbo.registry.support.AbstractRegistryFactory; -import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter; +import org.apache.dubbo.remoting.zookeeper.curator5.ZookeeperClientManager; import org.apache.dubbo.rpc.model.ApplicationModel; /** @@ -28,7 +28,7 @@ */ public class ZookeeperRegistryFactory extends AbstractRegistryFactory { - private ZookeeperTransporter zookeeperTransporter; + private ZookeeperClientManager zookeeperClientManager; // for compatible usage public ZookeeperRegistryFactory() { @@ -37,16 +37,16 @@ public ZookeeperRegistryFactory() { public ZookeeperRegistryFactory(ApplicationModel applicationModel) { this.applicationModel = applicationModel; - this.zookeeperTransporter = ZookeeperTransporter.getExtension(applicationModel); + this.zookeeperClientManager = ZookeeperClientManager.getInstance(applicationModel); } @DisableInject - public void setZookeeperTransporter(ZookeeperTransporter zookeeperTransporter) { - this.zookeeperTransporter = zookeeperTransporter; + public void setZookeeperTransporter(ZookeeperClientManager zookeeperClientManager) { + this.zookeeperClientManager = zookeeperClientManager; } @Override public Registry createRegistry(URL url) { - return new ZookeeperRegistry(url, zookeeperTransporter); + return new ZookeeperRegistry(url, zookeeperClientManager); } } diff --git a/dubbo-remoting/dubbo-remoting-zookeeper-api/pom.xml b/dubbo-remoting/dubbo-remoting-zookeeper-api/pom.xml deleted file mode 100644 index 4f140f5f49e..00000000000 --- a/dubbo-remoting/dubbo-remoting-zookeeper-api/pom.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - 4.0.0 - - org.apache.dubbo - dubbo-remoting - ${revision} - ../pom.xml - - dubbo-remoting-zookeeper-api - jar - ${project.artifactId} - The zookeeper remoting module of dubbo project - - false - 3.4.14 - 4.3.0 - - - - org.apache.dubbo - dubbo-common - ${project.parent.version} - - - - org.apache.dubbo - dubbo-test-common - ${project.parent.version} - test - - - diff --git a/dubbo-remoting/dubbo-remoting-zookeeper-api/src/main/java/org/apache/dubbo/remoting/RemotingScopeModelInitializer.java b/dubbo-remoting/dubbo-remoting-zookeeper-api/src/main/java/org/apache/dubbo/remoting/RemotingScopeModelInitializer.java deleted file mode 100644 index 820f45e2b85..00000000000 --- a/dubbo-remoting/dubbo-remoting-zookeeper-api/src/main/java/org/apache/dubbo/remoting/RemotingScopeModelInitializer.java +++ /dev/null @@ -1,66 +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.remoting; - -import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; -import org.apache.dubbo.common.logger.LoggerFactory; -import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter; -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.ScopeModelInitializer; - -import java.util.List; - -import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_FAILED_DESTROY_ZOOKEEPER; - -/** - * Scope model initializer for remoting-api - */ -public class RemotingScopeModelInitializer implements ScopeModelInitializer { - - private static final ErrorTypeAwareLogger logger = - LoggerFactory.getErrorTypeAwareLogger(RemotingScopeModelInitializer.class); - - @Override - public void initializeFrameworkModel(FrameworkModel frameworkModel) {} - - @Override - public void initializeApplicationModel(ApplicationModel applicationModel) { - applicationModel.addDestroyListener(m -> { - // destroy zookeeper clients if any - try { - List transporters = applicationModel - .getExtensionLoader(ZookeeperTransporter.class) - .getLoadedExtensionInstances(); - for (ZookeeperTransporter zkTransporter : transporters) { - zkTransporter.destroy(); - } - } catch (Exception e) { - logger.error( - TRANSPORT_FAILED_DESTROY_ZOOKEEPER, - "", - "", - "Error encountered while destroying ZookeeperTransporter: " + e.getMessage(), - e); - } - }); - } - - @Override - public void initializeModuleModel(ModuleModel moduleModel) {} -} diff --git a/dubbo-remoting/dubbo-remoting-zookeeper-api/src/main/java/org/apache/dubbo/remoting/zookeeper/ZookeeperTransporter.java b/dubbo-remoting/dubbo-remoting-zookeeper-api/src/main/java/org/apache/dubbo/remoting/zookeeper/ZookeeperTransporter.java deleted file mode 100644 index f73bc6b1a7e..00000000000 --- a/dubbo-remoting/dubbo-remoting-zookeeper-api/src/main/java/org/apache/dubbo/remoting/zookeeper/ZookeeperTransporter.java +++ /dev/null @@ -1,50 +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.remoting.zookeeper; - -import org.apache.dubbo.common.URL; -import org.apache.dubbo.common.extension.ExtensionLoader; -import org.apache.dubbo.common.extension.ExtensionScope; -import org.apache.dubbo.common.extension.SPI; -import org.apache.dubbo.rpc.model.ApplicationModel; - -@SPI(scope = ExtensionScope.APPLICATION) -public interface ZookeeperTransporter { - - String CURATOR_5 = "curator5"; - - String CURATOR = "curator"; - - ZookeeperClient connect(URL url); - - void destroy(); - - static ZookeeperTransporter getExtension(ApplicationModel applicationModel) { - ExtensionLoader extensionLoader = - applicationModel.getExtensionLoader(ZookeeperTransporter.class); - return isHighVersionCurator() ? extensionLoader.getExtension(CURATOR_5) : extensionLoader.getExtension(CURATOR); - } - - static boolean isHighVersionCurator() { - try { - Class.forName("org.apache.curator.framework.recipes.cache.CuratorCache"); - return true; - } catch (ClassNotFoundException e) { - return false; - } - } -} diff --git a/dubbo-remoting/dubbo-remoting-zookeeper-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.model.ScopeModelInitializer b/dubbo-remoting/dubbo-remoting-zookeeper-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.model.ScopeModelInitializer deleted file mode 100644 index 1568955be79..00000000000 --- a/dubbo-remoting/dubbo-remoting-zookeeper-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.model.ScopeModelInitializer +++ /dev/null @@ -1 +0,0 @@ -dubbo-remoting-api=org.apache.dubbo.remoting.RemotingScopeModelInitializer diff --git a/dubbo-remoting/dubbo-remoting-zookeeper-curator5/pom.xml b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/pom.xml index 9015bb26eea..5f57672cedb 100644 --- a/dubbo-remoting/dubbo-remoting-zookeeper-curator5/pom.xml +++ b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/pom.xml @@ -26,19 +26,26 @@ dubbo-remoting-zookeeper-curator5 jar ${project.artifactId} - The zookeeper curator5 remoting module of dubbo project + The zookeeper remoting module of dubbo project false - 5.1.0 3.7.2 + 5.1.0 - org.apache.dubbo - dubbo-remoting-zookeeper-api + dubbo-common ${project.parent.version} + + + org.apache.dubbo + dubbo-test-common + ${project.parent.version} + test + + org.apache.dubbo dubbo-common diff --git a/dubbo-remoting/dubbo-remoting-zookeeper-api/src/main/java/org/apache/dubbo/remoting/zookeeper/AbstractZookeeperClient.java b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/AbstractZookeeperClient.java similarity index 99% rename from dubbo-remoting/dubbo-remoting-zookeeper-api/src/main/java/org/apache/dubbo/remoting/zookeeper/AbstractZookeeperClient.java rename to dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/AbstractZookeeperClient.java index e830246617a..fe7a9b6015f 100644 --- a/dubbo-remoting/dubbo-remoting-zookeeper-api/src/main/java/org/apache/dubbo/remoting/zookeeper/AbstractZookeeperClient.java +++ b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/AbstractZookeeperClient.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.remoting.zookeeper; +package org.apache.dubbo.remoting.zookeeper.curator5; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.config.configcenter.ConfigItem; diff --git a/dubbo-remoting/dubbo-remoting-zookeeper-api/src/main/java/org/apache/dubbo/remoting/zookeeper/ChildListener.java b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/ChildListener.java similarity index 94% rename from dubbo-remoting/dubbo-remoting-zookeeper-api/src/main/java/org/apache/dubbo/remoting/zookeeper/ChildListener.java rename to dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/ChildListener.java index 5ada2815a87..4586f23d9c3 100644 --- a/dubbo-remoting/dubbo-remoting-zookeeper-api/src/main/java/org/apache/dubbo/remoting/zookeeper/ChildListener.java +++ b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/ChildListener.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.remoting.zookeeper; +package org.apache.dubbo.remoting.zookeeper.curator5; import java.util.List; diff --git a/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperClient.java b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperClient.java index 65b6bd67975..fd51c9f0488 100644 --- a/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperClient.java +++ b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperClient.java @@ -20,11 +20,6 @@ import org.apache.dubbo.common.config.configcenter.ConfigItem; import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; -import org.apache.dubbo.remoting.zookeeper.AbstractZookeeperClient; -import org.apache.dubbo.remoting.zookeeper.ChildListener; -import org.apache.dubbo.remoting.zookeeper.DataListener; -import org.apache.dubbo.remoting.zookeeper.EventType; -import org.apache.dubbo.remoting.zookeeper.StateListener; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; diff --git a/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperTransporter.java b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperTransporter.java deleted file mode 100644 index 223981a2558..00000000000 --- a/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperTransporter.java +++ /dev/null @@ -1,29 +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.remoting.zookeeper.curator5; - -import org.apache.dubbo.common.URL; -import org.apache.dubbo.remoting.zookeeper.AbstractZookeeperTransporter; -import org.apache.dubbo.remoting.zookeeper.ZookeeperClient; - -public class Curator5ZookeeperTransporter extends AbstractZookeeperTransporter { - - @Override - public ZookeeperClient createZookeeperClient(URL url) { - return new Curator5ZookeeperClient(url); - } -} diff --git a/dubbo-remoting/dubbo-remoting-zookeeper-api/src/main/java/org/apache/dubbo/remoting/zookeeper/DataListener.java b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/DataListener.java similarity index 94% rename from dubbo-remoting/dubbo-remoting-zookeeper-api/src/main/java/org/apache/dubbo/remoting/zookeeper/DataListener.java rename to dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/DataListener.java index 95b948adafa..483c9d63acd 100644 --- a/dubbo-remoting/dubbo-remoting-zookeeper-api/src/main/java/org/apache/dubbo/remoting/zookeeper/DataListener.java +++ b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/DataListener.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.remoting.zookeeper; +package org.apache.dubbo.remoting.zookeeper.curator5; /** * 2019-02-26 diff --git a/dubbo-remoting/dubbo-remoting-zookeeper-api/src/main/java/org/apache/dubbo/remoting/zookeeper/EventType.java b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/EventType.java similarity index 96% rename from dubbo-remoting/dubbo-remoting-zookeeper-api/src/main/java/org/apache/dubbo/remoting/zookeeper/EventType.java rename to dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/EventType.java index 9e288036472..25e844fb40f 100644 --- a/dubbo-remoting/dubbo-remoting-zookeeper-api/src/main/java/org/apache/dubbo/remoting/zookeeper/EventType.java +++ b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/EventType.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.remoting.zookeeper; +package org.apache.dubbo.remoting.zookeeper.curator5; /** * 2019-02-26 diff --git a/dubbo-remoting/dubbo-remoting-zookeeper-api/src/main/java/org/apache/dubbo/remoting/zookeeper/StateListener.java b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/StateListener.java similarity index 94% rename from dubbo-remoting/dubbo-remoting-zookeeper-api/src/main/java/org/apache/dubbo/remoting/zookeeper/StateListener.java rename to dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/StateListener.java index 202b6cc63bf..432db95eb35 100644 --- a/dubbo-remoting/dubbo-remoting-zookeeper-api/src/main/java/org/apache/dubbo/remoting/zookeeper/StateListener.java +++ b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/StateListener.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.remoting.zookeeper; +package org.apache.dubbo.remoting.zookeeper.curator5; public interface StateListener { diff --git a/dubbo-remoting/dubbo-remoting-zookeeper-api/src/main/java/org/apache/dubbo/remoting/zookeeper/ZookeeperClient.java b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/ZookeeperClient.java similarity index 98% rename from dubbo-remoting/dubbo-remoting-zookeeper-api/src/main/java/org/apache/dubbo/remoting/zookeeper/ZookeeperClient.java rename to dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/ZookeeperClient.java index b2877cd2598..5371f393fd1 100644 --- a/dubbo-remoting/dubbo-remoting-zookeeper-api/src/main/java/org/apache/dubbo/remoting/zookeeper/ZookeeperClient.java +++ b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/ZookeeperClient.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.remoting.zookeeper; +package org.apache.dubbo.remoting.zookeeper.curator5; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.config.configcenter.ConfigItem; diff --git a/dubbo-remoting/dubbo-remoting-zookeeper-api/src/main/java/org/apache/dubbo/remoting/zookeeper/AbstractZookeeperTransporter.java b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/ZookeeperClientManager.java similarity index 77% rename from dubbo-remoting/dubbo-remoting-zookeeper-api/src/main/java/org/apache/dubbo/remoting/zookeeper/AbstractZookeeperTransporter.java rename to dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/ZookeeperClientManager.java index 802ec8820c2..53c63a889e8 100644 --- a/dubbo-remoting/dubbo-remoting-zookeeper-api/src/main/java/org/apache/dubbo/remoting/zookeeper/AbstractZookeeperTransporter.java +++ b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/ZookeeperClientManager.java @@ -14,14 +14,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.remoting.zookeeper; +package org.apache.dubbo.remoting.zookeeper.curator5; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.constants.RemotingConstants; -import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.url.component.ServiceConfigURL; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.rpc.model.ApplicationModel; import java.util.ArrayList; import java.util.Collections; @@ -31,25 +32,42 @@ import java.util.concurrent.ConcurrentHashMap; import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; +import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_FAILED_DESTROY_ZOOKEEPER; -/** - * AbstractZookeeperTransporter is abstract implements of ZookeeperTransporter. - *

- * If you want to extend this, implements createZookeeperClient. - */ -public abstract class AbstractZookeeperTransporter implements ZookeeperTransporter { - private static final Logger logger = LoggerFactory.getLogger(ZookeeperTransporter.class); +public class ZookeeperClientManager { + + private static final ErrorTypeAwareLogger logger = + LoggerFactory.getErrorTypeAwareLogger(ZookeeperClientManager.class); private final Map zookeeperClientMap = new ConcurrentHashMap<>(); + private static final Map managerMap = new ConcurrentHashMap<>(); /** - * share connect for registry, metadata, etc.. - *

- * Make sure the connection is connected. - * - * @param url - * @return + * Use getInstance instead of get Instance + * This method is made public solely for unit test purposes. */ - @Override + public ZookeeperClientManager() {} + + public static ZookeeperClientManager getInstance(ApplicationModel applicationModel) { + if (!managerMap.containsKey(applicationModel) || managerMap.get(applicationModel) == null) { + ZookeeperClientManager clientManager = new ZookeeperClientManager(); + applicationModel.addDestroyListener(m -> { + // destroy zookeeper clients if any + try { + clientManager.destroy(); + } catch (Exception e) { + logger.error( + TRANSPORT_FAILED_DESTROY_ZOOKEEPER, + "", + "", + "Error encountered while destroying ZookeeperTransporter: " + e.getMessage(), + e); + } + }); + managerMap.put(applicationModel, clientManager); + } + return managerMap.get(applicationModel); + } + public ZookeeperClient connect(URL url) { ZookeeperClient zookeeperClient; // address format: {[username:password@]address} @@ -68,29 +86,13 @@ public ZookeeperClient connect(URL url) { return zookeeperClient; } - zookeeperClient = createZookeeperClient(url); + zookeeperClient = new Curator5ZookeeperClient(url); logger.info("No valid zookeeper client found from cache, therefore create a new client for url. " + url); writeToClientMap(addressList, zookeeperClient); } return zookeeperClient; } - /** - * @param url the url that will create zookeeper connection . - * The url in AbstractZookeeperTransporter#connect parameter is rewritten by this one. - * such as: zookeeper://127.0.0.1:2181/org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter - * @return - */ - protected abstract ZookeeperClient createZookeeperClient(URL url); - - /** - * get the ZookeeperClient from cache, the ZookeeperClient must be connected. - *

- * It is not private method for unit test. - * - * @param addressList - * @return - */ public ZookeeperClient fetchAndUpdateZookeeperClientCache(List addressList) { ZookeeperClient zookeeperClient = null; for (String address : addressList) { @@ -173,7 +175,7 @@ URL toClientURL(URL url) { url.getPassword(), url.getHost(), url.getPort(), - ZookeeperTransporter.class.getName(), + ZookeeperClientManager.class.getName(), parameterMap); } @@ -186,7 +188,6 @@ public Map getZookeeperClientMap() { return zookeeperClientMap; } - @Override public void destroy() { // only destroy zk clients here for (ZookeeperClient client : zookeeperClientMap.values()) { diff --git a/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.aot.api.ReflectionTypeDescriberRegistrar b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.aot.api.ReflectionTypeDescriberRegistrar index ed05e185646..fbf8d18b8d4 100644 --- a/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.aot.api.ReflectionTypeDescriberRegistrar +++ b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.aot.api.ReflectionTypeDescriberRegistrar @@ -1 +1 @@ -curator5Zookeeper=org.apache.dubbo.remoting.zookeeper.curator5.aot.Curator5ZookeeperReflectionTypeDescriberRegistrar +curator5Zookeeper=org.apache.dubbo.remoting.zookeeper.aot.Curator5ZookeeperReflectionTypeDescriberRegistrar diff --git a/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter deleted file mode 100644 index 5c998c75432..00000000000 --- a/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter +++ /dev/null @@ -1 +0,0 @@ -curator5=org.apache.dubbo.remoting.zookeeper.curator5.Curator5ZookeeperTransporter diff --git a/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/test/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperTransporterTest.java b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/test/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperClientManagerTest.java similarity index 80% rename from dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/test/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperTransporterTest.java rename to dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/test/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperClientManagerTest.java index f94f4e0053e..e256e4557b6 100644 --- a/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/test/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperTransporterTest.java +++ b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/test/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperClientManagerTest.java @@ -17,7 +17,6 @@ package org.apache.dubbo.remoting.zookeeper.curator5; import org.apache.dubbo.common.URL; -import org.apache.dubbo.remoting.zookeeper.ZookeeperClient; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -27,9 +26,9 @@ import static org.hamcrest.core.IsNot.not; import static org.hamcrest.core.IsNull.nullValue; -class Curator5ZookeeperTransporterTest { +class Curator5ZookeeperClientManagerTest { private ZookeeperClient zookeeperClient; - private Curator5ZookeeperTransporter curatorZookeeperTransporter; + private ZookeeperClientManager zookeeperClientManager; private static String zookeeperConnectionAddress1; @BeforeAll @@ -39,9 +38,8 @@ public static void beforeAll() { @BeforeEach public void setUp() { - zookeeperClient = - new Curator5ZookeeperTransporter().connect(URL.valueOf(zookeeperConnectionAddress1 + "/service")); - curatorZookeeperTransporter = new Curator5ZookeeperTransporter(); + zookeeperClient = new ZookeeperClientManager().connect(URL.valueOf(zookeeperConnectionAddress1 + "/service")); + zookeeperClientManager = new ZookeeperClientManager(); } @Test diff --git a/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/test/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperClientTest.java b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/test/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperClientTest.java index 50e96f93543..e515fc6504b 100644 --- a/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/test/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperClientTest.java +++ b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/test/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperClientTest.java @@ -18,7 +18,6 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.common.config.configcenter.ConfigItem; -import org.apache.dubbo.remoting.zookeeper.ChildListener; import java.nio.charset.StandardCharsets; import java.util.List; diff --git a/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/test/java/org/apache/dubbo/remoting/zookeeper/curator5/support/AbstractZookeeperTransporterTest.java b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/test/java/org/apache/dubbo/remoting/zookeeper/curator5/support/ZookeeperClientManagerTest.java similarity index 71% rename from dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/test/java/org/apache/dubbo/remoting/zookeeper/curator5/support/AbstractZookeeperTransporterTest.java rename to dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/test/java/org/apache/dubbo/remoting/zookeeper/curator5/support/ZookeeperClientManagerTest.java index 5b3eac89683..a66d94b0edd 100644 --- a/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/test/java/org/apache/dubbo/remoting/zookeeper/curator5/support/AbstractZookeeperTransporterTest.java +++ b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/test/java/org/apache/dubbo/remoting/zookeeper/curator5/support/ZookeeperClientManagerTest.java @@ -17,9 +17,8 @@ package org.apache.dubbo.remoting.zookeeper.curator5.support; import org.apache.dubbo.common.URL; -import org.apache.dubbo.remoting.zookeeper.AbstractZookeeperTransporter; -import org.apache.dubbo.remoting.zookeeper.ZookeeperClient; -import org.apache.dubbo.remoting.zookeeper.curator5.Curator5ZookeeperTransporter; +import org.apache.dubbo.remoting.zookeeper.curator5.ZookeeperClient; +import org.apache.dubbo.remoting.zookeeper.curator5.ZookeeperClientManager; import java.util.List; @@ -33,11 +32,11 @@ import static org.hamcrest.core.IsNull.nullValue; /** - * AbstractZookeeperTransporterTest + * ZookeeperManagerTest */ -class AbstractZookeeperTransporterTest { +class ZookeeperClientManagerTest { private ZookeeperClient zookeeperClient; - private AbstractZookeeperTransporter abstractZookeeperTransporter; + private ZookeeperClientManager zookeeperClientManager; private static int zookeeperServerPort1, zookeeperServerPort2; private static String zookeeperConnectionAddress1, zookeeperConnectionAddress2; @@ -54,9 +53,8 @@ public static void beforeAll() { @BeforeEach public void setUp() throws Exception { - zookeeperClient = - new Curator5ZookeeperTransporter().connect(URL.valueOf(zookeeperConnectionAddress1 + "/service")); - abstractZookeeperTransporter = new Curator5ZookeeperTransporter(); + zookeeperClient = new ZookeeperClientManager().connect(URL.valueOf(zookeeperConnectionAddress1 + "/service")); + zookeeperClientManager = new ZookeeperClientManager(); } @Test @@ -70,7 +68,7 @@ void testGetURLBackupAddress() { URL url = URL.valueOf( zookeeperConnectionAddress1 + "/org.apache.dubbo.registry.RegistryService?backup=127.0.0.1:" + 9099 + "&application=metadatareport-local-xml-provider2&dubbo=2.0.2&interface=org.apache.dubbo.registry.RegistryService&pid=47418&specVersion=2.7.0-SNAPSHOT×tamp=1547102428828"); - List stringList = abstractZookeeperTransporter.getURLBackupAddress(url); + List stringList = zookeeperClientManager.getURLBackupAddress(url); Assertions.assertEquals(stringList.size(), 2); Assertions.assertEquals(stringList.get(0), "127.0.0.1:" + zookeeperServerPort1); Assertions.assertEquals(stringList.get(1), "127.0.0.1:9099"); @@ -81,7 +79,7 @@ void testGetURLBackupAddressNoBack() { URL url = URL.valueOf( zookeeperConnectionAddress1 + "/org.apache.dubbo.registry.RegistryService?application=metadatareport-local-xml-provider2&dubbo=2.0.2&interface=org.apache.dubbo.registry.RegistryService&pid=47418&specVersion=2.7.0-SNAPSHOT×tamp=1547102428828"); - List stringList = abstractZookeeperTransporter.getURLBackupAddress(url); + List stringList = zookeeperClientManager.getURLBackupAddress(url); Assertions.assertEquals(stringList.size(), 1); Assertions.assertEquals(stringList.get(0), "127.0.0.1:" + zookeeperServerPort1); } @@ -92,13 +90,12 @@ void testFetchAndUpdateZookeeperClientCache() { zookeeperConnectionAddress1 + "/org.apache.dubbo.registry.RegistryService?backup=127.0.0.1:" + zookeeperServerPort1 + ",127.0.0.1:" + zookeeperServerPort2 + "&application=metadatareport-local-xml-provider2&dubbo=2.0.2&interface=org.apache.dubbo.registry.RegistryService&pid=47418&specVersion=2.7.0-SNAPSHOT×tamp=1547102428828"); - ZookeeperClient newZookeeperClient = abstractZookeeperTransporter.connect(url); + ZookeeperClient newZookeeperClient = zookeeperClientManager.connect(url); // just for connected newZookeeperClient.getContent("/dubbo/test"); + Assertions.assertEquals(zookeeperClientManager.getZookeeperClientMap().size(), 2); Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().size(), 2); - Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().get("127.0.0.1:" + zookeeperServerPort1), + zookeeperClientManager.getZookeeperClientMap().get("127.0.0.1:" + zookeeperServerPort1), newZookeeperClient); URL url2 = URL.valueOf( @@ -113,8 +110,8 @@ void testFetchAndUpdateZookeeperClientCache() { } private void checkFetchAndUpdateCacheNotNull(URL url) { - List addressList = abstractZookeeperTransporter.getURLBackupAddress(url); - ZookeeperClient zookeeperClient = abstractZookeeperTransporter.fetchAndUpdateZookeeperClientCache(addressList); + List addressList = zookeeperClientManager.getURLBackupAddress(url); + ZookeeperClient zookeeperClient = zookeeperClientManager.fetchAndUpdateZookeeperClientCache(addressList); Assertions.assertNotNull(zookeeperClient); } @@ -126,24 +123,22 @@ void testRepeatConnect() { URL url2 = URL.valueOf( zookeeperConnectionAddress1 + "/org.apache.dubbo.metadata.store.MetadataReport?address=zookeeper://127.0.0.1:2181&application=metadatareport-local-xml-provider2&cycle-report=false&interface=org.apache.dubbo.metadata.store.MetadataReport&retry-period=4590&retry-times=23&sync-report=true"); - ZookeeperClient newZookeeperClient = abstractZookeeperTransporter.connect(url); + ZookeeperClient newZookeeperClient = zookeeperClientManager.connect(url); // just for connected newZookeeperClient.getContent("/dubbo/test"); + Assertions.assertEquals(zookeeperClientManager.getZookeeperClientMap().size(), 1); Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().size(), 1); - Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().get("127.0.0.1:" + zookeeperServerPort1), + zookeeperClientManager.getZookeeperClientMap().get("127.0.0.1:" + zookeeperServerPort1), newZookeeperClient); Assertions.assertTrue(newZookeeperClient.isConnected()); - ZookeeperClient newZookeeperClient2 = abstractZookeeperTransporter.connect(url2); + ZookeeperClient newZookeeperClient2 = zookeeperClientManager.connect(url2); // just for connected newZookeeperClient2.getContent("/dubbo/test"); Assertions.assertEquals(newZookeeperClient, newZookeeperClient2); + Assertions.assertEquals(zookeeperClientManager.getZookeeperClientMap().size(), 1); Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().size(), 1); - Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().get("127.0.0.1:" + zookeeperServerPort1), + zookeeperClientManager.getZookeeperClientMap().get("127.0.0.1:" + zookeeperServerPort1), newZookeeperClient); } @@ -155,23 +150,21 @@ void testNotRepeatConnect() { URL url2 = URL.valueOf( zookeeperConnectionAddress2 + "/org.apache.dubbo.metadata.store.MetadataReport?address=zookeeper://127.0.0.1:2181&application=metadatareport-local-xml-provider2&cycle-report=false&interface=org.apache.dubbo.metadata.store.MetadataReport&retry-period=4590&retry-times=23&sync-report=true"); - ZookeeperClient newZookeeperClient = abstractZookeeperTransporter.connect(url); + ZookeeperClient newZookeeperClient = zookeeperClientManager.connect(url); // just for connected newZookeeperClient.getContent("/dubbo/test"); + Assertions.assertEquals(zookeeperClientManager.getZookeeperClientMap().size(), 1); Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().size(), 1); - Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().get("127.0.0.1:" + zookeeperServerPort1), + zookeeperClientManager.getZookeeperClientMap().get("127.0.0.1:" + zookeeperServerPort1), newZookeeperClient); - ZookeeperClient newZookeeperClient2 = abstractZookeeperTransporter.connect(url2); + ZookeeperClient newZookeeperClient2 = zookeeperClientManager.connect(url2); // just for connected newZookeeperClient2.getContent("/dubbo/test"); Assertions.assertNotEquals(newZookeeperClient, newZookeeperClient2); + Assertions.assertEquals(zookeeperClientManager.getZookeeperClientMap().size(), 2); Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().size(), 2); - Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().get("127.0.0.1:" + zookeeperServerPort2), + zookeeperClientManager.getZookeeperClientMap().get("127.0.0.1:" + zookeeperServerPort2), newZookeeperClient2); } @@ -186,23 +179,21 @@ void testRepeatConnectForBackUpAdd() { zookeeperConnectionAddress1 + "/org.apache.dubbo.metadata.store.MetadataReport?backup=127.0.0.1:" + zookeeperServerPort2 + "&address=zookeeper://127.0.0.1:2181&application=metadatareport-local-xml-provider2&cycle-report=false&interface=org.apache.dubbo.metadata.store.MetadataReport&retry-period=4590&retry-times=23&sync-report=true"); - ZookeeperClient newZookeeperClient = abstractZookeeperTransporter.connect(url); + ZookeeperClient newZookeeperClient = zookeeperClientManager.connect(url); // just for connected newZookeeperClient.getContent("/dubbo/test"); + Assertions.assertEquals(zookeeperClientManager.getZookeeperClientMap().size(), 1); Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().size(), 1); - Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().get("127.0.0.1:" + zookeeperServerPort1), + zookeeperClientManager.getZookeeperClientMap().get("127.0.0.1:" + zookeeperServerPort1), newZookeeperClient); - ZookeeperClient newZookeeperClient2 = abstractZookeeperTransporter.connect(url2); + ZookeeperClient newZookeeperClient2 = zookeeperClientManager.connect(url2); // just for connected newZookeeperClient2.getContent("/dubbo/test"); Assertions.assertEquals(newZookeeperClient, newZookeeperClient2); + Assertions.assertEquals(zookeeperClientManager.getZookeeperClientMap().size(), 2); Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().size(), 2); - Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().get("127.0.0.1:" + zookeeperServerPort2), + zookeeperClientManager.getZookeeperClientMap().get("127.0.0.1:" + zookeeperServerPort2), newZookeeperClient2); } @@ -216,23 +207,21 @@ void testRepeatConnectForNoMatchBackUpAdd() { URL url2 = URL.valueOf( zookeeperConnectionAddress2 + "/org.apache.dubbo.metadata.store.MetadataReport?address=zookeeper://127.0.0.1:2181&application=metadatareport-local-xml-provider2&cycle-report=false&interface=org.apache.dubbo.metadata.store.MetadataReport&retry-period=4590&retry-times=23&sync-report=true"); - ZookeeperClient newZookeeperClient = abstractZookeeperTransporter.connect(url); + ZookeeperClient newZookeeperClient = zookeeperClientManager.connect(url); // just for connected newZookeeperClient.getContent("/dubbo/test"); + Assertions.assertEquals(zookeeperClientManager.getZookeeperClientMap().size(), 1); Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().size(), 1); - Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().get("127.0.0.1:" + zookeeperServerPort1), + zookeeperClientManager.getZookeeperClientMap().get("127.0.0.1:" + zookeeperServerPort1), newZookeeperClient); - ZookeeperClient newZookeeperClient2 = abstractZookeeperTransporter.connect(url2); + ZookeeperClient newZookeeperClient2 = zookeeperClientManager.connect(url2); // just for connected newZookeeperClient2.getContent("/dubbo/test"); Assertions.assertNotEquals(newZookeeperClient, newZookeeperClient2); + Assertions.assertEquals(zookeeperClientManager.getZookeeperClientMap().size(), 2); Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().size(), 2); - Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().get("127.0.0.1:" + zookeeperServerPort2), + zookeeperClientManager.getZookeeperClientMap().get("127.0.0.1:" + zookeeperServerPort2), newZookeeperClient2); } @@ -240,8 +229,8 @@ void testRepeatConnectForNoMatchBackUpAdd() { void testSameHostWithDifferentUser() { URL url1 = URL.valueOf("zookeeper://us1:pw1@127.0.0.1:" + zookeeperServerPort1 + "/path1"); URL url2 = URL.valueOf("zookeeper://us2:pw2@127.0.0.1:" + zookeeperServerPort1 + "/path2"); - ZookeeperClient client1 = abstractZookeeperTransporter.connect(url1); - ZookeeperClient client2 = abstractZookeeperTransporter.connect(url2); + ZookeeperClient client1 = zookeeperClientManager.connect(url1); + ZookeeperClient client2 = zookeeperClientManager.connect(url2); assertThat(client1, not(client2)); } } diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/pom.xml b/dubbo-remoting/dubbo-remoting-zookeeper/pom.xml deleted file mode 100644 index ef9990c0829..00000000000 --- a/dubbo-remoting/dubbo-remoting-zookeeper/pom.xml +++ /dev/null @@ -1,81 +0,0 @@ - - - - 4.0.0 - - org.apache.dubbo - dubbo-remoting - ${revision} - ../pom.xml - - dubbo-remoting-zookeeper - jar - ${project.artifactId} - The zookeeper remoting module of dubbo project - - false - 3.4.14 - 4.3.0 - - - - org.apache.dubbo - dubbo-remoting-zookeeper-api - ${project.parent.version} - - - org.apache.dubbo - dubbo-common - ${project.parent.version} - - - org.apache.curator - curator-recipes - ${curator_version} - - - org.apache.curator - curator-framework - ${curator_version} - - - org.apache.curator - curator-x-discovery - ${curator_version} - - - - org.apache.dubbo - dubbo-native - ${project.parent.version} - - - - org.apache.zookeeper - zookeeper - ${zookeeper_version} - - - - org.apache.dubbo - dubbo-test-common - ${project.parent.version} - test - - - diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java b/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java deleted file mode 100644 index e9a99f38b44..00000000000 --- a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java +++ /dev/null @@ -1,591 +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.remoting.zookeeper.curator; - -import org.apache.dubbo.common.URL; -import org.apache.dubbo.common.config.configcenter.ConfigItem; -import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; -import org.apache.dubbo.common.logger.LoggerFactory; -import org.apache.dubbo.common.utils.NamedThreadFactory; -import org.apache.dubbo.common.utils.StringUtils; -import org.apache.dubbo.remoting.zookeeper.AbstractZookeeperClient; -import org.apache.dubbo.remoting.zookeeper.ChildListener; -import org.apache.dubbo.remoting.zookeeper.DataListener; -import org.apache.dubbo.remoting.zookeeper.EventType; -import org.apache.dubbo.remoting.zookeeper.StateListener; - -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; - -import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.framework.CuratorFrameworkFactory; -import org.apache.curator.framework.api.ACLProvider; -import org.apache.curator.framework.api.CuratorWatcher; -import org.apache.curator.framework.recipes.cache.ChildData; -import org.apache.curator.framework.recipes.cache.NodeCache; -import org.apache.curator.framework.recipes.cache.NodeCacheListener; -import org.apache.curator.framework.state.ConnectionState; -import org.apache.curator.framework.state.ConnectionStateListener; -import org.apache.curator.retry.RetryNTimes; -import org.apache.zookeeper.CreateMode; -import org.apache.zookeeper.KeeperException.NoNodeException; -import org.apache.zookeeper.KeeperException.NodeExistsException; -import org.apache.zookeeper.WatchedEvent; -import org.apache.zookeeper.Watcher; -import org.apache.zookeeper.ZooDefs; -import org.apache.zookeeper.data.ACL; -import org.apache.zookeeper.data.Stat; - -import static org.apache.dubbo.common.constants.CommonConstants.SESSION_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; -import static org.apache.dubbo.common.constants.LoggerCodeConstants.CONFIG_FAILED_CONNECT_REGISTRY; -import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_ZOOKEEPER_EXCEPTION; - -public class CuratorZookeeperClient - extends AbstractZookeeperClient< - CuratorZookeeperClient.NodeCacheListenerImpl, CuratorZookeeperClient.CuratorWatcherImpl> { - - protected static final ErrorTypeAwareLogger logger = - LoggerFactory.getErrorTypeAwareLogger(CuratorZookeeperClient.class); - - private static final Charset CHARSET = StandardCharsets.UTF_8; - private final CuratorFramework client; - private static final Map nodeCacheMap = new ConcurrentHashMap<>(); - - public CuratorZookeeperClient(URL url) { - super(url); - try { - int timeout = url.getParameter(TIMEOUT_KEY, DEFAULT_CONNECTION_TIMEOUT_MS); - int sessionExpireMs = url.getParameter(SESSION_KEY, DEFAULT_SESSION_TIMEOUT_MS); - CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder() - .connectString(url.getBackupAddress()) - .retryPolicy(new RetryNTimes(1, 1000)) - .connectionTimeoutMs(timeout) - .sessionTimeoutMs(sessionExpireMs); - String userInformation = url.getUserInformation(); - if (StringUtils.isNotEmpty(userInformation)) { - builder = builder.authorization("digest", userInformation.getBytes()); - builder.aclProvider(new ACLProvider() { - @Override - public List getDefaultAcl() { - return ZooDefs.Ids.CREATOR_ALL_ACL; - } - - @Override - public List getAclForPath(String path) { - return ZooDefs.Ids.CREATOR_ALL_ACL; - } - }); - } - client = builder.build(); - client.getConnectionStateListenable().addListener(new CuratorConnectionStateListener(url)); - client.start(); - - boolean connected = client.blockUntilConnected(timeout, TimeUnit.MILLISECONDS); - if (!connected) { - IllegalStateException illegalStateException = - new IllegalStateException("zookeeper not connected, the address is: " + url); - - // 5-1 Failed to connect to configuration center. - logger.error( - CONFIG_FAILED_CONNECT_REGISTRY, - "Zookeeper server offline", - "", - "Failed to connect with zookeeper", - illegalStateException); - - throw illegalStateException; - } - - CuratorWatcherImpl.closed = false; - } catch (Exception e) { - close(); - throw new IllegalStateException(e.getMessage(), e); - } - } - - @Override - public void createPersistent(String path, boolean faultTolerant) { - try { - client.create().forPath(path); - } catch (NodeExistsException e) { - if (!faultTolerant) { - logger.warn(REGISTRY_ZOOKEEPER_EXCEPTION, "", "", "ZNode " + path + " already exists.", e); - throw new IllegalStateException(e.getMessage(), e); - } - } catch (Exception e) { - throw new IllegalStateException(e.getMessage(), e); - } - } - - @Override - public void createEphemeral(String path, boolean faultTolerant) { - try { - client.create().withMode(CreateMode.EPHEMERAL).forPath(path); - } catch (NodeExistsException e) { - if (faultTolerant) { - logger.info("ZNode " + path - + " already exists, since we will only try to recreate a node on a session expiration" - + ", this duplication might be caused by a delete delay from the zk server, which means the old expired session" - + " may still holds this ZNode and the server just hasn't got time to do the deletion. In this case, " - + "we can just try to delete and create again."); - deletePath(path); - createEphemeral(path, true); - } else { - logger.warn(REGISTRY_ZOOKEEPER_EXCEPTION, "", "", "ZNode " + path + " already exists.", e); - throw new IllegalStateException(e.getMessage(), e); - } - } catch (Exception e) { - throw new IllegalStateException(e.getMessage(), e); - } - } - - @Override - protected void createPersistent(String path, String data, boolean faultTolerant) { - byte[] dataBytes = data.getBytes(CHARSET); - try { - client.create().forPath(path, dataBytes); - } catch (NodeExistsException e) { - if (faultTolerant) { - logger.info("ZNode " + path + " already exists. Will be override with new data."); - try { - client.setData().forPath(path, dataBytes); - } catch (Exception e1) { - throw new IllegalStateException(e.getMessage(), e1); - } - } else { - logger.warn(REGISTRY_ZOOKEEPER_EXCEPTION, "", "", "ZNode " + path + " already exists.", e); - throw new IllegalStateException(e.getMessage(), e); - } - } catch (Exception e) { - throw new IllegalStateException(e.getMessage(), e); - } - } - - @Override - protected void createEphemeral(String path, String data, boolean faultTolerant) { - byte[] dataBytes = data.getBytes(CHARSET); - try { - client.create().withMode(CreateMode.EPHEMERAL).forPath(path, dataBytes); - } catch (NodeExistsException e) { - if (faultTolerant) { - logger.info("ZNode " + path - + " already exists, since we will only try to recreate a node on a session expiration" - + ", this duplication might be caused by a delete delay from the zk server, which means the old expired session" - + " may still holds this ZNode and the server just hasn't got time to do the deletion. In this case, " - + "we can just try to delete and create again."); - deletePath(path); - createEphemeral(path, data, true); - } else { - logger.warn(REGISTRY_ZOOKEEPER_EXCEPTION, "", "", "ZNode " + path + " already exists.", e); - throw new IllegalStateException(e.getMessage(), e); - } - } catch (Exception e) { - throw new IllegalStateException(e.getMessage(), e); - } - } - - @Override - protected void update(String path, String data, int version) { - byte[] dataBytes = data.getBytes(CHARSET); - try { - client.setData().withVersion(version).forPath(path, dataBytes); - } catch (Exception e) { - throw new IllegalStateException(e.getMessage(), e); - } - } - - @Override - protected void update(String path, String data) { - byte[] dataBytes = data.getBytes(CHARSET); - try { - client.setData().forPath(path, dataBytes); - } catch (Exception e) { - throw new IllegalStateException(e.getMessage(), e); - } - } - - @Override - protected void createOrUpdatePersistent(String path, String data) { - try { - if (checkExists(path)) { - update(path, data); - } else { - createPersistent(path, data, true); - } - } catch (Exception e) { - throw new IllegalStateException(e.getMessage(), e); - } - } - - @Override - protected void createOrUpdateEphemeral(String path, String data) { - try { - if (checkExists(path)) { - update(path, data); - } else { - createEphemeral(path, data, true); - } - } catch (Exception e) { - throw new IllegalStateException(e.getMessage(), e); - } - } - - @Override - protected void createOrUpdatePersistent(String path, String data, Integer version) { - try { - if (checkExists(path) && version != null) { - update(path, data, version); - } else { - createPersistent(path, data, false); - } - } catch (Exception e) { - throw new IllegalStateException(e.getMessage(), e); - } - } - - @Override - protected void createOrUpdateEphemeral(String path, String data, Integer version) { - try { - if (checkExists(path) && version != null) { - update(path, data, version); - } else { - createEphemeral(path, data, false); - } - } catch (Exception e) { - throw new IllegalStateException(e.getMessage(), e); - } - } - - @Override - protected void deletePath(String path) { - try { - client.delete().deletingChildrenIfNeeded().forPath(path); - } catch (NoNodeException ignored) { - } catch (Exception e) { - throw new IllegalStateException(e.getMessage(), e); - } - } - - @Override - public List getChildren(String path) { - try { - return client.getChildren().forPath(path); - } catch (NoNodeException e) { - return null; - } catch (Exception e) { - throw new IllegalStateException(e.getMessage(), e); - } - } - - @Override - public boolean checkExists(String path) { - try { - if (client.checkExists().forPath(path) != null) { - return true; - } - } catch (Exception ignored) { - } - return false; - } - - @Override - public boolean isConnected() { - return client.getZookeeperClient().isConnected(); - } - - @Override - public String doGetContent(String path) { - try { - byte[] dataBytes = client.getData().forPath(path); - return (dataBytes == null || dataBytes.length == 0) ? null : new String(dataBytes, CHARSET); - } catch (NoNodeException e) { - // ignore NoNode Exception. - } catch (Exception e) { - throw new IllegalStateException(e.getMessage(), e); - } - return null; - } - - @Override - public ConfigItem doGetConfigItem(String path) { - String content; - Stat stat; - try { - stat = new Stat(); - byte[] dataBytes = client.getData().storingStatIn(stat).forPath(path); - content = (dataBytes == null || dataBytes.length == 0) ? null : new String(dataBytes, CHARSET); - } catch (NoNodeException e) { - return new ConfigItem(); - } catch (Exception e) { - throw new IllegalStateException(e.getMessage(), e); - } - return new ConfigItem(content, stat); - } - - @Override - public void doClose() { - super.close(); - client.close(); - CuratorWatcherImpl.closed = true; - synchronized (CuratorWatcherImpl.class) { - if (CuratorWatcherImpl.CURATOR_WATCHER_EXECUTOR_SERVICE != null) { - CuratorWatcherImpl.CURATOR_WATCHER_EXECUTOR_SERVICE.shutdown(); - CuratorWatcherImpl.CURATOR_WATCHER_EXECUTOR_SERVICE = null; - } - } - } - - @Override - public CuratorZookeeperClient.CuratorWatcherImpl createTargetChildListener(String path, ChildListener listener) { - return new CuratorZookeeperClient.CuratorWatcherImpl(client, listener, path); - } - - @Override - public List addTargetChildListener(String path, CuratorWatcherImpl listener) { - try { - return client.getChildren().usingWatcher(listener).forPath(path); - } catch (NoNodeException e) { - return null; - } catch (Exception e) { - throw new IllegalStateException(e.getMessage(), e); - } - } - - @Override - protected CuratorZookeeperClient.NodeCacheListenerImpl createTargetDataListener( - String path, DataListener listener) { - return new NodeCacheListenerImpl(listener, path); - } - - @Override - protected void addTargetDataListener(String path, CuratorZookeeperClient.NodeCacheListenerImpl nodeCacheListener) { - this.addTargetDataListener(path, nodeCacheListener, null); - } - - @Override - protected void addTargetDataListener( - String path, CuratorZookeeperClient.NodeCacheListenerImpl nodeCacheListener, Executor executor) { - try { - NodeCache nodeCache = new NodeCache(client, path); - if (nodeCacheMap.putIfAbsent(path, nodeCache) != null) { - return; - } - if (executor == null) { - nodeCache.getListenable().addListener(nodeCacheListener); - } else { - nodeCache.getListenable().addListener(nodeCacheListener, executor); - } - - nodeCache.start(); - } catch (Exception e) { - throw new IllegalStateException("Add nodeCache listener for path:" + path, e); - } - } - - @Override - protected void removeTargetDataListener( - String path, CuratorZookeeperClient.NodeCacheListenerImpl nodeCacheListener) { - NodeCache nodeCache = nodeCacheMap.get(path); - if (nodeCache != null) { - nodeCache.getListenable().removeListener(nodeCacheListener); - } - nodeCacheListener.dataListener = null; - } - - @Override - public void removeTargetChildListener(String path, CuratorWatcherImpl listener) { - listener.unwatch(); - } - - static class NodeCacheListenerImpl implements NodeCacheListener { - - private volatile DataListener dataListener; - - private String path; - - protected NodeCacheListenerImpl() {} - - public NodeCacheListenerImpl(DataListener dataListener, String path) { - this.dataListener = dataListener; - this.path = path; - } - - @Override - public void nodeChanged() throws Exception { - ChildData childData = nodeCacheMap.get(path).getCurrentData(); - String content = null; - EventType eventType; - if (childData == null) { - eventType = EventType.NodeDeleted; - } else if (childData.getStat().getVersion() == 0) { - content = new String(childData.getData(), CHARSET); - eventType = EventType.NodeCreated; - } else { - content = new String(childData.getData(), CHARSET); - eventType = EventType.NodeDataChanged; - } - dataListener.dataChanged(path, content, eventType); - } - } - - static class CuratorWatcherImpl implements CuratorWatcher { - - private static volatile ExecutorService CURATOR_WATCHER_EXECUTOR_SERVICE; - - private static volatile boolean closed = false; - - private CuratorFramework client; - private volatile ChildListener childListener; - private String path; - - private static void initExecutorIfNecessary() { - if (!closed && CURATOR_WATCHER_EXECUTOR_SERVICE == null) { - synchronized (CuratorWatcherImpl.class) { - if (!closed && CURATOR_WATCHER_EXECUTOR_SERVICE == null) { - CURATOR_WATCHER_EXECUTOR_SERVICE = - Executors.newSingleThreadExecutor(new NamedThreadFactory("Dubbo-CuratorWatcher")); - } - } - } - } - - public CuratorWatcherImpl(CuratorFramework client, ChildListener listener, String path) { - this.client = client; - this.childListener = listener; - this.path = path; - } - - protected CuratorWatcherImpl() {} - - public void unwatch() { - this.childListener = null; - } - - @Override - public void process(WatchedEvent event) throws Exception { - // if client connect or disconnect to server, zookeeper will queue - // watched event(Watcher.Event.EventType.None, .., path = null). - if (event.getType() == Watcher.Event.EventType.None) { - return; - } - - if (childListener != null) { - Runnable task = () -> Optional.ofNullable(childListener).ifPresent(c -> { - try { - c.childChanged( - path, - client.getChildren() - .usingWatcher(CuratorWatcherImpl.this) - .forPath(path)); - } catch (Exception e) { - logger.warn(REGISTRY_ZOOKEEPER_EXCEPTION, "", "", "client get children error", e); - } - }); - initExecutorIfNecessary(); - if (!closed && CURATOR_WATCHER_EXECUTOR_SERVICE != null) { - CURATOR_WATCHER_EXECUTOR_SERVICE.execute(task); - } - } - } - } - - private class CuratorConnectionStateListener implements ConnectionStateListener { - private final long UNKNOWN_SESSION_ID = -1L; - private long lastSessionId; - private int timeout; - private int sessionExpireMs; - - public CuratorConnectionStateListener(URL url) { - this.timeout = url.getParameter(TIMEOUT_KEY, DEFAULT_CONNECTION_TIMEOUT_MS); - this.sessionExpireMs = url.getParameter(SESSION_KEY, DEFAULT_SESSION_TIMEOUT_MS); - } - - @Override - public void stateChanged(CuratorFramework client, ConnectionState state) { - long sessionId = UNKNOWN_SESSION_ID; - try { - sessionId = client.getZookeeperClient().getZooKeeper().getSessionId(); - } catch (Exception e) { - logger.warn( - REGISTRY_ZOOKEEPER_EXCEPTION, - "", - "", - "Curator client state changed, but failed to get the related zk session instance."); - } - - if (state == ConnectionState.LOST) { - logger.warn( - REGISTRY_ZOOKEEPER_EXCEPTION, - "", - "", - "Curator zookeeper session " + Long.toHexString(lastSessionId) + " expired."); - CuratorZookeeperClient.this.stateChanged(StateListener.SESSION_LOST); - } else if (state == ConnectionState.SUSPENDED) { - logger.warn( - REGISTRY_ZOOKEEPER_EXCEPTION, - "", - "", - "Curator zookeeper connection of session " + Long.toHexString(sessionId) + " timed out. " - + "connection timeout value is " + timeout + ", session expire timeout value is " - + sessionExpireMs); - CuratorZookeeperClient.this.stateChanged(StateListener.SUSPENDED); - } else if (state == ConnectionState.CONNECTED) { - lastSessionId = sessionId; - logger.info("Curator zookeeper client instance initiated successfully, session id is " - + Long.toHexString(sessionId)); - CuratorZookeeperClient.this.stateChanged(StateListener.CONNECTED); - } else if (state == ConnectionState.RECONNECTED) { - if (lastSessionId == sessionId && sessionId != UNKNOWN_SESSION_ID) { - logger.warn( - REGISTRY_ZOOKEEPER_EXCEPTION, - "", - "", - "Curator zookeeper connection recovered from connection lose, " + "reuse the old session " - + Long.toHexString(sessionId)); - CuratorZookeeperClient.this.stateChanged(StateListener.RECONNECTED); - } else { - logger.warn( - REGISTRY_ZOOKEEPER_EXCEPTION, - "", - "", - "New session created after old session lost, " + "old session " - + Long.toHexString(lastSessionId) + ", new session " + Long.toHexString(sessionId)); - lastSessionId = sessionId; - CuratorZookeeperClient.this.stateChanged(StateListener.NEW_SESSION_CREATED); - } - } - } - } - - /** - * just for unit test - * - * @return - */ - CuratorFramework getClient() { - return client; - } -} diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperTransporter.java b/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperTransporter.java deleted file mode 100644 index c69ab90368e..00000000000 --- a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperTransporter.java +++ /dev/null @@ -1,28 +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.remoting.zookeeper.curator; - -import org.apache.dubbo.common.URL; -import org.apache.dubbo.remoting.zookeeper.AbstractZookeeperTransporter; -import org.apache.dubbo.remoting.zookeeper.ZookeeperClient; - -public class CuratorZookeeperTransporter extends AbstractZookeeperTransporter { - @Override - public ZookeeperClient createZookeeperClient(URL url) { - return new CuratorZookeeperClient(url); - } -} diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/aot/CuratorZookeeperReflectionTypeDescriberRegistrar.java b/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/aot/CuratorZookeeperReflectionTypeDescriberRegistrar.java deleted file mode 100644 index 7e37b47590c..00000000000 --- a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/aot/CuratorZookeeperReflectionTypeDescriberRegistrar.java +++ /dev/null @@ -1,52 +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.remoting.zookeeper.curator.aot; - -import org.apache.dubbo.aot.api.MemberCategory; -import org.apache.dubbo.aot.api.ReflectionTypeDescriberRegistrar; -import org.apache.dubbo.aot.api.TypeDescriber; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.apache.zookeeper.ClientCnxnSocketNIO; - -public class CuratorZookeeperReflectionTypeDescriberRegistrar implements ReflectionTypeDescriberRegistrar { - - @Override - public List getTypeDescribers() { - List typeDescribers = new ArrayList<>(); - typeDescribers.add(buildTypeDescriberWithDeclaredConstructors(ClientCnxnSocketNIO.class)); - return typeDescribers; - } - - private TypeDescriber buildTypeDescriberWithDeclaredMethods(Class c) { - Set memberCategories = new HashSet<>(); - memberCategories.add(MemberCategory.INVOKE_DECLARED_METHODS); - return new TypeDescriber( - c.getName(), null, new HashSet<>(), new HashSet<>(), new HashSet<>(), memberCategories); - } - - private TypeDescriber buildTypeDescriberWithDeclaredConstructors(Class c) { - Set memberCategories = new HashSet<>(); - memberCategories.add(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS); - return new TypeDescriber( - c.getName(), null, new HashSet<>(), new HashSet<>(), new HashSet<>(), memberCategories); - } -} diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.aot.api.ReflectionTypeDescriberRegistrar b/dubbo-remoting/dubbo-remoting-zookeeper/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.aot.api.ReflectionTypeDescriberRegistrar deleted file mode 100644 index 5312e63a093..00000000000 --- a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.aot.api.ReflectionTypeDescriberRegistrar +++ /dev/null @@ -1 +0,0 @@ -curatorZookeeper=org.apache.dubbo.remoting.zookeeper.curator.aot.CuratorZookeeperReflectionTypeDescriberRegistrar diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter b/dubbo-remoting/dubbo-remoting-zookeeper/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter deleted file mode 100644 index 44f9374cd15..00000000000 --- a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter +++ /dev/null @@ -1 +0,0 @@ -curator=org.apache.dubbo.remoting.zookeeper.curator.CuratorZookeeperTransporter diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClientTest.java b/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClientTest.java deleted file mode 100644 index 818b3f95550..00000000000 --- a/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClientTest.java +++ /dev/null @@ -1,515 +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.remoting.zookeeper.curator; - -import org.apache.dubbo.common.URL; -import org.apache.dubbo.common.config.configcenter.ConfigItem; -import org.apache.dubbo.remoting.zookeeper.ChildListener; - -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.framework.CuratorFrameworkFactory; -import org.apache.curator.retry.ExponentialBackoffRetry; -import org.apache.zookeeper.WatchedEvent; -import org.apache.zookeeper.data.Stat; -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.Disabled; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledForJreRange; -import org.junit.jupiter.api.condition.JRE; - -import static org.awaitility.Awaitility.await; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.mockito.Mockito.mock; - -@DisabledForJreRange(min = JRE.JAVA_16) -class CuratorZookeeperClientTest { - private CuratorZookeeperClient curatorClient; - CuratorFramework client = null; - - private static int zookeeperServerPort1; - private static String zookeeperConnectionAddress1; - - @BeforeAll - public static void beforeAll() { - zookeeperConnectionAddress1 = System.getProperty("zookeeper.connection.address.1"); - zookeeperServerPort1 = Integer.parseInt( - zookeeperConnectionAddress1.substring(zookeeperConnectionAddress1.lastIndexOf(":") + 1)); - } - - @BeforeEach - public void setUp() throws Exception { - curatorClient = new CuratorZookeeperClient( - URL.valueOf(zookeeperConnectionAddress1 + "/org.apache.dubbo.registry.RegistryService")); - client = CuratorFrameworkFactory.newClient( - "127.0.0.1:" + zookeeperServerPort1, new ExponentialBackoffRetry(1000, 3)); - client.start(); - } - - @Test - void testCheckExists() { - String path = "/dubbo/org.apache.dubbo.demo.DemoService/providers"; - curatorClient.create(path, false, true); - assertThat(curatorClient.checkExists(path), is(true)); - assertThat(curatorClient.checkExists(path + "/noneexits"), is(false)); - } - - @Test - void testChildrenPath() { - String path = "/dubbo/org.apache.dubbo.demo.DemoService/providers"; - curatorClient.create(path, false, true); - curatorClient.create(path + "/provider1", false, true); - curatorClient.create(path + "/provider2", false, true); - - List children = curatorClient.getChildren(path); - assertThat(children.size(), is(2)); - } - - @Test - @Disabled("Global registry center") - public void testChildrenListener() throws InterruptedException { - String path = "/dubbo/org.apache.dubbo.demo.DemoService/providers"; - curatorClient.create(path, false, true); - final CountDownLatch countDownLatch = new CountDownLatch(1); - curatorClient.addTargetChildListener(path, new CuratorZookeeperClient.CuratorWatcherImpl() { - - @Override - public void process(WatchedEvent watchedEvent) { - countDownLatch.countDown(); - } - }); - curatorClient.createPersistent(path + "/provider1", true); - countDownLatch.await(); - } - - @Test - void testWithInvalidServer() { - Assertions.assertThrows(IllegalStateException.class, () -> { - curatorClient = new CuratorZookeeperClient(URL.valueOf("zookeeper://127.0.0.1:1/service")); - curatorClient.create("/testPath", true, true); - }); - } - - @Test - @Disabled("Global registry center cannot stop") - public void testWithStoppedServer() { - Assertions.assertThrows(IllegalStateException.class, () -> { - curatorClient.create("/testPath", true, true); - curatorClient.delete("/testPath"); - }); - } - - @Test - void testRemoveChildrenListener() { - ChildListener childListener = mock(ChildListener.class); - curatorClient.addChildListener("/children", childListener); - curatorClient.removeChildListener("/children", childListener); - } - - @Test - void testCreateExistingPath() { - curatorClient.create("/pathOne", false, true); - curatorClient.create("/pathOne", false, true); - } - - @Test - void testConnectedStatus() { - curatorClient.createEphemeral("/testPath", true); - boolean connected = curatorClient.isConnected(); - assertThat(connected, is(true)); - } - - @Test - void testCreateContent4Persistent() { - String path = "/curatorTest4CrContent/content.data"; - String content = "createContentTest"; - curatorClient.delete(path); - assertThat(curatorClient.checkExists(path), is(false)); - assertNull(curatorClient.getContent(path)); - - curatorClient.createOrUpdate(path, content, false); - assertThat(curatorClient.checkExists(path), is(true)); - assertEquals(curatorClient.getContent(path), content); - } - - @Test - void testCreateContent4Temp() { - String path = "/curatorTest4CrContent/content.data"; - String content = "createContentTest"; - curatorClient.delete(path); - assertThat(curatorClient.checkExists(path), is(false)); - assertNull(curatorClient.getContent(path)); - - curatorClient.createOrUpdate(path, content, true); - assertThat(curatorClient.checkExists(path), is(true)); - assertEquals(curatorClient.getContent(path), content); - } - - @Test - void testCreatePersistentFailed() { - String path = "/dubbo/test/path"; - curatorClient.delete(path); - curatorClient.create(path, false, true); - Assertions.assertTrue(curatorClient.checkExists(path)); - - curatorClient.createPersistent(path, true); - Assertions.assertTrue(curatorClient.checkExists(path)); - - curatorClient.createPersistent(path, true); - Assertions.assertTrue(curatorClient.checkExists(path)); - - Assertions.assertThrows(IllegalStateException.class, () -> { - curatorClient.createPersistent(path, false); - }); - Assertions.assertTrue(curatorClient.checkExists(path)); - } - - @Test - void testCreateEphemeralFailed() { - String path = "/dubbo/test/path"; - curatorClient.delete(path); - curatorClient.create(path, true, true); - Assertions.assertTrue(curatorClient.checkExists(path)); - - curatorClient.createEphemeral(path, true); - Assertions.assertTrue(curatorClient.checkExists(path)); - - curatorClient.createEphemeral(path, true); - Assertions.assertTrue(curatorClient.checkExists(path)); - - Assertions.assertThrows(IllegalStateException.class, () -> { - curatorClient.createEphemeral(path, false); - }); - Assertions.assertTrue(curatorClient.checkExists(path)); - } - - @AfterEach - public void tearDown() throws Exception { - curatorClient.close(); - } - - @Test - void testAddTargetDataListener() throws Exception { - String listenerPath = "/dubbo/service.name/configuration"; - String path = listenerPath + "/dat/data"; - String value = "vav"; - - curatorClient.createOrUpdate(path + "/d.json", value, true); - String valueFromCache = curatorClient.getContent(path + "/d.json"); - Assertions.assertEquals(value, valueFromCache); - final AtomicInteger atomicInteger = new AtomicInteger(0); - curatorClient.addTargetDataListener(path + "/d.json", new CuratorZookeeperClient.NodeCacheListenerImpl() { - - @Override - public void nodeChanged() { - atomicInteger.incrementAndGet(); - } - }); - - valueFromCache = curatorClient.getContent(path + "/d.json"); - Assertions.assertNotNull(valueFromCache); - - int currentCount1 = atomicInteger.get(); - curatorClient.getClient().setData().forPath(path + "/d.json", "foo".getBytes()); - await().until(() -> atomicInteger.get() > currentCount1); - int currentCount2 = atomicInteger.get(); - curatorClient.getClient().setData().forPath(path + "/d.json", "bar".getBytes()); - await().until(() -> atomicInteger.get() > currentCount2); - int currentCount3 = atomicInteger.get(); - curatorClient.delete(path + "/d.json"); - valueFromCache = curatorClient.getContent(path + "/d.json"); - Assertions.assertNull(valueFromCache); - await().until(() -> atomicInteger.get() > currentCount3); - } - - @Test - void testPersistentCas1() throws Exception { - // test create failed when others create success - String path = "/dubbo/mapping/org.apache.dubbo.demo.DemoService"; - AtomicReference runnable = new AtomicReference<>(); - CuratorZookeeperClient curatorClient = - new CuratorZookeeperClient( - URL.valueOf(zookeeperConnectionAddress1 + "/org.apache.dubbo.registry.RegistryService")) { - @Override - protected void createPersistent(String path, String data, boolean faultTolerant) { - if (runnable.get() != null) { - runnable.get().run(); - } - super.createPersistent(path, data, faultTolerant); - } - - @Override - protected void update(String path, String data, int version) { - if (runnable.get() != null) { - runnable.get().run(); - } - super.update(path, data, version); - } - }; - curatorClient.delete(path); - - runnable.set(() -> { - try { - client.create().forPath(path, "version x".getBytes(StandardCharsets.UTF_8)); - } catch (Exception e) { - throw new RuntimeException(e); - } - }); - Assertions.assertThrows( - IllegalStateException.class, () -> curatorClient.createOrUpdate(path, "version 1", false, 0)); - Assertions.assertEquals("version x", curatorClient.getContent(path)); - - client.setData().forPath(path, "version 1".getBytes(StandardCharsets.UTF_8)); - - ConfigItem configItem = curatorClient.getConfigItem(path); - runnable.set(() -> { - try { - client.setData().forPath(path, "version x".getBytes(StandardCharsets.UTF_8)); - } catch (Exception e) { - throw new RuntimeException(e); - } - }); - int version1 = ((Stat) configItem.getTicket()).getVersion(); - Assertions.assertThrows( - IllegalStateException.class, () -> curatorClient.createOrUpdate(path, "version 2", false, version1)); - Assertions.assertEquals("version x", curatorClient.getContent(path)); - - runnable.set(null); - configItem = curatorClient.getConfigItem(path); - int version2 = ((Stat) configItem.getTicket()).getVersion(); - curatorClient.createOrUpdate(path, "version 2", false, version2); - Assertions.assertEquals("version 2", curatorClient.getContent(path)); - - curatorClient.close(); - } - - @Test - void testPersistentCas2() { - // test update failed when others create success - String path = "/dubbo/mapping/org.apache.dubbo.demo.DemoService"; - CuratorZookeeperClient curatorClient = new CuratorZookeeperClient( - URL.valueOf(zookeeperConnectionAddress1 + "/org.apache.dubbo.registry.RegistryService")); - curatorClient.delete(path); - - curatorClient.createOrUpdate(path, "version x", false); - Assertions.assertThrows( - IllegalStateException.class, () -> curatorClient.createOrUpdate(path, "version 1", false, null)); - Assertions.assertEquals("version x", curatorClient.getContent(path)); - - curatorClient.close(); - } - - @Test - void testPersistentNonVersion() { - String path = "/dubbo/metadata/org.apache.dubbo.demo.DemoService"; - AtomicReference runnable = new AtomicReference<>(); - CuratorZookeeperClient curatorClient = - new CuratorZookeeperClient( - URL.valueOf(zookeeperConnectionAddress1 + "/org.apache.dubbo.registry.RegistryService")) { - @Override - protected void createPersistent(String path, String data, boolean faultTolerant) { - if (runnable.get() != null) { - runnable.get().run(); - } - super.createPersistent(path, data, faultTolerant); - } - - @Override - protected void update(String path, String data, int version) { - if (runnable.get() != null) { - runnable.get().run(); - } - super.update(path, data, version); - } - }; - curatorClient.delete(path); - - curatorClient.createOrUpdate(path, "version 0", false); - Assertions.assertEquals("version 0", curatorClient.getContent(path)); - curatorClient.delete(path); - - runnable.set(() -> { - try { - client.create().forPath(path, "version x".getBytes(StandardCharsets.UTF_8)); - } catch (Exception e) { - throw new RuntimeException(e); - } - }); - curatorClient.createOrUpdate(path, "version 1", false); - Assertions.assertEquals("version 1", curatorClient.getContent(path)); - - runnable.set(() -> { - try { - client.setData().forPath(path, "version x".getBytes(StandardCharsets.UTF_8)); - } catch (Exception e) { - throw new RuntimeException(e); - } - }); - curatorClient.createOrUpdate(path, "version 2", false); - Assertions.assertEquals("version 2", curatorClient.getContent(path)); - - runnable.set(null); - curatorClient.createOrUpdate(path, "version 3", false); - Assertions.assertEquals("version 3", curatorClient.getContent(path)); - - curatorClient.close(); - } - - @Test - void testEphemeralCas1() throws Exception { - // test create failed when others create success - String path = "/dubbo/mapping/org.apache.dubbo.demo.DemoService"; - AtomicReference runnable = new AtomicReference<>(); - CuratorZookeeperClient curatorClient = - new CuratorZookeeperClient( - URL.valueOf(zookeeperConnectionAddress1 + "/org.apache.dubbo.registry.RegistryService")) { - @Override - protected void createEphemeral(String path, String data, boolean faultTolerant) { - if (runnable.get() != null) { - runnable.get().run(); - } - super.createPersistent(path, data, faultTolerant); - } - - @Override - protected void update(String path, String data, int version) { - if (runnable.get() != null) { - runnable.get().run(); - } - super.update(path, data, version); - } - }; - curatorClient.delete(path); - - runnable.set(() -> { - try { - client.create().forPath(path, "version x".getBytes(StandardCharsets.UTF_8)); - } catch (Exception e) { - throw new RuntimeException(e); - } - }); - Assertions.assertThrows( - IllegalStateException.class, () -> curatorClient.createOrUpdate(path, "version 1", true, 0)); - Assertions.assertEquals("version x", curatorClient.getContent(path)); - - client.setData().forPath(path, "version 1".getBytes(StandardCharsets.UTF_8)); - - ConfigItem configItem = curatorClient.getConfigItem(path); - runnable.set(() -> { - try { - client.setData().forPath(path, "version x".getBytes(StandardCharsets.UTF_8)); - } catch (Exception e) { - throw new RuntimeException(e); - } - }); - int version1 = ((Stat) configItem.getTicket()).getVersion(); - Assertions.assertThrows( - IllegalStateException.class, () -> curatorClient.createOrUpdate(path, "version 2", true, version1)); - Assertions.assertEquals("version x", curatorClient.getContent(path)); - - runnable.set(null); - configItem = curatorClient.getConfigItem(path); - int version2 = ((Stat) configItem.getTicket()).getVersion(); - curatorClient.createOrUpdate(path, "version 2", true, version2); - Assertions.assertEquals("version 2", curatorClient.getContent(path)); - - curatorClient.close(); - } - - @Test - void testEphemeralCas2() { - // test update failed when others create success - String path = "/dubbo/mapping/org.apache.dubbo.demo.DemoService"; - CuratorZookeeperClient curatorClient = new CuratorZookeeperClient( - URL.valueOf(zookeeperConnectionAddress1 + "/org.apache.dubbo.registry.RegistryService")); - curatorClient.delete(path); - - curatorClient.createOrUpdate(path, "version x", true); - Assertions.assertThrows( - IllegalStateException.class, () -> curatorClient.createOrUpdate(path, "version 1", true, null)); - Assertions.assertEquals("version x", curatorClient.getContent(path)); - - curatorClient.close(); - } - - @Test - void testEphemeralNonVersion() { - String path = "/dubbo/metadata/org.apache.dubbo.demo.DemoService"; - AtomicReference runnable = new AtomicReference<>(); - CuratorZookeeperClient curatorClient = - new CuratorZookeeperClient( - URL.valueOf(zookeeperConnectionAddress1 + "/org.apache.dubbo.registry.RegistryService")) { - @Override - protected void createPersistent(String path, String data, boolean faultTolerant) { - if (runnable.get() != null) { - runnable.get().run(); - } - super.createPersistent(path, data, faultTolerant); - } - - @Override - protected void update(String path, String data, int version) { - if (runnable.get() != null) { - runnable.get().run(); - } - super.update(path, data, version); - } - }; - curatorClient.delete(path); - - curatorClient.createOrUpdate(path, "version 0", true); - Assertions.assertEquals("version 0", curatorClient.getContent(path)); - curatorClient.delete(path); - - runnable.set(() -> { - try { - client.create().forPath(path, "version x".getBytes(StandardCharsets.UTF_8)); - } catch (Exception e) { - throw new RuntimeException(e); - } - }); - curatorClient.createOrUpdate(path, "version 1", true); - Assertions.assertEquals("version 1", curatorClient.getContent(path)); - - runnable.set(() -> { - try { - client.setData().forPath(path, "version x".getBytes(StandardCharsets.UTF_8)); - } catch (Exception e) { - throw new RuntimeException(e); - } - }); - curatorClient.createOrUpdate(path, "version 2", true); - Assertions.assertEquals("version 2", curatorClient.getContent(path)); - - runnable.set(null); - curatorClient.createOrUpdate(path, "version 3", true); - Assertions.assertEquals("version 3", curatorClient.getContent(path)); - - curatorClient.close(); - } -} diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperTransporterTest.java b/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperTransporterTest.java deleted file mode 100644 index 328107ae13a..00000000000 --- a/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperTransporterTest.java +++ /dev/null @@ -1,55 +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.remoting.zookeeper.curator; - -import org.apache.dubbo.common.URL; -import org.apache.dubbo.remoting.zookeeper.ZookeeperClient; - -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledForJreRange; -import org.junit.jupiter.api.condition.JRE; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.IsNot.not; -import static org.hamcrest.core.IsNull.nullValue; - -@DisabledForJreRange(min = JRE.JAVA_16) -class CuratorZookeeperTransporterTest { - private ZookeeperClient zookeeperClient; - private CuratorZookeeperTransporter curatorZookeeperTransporter; - private static String zookeeperConnectionAddress1; - - @BeforeAll - public static void beforeAll() { - zookeeperConnectionAddress1 = System.getProperty("zookeeper.connection.address.1"); - } - - @BeforeEach - public void setUp() throws Exception { - zookeeperClient = - new CuratorZookeeperTransporter().connect(URL.valueOf(zookeeperConnectionAddress1 + "/service")); - curatorZookeeperTransporter = new CuratorZookeeperTransporter(); - } - - @Test - void testZookeeperClient() { - assertThat(zookeeperClient, not(nullValue())); - zookeeperClient.close(); - } -} diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/curator/support/AbstractZookeeperTransporterTest.java b/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/curator/support/AbstractZookeeperTransporterTest.java deleted file mode 100644 index 37cc93c0f28..00000000000 --- a/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/curator/support/AbstractZookeeperTransporterTest.java +++ /dev/null @@ -1,250 +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.remoting.zookeeper.curator.support; - -import org.apache.dubbo.common.URL; -import org.apache.dubbo.remoting.zookeeper.AbstractZookeeperTransporter; -import org.apache.dubbo.remoting.zookeeper.ZookeeperClient; -import org.apache.dubbo.remoting.zookeeper.curator.CuratorZookeeperTransporter; - -import java.util.List; - -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.junit.jupiter.api.condition.DisabledForJreRange; -import org.junit.jupiter.api.condition.JRE; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.IsNot.not; -import static org.hamcrest.core.IsNull.nullValue; - -/** - * AbstractZookeeperTransporterTest - */ -@DisabledForJreRange(min = JRE.JAVA_16) -class AbstractZookeeperTransporterTest { - private ZookeeperClient zookeeperClient; - private AbstractZookeeperTransporter abstractZookeeperTransporter; - - private static int zookeeperServerPort1, zookeeperServerPort2; - private static String zookeeperConnectionAddress1, zookeeperConnectionAddress2; - - @BeforeAll - public static void beforeAll() { - zookeeperConnectionAddress1 = System.getProperty("zookeeper.connection.address.1"); - zookeeperConnectionAddress2 = System.getProperty("zookeeper.connection.address.2"); - zookeeperServerPort1 = Integer.parseInt( - zookeeperConnectionAddress1.substring(zookeeperConnectionAddress1.lastIndexOf(":") + 1)); - zookeeperServerPort2 = Integer.parseInt( - zookeeperConnectionAddress2.substring(zookeeperConnectionAddress2.lastIndexOf(":") + 1)); - } - - @BeforeEach - public void setUp() throws Exception { - zookeeperClient = new CuratorZookeeperTransporter() - .connect(URL.valueOf("zookeeper://127.0.0.1:" + zookeeperServerPort1 + "/service")); - abstractZookeeperTransporter = new CuratorZookeeperTransporter(); - } - - @Test - void testZookeeperClient() { - assertThat(zookeeperClient, not(nullValue())); - zookeeperClient.close(); - } - - @Test - void testGetURLBackupAddress() { - URL url = URL.valueOf( - zookeeperConnectionAddress1 + "/org.apache.dubbo.registry.RegistryService?backup=127.0.0.1:" + 9099 - + "&application=metadatareport-local-xml-provider2&dubbo=2.0.2&interface=org.apache.dubbo.registry.RegistryService&pid=47418&specVersion=2.7.0-SNAPSHOT×tamp=1547102428828"); - List stringList = abstractZookeeperTransporter.getURLBackupAddress(url); - Assertions.assertEquals(stringList.size(), 2); - Assertions.assertEquals(stringList.get(0), "127.0.0.1:" + zookeeperServerPort1); - Assertions.assertEquals(stringList.get(1), "127.0.0.1:9099"); - } - - @Test - void testGetURLBackupAddressNoBack() { - URL url = URL.valueOf( - zookeeperConnectionAddress1 - + "/org.apache.dubbo.registry.RegistryService?application=metadatareport-local-xml-provider2&dubbo=2.0.2&interface=org.apache.dubbo.registry.RegistryService&pid=47418&specVersion=2.7.0-SNAPSHOT×tamp=1547102428828"); - List stringList = abstractZookeeperTransporter.getURLBackupAddress(url); - Assertions.assertEquals(stringList.size(), 1); - Assertions.assertEquals(stringList.get(0), "127.0.0.1:" + zookeeperServerPort1); - } - - @Test - void testFetchAndUpdateZookeeperClientCache() { - URL url = URL.valueOf( - zookeeperConnectionAddress1 + "/org.apache.dubbo.registry.RegistryService?backup=127.0.0.1:" - + zookeeperServerPort1 + ",127.0.0.1:" + zookeeperServerPort2 - + "&application=metadatareport-local-xml-provider2&dubbo=2.0.2&interface=org.apache.dubbo.registry.RegistryService&pid=47418&specVersion=2.7.0-SNAPSHOT×tamp=1547102428828"); - ZookeeperClient newZookeeperClient = abstractZookeeperTransporter.connect(url); - // just for connected - newZookeeperClient.getContent("/dubbo/test"); - Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().size(), 2); - Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().get("127.0.0.1:" + zookeeperServerPort1), - newZookeeperClient); - - URL url2 = URL.valueOf( - "zookeeper://127.0.0.1:" + zookeeperServerPort1 - + "/org.apache.dubbo.metadata.store.MetadataReport?address=zookeeper://127.0.0.1:2181&application=metadatareport-local-xml-provider2&cycle-report=false&interface=org.apache.dubbo.metadata.store.MetadataReport&retry-period=4590&retry-times=23&sync-report=true"); - checkFetchAndUpdateCacheNotNull(url2); - URL url3 = URL.valueOf( - "zookeeper://127.0.0.1:8778/org.apache.dubbo.metadata.store.MetadataReport?backup=127.0.0.1:" - + zookeeperServerPort2 - + "&address=zookeeper://127.0.0.1:2181&application=metadatareport-local-xml-provider2&cycle-report=false&interface=org.apache.dubbo.metadata.store.MetadataReport&retry-period=4590&retry-times=23&sync-report=true"); - checkFetchAndUpdateCacheNotNull(url3); - } - - private void checkFetchAndUpdateCacheNotNull(URL url) { - List addressList = abstractZookeeperTransporter.getURLBackupAddress(url); - ZookeeperClient zookeeperClient = abstractZookeeperTransporter.fetchAndUpdateZookeeperClientCache(addressList); - Assertions.assertNotNull(zookeeperClient); - } - - @Test - void testRepeatConnect() { - URL url = URL.valueOf( - zookeeperConnectionAddress1 - + "/org.apache.dubbo.registry.RegistryService?application=metadatareport-local-xml-provider2&dubbo=2.0.2&interface=org.apache.dubbo.registry.RegistryService&pid=47418&specVersion=2.7.0-SNAPSHOT×tamp=1547102428828"); - URL url2 = URL.valueOf( - zookeeperConnectionAddress1 - + "/org.apache.dubbo.metadata.store.MetadataReport?address=zookeeper://127.0.0.1:2181&application=metadatareport-local-xml-provider2&cycle-report=false&interface=org.apache.dubbo.metadata.store.MetadataReport&retry-period=4590&retry-times=23&sync-report=true"); - ZookeeperClient newZookeeperClient = abstractZookeeperTransporter.connect(url); - // just for connected - newZookeeperClient.getContent("/dubbo/test"); - Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().size(), 1); - Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().get("127.0.0.1:" + zookeeperServerPort1), - newZookeeperClient); - Assertions.assertTrue(newZookeeperClient.isConnected()); - - ZookeeperClient newZookeeperClient2 = abstractZookeeperTransporter.connect(url2); - // just for connected - newZookeeperClient2.getContent("/dubbo/test"); - Assertions.assertEquals(newZookeeperClient, newZookeeperClient2); - Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().size(), 1); - Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().get("127.0.0.1:" + zookeeperServerPort1), - newZookeeperClient); - } - - @Test - void testNotRepeatConnect() { - URL url = URL.valueOf( - zookeeperConnectionAddress1 - + "/org.apache.dubbo.registry.RegistryService?application=metadatareport-local-xml-provider2&dubbo=2.0.2&interface=org.apache.dubbo.registry.RegistryService&pid=47418&specVersion=2.7.0-SNAPSHOT×tamp=1547102428828"); - URL url2 = URL.valueOf( - zookeeperConnectionAddress2 - + "/org.apache.dubbo.metadata.store.MetadataReport?address=zookeeper://127.0.0.1:2181&application=metadatareport-local-xml-provider2&cycle-report=false&interface=org.apache.dubbo.metadata.store.MetadataReport&retry-period=4590&retry-times=23&sync-report=true"); - ZookeeperClient newZookeeperClient = abstractZookeeperTransporter.connect(url); - // just for connected - newZookeeperClient.getContent("/dubbo/test"); - Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().size(), 1); - Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().get("127.0.0.1:" + zookeeperServerPort1), - newZookeeperClient); - - ZookeeperClient newZookeeperClient2 = abstractZookeeperTransporter.connect(url2); - // just for connected - newZookeeperClient2.getContent("/dubbo/test"); - Assertions.assertNotEquals(newZookeeperClient, newZookeeperClient2); - Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().size(), 2); - Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().get("127.0.0.1:" + zookeeperServerPort2), - newZookeeperClient2); - } - - @Test - void testRepeatConnectForBackUpAdd() { - - URL url = URL.valueOf( - zookeeperConnectionAddress1 + "/org.apache.dubbo.registry.RegistryService?backup=127.0.0.1:" - + zookeeperServerPort1 - + "&application=metadatareport-local-xml-provider2&dubbo=2.0.2&interface=org.apache.dubbo.registry.RegistryService&pid=47418&specVersion=2.7.0-SNAPSHOT×tamp=1547102428828"); - URL url2 = URL.valueOf( - zookeeperConnectionAddress1 + "/org.apache.dubbo.metadata.store.MetadataReport?backup=127.0.0.1:" - + zookeeperServerPort2 - + "&address=zookeeper://127.0.0.1:2181&application=metadatareport-local-xml-provider2&cycle-report=false&interface=org.apache.dubbo.metadata.store.MetadataReport&retry-period=4590&retry-times=23&sync-report=true"); - ZookeeperClient newZookeeperClient = abstractZookeeperTransporter.connect(url); - // just for connected - newZookeeperClient.getContent("/dubbo/test"); - Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().size(), 1); - Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().get("127.0.0.1:" + zookeeperServerPort1), - newZookeeperClient); - - ZookeeperClient newZookeeperClient2 = abstractZookeeperTransporter.connect(url2); - // just for connected - newZookeeperClient2.getContent("/dubbo/test"); - Assertions.assertEquals(newZookeeperClient, newZookeeperClient2); - Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().size(), 2); - Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().get("127.0.0.1:" + zookeeperServerPort2), - newZookeeperClient2); - } - - @Test - void testRepeatConnectForNoMatchBackUpAdd() { - - URL url = URL.valueOf( - zookeeperConnectionAddress1 + "/org.apache.dubbo.registry.RegistryService?backup=127.0.0.1:" - + zookeeperServerPort1 - + "&application=metadatareport-local-xml-provider2&dubbo=2.0.2&interface=org.apache.dubbo.registry.RegistryService&pid=47418&specVersion=2.7.0-SNAPSHOT×tamp=1547102428828"); - URL url2 = URL.valueOf( - zookeeperConnectionAddress2 - + "/org.apache.dubbo.metadata.store.MetadataReport?address=zookeeper://127.0.0.1:2181&application=metadatareport-local-xml-provider2&cycle-report=false&interface=org.apache.dubbo.metadata.store.MetadataReport&retry-period=4590&retry-times=23&sync-report=true"); - ZookeeperClient newZookeeperClient = abstractZookeeperTransporter.connect(url); - // just for connected - newZookeeperClient.getContent("/dubbo/test"); - Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().size(), 1); - Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().get("127.0.0.1:" + zookeeperServerPort1), - newZookeeperClient); - - ZookeeperClient newZookeeperClient2 = abstractZookeeperTransporter.connect(url2); - // just for connected - newZookeeperClient2.getContent("/dubbo/test"); - Assertions.assertNotEquals(newZookeeperClient, newZookeeperClient2); - Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().size(), 2); - Assertions.assertEquals( - abstractZookeeperTransporter.getZookeeperClientMap().get("127.0.0.1:" + zookeeperServerPort2), - newZookeeperClient2); - } - - @Test - void testSameHostWithDifferentUser() { - URL url1 = URL.valueOf("zookeeper://us1:pw1@127.0.0.1:" + zookeeperServerPort1 + "/path1"); - URL url2 = URL.valueOf("zookeeper://us2:pw2@127.0.0.1:" + zookeeperServerPort1 + "/path2"); - ZookeeperClient client1 = abstractZookeeperTransporter.connect(url1); - ZookeeperClient client2 = abstractZookeeperTransporter.connect(url2); - assertThat(client1, not(client2)); - } -} diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/test/resources/dubbo.properties b/dubbo-remoting/dubbo-remoting-zookeeper/src/test/resources/dubbo.properties deleted file mode 100644 index 1aade88a561..00000000000 --- a/dubbo-remoting/dubbo-remoting-zookeeper/src/test/resources/dubbo.properties +++ /dev/null @@ -1,2 +0,0 @@ -dubbo.application.enable-file-cache=false -dubbo.service.shutdown.wait=200 diff --git a/dubbo-remoting/pom.xml b/dubbo-remoting/pom.xml index e7aca3685e2..a2604965d06 100644 --- a/dubbo-remoting/pom.xml +++ b/dubbo-remoting/pom.xml @@ -30,8 +30,6 @@ dubbo-remoting-api dubbo-remoting-netty - dubbo-remoting-zookeeper-api - dubbo-remoting-zookeeper dubbo-remoting-zookeeper-curator5 dubbo-remoting-netty4 dubbo-remoting-http12 diff --git a/dubbo-test/dubbo-dependencies-all/pom.xml b/dubbo-test/dubbo-dependencies-all/pom.xml index 307a81e88b0..b86a36b8901 100644 --- a/dubbo-test/dubbo-dependencies-all/pom.xml +++ b/dubbo-test/dubbo-dependencies-all/pom.xml @@ -310,16 +310,6 @@ dubbo-remoting-netty4 ${project.version} - - org.apache.dubbo - dubbo-remoting-zookeeper-api - ${project.version} - - - org.apache.dubbo - dubbo-remoting-zookeeper - ${project.version} - org.apache.dubbo dubbo-remoting-zookeeper-curator5