This is an automated email from the ASF dual-hosted git repository. albumenj pushed a commit to branch 2.6.10-release in repository https://gitbox.apache.org/repos/asf/dubbo.git
commit 6cea97fcade6d50321adb99750344902c432ef0c Author: Albumen Kevin <[email protected]> AuthorDate: Mon May 17 11:50:45 2021 +0800 Fix UT - Port --- .../remoting/exchange/support/header/HeartbeatHandlerTest.java | 8 ++++---- .../dubbo/remoting/transport/netty/ClientReconnectTest.java | 8 ++++---- .../alibaba/dubbo/remoting/transport/netty/ThreadNameTest.java | 3 ++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/dubbo-remoting/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/exchange/support/header/HeartbeatHandlerTest.java b/dubbo-remoting/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/exchange/support/header/HeartbeatHandlerTest.java index b8f7218..43d1ed2 100644 --- a/dubbo-remoting/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/exchange/support/header/HeartbeatHandlerTest.java +++ b/dubbo-remoting/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/exchange/support/header/HeartbeatHandlerTest.java @@ -21,6 +21,7 @@ import com.alibaba.dubbo.common.Constants; import com.alibaba.dubbo.common.URL; import com.alibaba.dubbo.common.logger.Logger; import com.alibaba.dubbo.common.logger.LoggerFactory; +import com.alibaba.dubbo.common.utils.NetUtils; import com.alibaba.dubbo.remoting.Channel; import com.alibaba.dubbo.remoting.RemotingException; import com.alibaba.dubbo.remoting.exchange.ExchangeChannel; @@ -29,7 +30,6 @@ import com.alibaba.dubbo.remoting.exchange.ExchangeHandler; import com.alibaba.dubbo.remoting.exchange.ExchangeServer; import com.alibaba.dubbo.remoting.exchange.Exchangers; import com.alibaba.dubbo.remoting.transport.dispatcher.FakeChannelHandlers; - import junit.framework.Assert; import org.junit.After; import org.junit.Test; @@ -56,7 +56,7 @@ public class HeartbeatHandlerTest { @Test public void testServerHeartbeat() throws Exception { - URL serverURL = URL.valueOf("header://localhost:55555?transporter=netty3"); + URL serverURL = URL.valueOf("header://localhost:" + NetUtils.getAvailablePort() + "?transporter=netty3"); serverURL = serverURL.addParameter(Constants.HEARTBEAT_KEY, 1000); TestHeartbeatHandler handler = new TestHeartbeatHandler(); server = Exchangers.bind(serverURL, handler); @@ -72,7 +72,7 @@ public class HeartbeatHandlerTest { @Test public void testHeartbeat() throws Exception { - URL serverURL = URL.valueOf("header://localhost:55555?transporter=netty3"); + URL serverURL = URL.valueOf("header://localhost:" + NetUtils.getAvailablePort() + "?transporter=netty3"); serverURL = serverURL.addParameter(Constants.HEARTBEAT_KEY, 1000); TestHeartbeatHandler handler = new TestHeartbeatHandler(); server = Exchangers.bind(serverURL, handler); @@ -89,7 +89,7 @@ public class HeartbeatHandlerTest { @Test public void testClientHeartbeat() throws Exception { FakeChannelHandlers.setTestingChannelHandlers(); - URL serverURL = URL.valueOf("header://localhost:55555?transporter=netty3"); + URL serverURL = URL.valueOf("header://localhost:" + NetUtils.getAvailablePort() + "?transporter=netty3"); TestHeartbeatHandler handler = new TestHeartbeatHandler(); server = Exchangers.bind(serverURL, handler); System.out.println("Server bind successfully"); diff --git a/dubbo-remoting/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/transport/netty/ClientReconnectTest.java b/dubbo-remoting/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/transport/netty/ClientReconnectTest.java index 1f1107e..5527c77 100644 --- a/dubbo-remoting/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/transport/netty/ClientReconnectTest.java +++ b/dubbo-remoting/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/transport/netty/ClientReconnectTest.java @@ -52,7 +52,7 @@ public class ClientReconnectTest { Client client = startClient(port, 200); Assert.assertEquals(false, client.isConnected()); Server server = startServer(port); - for (int i = 0; i < 100 && !client.isConnected(); i++) { + for (int i = 0; i < 1000 && !client.isConnected(); i++) { Thread.sleep(10); } Assert.assertEquals(true, client.isConnected()); @@ -80,7 +80,7 @@ public class ClientReconnectTest { public void testReconnectWarnLog() throws RemotingException, InterruptedException { int port = NetUtils.getAvailablePort(); DubboAppender.doStart(); - String url = "exchange://127.0.0.2:" + port + "/client.reconnect.test?check=false&client=netty3&" + String url = "exchange://127.0.0.2:" + port + "/client.reconnect.test?check=false&client=netty3&" + Constants.RECONNECT_KEY + "=" + 1; //1ms reconnect, ensure that there is enough frequency to reconnect try { Exchangers.connect(url); @@ -97,12 +97,12 @@ public class ClientReconnectTest { } public Client startClient(int port, int reconnectPeriod) throws RemotingException { - final String url = "exchange://127.0.0.1:" + port + "/client.reconnect.test?check=false&client=netty3&" + Constants.RECONNECT_KEY + "=" + reconnectPeriod; + final String url = "exchange://127.0.0.1:" + port + "/client.reconnect.test?check=false&client=netty3&" + Constants.RECONNECT_KEY + "=" + reconnectPeriod; return Exchangers.connect(url); } public Server startServer(int port) throws RemotingException { - final String url = "exchange://127.0.0.1:" + port + "/client.reconnect.test?server=netty3"; + final String url = "exchange://127.0.0.1:" + port + "/client.reconnect.test?server=netty3"; return Exchangers.bind(url, new HandlerAdapter()); } diff --git a/dubbo-remoting/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/transport/netty/ThreadNameTest.java b/dubbo-remoting/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/transport/netty/ThreadNameTest.java index 9050161..cb6b23d 100644 --- a/dubbo-remoting/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/transport/netty/ThreadNameTest.java +++ b/dubbo-remoting/dubbo-remoting-netty/src/test/java/com/alibaba/dubbo/remoting/transport/netty/ThreadNameTest.java @@ -17,6 +17,7 @@ package com.alibaba.dubbo.remoting.transport.netty; import com.alibaba.dubbo.common.URL; +import com.alibaba.dubbo.common.utils.NetUtils; import com.alibaba.dubbo.remoting.Channel; import com.alibaba.dubbo.remoting.ChannelHandler; import com.alibaba.dubbo.remoting.RemotingException; @@ -39,7 +40,7 @@ public class ThreadNameTest { @Before public void before() throws Exception { - int port = 55555; + int port = NetUtils.getAvailablePort(); serverURL = URL.valueOf("netty://localhost").setPort(port); clientURL = URL.valueOf("netty://localhost").setPort(port);
