From 4c5a6dfa2fb004e4fb1525f99526952343331a95 Mon Sep 17 00:00:00 2001 From: aofall <10182210+aofall@users.noreply.github.com> Date: Sat, 15 Jun 2024 19:17:02 +0800 Subject: [PATCH] Bump jetcd vertsion from 0.5.7 to 0.7.7 (#416) * 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 * ci: Upload coverage to Codecov after unit test --- .github/workflows/build-and-test-pr.yml | 4 +- .../build-and-test-scheduled-3.1.yml | 4 +- .github/workflows/release-test.yml | 4 +- .../dubbo-configcenter-etcd/pom.xml | 5 ++ .../etcd/EtcdDynamicConfiguration.java | 8 ++- .../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 +++++++--- 14 files changed, 138 insertions(+), 55 deletions(-) create mode 100644 dubbo-registry-extensions/dubbo-registry-etcd3/src/main/java/org/apache/dubbo/registry/etcd/EtcdCompatibleRegistryFactory.java diff --git a/.github/workflows/build-and-test-pr.yml b/.github/workflows/build-and-test-pr.yml index 8dcdee3a..c9a96e59 100644 --- a/.github/workflows/build-and-test-pr.yml +++ b/.github/workflows/build-and-test-pr.yml @@ -137,8 +137,6 @@ jobs: with: name: "checkstyle-file" path: ${{ github.workspace }}/checkstyle.zip - - name: "Upload coverage to Codecov" - uses: codecov/codecov-action@v4 - name: "Calculate Dubbo-SPI-Extensions Version" id: dubbo-spi-extensions-version run: | @@ -295,6 +293,8 @@ jobs: with: name: coverage-result-${{ matrix.os }}-${{ matrix.jdk }} path: "**/target/site/**/jacoco.xml" + - name: "Upload coverage to Codecov" + uses: codecov/codecov-action@v4 # error-code-inspecting: # needs: [check-license, build-tools] diff --git a/.github/workflows/build-and-test-scheduled-3.1.yml b/.github/workflows/build-and-test-scheduled-3.1.yml index ec264fd4..36584493 100644 --- a/.github/workflows/build-and-test-scheduled-3.1.yml +++ b/.github/workflows/build-and-test-scheduled-3.1.yml @@ -143,8 +143,6 @@ jobs: with: name: "checkstyle-file" path: ${{ github.workspace }}/checkstyle.zip - - name: "Upload coverage to Codecov" - uses: codecov/codecov-action@v4 - name: "Calculate Dubbo-SPI-Extensions Version" id: dubbo-spi-extensions-version run: | @@ -301,6 +299,8 @@ jobs: with: name: coverage-result-${{ matrix.os }}-${{ matrix.jdk }} path: "**/target/site/**/jacoco.xml" + - name: "Upload coverage to Codecov" + uses: codecov/codecov-action@v4 # error-code-inspecting: # needs: [check-license, build-tools] diff --git a/.github/workflows/release-test.yml b/.github/workflows/release-test.yml index 09057282..acf7c1aa 100644 --- a/.github/workflows/release-test.yml +++ b/.github/workflows/release-test.yml @@ -143,8 +143,6 @@ jobs: with: name: "checkstyle-file" path: ${{ github.workspace }}/checkstyle.zip - - name: "Upload coverage to Codecov" - uses: codecov/codecov-action@v4 - name: "Calculate Dubbo-SPI-Extensions Version" id: dubbo-spi-extensions-version run: | @@ -301,6 +299,8 @@ jobs: with: name: coverage-result-${{ matrix.os }}-${{ matrix.jdk }} path: "**/target/site/**/jacoco.xml" + - name: "Upload coverage to Codecov" + uses: codecov/codecov-action@v4 # error-code-inspecting: # needs: [check-license, build-tools] diff --git a/dubbo-configcenter-extensions/dubbo-configcenter-etcd/pom.xml b/dubbo-configcenter-extensions/dubbo-configcenter-etcd/pom.xml index 05d3098e..edcef8eb 100644 --- a/dubbo-configcenter-extensions/dubbo-configcenter-etcd/pom.xml +++ b/dubbo-configcenter-extensions/dubbo-configcenter-etcd/pom.xml @@ -43,6 +43,11 @@ jetcd-launcher test + + io.etcd + jetcd-test + test + org.testcontainers testcontainers 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 59b384b6..03beb601 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.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 @@ */ 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 void onNext(WatchResponse watchResponse) { @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 60e6889f..fbce0dee 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 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 @@ */ 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 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 @@ private void put(String key, String value) { 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 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 bf9c56b7..36346f7a 100644 --- a/dubbo-extensions-dependencies-bom/pom.xml +++ b/dubbo-extensions-dependencies-bom/pom.xml @@ -121,9 +121,8 @@ 1.1.7 1.7.25 2.4.4 - 0.5.7 + 0.7.7 1.53.0 - 0.5.7 4.1.66.Final 2.2.1 1.4.2 @@ -409,6 +408,11 @@ + + io.etcd + jetcd-test + ${jetcd_version} + io.grpc grpc-core @@ -442,7 +446,7 @@ io.etcd jetcd-launcher - ${etcd_launcher_version} + ${jetcd_version} com.github.spotbugs 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 dfbdfa61..7a46a344 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 @@ jetcd-launcher test + + io.etcd + jetcd-test + test + org.testcontainers testcontainers 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 119522cf..a11e26e7 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.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 clientEndPoints = etcdCluster.getClientEndpoints(); + etcdClientForTest = Client.builder().endpoints(etcdCluster.clientEndpoints()).build(); + List 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 void setUp() { @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 00000000..8750a965 --- /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 4a6d09c9..c5bd906b 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 82e32a51..1dd4e936 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 9e7f187c..288d86cc 100644 --- a/dubbo-remoting-extensions/dubbo-remoting-etcd3/pom.xml +++ b/dubbo-remoting-extensions/dubbo-remoting-etcd3/pom.xml @@ -53,6 +53,11 @@ io.etcd jetcd-core + + io.etcd + jetcd-test + test + io.grpc grpc-core 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 61889848..a2feec6a 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.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 @@ @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(); }