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 a7fb614  [Github-Actions] Improve Test cases (#7849)
a7fb614 is described below

commit a7fb614c13fe18af5fda8c8bebd543a831c0c72c
Author: Albumen Kevin <[email protected]>
AuthorDate: Mon May 24 16:35:36 2021 +0800

    [Github-Actions] Improve Test cases (#7849)
    
    * Improve Test cases for Dubbo 3.0, from #7592 #7829
    
    * Fix compile error
    
    * move static field recover to final block
    
    * Move application config set to ApplicationModel in ReferenceConfigTest
---
 .github/workflows/build-and-test-3.yml             |  4 +-
 .../apache/dubbo/config/ReferenceConfigTest.java   | 10 +--
 .../PublishingServiceDefinitionListenerTest.java   |  5 +-
 dubbo-config/dubbo-config-spring/pom.xml           | 11 +++
 dubbo-dependencies-bom/pom.xml                     |  4 +-
 dubbo-metadata/dubbo-metadata-report-redis/pom.xml |  2 +-
 .../store/redis/RedisMetadataReportTest.java       | 70 ++++++++++------
 .../apache/dubbo/monitor/dubbo/MetricsFilter.java  |  2 +-
 .../dubbo/monitor/dubbo/MetricsFilterTest.java     | 98 ++++++++++++++++------
 .../registry/multicast/MulticastRegistryTest.java  |  7 +-
 dubbo-registry/dubbo-registry-multiple/pom.xml     |  5 --
 .../remoting/transport/netty/ThreadNameTest.java   | 24 ++++--
 12 files changed, 163 insertions(+), 79 deletions(-)

diff --git a/.github/workflows/build-and-test-3.yml 
b/.github/workflows/build-and-test-3.yml
index 4cfa652..a7aa668 100644
--- a/.github/workflows/build-and-test-3.yml
+++ b/.github/workflows/build-and-test-3.yml
@@ -71,13 +71,13 @@ jobs:
           restore-keys: |
             ${{ runner.os }}-maven-
       - name: "Test with Maven with Integration Tests"
-        timeout-minutes: 30
+        timeout-minutes: 40
         if: ${{ startsWith( matrix.os, 'ubuntu') }}
         run: ./mvnw --batch-mode -U -e --no-transfer-progress clean test 
verify -Dmaven.wagon.httpconnectionManager.ttlSeconds=120 
-Dmaven.wagon.http.retryHandler.count=5 -DskipTests=false 
-DskipIntegrationTests=false -Dcheckstyle.skip=false -Drat.skip=false 
-Dmaven.javadoc.skip=true
       - name: "Test with Maven without Integration Tests"
         env:
           DISABLE_FILE_SYSTEM_TEST: true
-        timeout-minutes: 30
+        timeout-minutes: 50
         if: ${{ startsWith( matrix.os, 'windows') }}
         run: ./mvnw --batch-mode -U -e --no-transfer-progress clean test 
verify -D"http.keepAlive=false" -D"maven.wagon.http.pool=false" 
-D"maven.wagon.httpconnectionManager.ttlSeconds=120" 
-D"maven.wagon.http.retryHandler.count=5" -DskipTests=false 
-DskipIntegrationTests=true -D"checkstyle.skip=false" -D"rat.skip=false" 
-D"maven.javadoc.skip=true"
       - name: "Pack rat file if failure"
diff --git 
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java
 
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java
index 775596c..3e8ad3a 100644
--- 
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java
+++ 
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java
@@ -29,6 +29,7 @@ import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 import static org.apache.dubbo.rpc.Constants.LOCAL_PROTOCOL;
+import static org.apache.dubbo.rpc.Constants.SCOPE_REMOTE;
 
 public class ReferenceConfigTest {
 
@@ -46,6 +47,7 @@ public class ReferenceConfigTest {
     public void testInjvm() throws Exception {
         ApplicationConfig application = new ApplicationConfig();
         application.setName("test-protocol-random-port");
+        ApplicationModel.getConfigManager().setApplication(application);
 
         RegistryConfig registry = new RegistryConfig();
         registry.setAddress("multicast://224.5.6.7:1234");
@@ -57,15 +59,13 @@ public class ReferenceConfigTest {
         demoService = new ServiceConfig<DemoService>();
         demoService.setInterface(DemoService.class);
         demoService.setRef(new DemoServiceImpl());
-        demoService.setApplication(application);
         demoService.setRegistry(registry);
         demoService.setProtocol(protocol);
 
         ReferenceConfig<DemoService> rc = new ReferenceConfig<DemoService>();
-        rc.setApplication(application);
         rc.setRegistry(registry);
         rc.setInterface(DemoService.class.getName());
-        rc.setInjvm(false);
+        rc.setScope(SCOPE_REMOTE);
 
         try {
             System.setProperty("java.net.preferIPv4Stack", "true");
@@ -86,13 +86,14 @@ public class ReferenceConfigTest {
     public void testReferenceRetry() {
         ApplicationConfig application = new ApplicationConfig();
         application.setName("test-reference-retry");
+        ApplicationModel.getConfigManager().setApplication(application);
+
         RegistryConfig registry = new RegistryConfig();
         registry.setAddress("multicast://224.5.6.7:1234");
         ProtocolConfig protocol = new ProtocolConfig();
         protocol.setName("mockprotocol");
 
         ReferenceConfig<DemoService> rc = new ReferenceConfig<DemoService>();
-        rc.setApplication(application);
         rc.setRegistry(registry);
         rc.setInterface(DemoService.class.getName());
 
@@ -110,7 +111,6 @@ public class ReferenceConfigTest {
         ServiceConfig<DemoService> sc = new ServiceConfig<DemoService>();
         sc.setInterface(DemoService.class);
         sc.setRef(new DemoServiceImpl());
-        sc.setApplication(application);
         sc.setRegistry(registry);
         sc.setProtocol(protocol);
 
diff --git 
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/event/listener/PublishingServiceDefinitionListenerTest.java
 
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/event/listener/PublishingServiceDefinitionListenerTest.java
index 0022aac..ad571f8 100644
--- 
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/event/listener/PublishingServiceDefinitionListenerTest.java
+++ 
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/event/listener/PublishingServiceDefinitionListenerTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.dubbo.config.event.listener;
 
+import org.apache.dubbo.common.utils.NetUtils;
 import org.apache.dubbo.config.ApplicationConfig;
 import org.apache.dubbo.config.ProtocolConfig;
 import org.apache.dubbo.config.RegistryConfig;
@@ -34,6 +35,8 @@ import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
+import java.util.Random;
+
 import static 
org.apache.dubbo.common.constants.CommonConstants.DEFAULT_METADATA_STORAGE_TYPE;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
@@ -67,7 +70,7 @@ public class PublishingServiceDefinitionListenerTest {
     @Test
     public void testOnServiceConfigExportedEvent() {
         ProtocolConfig protocolConfig = new ProtocolConfig("dubbo");
-        protocolConfig.setPort(-1);
+        protocolConfig.setPort(NetUtils.getAvailablePort(20880 + new 
Random().nextInt(10000)));
 
         ServiceConfig<EchoService> serviceConfig = new ServiceConfig<>();
         serviceConfig.setInterface(EchoService.class);
diff --git a/dubbo-config/dubbo-config-spring/pom.xml 
b/dubbo-config/dubbo-config-spring/pom.xml
index b96ab26..df9fbfd 100644
--- a/dubbo-config/dubbo-config-spring/pom.xml
+++ b/dubbo-config/dubbo-config-spring/pom.xml
@@ -193,5 +193,16 @@
                 </includes>
             </testResource>
         </testResources>
+
+        <plugins>
+            <plugin>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <groupId>org.apache.maven.plugins</groupId>
+                <configuration>
+                    <forkCount>1</forkCount>
+                    <reuseForks>false</reuseForks>
+                </configuration>
+            </plugin>
+        </plugins>
     </build>
 </project>
diff --git a/dubbo-dependencies-bom/pom.xml b/dubbo-dependencies-bom/pom.xml
index 5d59d8d..60d1491 100644
--- a/dubbo-dependencies-bom/pom.xml
+++ b/dubbo-dependencies-bom/pom.xml
@@ -142,7 +142,7 @@
         <log4j2_version>2.11.1</log4j2_version>
         <commons_io_version>2.6</commons_io_version>
 
-        <embedded_redis_version>0.6</embedded_redis_version>
+        <embedded_redis_version>0.10.0</embedded_redis_version>
 
         <!-- Eureka -->
         <eureka.version>1.9.12</eureka.version>
@@ -639,7 +639,7 @@
                 <scope>test</scope>
             </dependency>
             <dependency>
-                <groupId>com.github.kstyrc</groupId>
+                <groupId>com.github.codemonstur</groupId>
                 <artifactId>embedded-redis</artifactId>
                 <version>${embedded_redis_version}</version>
                 <scope>test</scope>
diff --git a/dubbo-metadata/dubbo-metadata-report-redis/pom.xml 
b/dubbo-metadata/dubbo-metadata-report-redis/pom.xml
index a743401..81d162d 100644
--- a/dubbo-metadata/dubbo-metadata-report-redis/pom.xml
+++ b/dubbo-metadata/dubbo-metadata-report-redis/pom.xml
@@ -44,7 +44,7 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>com.github.kstyrc</groupId>
+            <groupId>com.github.codemonstur</groupId>
             <artifactId>embedded-redis</artifactId>
             <scope>test</scope>
         </dependency>
diff --git 
a/dubbo-metadata/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java
 
b/dubbo-metadata/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java
index 900bf37..adf6e97 100644
--- 
a/dubbo-metadata/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java
+++ 
b/dubbo-metadata/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java
@@ -16,7 +16,6 @@
  */
 package org.apache.dubbo.metadata.store.redis;
 
-import org.apache.commons.lang3.SystemUtils;
 import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.utils.NetUtils;
 import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder;
@@ -26,6 +25,7 @@ import 
org.apache.dubbo.metadata.report.identifier.MetadataIdentifier;
 import org.apache.dubbo.rpc.RpcException;
 
 import com.google.gson.Gson;
+import org.apache.commons.lang3.SystemUtils;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
@@ -35,52 +35,70 @@ import redis.clients.jedis.Jedis;
 import redis.clients.jedis.exceptions.JedisConnectionException;
 import redis.clients.jedis.exceptions.JedisDataException;
 import redis.embedded.RedisServer;
-import redis.embedded.RedisServerBuilder;
 
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Random;
 
 import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE;
 import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE;
 import static 
org.apache.dubbo.metadata.report.support.Constants.SYNC_REPORT_KEY;
+import static redis.embedded.RedisServer.newRedisServer;
 
-/**
- * 2018/10/9
- */
 public class RedisMetadataReportTest {
+
+    private static final String
+            REDIS_URL_TEMPLATE = "redis://%slocalhost:%d",
+            REDIS_PASSWORD = "チェリー",
+            REDIS_URL_AUTH_SECTION = "username:" + REDIS_PASSWORD + "@";
+
     RedisMetadataReport redisMetadataReport;
     RedisMetadataReport syncRedisMetadataReport;
     RedisServer redisServer;
     URL registryUrl;
 
     @BeforeEach
-    public void constructor(TestInfo testInfo) throws IOException {
-        int redisPort = NetUtils.getAvailablePort();
-        String methodName = testInfo.getTestMethod().get().getName();
-        if ("testAuthRedisMetadata".equals(methodName) || 
("testWrongAuthRedisMetadata".equals(methodName))) {
-            String password = "チェリー";
-            RedisServerBuilder builder = 
RedisServer.builder().port(redisPort).setting("requirepass " + password);
-            if (SystemUtils.IS_OS_WINDOWS) {
-                // set maxheap to fix Windows error 0x70 while starting redis
-                builder.setting("maxheap 128mb");
+    public void constructor(final TestInfo testInfo) throws IOException {
+        final boolean usesAuthentication = usesAuthentication(testInfo);
+        int redisPort = 0;
+        IOException exception = null;
+
+        for (int i = 0; i < 10; i++) {
+            try {
+                redisPort = NetUtils.getAvailablePort(30000 + new 
Random().nextInt(10000));
+                redisServer = newRedisServer()
+                        .port(redisPort)
+                        // set maxheap to fix Windows error 0x70 while 
starting redis
+                        .settingIf(SystemUtils.IS_OS_WINDOWS, "maxheap 128mb")
+                        .settingIf(usesAuthentication, "requirepass " + 
REDIS_PASSWORD)
+                        .build();
+                this.redisServer.start();
+                exception = null;
+            } catch (IOException e) {
+                e.printStackTrace();
+                exception = e;
             }
-            redisServer = builder.build();
-            registryUrl = URL.valueOf("redis://username:" + password + 
"@localhost:" + redisPort);
-        } else {
-            RedisServerBuilder builder = RedisServer.builder().port(redisPort);
-            if (SystemUtils.IS_OS_WINDOWS) {
-                // set maxheap to fix Windows error 0x70 while starting redis
-                builder.setting("maxheap 128mb");
+            if (exception == null) {
+                break;
             }
-            redisServer = builder.build();
-            registryUrl = URL.valueOf("redis://localhost:" + redisPort);
         }
 
-        this.redisServer.start();
+        Assertions.assertNull(exception);
+        registryUrl = newRedisUrl(usesAuthentication, redisPort);
         redisMetadataReport = (RedisMetadataReport) new 
RedisMetadataReportFactory().createMetadataReport(registryUrl);
-        URL asyncRegistryUrl = URL.valueOf("redis://localhost:" + redisPort + 
"?" + SYNC_REPORT_KEY + "=true");
-        syncRedisMetadataReport = (RedisMetadataReport) new 
RedisMetadataReportFactory().createMetadataReport(registryUrl);
+        URL syncRegistryUrl = registryUrl.addParameter(SYNC_REPORT_KEY 
,"true");
+        syncRedisMetadataReport = (RedisMetadataReport) new 
RedisMetadataReportFactory().createMetadataReport(syncRegistryUrl);
+    }
+
+    private static boolean usesAuthentication(final TestInfo testInfo) {
+        final String methodName = testInfo.getTestMethod().get().getName();
+        return "testAuthRedisMetadata".equals(methodName) || 
"testWrongAuthRedisMetadata".equals(methodName);
+    }
+
+    private static URL newRedisUrl(final boolean usesAuthentication, final int 
redisPort) {
+        final String urlAuthSection = usesAuthentication ? 
REDIS_URL_AUTH_SECTION : "";
+        return URL.valueOf(String.format(REDIS_URL_TEMPLATE, urlAuthSection, 
redisPort));
     }
 
     @AfterEach
diff --git 
a/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/MetricsFilter.java
 
b/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/MetricsFilter.java
index abc6aa4..a3da989 100644
--- 
a/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/MetricsFilter.java
+++ 
b/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/MetricsFilter.java
@@ -70,7 +70,7 @@ import static org.apache.dubbo.monitor.Constants.SERVICE;
 public class MetricsFilter implements Filter {
 
     private static final Logger logger = 
LoggerFactory.getLogger(MetricsFilter.class);
-    private static volatile AtomicBoolean exported = new AtomicBoolean(false);
+    protected static volatile AtomicBoolean exported = new 
AtomicBoolean(false);
     private Integer port;
     private String protocolName;
 
diff --git 
a/dubbo-monitor/dubbo-monitor-default/src/test/java/org/apache/dubbo/monitor/dubbo/MetricsFilterTest.java
 
b/dubbo-monitor/dubbo-monitor-default/src/test/java/org/apache/dubbo/monitor/dubbo/MetricsFilterTest.java
index b146734..29bb535 100644
--- 
a/dubbo-monitor/dubbo-monitor-default/src/test/java/org/apache/dubbo/monitor/dubbo/MetricsFilterTest.java
+++ 
b/dubbo-monitor/dubbo-monitor-default/src/test/java/org/apache/dubbo/monitor/dubbo/MetricsFilterTest.java
@@ -42,11 +42,15 @@ import org.junit.jupiter.api.Test;
 import org.mockito.Mockito;
 
 import java.util.HashMap;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Random;
+import java.util.concurrent.Callable;
 import java.util.function.Function;
 
 import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE;
+import static org.apache.dubbo.common.constants.CommonConstants.METRICS_PORT;
 import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER;
 import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
@@ -62,8 +66,9 @@ import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.mock;
 
 public class MetricsFilterTest {
+    private int port = NetUtils.getAvailablePort(20880 + new 
Random().nextInt(10000));
 
-    private final Function<URL, Invoker<DemoService>> invokerFunction = 
(url)-> {
+    private final Function<URL, Invoker<DemoService>> invokerFunction = (url) 
-> {
         Invoker<DemoService> serviceInvoker = mock(Invoker.class);
 
         given(serviceInvoker.isAvailable()).willReturn(false);
@@ -75,7 +80,8 @@ public class MetricsFilterTest {
     };
 
     private URL getUrl() {
-        return URL.valueOf("dubbo://" + NetUtils.getLocalHost() + 
":20880/org.apache.dubbo.monitor.dubbo.service.DemoService");
+        return URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":" + port +
+                "/org.apache.dubbo.monitor.dubbo.service.DemoService?" + 
METRICS_PORT + "=" + port);
     }
 
     private void onInvokeReturns(Invoker<DemoService> invoker, AppResponse 
response) {
@@ -87,16 +93,58 @@ public class MetricsFilterTest {
     }
 
     @Test
-    public void testConsumerSuccess() throws Exception {
+    public void testAll() {
+        List<Callable<Void>> testcases = new LinkedList<>();
+        testcases.add(() -> {
+            testConsumerSuccess();
+            return null;
+        });
+        testcases.add(() -> {
+            testConsumerTimeout();
+            return null;
+        });
+        testcases.add(() -> {
+            testProviderSuccess();
+            return null;
+        });
+        testcases.add(() -> {
+            testInvokeMetricsService();
+            return null;
+        });
+        testcases.add(() -> {
+            testInvokeMetricsMethodService();
+            return null;
+        });
+
+        for (Callable<Void> testcase : testcases) {
+            Throwable throwable = null;
+            for (int i = 0; i < 10; i++) {
+                try {
+                    port = NetUtils.getAvailablePort(20880 + new 
Random().nextInt(10000));
+                    testcase.call();
+                    throwable = null;
+                    break;
+                } catch (Throwable t) {
+                    t.printStackTrace();
+                    throwable = t;
+                } finally {
+                    MetricsFilter.exported.set(false);
+                }
+            }
+            Assertions.assertNull(throwable);
+        }
+    }
+
+    private void testConsumerSuccess() throws Exception {
         IMetricManager metricManager = MetricManager.getIMetricManager();
         metricManager.clear();
         MetricsFilter metricsFilter = new MetricsFilter();
         Invocation invocation = new RpcInvocation("sayName", 
DemoService.class.getName(), "", new Class<?>[]{Integer.class}, new Object[0]);
-        
RpcContext.getServiceContext().setRemoteAddress(NetUtils.getLocalHost(), 
20880).setLocalAddress(NetUtils.getLocalHost(), 2345);
+        
RpcContext.getServiceContext().setRemoteAddress(NetUtils.getLocalHost(), 
port).setLocalAddress(NetUtils.getLocalHost(), 2345);
         URL url = getUrl().addParameter(SIDE_KEY, CONSUMER_SIDE);
         Invoker<DemoService> invoker = invokerFunction.apply(url);
         AppResponse response = AppResponseBuilder.create()
-            .build();
+                .build();
         onInvokeReturns(invoker, response);
         for (int i = 0; i < 100; i++) {
             metricsFilter.invoke(invoker, invocation);
@@ -115,13 +163,12 @@ public class MetricsFilterTest {
 
     }
 
-    @Test
-    public void testConsumerTimeout() {
+    private void testConsumerTimeout() {
         IMetricManager metricManager = MetricManager.getIMetricManager();
         metricManager.clear();
         MetricsFilter metricsFilter = new MetricsFilter();
         Invocation invocation = new RpcInvocation("timeoutException", 
DemoService.class.getName(), "", null, null);
-        
RpcContext.getServiceContext().setRemoteAddress(NetUtils.getLocalHost(), 
20880).setLocalAddress(NetUtils.getLocalHost(), 2345);
+        
RpcContext.getServiceContext().setRemoteAddress(NetUtils.getLocalHost(), 
port).setLocalAddress(NetUtils.getLocalHost(), 2345);
         URL url = getUrl().addParameter(SIDE_KEY, CONSUMER_SIDE)
                 .addParameter(TIMEOUT_KEY, 300);
         Invoker<DemoService> invoker = invokerFunction.apply(url);
@@ -147,13 +194,12 @@ public class MetricsFilterTest {
 
     }
 
-    @Test
-    public void testProviderSuccess() throws Exception {
+    private void testProviderSuccess() throws Exception {
         IMetricManager metricManager = MetricManager.getIMetricManager();
         metricManager.clear();
         MetricsFilter metricsFilter = new MetricsFilter();
         Invocation invocation = new RpcInvocation("sayName", 
DemoService.class.getName(), "", new Class<?>[0], new Object[0]);
-        
RpcContext.getServiceContext().setRemoteAddress(NetUtils.getLocalHost(), 
20880).setLocalAddress(NetUtils.getLocalHost(), 2345);
+        
RpcContext.getServiceContext().setRemoteAddress(NetUtils.getLocalHost(), 
port).setLocalAddress(NetUtils.getLocalHost(), 2345);
         URL url = getUrl().addParameter(SIDE_KEY, PROVIDER)
                 .addParameter(TIMEOUT_KEY, 300);
         Invoker<DemoService> invoker = invokerFunction.apply(url);
@@ -176,13 +222,12 @@ public class MetricsFilterTest {
         Assertions.assertEquals(100, 
dubboMethod.getMethodCountPerCategory(0).get("success").get(timestamp));
     }
 
-    @Test
-    public void testInvokeMetricsService() {
+    private void testInvokeMetricsService() {
         IMetricManager metricManager = MetricManager.getIMetricManager();
         metricManager.clear();
         MetricsFilter metricsFilter = new MetricsFilter();
         Invocation invocation = new RpcInvocation("sayName", 
DemoService.class.getName(), "", new Class<?>[0], new Object[0]);
-        
RpcContext.getServiceContext().setRemoteAddress(NetUtils.getLocalHost(), 
20880).setLocalAddress(NetUtils.getLocalHost(), 2345);
+        
RpcContext.getServiceContext().setRemoteAddress(NetUtils.getLocalHost(), 
port).setLocalAddress(NetUtils.getLocalHost(), 2345);
         URL url = getUrl().addParameter(SIDE_KEY, PROVIDER)
                 .addParameter(TIMEOUT_KEY, 300);
         Invoker<DemoService> serviceInvoker = invokerFunction.apply(url);
@@ -199,7 +244,7 @@ public class MetricsFilterTest {
             }
         }
         Protocol protocol = new DubboProtocol();
-        url = URL.valueOf("dubbo://" + 
NetUtils.getLocalAddress().getHostName() + ":20880/" + 
MetricsService.class.getName());
+        url = URL.valueOf("dubbo://" + 
NetUtils.getLocalAddress().getHostName() + ":" + port + "/" + 
MetricsService.class.getName());
         Invoker<MetricsService> invoker = protocol.refer(MetricsService.class, 
url);
         invocation = new RpcInvocation("getMetricsByGroup", 
DemoService.class.getName(), "", new Class<?>[]{String.class}, new 
Object[]{DUBBO_GROUP});
         try {
@@ -225,14 +270,13 @@ public class MetricsFilterTest {
         Assertions.assertEquals(50.0 / 100.0, metricMap.get("success_rate"));
     }
 
-    @Test
-    public void testInvokeMetricsMethodService() {
+    private void testInvokeMetricsMethodService() {
         IMetricManager metricManager = MetricManager.getIMetricManager();
         metricManager.clear();
         MetricsFilter metricsFilter = new MetricsFilter();
         Invocation sayNameInvocation = new RpcInvocation("sayName", 
DemoService.class.getName(), "", new Class<?>[0], new Object[0]);
         Invocation echoInvocation = new RpcInvocation("echo", 
DemoService.class.getName(), "", new Class<?>[]{Integer.class}, new 
Integer[]{1});
-        
RpcContext.getServiceContext().setRemoteAddress(NetUtils.getLocalHost(), 
20880).setLocalAddress(NetUtils.getLocalHost(), 2345);
+        
RpcContext.getServiceContext().setRemoteAddress(NetUtils.getLocalHost(), 
port).setLocalAddress(NetUtils.getLocalHost(), 2345);
         URL url = getUrl().addParameter(SIDE_KEY, PROVIDER)
                 .addParameter(TIMEOUT_KEY, 300);
         Invoker<DemoService> serviceInvoker = invokerFunction.apply(url);
@@ -256,7 +300,7 @@ public class MetricsFilterTest {
         }
 
         Protocol protocol = new DubboProtocol();
-        url = URL.valueOf("dubbo://" + 
NetUtils.getLocalAddress().getHostName() + ":20880/" + 
MetricsService.class.getName());
+        url = URL.valueOf("dubbo://" + 
NetUtils.getLocalAddress().getHostName() + ":" + port + "/" + 
MetricsService.class.getName());
         Invoker<MetricsService> invoker = protocol.refer(MetricsService.class, 
url);
         Invocation invocation = new RpcInvocation("getMetricsByGroup", 
DemoService.class.getName(), "", new Class<?>[]{String.class}, new 
Object[]{DUBBO_GROUP});
         try {
@@ -282,23 +326,23 @@ public class MetricsFilterTest {
         }
 
         Assertions.assertEquals(50.0,
-            
methodMetricMap.get("org.apache.dubbo.monitor.dubbo.service.DemoService.void 
sayName()").get("success_bucket_count"));
+                
methodMetricMap.get("org.apache.dubbo.monitor.dubbo.service.DemoService.void 
sayName()").get("success_bucket_count"));
         Assertions.assertEquals(50.0,
-            
methodMetricMap.get("org.apache.dubbo.monitor.dubbo.service.DemoService.void 
echo(Integer)").get("success_bucket_count"));
+                
methodMetricMap.get("org.apache.dubbo.monitor.dubbo.service.DemoService.void 
echo(Integer)").get("success_bucket_count"));
 
         Assertions.assertEquals(50.0,
-            
methodMetricMap.get("org.apache.dubbo.monitor.dubbo.service.DemoService.void 
sayName()").get("timeoutError_bucket_count"));
+                
methodMetricMap.get("org.apache.dubbo.monitor.dubbo.service.DemoService.void 
sayName()").get("timeoutError_bucket_count"));
         Assertions.assertEquals(50.0,
-            
methodMetricMap.get("org.apache.dubbo.monitor.dubbo.service.DemoService.void 
echo(Integer)").get("timeoutError_bucket_count"));
+                
methodMetricMap.get("org.apache.dubbo.monitor.dubbo.service.DemoService.void 
echo(Integer)").get("timeoutError_bucket_count"));
 
         Assertions.assertEquals(100.0 / 15,
-            
methodMetricMap.get("org.apache.dubbo.monitor.dubbo.service.DemoService.void 
sayName()").get("qps"));
+                
methodMetricMap.get("org.apache.dubbo.monitor.dubbo.service.DemoService.void 
sayName()").get("qps"));
         Assertions.assertEquals(100.0 / 15,
-            
methodMetricMap.get("org.apache.dubbo.monitor.dubbo.service.DemoService.void 
echo(Integer)").get("qps"));
+                
methodMetricMap.get("org.apache.dubbo.monitor.dubbo.service.DemoService.void 
echo(Integer)").get("qps"));
 
         Assertions.assertEquals(50.0 / 100.0,
-            
methodMetricMap.get("org.apache.dubbo.monitor.dubbo.service.DemoService.void 
sayName()").get("success_rate"));
+                
methodMetricMap.get("org.apache.dubbo.monitor.dubbo.service.DemoService.void 
sayName()").get("success_rate"));
         Assertions.assertEquals(50.0 / 100.0,
-            
methodMetricMap.get("org.apache.dubbo.monitor.dubbo.service.DemoService.void 
echo(Integer)").get("success_rate"));
+                
methodMetricMap.get("org.apache.dubbo.monitor.dubbo.service.DemoService.void 
echo(Integer)").get("success_rate"));
     }
 }
diff --git 
a/dubbo-registry/dubbo-registry-multicast/src/test/java/org/apache/dubbo/registry/multicast/MulticastRegistryTest.java
 
b/dubbo-registry/dubbo-registry-multicast/src/test/java/org/apache/dubbo/registry/multicast/MulticastRegistryTest.java
index 598f34a..32e71d0 100644
--- 
a/dubbo-registry/dubbo-registry-multicast/src/test/java/org/apache/dubbo/registry/multicast/MulticastRegistryTest.java
+++ 
b/dubbo-registry/dubbo-registry-multicast/src/test/java/org/apache/dubbo/registry/multicast/MulticastRegistryTest.java
@@ -29,6 +29,7 @@ import java.net.MulticastSocket;
 import java.net.UnknownHostException;
 import java.util.List;
 import java.util.Map;
+import java.util.Random;
 import java.util.Set;
 
 import static 
org.apache.dubbo.common.constants.RegistryConstants.EMPTY_PROTOCOL;
@@ -84,7 +85,7 @@ public class MulticastRegistryTest {
      */
     @Test
     public void testGetCustomPort() {
-        int port = NetUtils.getAvailablePort();
+        int port = NetUtils.getAvailablePort(20880 + new 
Random().nextInt(10000));
         URL customPortUrl = URL.valueOf("multicast://239.239.239.239:" + port);
         MulticastRegistry multicastRegistry = new 
MulticastRegistry(customPortUrl);
         assertThat(multicastRegistry.getUrl().getPort(), is(port));
@@ -186,7 +187,7 @@ public class MulticastRegistryTest {
      */
     @Test
     public void testAvailability() {
-        int port = NetUtils.getAvailablePort();
+        int port = NetUtils.getAvailablePort(20880 + new 
Random().nextInt(10000));
         MulticastRegistry registry = new 
MulticastRegistry(URL.valueOf("multicast://224.5.6.8:" + port));
         assertTrue(registry.isAvailable());
     }
@@ -224,7 +225,7 @@ public class MulticastRegistryTest {
      */
     @Test
     public void testCustomedPort() {
-        int port = NetUtils.getAvailablePort();
+        int port = NetUtils.getAvailablePort(20880 + new 
Random().nextInt(10000));
         MulticastRegistry multicastRegistry = new 
MulticastRegistry(URL.valueOf("multicast://224.5.6.7:" + port));
         try {
             MulticastSocket multicastSocket = 
multicastRegistry.getMulticastSocket();
diff --git a/dubbo-registry/dubbo-registry-multiple/pom.xml 
b/dubbo-registry/dubbo-registry-multiple/pom.xml
index e4c5165..5a8c005 100644
--- a/dubbo-registry/dubbo-registry-multiple/pom.xml
+++ b/dubbo-registry/dubbo-registry-multiple/pom.xml
@@ -47,11 +47,6 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>com.github.kstyrc</groupId>
-            <artifactId>embedded-redis</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
             <groupId>org.apache.commons</groupId>
             <artifactId>commons-lang3</artifactId>
             <scope>test</scope>
diff --git 
a/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/transport/netty/ThreadNameTest.java
 
b/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/transport/netty/ThreadNameTest.java
index 001b56a..ef3b23a 100644
--- 
a/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/transport/netty/ThreadNameTest.java
+++ 
b/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/transport/netty/ThreadNameTest.java
@@ -27,6 +27,10 @@ import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
+import java.util.Random;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
 public class ThreadNameTest {
 
     private NettyServer server;
@@ -41,15 +45,17 @@ public class ThreadNameTest {
     private static String serverRegex = 
"DubboServerHandler\\-localhost:(\\d+)\\-thread\\-(\\d+)";
     private static String clientRegex = 
"DubboClientHandler\\-localhost:(\\d+)\\-thread\\-(\\d+)";
 
+    private final CountDownLatch serverLatch = new CountDownLatch(1);
+    private final CountDownLatch clientLatch = new CountDownLatch(1);
+
     @BeforeEach
     public void before() throws Exception {
-        int port = NetUtils.getAvailablePort();
+        int port = NetUtils.getAvailablePort(20880 + new 
Random().nextInt(10000));
         serverURL = 
URL.valueOf("telnet://localhost?side=provider").setPort(port);
         clientURL = 
URL.valueOf("telnet://localhost?side=consumer").setPort(port);
 
-        serverHandler = new ThreadNameVerifyHandler(serverRegex, false);
-        clientHandler = new ThreadNameVerifyHandler(clientRegex, true);
-
+        serverHandler = new ThreadNameVerifyHandler(serverRegex, false, 
serverLatch);
+        clientHandler = new ThreadNameVerifyHandler(clientRegex, true, 
clientLatch);
         server = new NettyServer(serverURL, serverHandler);
         client = new NettyClient(clientURL, clientHandler);
     }
@@ -70,7 +76,8 @@ public class ThreadNameTest {
     @Test
     public void testThreadName() throws Exception {
         client.send("hello");
-        Thread.sleep(1000L * 5L);
+        serverLatch.await(30, TimeUnit.SECONDS);
+        clientLatch.await(30, TimeUnit.SECONDS);
         if (!serverHandler.isSuccess() || !clientHandler.isSuccess()) {
             Assertions.fail();
         }
@@ -81,10 +88,12 @@ public class ThreadNameTest {
         private String message;
         private boolean success;
         private boolean client;
+        private CountDownLatch latch;
 
-        ThreadNameVerifyHandler(String msg, boolean client) {
+        ThreadNameVerifyHandler(String msg, boolean client, CountDownLatch 
latch) {
             message = msg;
             this.client = client;
+            this.latch = latch;
         }
 
         public boolean isSuccess() {
@@ -95,6 +104,9 @@ public class ThreadNameTest {
             if (!success) {
                 success = Thread.currentThread().getName().matches(message);
             }
+            if(success) {
+                latch.countDown();
+            }
         }
 
         private void output(String method) {

Reply via email to