This is an automated email from the ASF dual-hosted git repository. songxiaosheng pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/dubbo-spi-extensions.git
The following commit(s) were added to refs/heads/master by this push: new 78f87c3 fix: try to fix etcd unit test failed sometimes (#312) 78f87c3 is described below commit 78f87c397f4e86bf274a3a7f389a88d760c8471c Author: aofall <10182210+aof...@users.noreply.github.com> AuthorDate: Sat Apr 27 15:03:18 2024 +0800 fix: try to fix etcd unit test failed sometimes (#312) * chore: enable logger * chore: upload unit test failed report * chore: adjust workflow * fix: dubbo-configcenter-etcd unit test failed GitHub Actions may overuse leads to long waiting times, do not setting timeout in countdown latch * chore: upgrade dependencies jetcd-launcher from 0.5.7 to 0.7.7 * update: compatible the latest version of jetcd * update: compatible the latest version of jetcd * add log for throwable * create etcd for each unit test * Add timeout for countdown latch --------- Co-authored-by: xiaosheng <songxiaosh...@apache.org> --- .../dubbo-configcenter-etcd/pom.xml | 5 +++++ .../support/etcd/EtcdDynamicConfiguration.java | 8 ++++++-- .../support/etcd/EtcdDynamicConfigurationTest.java | 23 +++++++++++++--------- dubbo-extensions-dependencies-bom/pom.xml | 9 +++++++-- .../dubbo-metadata-report-etcd/pom.xml | 5 +++++ .../store/etcd/EtcdMetadataReportTest.java | 12 +++++++---- .../dubbo-remoting-etcd3/pom.xml | 6 ++++++ .../dubbo/remoting/etcd/jetcd/LeaseTest.java | 20 ++++++++++++++++--- 8 files changed, 68 insertions(+), 20 deletions(-) diff --git a/dubbo-configcenter-extensions/dubbo-configcenter-etcd/pom.xml b/dubbo-configcenter-extensions/dubbo-configcenter-etcd/pom.xml index 653fba3..6a40f0e 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> 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 6d926fe..c7276a5 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; @@ -24,11 +25,10 @@ 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.junit.After; import org.junit.Assert; -import org.junit.Before; import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -61,16 +61,21 @@ public class EtcdDynamicConfigurationTest { public EtcdCluster etcdCluster; // This will involve Docker pulling the image very slowly - @Before + @BeforeEach public void setUp() { try { - etcdCluster = EtcdClusterFactory.buildCluster(getClass().getSimpleName(), 3, false); + EtcdClusterExtension clusterExtension = EtcdClusterExtension.builder() + .withClusterName(getClass().getSimpleName()) + .withNodes(3) + .withSsl(false) + .build(); + etcdCluster = clusterExtension.cluster(); etcdCluster.start(); - client = Client.builder().endpoints(etcdCluster.getClientEndpoints()).build(); + client = Client.builder().endpoints(etcdCluster.clientEndpoints()).build(); - List<URI> clientEndPoints = etcdCluster.getClientEndpoints(); + List<URI> clientEndPoints = etcdCluster.clientEndpoints(); String ipAddress = clientEndPoints.get(0).getHost() + ":" + clientEndPoints.get(0).getPort(); //"127.0.0.1:2379"; @@ -121,7 +126,7 @@ public class EtcdDynamicConfigurationTest { put("/dubbo/config/dubbo/testapp/tagrouters", "new value2"); Thread.sleep(1000); - Assert.assertTrue(latch.await(5, TimeUnit.SECONDS)); + Assert.assertTrue(latch.await(1, TimeUnit.MINUTES)); Assert.assertEquals(1, listener1.getCount("AService/configurators")); Assert.assertEquals(1, listener2.getCount("AService/configurators")); Assert.assertEquals(1, listener3.getCount("testapp/tagrouters")); @@ -170,7 +175,7 @@ public class EtcdDynamicConfigurationTest { } - @After + @AfterEach public void tearDown() { if (etcdCluster != null) { etcdCluster.close(); diff --git a/dubbo-extensions-dependencies-bom/pom.xml b/dubbo-extensions-dependencies-bom/pom.xml index 32f8c27..4354fb0 100644 --- a/dubbo-extensions-dependencies-bom/pom.xml +++ b/dubbo-extensions-dependencies-bom/pom.xml @@ -121,9 +121,9 @@ <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> + <etcd_launcher_version>0.7.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> @@ -410,6 +410,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> 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 1bf4d71..c711683 100644 --- a/dubbo-metadata-report-extensions/dubbo-metadata-report-etcd/pom.xml +++ b/dubbo-metadata-report-extensions/dubbo-metadata-report-etcd/pom.xml @@ -96,6 +96,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..28d0749 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,11 @@ 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 final EtcdCluster etcdCluster = EtcdClusterExtension.builder().withClusterName(getClass().getSimpleName()) + .withNodes(1) + .withSsl(false) + .build().cluster(); + private Client etcdClientForTest; private EtcdMetadataReport etcdMetadataReport; private URL registryUrl; @@ -66,8 +70,8 @@ public class EtcdMetadataReportTest { @BeforeEach public void setUp() { 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); diff --git a/dubbo-remoting-extensions/dubbo-remoting-etcd3/pom.xml b/dubbo-remoting-extensions/dubbo-remoting-etcd3/pom.xml index 9aafa49..b5c1b1b 100644 --- a/dubbo-remoting-extensions/dubbo-remoting-etcd3/pom.xml +++ b/dubbo-remoting-extensions/dubbo-remoting-etcd3/pom.xml @@ -103,6 +103,12 @@ <scope>test</scope> </dependency> + <dependency> + <groupId>io.etcd</groupId> + <artifactId>jetcd-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>io.netty</groupId> <artifactId>netty-all</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..2ddb361 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,11 +39,12 @@ 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.launcher.EtcdClusterImpl; 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.junit.jupiter.api.AfterEach; @@ -51,6 +52,8 @@ 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.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; @@ -65,6 +68,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; @@ -77,7 +82,16 @@ public class LeaseTest { @BeforeAll public static void beforeClass() { - cluster = EtcdClusterFactory.buildCluster("etcd-lease", 3, false); + 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(); } @@ -88,7 +102,7 @@ public class LeaseTest { @BeforeEach public void setUp() { - client = Client.builder().endpoints(cluster.getClientEndpoints()).build(); + client = Client.builder().endpoints(cluster.clientEndpoints()).build(); kvClient = client.getKVClient(); leaseClient = client.getLeaseClient(); }