You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2021/12/20 05:41:20 UTC

[dubbo] branch 3.0.5-release updated: Adjust the way to obtain codec extension (#9442)

This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch 3.0.5-release
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.0.5-release by this push:
     new 3d7557b   Adjust the way to obtain codec extension (#9442)
3d7557b is described below

commit 3d7557b0c44a5cfb84af8bd6cee0cb11407443b7
Author: huazhongming <cr...@gmail.com>
AuthorDate: Mon Dec 20 13:40:05 2021 +0800

     Adjust the way to obtain codec extension (#9442)
    
    Fixes #9440, #9435
---
 .../dubbo/remoting/transport/AbstractEndpoint.java    | 11 ++++++++---
 .../exchange/support/header/HeartbeatHandlerTest.java | 19 +++++++++++--------
 .../remoting/transport/netty/ClientReconnectTest.java |  2 +-
 .../remoting/transport/netty/NettyClientTest.java     |  8 ++++----
 .../transport/netty/NettyClientToServerTest.java      |  4 ++--
 .../remoting/transport/netty/NettyStringTest.java     |  4 ++--
 .../remoting/transport/netty/ThreadNameTest.java      |  4 ++--
 7 files changed, 30 insertions(+), 22 deletions(-)

diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractEndpoint.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractEndpoint.java
index cb442d6..fbba378 100644
--- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractEndpoint.java
+++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractEndpoint.java
@@ -20,6 +20,7 @@ import org.apache.dubbo.common.Resetable;
 import org.apache.dubbo.common.URL;
 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.ChannelHandler;
 import org.apache.dubbo.remoting.Codec;
 import org.apache.dubbo.remoting.Codec2;
@@ -47,13 +48,17 @@ public abstract class AbstractEndpoint extends AbstractPeer implements Resetable
     }
 
     protected static Codec2 getChannelCodec(URL url) {
-        String codecName = url.getProtocol(); // codec extension name must stay the same with protocol name
+        String codecName = url.getParameter(Constants.CODEC_KEY);
+        if (StringUtils.isEmpty(codecName)) {
+            // codec extension name must stay the same with protocol name
+            codecName = url.getProtocol();
+        }
         FrameworkModel frameworkModel = getFrameworkModel(url.getScopeModel());
         if (frameworkModel.getExtensionLoader(Codec2.class).hasExtension(codecName)) {
             return frameworkModel.getExtensionLoader(Codec2.class).getExtension(codecName);
         } else {
             return new CodecAdapter(frameworkModel.getExtensionLoader(Codec.class)
-                    .getExtension(codecName));
+                .getExtension(codecName));
         }
     }
 
@@ -61,7 +66,7 @@ public abstract class AbstractEndpoint extends AbstractPeer implements Resetable
     public void reset(URL url) {
         if (isClosed()) {
             throw new IllegalStateException("Failed to reset parameters "
-                    + url + ", cause: Channel closed. channel: " + getLocalAddress());
+                + url + ", cause: Channel closed. channel: " + getLocalAddress());
         }
 
         try {
diff --git a/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/exchange/support/header/HeartbeatHandlerTest.java b/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/exchange/support/header/HeartbeatHandlerTest.java
index 9836dff..3fbac22 100644
--- a/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/exchange/support/header/HeartbeatHandlerTest.java
+++ b/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/exchange/support/header/HeartbeatHandlerTest.java
@@ -67,9 +67,9 @@ public class HeartbeatHandlerTest {
     public void testServerHeartbeat() throws Exception {
         FakeChannelHandlers.resetChannelHandlers();
         URL serverURL = URL.valueOf("telnet://localhost:" + NetUtils.getAvailablePort(56780))
-                .addParameter(Constants.EXCHANGER_KEY, HeaderExchanger.NAME)
-                .addParameter(Constants.TRANSPORTER_KEY, "netty3")
-                .addParameter(Constants.HEARTBEAT_KEY, 1000);
+            .addParameter(Constants.EXCHANGER_KEY, HeaderExchanger.NAME)
+            .addParameter(Constants.TRANSPORTER_KEY, "netty3")
+            .addParameter(Constants.HEARTBEAT_KEY, 1000);
         CountDownLatch connect = new CountDownLatch(1);
         CountDownLatch disconnect = new CountDownLatch(1);
         TestHeartbeatHandler handler = new TestHeartbeatHandler(connect, disconnect);
@@ -82,6 +82,7 @@ public class HeartbeatHandlerTest {
         // Let the client not reply to the heartbeat, and turn off automatic reconnect to simulate the client dropped.
         serverURL = serverURL.addParameter(Constants.HEARTBEAT_KEY, 600 * 1000);
         serverURL = serverURL.addParameter(Constants.RECONNECT_KEY, false);
+        serverURL = serverURL.addParameter(Constants.CODEC_KEY, "telnet");
 
         client = Exchangers.connect(serverURL);
         disconnect.await();
@@ -92,9 +93,10 @@ public class HeartbeatHandlerTest {
     @Test
     public void testHeartbeat() throws Exception {
         URL serverURL = URL.valueOf("telnet://localhost:" + NetUtils.getAvailablePort(56785))
-                .addParameter(Constants.EXCHANGER_KEY, HeaderExchanger.NAME)
-                .addParameter(Constants.TRANSPORTER_KEY, "netty3")
-                .addParameter(Constants.HEARTBEAT_KEY, 1000);
+            .addParameter(Constants.EXCHANGER_KEY, HeaderExchanger.NAME)
+            .addParameter(Constants.TRANSPORTER_KEY, "netty3")
+            .addParameter(Constants.HEARTBEAT_KEY, 1000)
+            .addParameter(Constants.CODEC_KEY, "telnet");
         CountDownLatch connect = new CountDownLatch(1);
         CountDownLatch disconnect = new CountDownLatch(1);
         TestHeartbeatHandler handler = new TestHeartbeatHandler(connect, disconnect);
@@ -113,8 +115,9 @@ public class HeartbeatHandlerTest {
     public void testClientHeartbeat() throws Exception {
         FakeChannelHandlers.setTestingChannelHandlers();
         URL serverURL = URL.valueOf("telnet://localhost:" + NetUtils.getAvailablePort(56790))
-                .addParameter(Constants.EXCHANGER_KEY, HeaderExchanger.NAME)
-                .addParameter(Constants.TRANSPORTER_KEY, "netty3");
+            .addParameter(Constants.EXCHANGER_KEY, HeaderExchanger.NAME)
+            .addParameter(Constants.TRANSPORTER_KEY, "netty3")
+            .addParameter(Constants.CODEC_KEY, "telnet");
         CountDownLatch connect = new CountDownLatch(1);
         CountDownLatch disconnect = new CountDownLatch(1);
         TestHeartbeatHandler handler = new TestHeartbeatHandler(connect, disconnect);
diff --git a/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/transport/netty/ClientReconnectTest.java b/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/transport/netty/ClientReconnectTest.java
index 167647a..edc65c9 100644
--- a/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/transport/netty/ClientReconnectTest.java
+++ b/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/transport/netty/ClientReconnectTest.java
@@ -70,7 +70,7 @@ public class ClientReconnectTest {
 
 
     public Client startClient(int port, int heartbeat) throws RemotingException {
-        final String url = "exchange://127.0.0.1:" + port + "/client.reconnect.test?check=false&client=netty3&" +
+        final String url = "exchange://127.0.0.1:" + port + "/client.reconnect.test?check=false&codec=exchange&client=netty3&" +
                 Constants.HEARTBEAT_KEY + "=" + heartbeat;
         return Exchangers.connect(url);
     }
diff --git a/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/transport/netty/NettyClientTest.java b/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/transport/netty/NettyClientTest.java
index 6ac5374..076ad34 100644
--- a/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/transport/netty/NettyClientTest.java
+++ b/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/transport/netty/NettyClientTest.java
@@ -40,7 +40,7 @@ public class NettyClientTest {
 
     @BeforeAll
     public static void setUp() throws Exception {
-        server = Exchangers.bind(URL.valueOf("exchange://localhost:" + port + "?server=netty3"), new TelnetServerHandler());
+        server = Exchangers.bind(URL.valueOf("exchange://localhost:" + port + "?server=netty3&codec=exchange"), new TelnetServerHandler());
     }
 
     @AfterAll
@@ -53,7 +53,7 @@ public class NettyClientTest {
     }
 
     public static void main(String[] args) throws RemotingException, InterruptedException {
-        ExchangeChannel client = Exchangers.connect(URL.valueOf("exchange://10.20.153.10:20880?client=netty3&heartbeat=1000"));
+        ExchangeChannel client = Exchangers.connect(URL.valueOf("exchange://10.20.153.10:20880?client=netty3&heartbeat=1000&codec=exchange"));
         Thread.sleep(60 * 1000 * 50);
     }
 
@@ -61,7 +61,7 @@ public class NettyClientTest {
     public void testClientClose() throws Exception {
         List<ExchangeChannel> clients = new ArrayList<ExchangeChannel>(100);
         for (int i = 0; i < 100; i++) {
-            ExchangeChannel client = Exchangers.connect(URL.valueOf("exchange://localhost:" + port + "?client=netty3"));
+            ExchangeChannel client = Exchangers.connect(URL.valueOf("exchange://localhost:" + port + "?client=netty3&codec=exchange"));
             Thread.sleep(5);
             clients.add(client);
         }
@@ -74,7 +74,7 @@ public class NettyClientTest {
     @Test
     public void testServerClose() throws Exception {
         for (int i = 0; i < 100; i++) {
-            RemotingServer aServer = Exchangers.bind(URL.valueOf("exchange://localhost:" + NetUtils.getAvailablePort(6000) + "?server=netty3"), new TelnetServerHandler());
+            RemotingServer aServer = Exchangers.bind(URL.valueOf("exchange://localhost:" + NetUtils.getAvailablePort(6000) + "?server=netty3&codec=exchange"), new TelnetServerHandler());
             aServer.close();
         }
     }
diff --git a/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/transport/netty/NettyClientToServerTest.java b/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/transport/netty/NettyClientToServerTest.java
index 4bc62df..51d8bd4 100644
--- a/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/transport/netty/NettyClientToServerTest.java
+++ b/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/transport/netty/NettyClientToServerTest.java
@@ -31,14 +31,14 @@ public class NettyClientToServerTest extends ClientToServerTest {
 
     protected ExchangeServer newServer(int port, Replier<?> receiver) throws RemotingException {
         // add heartbeat cycle to avoid unstable ut.
-        URL url = URL.valueOf("exchange://localhost:" + port + "?server=netty3");
+        URL url = URL.valueOf("exchange://localhost:" + port + "?server=netty3&codec=exchange");
         url = url.addParameter(Constants.HEARTBEAT_KEY, 600 * 1000);
         return Exchangers.bind(url, receiver);
     }
 
     protected ExchangeChannel newClient(int port) throws RemotingException {
         // add heartbeat cycle to avoid unstable ut.
-        URL url = URL.valueOf("exchange://localhost:" + port + "?client=netty3&timeout=3000");
+        URL url = URL.valueOf("exchange://localhost:" + port + "?client=netty3&timeout=3000&codec=exchange");
         url = url.addParameter(Constants.HEARTBEAT_KEY, 600 * 1000);
         return Exchangers.connect(url);
     }
diff --git a/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/transport/netty/NettyStringTest.java b/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/transport/netty/NettyStringTest.java
index d08d781..6781897 100644
--- a/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/transport/netty/NettyStringTest.java
+++ b/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/transport/netty/NettyStringTest.java
@@ -40,8 +40,8 @@ public class NettyStringTest {
         //int port = 10001;
         int port = NetUtils.getAvailablePort();
         System.out.println(port);
-        server = Exchangers.bind(URL.valueOf("telnet://0.0.0.0:" + port + "?server=netty3"), new TelnetServerHandler());
-        client = Exchangers.connect(URL.valueOf("telnet://127.0.0.1:" + port + "?client=netty3"), new TelnetClientHandler());
+        server = Exchangers.bind(URL.valueOf("telnet://0.0.0.0:" + port + "?server=netty3&codec=telnet"), new TelnetServerHandler());
+        client = Exchangers.connect(URL.valueOf("telnet://127.0.0.1:" + port + "?client=netty3&codec=telnet"), new TelnetClientHandler());
     }
 
     @AfterAll
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 abb02a8..26c5edc 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
@@ -51,10 +51,10 @@ public class ThreadNameTest {
     @BeforeEach
     public void before() throws Exception {
         int port = NetUtils.getAvailablePort(20880 + new Random().nextInt(10000));
-        serverURL = URL.valueOf("telnet://localhost?side=provider")
+        serverURL = URL.valueOf("telnet://localhost?side=provider&codec=telnet")
             .setPort(port)
             .setScopeModel(ApplicationModel.defaultModel());
-        clientURL = URL.valueOf("telnet://localhost?side=consumer")
+        clientURL = URL.valueOf("telnet://localhost?side=consumer&codec=telnet")
             .setPort(port)
             .setScopeModel(ApplicationModel.defaultModel());