You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/07/13 14:47:46 UTC
[dubbo] branch 3.0 updated: Compatible for curator5. (#8263)
This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.0 by this push:
new dcdfe5a Compatible for curator5. (#8263)
dcdfe5a is described below
commit dcdfe5afa4b5c92e6f15327d4c798a5b632d4e69
Author: 赵延 <10...@qq.com>
AuthorDate: Tue Jul 13 22:47:25 2021 +0800
Compatible for curator5. (#8263)
* compatible for curator5.
* compatible for curator5.
* fix ut.
* dependency fix.
* for compatible, dubbo-sample CompatibleRegistry use setMethod.
* ut fix.
* use curator as the default ZookeeperTransporter.
* ut fix.
* code clean. make ZookeeperTransporter inject at constructor.
---
dubbo-compatible/pom.xml | 5 +
.../dubbo-configcenter-zookeeper/pom.xml | 5 +
.../ZookeeperDynamicConfigurationFactory.java | 6 +
dubbo-distribution/dubbo-all/pom.xml | 8 +
dubbo-distribution/dubbo-bom/pom.xml | 5 +
.../zookeeper/ZookeeperMetadataReportFactory.java | 6 +
.../zookeeper/ZookeeperMetadataReportTest.java | 4 -
dubbo-registry/dubbo-registry-zookeeper/pom.xml | 7 +-
.../zookeeper/ZookeeperRegistryFactory.java | 11 +-
.../registry/zookeeper/ZookeeperRegistryTest.java | 2 -
dubbo-remoting/dubbo-remoting-api/pom.xml | 2 +-
.../zookeeper}/AbstractZookeeperClient.java | 6 +-
.../zookeeper}/AbstractZookeeperTransporter.java | 10 +-
.../dubbo/remoting/zookeeper/ChildListener.java | 0
.../dubbo/remoting/zookeeper/DataListener.java | 0
.../apache/dubbo/remoting/zookeeper/EventType.java | 21 ---
.../dubbo/remoting/zookeeper/StateListener.java | 0
.../dubbo/remoting/zookeeper/ZookeeperClient.java | 0
.../remoting/zookeeper/ZookeeperTransporter.java | 30 +++-
.../dubbo-remoting-zookeeper-curator5}/pom.xml | 34 +++-
.../curator5/Curator5ZookeeperClient.java} | 32 ++--
.../curator5/Curator5ZookeeperTransporter.java} | 16 +-
...e.dubbo.remoting.zookeeper.ZookeeperTransporter | 1 +
.../curator5/Curator5ZookeeperClientTest.java | 195 +++++++++++++++++++++
.../curator5/Curator5ZookeeperTransporterTest.java | 57 ++++++
.../support/AbstractZookeeperTransporterTest.java | 9 +-
.../zookeeper/curator/CuratorZookeeperClient.java | 2 +-
.../curator/CuratorZookeeperTransporter.java | 2 +-
.../support/AbstractZookeeperTransporterTest.java | 3 +-
dubbo-remoting/pom.xml | 3 +-
30 files changed, 392 insertions(+), 90 deletions(-)
diff --git a/dubbo-compatible/pom.xml b/dubbo-compatible/pom.xml
index eb1a2b5..d12ddd9 100644
--- a/dubbo-compatible/pom.xml
+++ b/dubbo-compatible/pom.xml
@@ -45,6 +45,11 @@
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-remoting-zookeeper-curator5</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rpc-rest</artifactId>
<version>${project.parent.version}</version>
</dependency>
diff --git a/dubbo-configcenter/dubbo-configcenter-zookeeper/pom.xml b/dubbo-configcenter/dubbo-configcenter-zookeeper/pom.xml
index c06de98..8fd6b83 100644
--- a/dubbo-configcenter/dubbo-configcenter-zookeeper/pom.xml
+++ b/dubbo-configcenter/dubbo-configcenter-zookeeper/pom.xml
@@ -39,6 +39,11 @@
<version>${project.parent.version}</version>
</dependency>
<dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-remoting-zookeeper-curator5</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
<scope>test</scope>
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 d5882d9..6dcedd9 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,6 +19,7 @@ package org.apache.dubbo.configcenter.support.zookeeper;
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.common.extension.DisableInject;
import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter;
/**
@@ -28,6 +29,11 @@ public class ZookeeperDynamicConfigurationFactory extends AbstractDynamicConfigu
private ZookeeperTransporter zookeeperTransporter;
+ public ZookeeperDynamicConfigurationFactory() {
+ this.zookeeperTransporter = ZookeeperTransporter.getExtension();
+ }
+
+ @DisableInject
public void setZookeeperTransporter(ZookeeperTransporter zookeeperTransporter) {
this.zookeeperTransporter = zookeeperTransporter;
}
diff --git a/dubbo-distribution/dubbo-all/pom.xml b/dubbo-distribution/dubbo-all/pom.xml
index 97ed890..dd5f2f3 100644
--- a/dubbo-distribution/dubbo-all/pom.xml
+++ b/dubbo-distribution/dubbo-all/pom.xml
@@ -89,6 +89,13 @@
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-remoting-zookeeper-curator5</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rpc-api</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
@@ -404,6 +411,7 @@
<include>org.apache.dubbo:dubbo-remoting-netty</include>
<include>org.apache.dubbo:dubbo-remoting-netty4</include>
<include>org.apache.dubbo:dubbo-remoting-zookeeper</include>
+ <include>org.apache.dubbo:dubbo-remoting-zookeeper-curator5</include>
<include>org.apache.dubbo:dubbo-rpc-api</include>
<include>org.apache.dubbo:dubbo-rpc-dubbo</include>
<include>org.apache.dubbo:dubbo-rpc-injvm</include>
diff --git a/dubbo-distribution/dubbo-bom/pom.xml b/dubbo-distribution/dubbo-bom/pom.xml
index ae7db74..821fa9e 100644
--- a/dubbo-distribution/dubbo-bom/pom.xml
+++ b/dubbo-distribution/dubbo-bom/pom.xml
@@ -95,6 +95,11 @@
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-remoting-zookeeper-curator5</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rpc-api</artifactId>
<version>${project.version}</version>
</dependency>
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 0ffed8d..ee3e2d9 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
@@ -17,6 +17,7 @@
package org.apache.dubbo.metadata.store.zookeeper;
import org.apache.dubbo.common.URL;
+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;
@@ -28,6 +29,11 @@ public class ZookeeperMetadataReportFactory extends AbstractMetadataReportFactor
private ZookeeperTransporter zookeeperTransporter;
+ public ZookeeperMetadataReportFactory() {
+ this.zookeeperTransporter = ZookeeperTransporter.getExtension();
+ }
+
+ @DisableInject
public void setZookeeperTransporter(ZookeeperTransporter zookeeperTransporter) {
this.zookeeperTransporter = zookeeperTransporter;
}
diff --git a/dubbo-metadata/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java b/dubbo-metadata/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java
index 2788812..f1ab756 100644
--- a/dubbo-metadata/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java
+++ b/dubbo-metadata/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java
@@ -17,7 +17,6 @@
package org.apache.dubbo.metadata.store.zookeeper;
import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder;
import org.apache.dubbo.metadata.definition.model.FullServiceDefinition;
@@ -26,7 +25,6 @@ import org.apache.dubbo.metadata.report.identifier.KeyTypeEnum;
import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier;
import org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier;
import org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier;
-import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter;
import com.google.gson.Gson;
import org.apache.curator.test.TestingServer;
@@ -60,8 +58,6 @@ public class ZookeeperMetadataReportTest {
this.registryUrl = URL.valueOf("zookeeper://127.0.0.1:" + zkServerPort);
zookeeperMetadataReportFactory = new ZookeeperMetadataReportFactory();
- ZookeeperTransporter zookeeperTransporter = ExtensionLoader.getExtensionLoader(ZookeeperTransporter.class).getExtension("curator");
- zookeeperMetadataReportFactory.setZookeeperTransporter(zookeeperTransporter);
this.zookeeperMetadataReport = (ZookeeperMetadataReport) zookeeperMetadataReportFactory.getMetadataReport(registryUrl);
}
diff --git a/dubbo-registry/dubbo-registry-zookeeper/pom.xml b/dubbo-registry/dubbo-registry-zookeeper/pom.xml
index 2d810db..81cdbc5 100644
--- a/dubbo-registry/dubbo-registry-zookeeper/pom.xml
+++ b/dubbo-registry/dubbo-registry-zookeeper/pom.xml
@@ -41,6 +41,11 @@
<version>${project.parent.version}</version>
</dependency>
<dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-remoting-zookeeper-curator5</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-x-discovery</artifactId>
</dependency>
@@ -50,4 +55,4 @@
<scope>test</scope>
</dependency>
</dependencies>
-</project>
\ No newline at end of file
+</project>
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 d393830..011683f 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
@@ -17,22 +17,23 @@
package org.apache.dubbo.registry.zookeeper;
import org.apache.dubbo.common.URL;
+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;
/**
* ZookeeperRegistryFactory.
- *
*/
public class ZookeeperRegistryFactory extends AbstractRegistryFactory {
private ZookeeperTransporter zookeeperTransporter;
- /**
- * Invisible injection of zookeeper client via IOC/SPI
- * @param zookeeperTransporter
- */
+ public ZookeeperRegistryFactory() {
+ this.zookeeperTransporter = ZookeeperTransporter.getExtension();
+ }
+
+ @DisableInject
public void setZookeeperTransporter(ZookeeperTransporter zookeeperTransporter) {
this.zookeeperTransporter = zookeeperTransporter;
}
diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/test/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistryTest.java b/dubbo-registry/dubbo-registry-zookeeper/src/test/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistryTest.java
index 60d79c8..004baff 100644
--- a/dubbo-registry/dubbo-registry-zookeeper/src/test/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistryTest.java
+++ b/dubbo-registry/dubbo-registry-zookeeper/src/test/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistryTest.java
@@ -22,7 +22,6 @@ import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.registry.NotifyListener;
import org.apache.dubbo.registry.Registry;
import org.apache.dubbo.registry.status.RegistryStatusChecker;
-import org.apache.dubbo.remoting.zookeeper.curator.CuratorZookeeperTransporter;
import org.apache.curator.test.TestingServer;
import org.junit.jupiter.api.AfterEach;
@@ -59,7 +58,6 @@ public class ZookeeperRegistryTest {
this.registryUrl = URL.valueOf("zookeeper://localhost:" + zkServerPort);
zookeeperRegistryFactory = new ZookeeperRegistryFactory();
- zookeeperRegistryFactory.setZookeeperTransporter(new CuratorZookeeperTransporter());
this.zookeeperRegistry = (ZookeeperRegistry) zookeeperRegistryFactory.createRegistry(registryUrl);
}
diff --git a/dubbo-remoting/dubbo-remoting-api/pom.xml b/dubbo-remoting/dubbo-remoting-api/pom.xml
index 7bc17ae..56f6b4f 100644
--- a/dubbo-remoting/dubbo-remoting-api/pom.xml
+++ b/dubbo-remoting/dubbo-remoting-api/pom.xml
@@ -51,4 +51,4 @@
<scope>test</scope>
</dependency>
</dependencies>
-</project>
\ No newline at end of file
+</project>
diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperClient.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/zookeeper/AbstractZookeeperClient.java
similarity index 96%
rename from dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperClient.java
rename to dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/zookeeper/AbstractZookeeperClient.java
index 178c4bd..ca620cb 100644
--- a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperClient.java
+++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/zookeeper/AbstractZookeeperClient.java
@@ -14,17 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.dubbo.remoting.zookeeper.support;
+package org.apache.dubbo.remoting.zookeeper;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.config.configcenter.ConfigItem;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.ConcurrentHashSet;
-import org.apache.dubbo.remoting.zookeeper.ChildListener;
-import org.apache.dubbo.remoting.zookeeper.DataListener;
-import org.apache.dubbo.remoting.zookeeper.StateListener;
-import org.apache.dubbo.remoting.zookeeper.ZookeeperClient;
import java.util.List;
import java.util.Set;
diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperTransporter.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/zookeeper/AbstractZookeeperTransporter.java
similarity index 94%
rename from dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperTransporter.java
rename to dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/zookeeper/AbstractZookeeperTransporter.java
index 1d5aa84..bd322d6 100644
--- a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperTransporter.java
+++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/zookeeper/AbstractZookeeperTransporter.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.support;
+package org.apache.dubbo.remoting.zookeeper;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.constants.RemotingConstants;
@@ -22,8 +22,6 @@ import org.apache.dubbo.common.logger.Logger;
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.remoting.zookeeper.ZookeeperClient;
-import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter;
import java.util.ArrayList;
import java.util.Collections;
@@ -91,7 +89,7 @@ public abstract class AbstractZookeeperTransporter implements ZookeeperTransport
* @param addressList
* @return
*/
- ZookeeperClient fetchAndUpdateZookeeperClientCache(List<String> addressList) {
+ public ZookeeperClient fetchAndUpdateZookeeperClientCache(List<String> addressList) {
ZookeeperClient zookeeperClient = null;
for (String address : addressList) {
@@ -111,7 +109,7 @@ public abstract class AbstractZookeeperTransporter implements ZookeeperTransport
* @param url such as:zookeeper://127.0.0.1:2181?127.0.0.1:8989,127.0.0.1:9999
* @return such as 127.0.0.1:2181,127.0.0.1:8989,127.0.0.1:9999
*/
- List<String> getURLBackupAddress(URL url) {
+ public List<String> getURLBackupAddress(URL url) {
List<String> addressList = new ArrayList<String>();
addressList.add(url.getAddress());
addressList.addAll(url.getParameter(RemotingConstants.BACKUP_KEY, Collections.EMPTY_LIST));
@@ -177,7 +175,7 @@ public abstract class AbstractZookeeperTransporter implements ZookeeperTransport
*
* @return
*/
- Map<String, ZookeeperClient> getZookeeperClientMap() {
+ public Map<String, ZookeeperClient> getZookeeperClientMap() {
return zookeeperClientMap;
}
}
diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/ChildListener.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/zookeeper/ChildListener.java
similarity index 100%
rename from dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/ChildListener.java
rename to dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/zookeeper/ChildListener.java
diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/DataListener.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/zookeeper/DataListener.java
similarity index 100%
rename from dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/DataListener.java
rename to dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/zookeeper/DataListener.java
diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/EventType.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/zookeeper/EventType.java
similarity index 66%
rename from dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/EventType.java
rename to dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/zookeeper/EventType.java
index a1de037..791e7e3 100644
--- a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/EventType.java
+++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/zookeeper/EventType.java
@@ -16,8 +16,6 @@
*/
package org.apache.dubbo.remoting.zookeeper;
-import org.apache.zookeeper.Watcher;
-
/**
* 2019-02-26
*/
@@ -33,7 +31,6 @@ public enum EventType {
INITIALIZED(10);
-
private final int intValue; // Integer representation of value
// for sending over wire
@@ -44,22 +41,4 @@ public enum EventType {
public int getIntValue() {
return intValue;
}
-
- public static Watcher.Event.EventType fromInt(int intValue) {
- switch (intValue) {
- case -1:
- return Watcher.Event.EventType.None;
- case 1:
- return Watcher.Event.EventType.NodeCreated;
- case 2:
- return Watcher.Event.EventType.NodeDeleted;
- case 3:
- return Watcher.Event.EventType.NodeDataChanged;
- case 4:
- return Watcher.Event.EventType.NodeChildrenChanged;
-
- default:
- throw new RuntimeException("Invalid integer value for conversion to EventType");
- }
- }
}
diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/StateListener.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/zookeeper/StateListener.java
similarity index 100%
rename from dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/StateListener.java
rename to dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/zookeeper/StateListener.java
diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/ZookeeperClient.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/zookeeper/ZookeeperClient.java
similarity index 100%
rename from dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/ZookeeperClient.java
rename to dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/zookeeper/ZookeeperClient.java
diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/ZookeeperTransporter.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/zookeeper/ZookeeperTransporter.java
similarity index 54%
copy from dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/ZookeeperTransporter.java
copy to dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/zookeeper/ZookeeperTransporter.java
index 638f3ed..2b360f1 100644
--- a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/ZookeeperTransporter.java
+++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/zookeeper/ZookeeperTransporter.java
@@ -17,14 +17,36 @@
package org.apache.dubbo.remoting.zookeeper;
import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.extension.Adaptive;
+import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.extension.SPI;
-import org.apache.dubbo.remoting.Constants;
-@SPI("curator")
+import static org.apache.dubbo.common.extension.ExtensionLoader.getExtensionLoader;
+
+@SPI
public interface ZookeeperTransporter {
- @Adaptive({Constants.CLIENT_KEY, Constants.TRANSPORTER_KEY})
+ String CURATOR_5 = "curator5";
+
+ String CURATOR = "curator";
+
ZookeeperClient connect(URL url);
+ static ZookeeperTransporter getExtension() {
+ ExtensionLoader<ZookeeperTransporter> extensionLoader = getExtensionLoader(ZookeeperTransporter.class);
+ boolean isHighVersion = isHighVersionCurator();
+ if (isHighVersion) {
+ return extensionLoader.getExtension(CURATOR_5);
+ }
+ return 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-registry/dubbo-registry-zookeeper/pom.xml b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/pom.xml
similarity index 61%
copy from dubbo-registry/dubbo-registry-zookeeper/pom.xml
copy to dubbo-remoting/dubbo-remoting-zookeeper-curator5/pom.xml
index 2d810db..0c32c7e 100644
--- a/dubbo-registry/dubbo-registry-zookeeper/pom.xml
+++ b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/pom.xml
@@ -13,41 +13,57 @@
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.
- -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-registry</artifactId>
+ <artifactId>dubbo-remoting</artifactId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
- <artifactId>dubbo-registry-zookeeper</artifactId>
+ <artifactId>dubbo-remoting-zookeeper-curator5</artifactId>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
- <description>The zookeeper registry module of dubbo project</description>
+ <description>The zookeeper curator5 remoting module of dubbo project</description>
<properties>
<skip_maven_deploy>false</skip_maven_deploy>
+ <curator5_version>5.0.0</curator5_version>
+ <zookeeper_version>3.6.0</zookeeper_version>
</properties>
+
<dependencies>
<dependency>
<groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-registry-api</artifactId>
+ <artifactId>dubbo-remoting-api</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-remoting-zookeeper</artifactId>
+ <artifactId>dubbo-common</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
- <artifactId>curator-x-discovery</artifactId>
+ <artifactId>curator-framework</artifactId>
+ <version>${curator5_version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.curator</groupId>
+ <artifactId>curator-recipes</artifactId>
+ <version>${curator5_version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.zookeeper</groupId>
+ <artifactId>zookeeper</artifactId>
+ <version>${zookeeper_version}</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
+ <version>${curator5_version}</version>
<scope>test</scope>
</dependency>
</dependencies>
-</project>
\ No newline at end of file
+</project>
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-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperClient.java
similarity index 91%
copy from dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java
copy to dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperClient.java
index 419c5fb..9bd1988 100644
--- a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java
+++ b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperClient.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.curator;
+package org.apache.dubbo.remoting.zookeeper.curator5;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.config.configcenter.ConfigItem;
@@ -24,7 +24,7 @@ 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 org.apache.dubbo.remoting.zookeeper.support.AbstractZookeeperClient;
+import org.apache.dubbo.remoting.zookeeper.AbstractZookeeperClient;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
@@ -53,16 +53,16 @@ import java.util.concurrent.TimeUnit;
import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
-public class CuratorZookeeperClient extends AbstractZookeeperClient<CuratorZookeeperClient.NodeCacheListenerImpl, CuratorZookeeperClient.CuratorWatcherImpl> {
+public class Curator5ZookeeperClient extends AbstractZookeeperClient<Curator5ZookeeperClient.NodeCacheListenerImpl, Curator5ZookeeperClient.CuratorWatcherImpl> {
- protected static final Logger logger = LoggerFactory.getLogger(CuratorZookeeperClient.class);
+ protected static final Logger logger = LoggerFactory.getLogger(Curator5ZookeeperClient.class);
private static final String ZK_SESSION_EXPIRE_KEY = "zk.session.expire";
private static final Charset CHARSET = StandardCharsets.UTF_8;
private final CuratorFramework client;
private static Map<String, NodeCache> nodeCacheMap = new ConcurrentHashMap<>();
- public CuratorZookeeperClient(URL url) {
+ public Curator5ZookeeperClient(URL url) {
super(url);
try {
int timeout = url.getParameter(TIMEOUT_KEY, DEFAULT_CONNECTION_TIMEOUT_MS);
@@ -256,8 +256,8 @@ public class CuratorZookeeperClient extends AbstractZookeeperClient<CuratorZooke
}
@Override
- public CuratorZookeeperClient.CuratorWatcherImpl createTargetChildListener(String path, ChildListener listener) {
- return new CuratorZookeeperClient.CuratorWatcherImpl(client, listener, path);
+ public Curator5ZookeeperClient.CuratorWatcherImpl createTargetChildListener(String path, ChildListener listener) {
+ return new Curator5ZookeeperClient.CuratorWatcherImpl(client, listener, path);
}
@Override
@@ -272,17 +272,17 @@ public class CuratorZookeeperClient extends AbstractZookeeperClient<CuratorZooke
}
@Override
- protected CuratorZookeeperClient.NodeCacheListenerImpl createTargetDataListener(String path, DataListener listener) {
+ protected Curator5ZookeeperClient.NodeCacheListenerImpl createTargetDataListener(String path, DataListener listener) {
return new NodeCacheListenerImpl(client, listener, path);
}
@Override
- protected void addTargetDataListener(String path, CuratorZookeeperClient.NodeCacheListenerImpl nodeCacheListener) {
+ protected void addTargetDataListener(String path, Curator5ZookeeperClient.NodeCacheListenerImpl nodeCacheListener) {
this.addTargetDataListener(path, nodeCacheListener, null);
}
@Override
- protected void addTargetDataListener(String path, CuratorZookeeperClient.NodeCacheListenerImpl nodeCacheListener, Executor executor) {
+ protected void addTargetDataListener(String path, Curator5ZookeeperClient.NodeCacheListenerImpl nodeCacheListener, Executor executor) {
try {
NodeCache nodeCache = new NodeCache(client, path);
if (nodeCacheMap.putIfAbsent(path, nodeCache) != null) {
@@ -301,7 +301,7 @@ public class CuratorZookeeperClient extends AbstractZookeeperClient<CuratorZooke
}
@Override
- protected void removeTargetDataListener(String path, CuratorZookeeperClient.NodeCacheListenerImpl nodeCacheListener) {
+ protected void removeTargetDataListener(String path, Curator5ZookeeperClient.NodeCacheListenerImpl nodeCacheListener) {
NodeCache nodeCache = nodeCacheMap.get(path);
if (nodeCache != null) {
nodeCache.getListenable().removeListener(nodeCacheListener);
@@ -402,25 +402,25 @@ public class CuratorZookeeperClient extends AbstractZookeeperClient<CuratorZooke
if (state == ConnectionState.LOST) {
logger.warn("Curator zookeeper session " + Long.toHexString(lastSessionId) + " expired.");
- CuratorZookeeperClient.this.stateChanged(StateListener.SESSION_LOST);
+ Curator5ZookeeperClient.this.stateChanged(StateListener.SESSION_LOST);
} else if (state == ConnectionState.SUSPENDED) {
logger.warn("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);
+ Curator5ZookeeperClient.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);
+ Curator5ZookeeperClient.this.stateChanged(StateListener.CONNECTED);
} else if (state == ConnectionState.RECONNECTED) {
if (lastSessionId == sessionId && sessionId != UNKNOWN_SESSION_ID) {
logger.warn("Curator zookeeper connection recovered from connection lose, " +
"reuse the old session " + Long.toHexString(sessionId));
- CuratorZookeeperClient.this.stateChanged(StateListener.RECONNECTED);
+ Curator5ZookeeperClient.this.stateChanged(StateListener.RECONNECTED);
} else {
logger.warn("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);
+ Curator5ZookeeperClient.this.stateChanged(StateListener.NEW_SESSION_CREATED);
}
}
}
diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/ZookeeperTransporter.java b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperTransporter.java
similarity index 68%
rename from dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/ZookeeperTransporter.java
rename to dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperTransporter.java
index 638f3ed..89cf403 100644
--- a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/ZookeeperTransporter.java
+++ b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperTransporter.java
@@ -14,17 +14,17 @@
* 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.extension.Adaptive;
-import org.apache.dubbo.common.extension.SPI;
-import org.apache.dubbo.remoting.Constants;
+import org.apache.dubbo.remoting.zookeeper.ZookeeperClient;
+import org.apache.dubbo.remoting.zookeeper.AbstractZookeeperTransporter;
-@SPI("curator")
-public interface ZookeeperTransporter {
+public class Curator5ZookeeperTransporter extends AbstractZookeeperTransporter {
- @Adaptive({Constants.CLIENT_KEY, Constants.TRANSPORTER_KEY})
- ZookeeperClient connect(URL url);
+ @Override
+ public ZookeeperClient createZookeeperClient(URL url) {
+ return new Curator5ZookeeperClient(url);
+ }
}
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
new file mode 100644
index 0000000..5c998c7
--- /dev/null
+++ b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter
@@ -0,0 +1 @@
+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/Curator5ZookeeperClientTest.java b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/test/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperClientTest.java
new file mode 100644
index 0000000..0cd3dd8
--- /dev/null
+++ b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/test/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperClientTest.java
@@ -0,0 +1,195 @@
+/*
+ * 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.common.utils.NetUtils;
+import org.apache.dubbo.remoting.zookeeper.ChildListener;
+
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.retry.ExponentialBackoffRetry;
+import org.apache.curator.test.TestingServer;
+import org.apache.zookeeper.WatchedEvent;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicInteger;
+
+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;
+
+public class Curator5ZookeeperClientTest {
+ private TestingServer zkServer;
+ private Curator5ZookeeperClient curatorClient;
+ CuratorFramework client = null;
+
+ @BeforeEach
+ public void setUp() throws Exception {
+ int zkServerPort = NetUtils.getAvailablePort();
+ zkServer = new TestingServer(zkServerPort, true);
+ curatorClient = new Curator5ZookeeperClient(URL.valueOf("zookeeper://127.0.0.1:" +
+ zkServerPort + "/org.apache.dubbo.registry.RegistryService"));
+ client = CuratorFrameworkFactory.newClient(zkServer.getConnectString(), new ExponentialBackoffRetry(1000, 3));
+ client.start();
+ }
+
+ @Test
+ public void testCheckExists() {
+ String path = "/dubbo/org.apache.dubbo.demo.DemoService/providers";
+ curatorClient.create(path, false);
+ assertThat(curatorClient.checkExists(path), is(true));
+ assertThat(curatorClient.checkExists(path + "/noneexits"), is(false));
+ }
+
+ @Test
+ public void testChildrenPath() {
+ String path = "/dubbo/org.apache.dubbo.demo.DemoService/providers";
+ curatorClient.create(path, false);
+ curatorClient.create(path + "/provider1", false);
+ curatorClient.create(path + "/provider2", false);
+
+ List<String> children = curatorClient.getChildren(path);
+ assertThat(children.size(), is(2));
+ }
+
+ @Test
+ public void testChildrenListener() throws InterruptedException {
+ String path = "/dubbo/org.apache.dubbo.demo.DemoService/providers";
+ curatorClient.create(path, false);
+ final CountDownLatch countDownLatch = new CountDownLatch(1);
+ curatorClient.addTargetChildListener(path, new Curator5ZookeeperClient.CuratorWatcherImpl() {
+
+ @Override
+ public void process(WatchedEvent watchedEvent) throws Exception {
+ countDownLatch.countDown();
+ }
+ });
+ curatorClient.createPersistent(path + "/provider1");
+ countDownLatch.await();
+ }
+
+
+ @Test
+ public void testWithInvalidServer() {
+ Assertions.assertThrows(IllegalStateException.class, () -> {
+ curatorClient = new Curator5ZookeeperClient(URL.valueOf("zookeeper://127.0.0.1:1/service"));
+ curatorClient.create("/testPath", true);
+ });
+ }
+
+ @Test
+ public void testWithStoppedServer() throws IOException {
+ Assertions.assertThrows(IllegalStateException.class, () -> {
+ curatorClient.create("/testPath", true);
+ zkServer.stop();
+ curatorClient.delete("/testPath");
+ });
+ }
+
+ @Test
+ public void testRemoveChildrenListener() {
+ ChildListener childListener = mock(ChildListener.class);
+ curatorClient.addChildListener("/children", childListener);
+ curatorClient.removeChildListener("/children", childListener);
+ }
+
+ @Test
+ public void testCreateExistingPath() {
+ curatorClient.create("/pathOne", false);
+ curatorClient.create("/pathOne", false);
+ }
+
+ @Test
+ public void testConnectedStatus() {
+ curatorClient.createEphemeral("/testPath");
+ boolean connected = curatorClient.isConnected();
+ assertThat(connected, is(true));
+ }
+
+ @Test
+ public void testCreateContent4Persistent() {
+ String path = "/curatorTest4CrContent/content.data";
+ String content = "createContentTest";
+ curatorClient.delete(path);
+ assertThat(curatorClient.checkExists(path), is(false));
+ assertNull(curatorClient.getContent(path));
+
+ curatorClient.create(path, content, false);
+ assertThat(curatorClient.checkExists(path), is(true));
+ assertEquals(curatorClient.getContent(path), content);
+ }
+
+ @Test
+ public void testCreateContent4Temp() {
+ String path = "/curatorTest4CrContent/content.data";
+ String content = "createContentTest";
+ curatorClient.delete(path);
+ assertThat(curatorClient.checkExists(path), is(false));
+ assertNull(curatorClient.getContent(path));
+
+ curatorClient.create(path, content, true);
+ assertThat(curatorClient.checkExists(path), is(true));
+ assertEquals(curatorClient.getContent(path), content);
+ }
+
+ @AfterEach
+ public void tearDown() throws Exception {
+ curatorClient.close();
+ zkServer.stop();
+ }
+
+ @Test
+ public void testAddTargetDataListener() throws Exception {
+ String listenerPath = "/dubbo/service.name/configuration";
+ String path = listenerPath + "/dat/data";
+ String value = "vav";
+
+ curatorClient.create(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 Curator5ZookeeperClient.NodeCacheListenerImpl() {
+
+ @Override
+ public void nodeChanged() throws Exception {
+ atomicInteger.incrementAndGet();
+ }
+ });
+
+ valueFromCache = curatorClient.getContent(path + "/d.json");
+ Assertions.assertNotNull(valueFromCache);
+
+ Thread.sleep(100);
+ curatorClient.getClient().setData().forPath(path + "/d.json", "foo".getBytes());
+ Thread.sleep(100);
+ curatorClient.getClient().setData().forPath(path + "/d.json", "bar".getBytes());
+ curatorClient.delete(path + "/d.json");
+ valueFromCache = curatorClient.getContent(path + "/d.json");
+ Assertions.assertNull(valueFromCache);
+ Thread.sleep(2000L);
+ Assertions.assertTrue(3L <= atomicInteger.get());
+ }
+}
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/Curator5ZookeeperTransporterTest.java
new file mode 100644
index 0000000..44c8b7b
--- /dev/null
+++ b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/test/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperTransporterTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.common.utils.NetUtils;
+import org.apache.dubbo.remoting.zookeeper.ZookeeperClient;
+
+import org.apache.curator.test.TestingServer;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.IsNot.not;
+import static org.hamcrest.core.IsNull.nullValue;
+
+public class Curator5ZookeeperTransporterTest {
+ private TestingServer zkServer;
+ private ZookeeperClient zookeeperClient;
+ private Curator5ZookeeperTransporter curatorZookeeperTransporter;
+ private int zkServerPort;
+
+ @BeforeEach
+ public void setUp() throws Exception {
+ zkServerPort = NetUtils.getAvailablePort();
+ zkServer = new TestingServer(zkServerPort, true);
+ zookeeperClient = new Curator5ZookeeperTransporter().connect(URL.valueOf("zookeeper://127.0.0.1:" +
+ zkServerPort + "/service"));
+ curatorZookeeperTransporter = new Curator5ZookeeperTransporter();
+ }
+
+ @Test
+ public void testZookeeperClient() {
+ assertThat(zookeeperClient, not(nullValue()));
+ zookeeperClient.close();
+ }
+
+ @AfterEach
+ public void tearDown() throws Exception {
+ zkServer.stop();
+ }
+}
diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperTransporterTest.java b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/test/java/org/apache/dubbo/remoting/zookeeper/curator5/support/AbstractZookeeperTransporterTest.java
similarity index 97%
copy from dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperTransporterTest.java
copy to dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/test/java/org/apache/dubbo/remoting/zookeeper/curator5/support/AbstractZookeeperTransporterTest.java
index 3662d8f..5bb45cf 100644
--- a/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperTransporterTest.java
+++ b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/test/java/org/apache/dubbo/remoting/zookeeper/curator5/support/AbstractZookeeperTransporterTest.java
@@ -14,12 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.dubbo.remoting.zookeeper.support;
+package org.apache.dubbo.remoting.zookeeper.curator5.support;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.utils.NetUtils;
+import org.apache.dubbo.remoting.zookeeper.AbstractZookeeperTransporter;
import org.apache.dubbo.remoting.zookeeper.ZookeeperClient;
-import org.apache.dubbo.remoting.zookeeper.curator.CuratorZookeeperTransporter;
+import org.apache.dubbo.remoting.zookeeper.curator5.Curator5ZookeeperTransporter;
import org.apache.curator.test.TestingServer;
import org.junit.jupiter.api.AfterEach;
@@ -46,9 +47,9 @@ public class AbstractZookeeperTransporterTest {
public void setUp() throws Exception {
zkServerPort = NetUtils.getAvailablePort();
zkServer = new TestingServer(zkServerPort, true);
- zookeeperClient = new CuratorZookeeperTransporter().connect(URL.valueOf("zookeeper://127.0.0.1:" +
+ zookeeperClient = new Curator5ZookeeperTransporter().connect(URL.valueOf("zookeeper://127.0.0.1:" +
zkServerPort + "/service"));
- abstractZookeeperTransporter = new CuratorZookeeperTransporter();
+ abstractZookeeperTransporter = new Curator5ZookeeperTransporter();
}
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
index 419c5fb..64188cd 100644
--- 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
@@ -24,7 +24,7 @@ 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 org.apache.dubbo.remoting.zookeeper.support.AbstractZookeeperClient;
+import org.apache.dubbo.remoting.zookeeper.AbstractZookeeperClient;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
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
index 21a2e09..a18b785 100644
--- 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
@@ -18,7 +18,7 @@ package org.apache.dubbo.remoting.zookeeper.curator;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.remoting.zookeeper.ZookeeperClient;
-import org.apache.dubbo.remoting.zookeeper.support.AbstractZookeeperTransporter;
+import org.apache.dubbo.remoting.zookeeper.AbstractZookeeperTransporter;
public class CuratorZookeeperTransporter extends AbstractZookeeperTransporter {
@Override
diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperTransporterTest.java b/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/curator/support/AbstractZookeeperTransporterTest.java
similarity index 99%
rename from dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperTransporterTest.java
rename to dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/curator/support/AbstractZookeeperTransporterTest.java
index 3662d8f..53c7ebe 100644
--- a/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperTransporterTest.java
+++ b/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/curator/support/AbstractZookeeperTransporterTest.java
@@ -14,10 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.dubbo.remoting.zookeeper.support;
+package org.apache.dubbo.remoting.zookeeper.curator.support;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.utils.NetUtils;
+import org.apache.dubbo.remoting.zookeeper.AbstractZookeeperTransporter;
import org.apache.dubbo.remoting.zookeeper.ZookeeperClient;
import org.apache.dubbo.remoting.zookeeper.curator.CuratorZookeeperTransporter;
diff --git a/dubbo-remoting/pom.xml b/dubbo-remoting/pom.xml
index e0ab094..4dcf7ed 100644
--- a/dubbo-remoting/pom.xml
+++ b/dubbo-remoting/pom.xml
@@ -35,6 +35,7 @@
<module>dubbo-remoting-http</module>
<module>dubbo-remoting-netty</module>
<module>dubbo-remoting-zookeeper</module>
+ <module>dubbo-remoting-zookeeper-curator5</module>
<module>dubbo-remoting-netty4</module>
</modules>
-</project>
\ No newline at end of file
+</project>