This is an automated email from the ASF dual-hosted git repository.
songxiaosheng pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo-spi-extensions.git
The following commit(s) were added to refs/heads/3.0 by this push:
new c6dc17d Bump jetcd vertsion from 0.5.7 to 0.7.7 (#398)
c6dc17d is described below
commit c6dc17d697bb98440d60a82a3dc041a6d686bf16
Author: aofall <[email protected]>
AuthorDate: Tue Jun 11 18:51:08 2024 +0800
Bump jetcd vertsion from 0.5.7 to 0.7.7 (#398)
* update jetcd version
* rename the dubbo-registry-etcd extension name from etcd3 to etcd
* fix unit test failed
* compatible old version
* add ASF header
---
.../dubbo-configcenter-etcd/pom.xml | 5 ++
.../support/etcd/EtcdDynamicConfiguration.java | 8 ++-
.../support/etcd/EtcdDynamicConfigurationTest.java | 64 +++++++++++++---------
dubbo-extensions-dependencies-bom/pom.xml | 10 +++-
.../dubbo-metadata-report-etcd/pom.xml | 5 ++
.../store/etcd/EtcdMetadataReportTest.java | 16 ++++--
.../etcd/EtcdCompatibleRegistryFactory.java | 28 ++++++++++
.../org.apache.dubbo.registry.RegistryFactory | 3 +-
.../dubbo/registry/etcd/EtcdRegistryTest.java | 4 +-
.../dubbo-remoting-etcd3/pom.xml | 5 ++
.../dubbo/remoting/etcd/jetcd/LeaseTest.java | 33 +++++++----
11 files changed, 132 insertions(+), 49 deletions(-)
diff --git a/dubbo-configcenter-extensions/dubbo-configcenter-etcd/pom.xml
b/dubbo-configcenter-extensions/dubbo-configcenter-etcd/pom.xml
index 05d3098..edcef8e 100644
--- a/dubbo-configcenter-extensions/dubbo-configcenter-etcd/pom.xml
+++ b/dubbo-configcenter-extensions/dubbo-configcenter-etcd/pom.xml
@@ -43,6 +43,11 @@
<artifactId>jetcd-launcher</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>io.etcd</groupId>
+ <artifactId>jetcd-test</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
diff --git
a/dubbo-configcenter-extensions/dubbo-configcenter-etcd/src/main/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfiguration.java
b/dubbo-configcenter-extensions/dubbo-configcenter-etcd/src/main/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfiguration.java
index 59b384b..03beb60 100644
---
a/dubbo-configcenter-extensions/dubbo-configcenter-etcd/src/main/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfiguration.java
+++
b/dubbo-configcenter-extensions/dubbo-configcenter-etcd/src/main/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfiguration.java
@@ -22,6 +22,8 @@ import
org.apache.dubbo.common.config.configcenter.ConfigChangeType;
import org.apache.dubbo.common.config.configcenter.ConfigChangedEvent;
import org.apache.dubbo.common.config.configcenter.ConfigurationListener;
import org.apache.dubbo.common.config.configcenter.DynamicConfiguration;
+import org.apache.dubbo.common.logger.Logger;
+import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.remoting.etcd.StateListener;
import org.apache.dubbo.remoting.etcd.jetcd.JEtcdClient;
@@ -48,6 +50,8 @@ import static
org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR;
*/
public class EtcdDynamicConfiguration implements DynamicConfiguration {
+ private static final Logger logger =
LoggerFactory.getLogger(EtcdDynamicConfiguration.class);
+
/**
* The final root path would be: /$NAME_SPACE/config
*/
@@ -71,7 +75,7 @@ public class EtcdDynamicConfiguration implements
DynamicConfiguration {
try {
recover();
} catch (Exception e) {
- // ignore
+ logger.error("add etcd watch failed", e);
}
}
});
@@ -164,7 +168,7 @@ public class EtcdDynamicConfiguration implements
DynamicConfiguration {
@Override
public void onError(Throwable throwable) {
- // ignore
+ logger.error("etcd watcher get an error", throwable);
}
@Override
diff --git
a/dubbo-configcenter-extensions/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java
b/dubbo-configcenter-extensions/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java
index 60e6889..fbce0de 100644
---
a/dubbo-configcenter-extensions/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java
+++
b/dubbo-configcenter-extensions/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java
@@ -17,6 +17,7 @@
package org.apache.dubbo.configcenter.support.etcd;
+import io.etcd.jetcd.test.EtcdClusterExtension;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.config.configcenter.ConfigChangedEvent;
import org.apache.dubbo.common.config.configcenter.ConfigurationListener;
@@ -25,7 +26,8 @@ import
org.apache.dubbo.common.config.configcenter.DynamicConfiguration;
import io.etcd.jetcd.ByteSequence;
import io.etcd.jetcd.Client;
import io.etcd.jetcd.launcher.EtcdCluster;
-import io.etcd.jetcd.launcher.EtcdClusterFactory;
+import org.apache.dubbo.common.logger.Logger;
+import org.apache.dubbo.common.logger.LoggerFactory;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
@@ -47,12 +49,45 @@ import static
org.apache.dubbo.remoting.etcd.Constants.SESSION_TIMEOUT_KEY;
*/
public class EtcdDynamicConfigurationTest {
+ private static final Logger logger =
LoggerFactory.getLogger(EtcdDynamicConfigurationTest.class);
+
private static EtcdDynamicConfiguration config;
- public EtcdCluster etcdCluster =
EtcdClusterFactory.buildCluster(getClass().getSimpleName(), 3, false);
+ public EtcdCluster etcdCluster;
private static Client client;
+ @BeforeEach
+ public void setUp() {
+ EtcdClusterExtension clusterExtension = EtcdClusterExtension.builder()
+ .withClusterName(getClass().getSimpleName())
+ .withNodes(3)
+ .withSsl(false)
+ .build();
+ etcdCluster = clusterExtension.cluster();
+
+ etcdCluster.start();
+
+ client =
Client.builder().endpoints(etcdCluster.clientEndpoints()).build();
+
+ List<URI> clientEndPoints = etcdCluster.clientEndpoints();
+
+ String ipAddress = clientEndPoints.get(0).getHost() + ":" +
clientEndPoints.get(0).getPort();
+ String urlForDubbo = "etcd://" + ipAddress +
"/org.apache.dubbo.etcd.testService";
+
+ // timeout in 15 seconds.
+ URL url = URL.valueOf(urlForDubbo)
+ .addParameter(SESSION_TIMEOUT_KEY, 15000);
+ config = new EtcdDynamicConfiguration(url);
+ }
+
+ @AfterEach
+ public void tearDown() {
+ if (etcdCluster != null) {
+ etcdCluster.close();
+ }
+ }
+
@Test
public void testGetConfig() {
@@ -124,31 +159,8 @@ public class EtcdDynamicConfigurationTest {
try {
client.getKVClient().put(ByteSequence.from(key, UTF_8),
ByteSequence.from(value, UTF_8)).get();
} catch (Exception e) {
- System.out.println("Error put value to etcd.");
+ logger.error("Error put value to etcd.");
}
}
- @BeforeEach
- public void setUp() {
-
- etcdCluster.start();
-
- client =
Client.builder().endpoints(etcdCluster.getClientEndpoints()).build();
-
- List<URI> clientEndPoints = etcdCluster.getClientEndpoints();
-
- String ipAddress = clientEndPoints.get(0).getHost() + ":" +
clientEndPoints.get(0).getPort();
- String urlForDubbo = "etcd3://" + ipAddress +
"/org.apache.dubbo.etcd.testService";
-
- // timeout in 15 seconds.
- URL url = URL.valueOf(urlForDubbo)
- .addParameter(SESSION_TIMEOUT_KEY, 15000);
- config = new EtcdDynamicConfiguration(url);
- }
-
- @AfterEach
- public void tearDown() {
- etcdCluster.close();
- }
-
}
diff --git a/dubbo-extensions-dependencies-bom/pom.xml
b/dubbo-extensions-dependencies-bom/pom.xml
index e9a6a1b..88ddcb4 100644
--- a/dubbo-extensions-dependencies-bom/pom.xml
+++ b/dubbo-extensions-dependencies-bom/pom.xml
@@ -121,9 +121,8 @@
<mina_version>1.1.7</mina_version>
<slf4j_version>1.7.25</slf4j_version>
<grizzly_version>2.4.4</grizzly_version>
- <jetcd_version>0.5.7</jetcd_version>
+ <jetcd_version>0.7.7</jetcd_version>
<grpc.version>1.53.0</grpc.version>
- <etcd_launcher_version>0.5.7</etcd_launcher_version>
<netty4_version>4.1.66.Final</netty4_version>
<consul_process_version>2.2.1</consul_process_version>
<consul_version>1.4.2</consul_version>
@@ -409,6 +408,11 @@
</exclusion>
</exclusions>
</dependency>
+ <dependency>
+ <groupId>io.etcd</groupId>
+ <artifactId>jetcd-test</artifactId>
+ <version>${jetcd_version}</version>
+ </dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-core</artifactId>
@@ -442,7 +446,7 @@
<dependency>
<groupId>io.etcd</groupId>
<artifactId>jetcd-launcher</artifactId>
- <version>${etcd_launcher_version}</version>
+ <version>${jetcd_version}</version>
<exclusions>
<exclusion>
<groupId>com.github.spotbugs</groupId>
diff --git
a/dubbo-metadata-report-extensions/dubbo-metadata-report-etcd/pom.xml
b/dubbo-metadata-report-extensions/dubbo-metadata-report-etcd/pom.xml
index dfbdfa6..7a46a34 100644
--- a/dubbo-metadata-report-extensions/dubbo-metadata-report-etcd/pom.xml
+++ b/dubbo-metadata-report-extensions/dubbo-metadata-report-etcd/pom.xml
@@ -51,6 +51,11 @@
<artifactId>jetcd-launcher</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>io.etcd</groupId>
+ <artifactId>jetcd-test</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
diff --git
a/dubbo-metadata-report-extensions/dubbo-metadata-report-etcd/src/test/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReportTest.java
b/dubbo-metadata-report-extensions/dubbo-metadata-report-etcd/src/test/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReportTest.java
index 119522c..a11e26e 100644
---
a/dubbo-metadata-report-extensions/dubbo-metadata-report-etcd/src/test/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReportTest.java
+++
b/dubbo-metadata-report-extensions/dubbo-metadata-report-etcd/src/test/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReportTest.java
@@ -17,6 +17,7 @@
package org.apache.dubbo.metadata.store.etcd;
+import io.etcd.jetcd.test.EtcdClusterExtension;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder;
@@ -30,7 +31,6 @@ import io.etcd.jetcd.ByteSequence;
import io.etcd.jetcd.Client;
import io.etcd.jetcd.kv.GetResponse;
import io.etcd.jetcd.launcher.EtcdCluster;
-import io.etcd.jetcd.launcher.EtcdClusterFactory;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
@@ -57,7 +57,7 @@ public class EtcdMetadataReportTest {
private static final String TEST_SERVICE =
"org.apache.dubbo.metadata.store.etcd.EtcdMetadata4TstService";
- private EtcdCluster etcdCluster =
EtcdClusterFactory.buildCluster(getClass().getSimpleName(), 1, false);
+ private EtcdCluster etcdCluster;
private Client etcdClientForTest;
private EtcdMetadataReport etcdMetadataReport;
private URL registryUrl;
@@ -65,9 +65,13 @@ public class EtcdMetadataReportTest {
@BeforeEach
public void setUp() {
+ etcdCluster =
EtcdClusterExtension.builder().withClusterName(getClass().getSimpleName())
+ .withNodes(1)
+ .withSsl(false)
+ .build().cluster();
etcdCluster.start();
- etcdClientForTest =
Client.builder().endpoints(etcdCluster.getClientEndpoints()).build();
- List<URI> clientEndPoints = etcdCluster.getClientEndpoints();
+ etcdClientForTest =
Client.builder().endpoints(etcdCluster.clientEndpoints()).build();
+ List<URI> clientEndPoints = etcdCluster.clientEndpoints();
this.registryUrl = URL.valueOf("etcd://" +
clientEndPoints.get(0).getHost() + ":" + clientEndPoints.get(0).getPort());
etcdMetadataReportFactory = new EtcdMetadataReportFactory();
this.etcdMetadataReport = (EtcdMetadataReport)
etcdMetadataReportFactory.createMetadataReport(registryUrl);
@@ -75,7 +79,9 @@ public class EtcdMetadataReportTest {
@AfterEach
public void tearDown() throws Exception {
- etcdCluster.close();
+ if (etcdCluster != null) {
+ etcdCluster.stop();
+ }
}
@Test
diff --git
a/dubbo-registry-extensions/dubbo-registry-etcd3/src/main/java/org/apache/dubbo/registry/etcd/EtcdCompatibleRegistryFactory.java
b/dubbo-registry-extensions/dubbo-registry-etcd3/src/main/java/org/apache/dubbo/registry/etcd/EtcdCompatibleRegistryFactory.java
new file mode 100644
index 0000000..8750a96
--- /dev/null
+++
b/dubbo-registry-extensions/dubbo-registry-etcd3/src/main/java/org/apache/dubbo/registry/etcd/EtcdCompatibleRegistryFactory.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.registry.etcd;
+
+public class EtcdCompatibleRegistryFactory extends EtcdServiceDiscoveryFactory
{
+
+ // The extension name of dubbo-registry-etcd is etcd3 and user should
config the URL as 'etcd3://localhost:2379'.
+ // But the extension name of dubbo-metadata-report-etcd and
dubbo-configcenter-etcd are etcd
+ // and user should config the URL as 'etcd://localhost:2379'.
+ // To avoid confusion for users when configuring URLs in registry, rename
the dubbo-registry-etcd extension name
+ // from etcd3 to etcd, and use extend class to compatible the old version
of dubbo-registry-etcd.
+ // It can unify the extension name and avoid confusion for users and
compatible the old version
+
+}
diff --git
a/dubbo-registry-extensions/dubbo-registry-etcd3/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory
b/dubbo-registry-extensions/dubbo-registry-etcd3/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory
index 4a6d09c..c5bd906 100644
---
a/dubbo-registry-extensions/dubbo-registry-etcd3/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory
+++
b/dubbo-registry-extensions/dubbo-registry-etcd3/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory
@@ -1 +1,2 @@
-etcd3=org.apache.dubbo.registry.etcd.EtcdRegistryFactory
\ No newline at end of file
+etcd=org.apache.dubbo.registry.etcd.EtcdRegistryFactory
+etcd3=org.apache.dubbo.registry.etcd.EtcdCompatibleRegistryFactory
diff --git
a/dubbo-registry-extensions/dubbo-registry-etcd3/src/test/java/org/apache/dubbo/registry/etcd/EtcdRegistryTest.java
b/dubbo-registry-extensions/dubbo-registry-etcd3/src/test/java/org/apache/dubbo/registry/etcd/EtcdRegistryTest.java
index 82e32a5..1dd4e93 100644
---
a/dubbo-registry-extensions/dubbo-registry-etcd3/src/test/java/org/apache/dubbo/registry/etcd/EtcdRegistryTest.java
+++
b/dubbo-registry-extensions/dubbo-registry-etcd3/src/test/java/org/apache/dubbo/registry/etcd/EtcdRegistryTest.java
@@ -95,9 +95,9 @@ public class EtcdRegistryTest {
URL serviceUrl = URL.valueOf("dubbo://" + NetUtils.getLocalHost() + "/" +
service + "?methods=test1,test2");
URL serviceUrl2 = URL.valueOf("dubbo://" + NetUtils.getLocalHost() + "/" +
service + "?methods=test1,test2,test3");
URL serviceUrl3 = URL.valueOf("dubbo://" + NetUtils.getLocalHost() + "/" +
outerService + "?methods=test1,test2");
- URL registryUrl =
URL.valueOf("etcd3://127.0.0.1:2379/org.apache.dubbo.registry.RegistryService");
+ URL registryUrl =
URL.valueOf("etcd://127.0.0.1:2379/org.apache.dubbo.registry.RegistryService");
URL consumerUrl = URL.valueOf("dubbo://" + NetUtils.getLocalHost() +
":2018" + "/" + service + "?methods=test1,test2");
- RegistryFactory registryFactory =
ExtensionLoader.getExtensionLoader(RegistryFactory.class).getExtension("etcd3",
false);
+ RegistryFactory registryFactory =
ExtensionLoader.getExtensionLoader(RegistryFactory.class).getExtension("etcd",
false);
EtcdRegistry registry;
URL subscribe = new URL(
ADMIN_PROTOCOL, NetUtils.getLocalHost(), 0, "",
diff --git a/dubbo-remoting-extensions/dubbo-remoting-etcd3/pom.xml
b/dubbo-remoting-extensions/dubbo-remoting-etcd3/pom.xml
index 9e7f187..288d86c 100644
--- a/dubbo-remoting-extensions/dubbo-remoting-etcd3/pom.xml
+++ b/dubbo-remoting-extensions/dubbo-remoting-etcd3/pom.xml
@@ -53,6 +53,11 @@
<groupId>io.etcd</groupId>
<artifactId>jetcd-core</artifactId>
</dependency>
+ <dependency>
+ <groupId>io.etcd</groupId>
+ <artifactId>jetcd-test</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-core</artifactId>
diff --git
a/dubbo-remoting-extensions/dubbo-remoting-etcd3/src/test/java/org/apache/dubbo/remoting/etcd/jetcd/LeaseTest.java
b/dubbo-remoting-extensions/dubbo-remoting-etcd3/src/test/java/org/apache/dubbo/remoting/etcd/jetcd/LeaseTest.java
index 6188984..a2feec6 100644
---
a/dubbo-remoting-extensions/dubbo-remoting-etcd3/src/test/java/org/apache/dubbo/remoting/etcd/jetcd/LeaseTest.java
+++
b/dubbo-remoting-extensions/dubbo-remoting-etcd3/src/test/java/org/apache/dubbo/remoting/etcd/jetcd/LeaseTest.java
@@ -39,15 +39,15 @@ import io.etcd.jetcd.Client;
import io.etcd.jetcd.KV;
import io.etcd.jetcd.Lease;
import io.etcd.jetcd.launcher.EtcdCluster;
-import io.etcd.jetcd.launcher.EtcdClusterFactory;
import io.etcd.jetcd.lease.LeaseKeepAliveResponse;
import io.etcd.jetcd.options.PutOption;
import io.etcd.jetcd.support.CloseableClient;
import io.etcd.jetcd.support.Observers;
+import io.etcd.jetcd.test.EtcdClusterExtension;
import io.grpc.stub.StreamObserver;
-import org.junit.jupiter.api.AfterAll;
+import org.apache.dubbo.common.logger.Logger;
+import org.apache.dubbo.common.logger.LoggerFactory;
import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@@ -65,6 +65,8 @@ import static org.assertj.core.api.Assertions.assertThat;
@Disabled
public class LeaseTest {
+ private static final Logger logger =
LoggerFactory.getLogger(LeaseTest.class);
+
private static EtcdCluster cluster;
private KV kvClient;
@@ -75,20 +77,31 @@ public class LeaseTest {
private static final ByteSequence KEY_2 = ByteSequence.from("foo2",
Charsets.UTF_8);
private static final ByteSequence VALUE = ByteSequence.from("bar",
Charsets.UTF_8);
- @BeforeAll
- public static void beforeClass() {
- cluster = EtcdClusterFactory.buildCluster("etcd-lease", 3, false);
+ @BeforeEach
+ public void beforeClass() {
+ EtcdClusterExtension clusterExtension = EtcdClusterExtension.builder()
+ .withClusterName("etcd-lease")
+ .withNodes(3)
+ .withSsl(false)
+ .build();
+ try {
+ cluster = clusterExtension.cluster();
+ } catch (Exception e) {
+ logger.error("Init etcd cluster failed");
+ }
cluster.start();
}
- @AfterAll
- public static void afterClass() {
- cluster.close();
+ @AfterEach
+ public void afterClass() {
+ if (cluster != null) {
+ cluster.stop();
+ }
}
@BeforeEach
public void setUp() {
- client =
Client.builder().endpoints(cluster.getClientEndpoints()).build();
+ client = Client.builder().endpoints(cluster.clientEndpoints()).build();
kvClient = client.getKVClient();
leaseClient = client.getLeaseClient();
}