You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/06/30 03:15:09 UTC

[dubbo] branch 3.0 updated: Add test case for MultiplexProtocolConnectionManager (#8164)

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 dc6dc64  Add test case for MultiplexProtocolConnectionManager (#8164)
dc6dc64 is described below

commit dc6dc64b5335a3f3a36f2d99a73b2791078ee4b0
Author: xiaoheng1 <20...@qq.com>
AuthorDate: Wed Jun 30 11:14:59 2021 +0800

    Add test case for MultiplexProtocolConnectionManager (#8164)
---
 .../MultiplexProtocolConnectionManagerTest.java    | 72 +++++++++++++++++++++
 .../api/SingleProtocolConnectionManagerTest.java   | 74 ++++++++++++++++++++++
 2 files changed, 146 insertions(+)

diff --git a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/api/MultiplexProtocolConnectionManagerTest.java b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/api/MultiplexProtocolConnectionManagerTest.java
new file mode 100644
index 0000000..c969d04
--- /dev/null
+++ b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/api/MultiplexProtocolConnectionManagerTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.remoting.api;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.extension.ExtensionLoader;
+import org.apache.dubbo.remoting.RemotingException;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.Field;
+import java.util.Map;
+import java.util.function.Consumer;
+
+public class MultiplexProtocolConnectionManagerTest {
+    private ConnectionManager connectionManager = ExtensionLoader.getExtensionLoader(ConnectionManager.class).getExtension("multiple");
+
+    @Test
+    public void testConnect() throws Exception {
+        URL url = URL.valueOf("empty://127.0.0.1:8080?foo=bar");
+        Connection connect = connectionManager.connect(url);
+        Assertions.assertNotNull(connect);
+        Field protocolsField = connectionManager.getClass().getDeclaredField("protocols");
+        protocolsField.setAccessible(true);
+        Map protocolMap = (Map) protocolsField.get(connectionManager);
+        Assertions.assertNotNull(protocolMap.get(url.getProtocol()));
+        connect.close();
+    }
+
+    @Test
+    public void testForEachConnection() throws RemotingException {
+        {
+            URL url = URL.valueOf("empty://127.0.0.1:8080?foo=bar");
+            Connection connect = connectionManager.connect(url);
+        }
+        {
+            URL url = URL.valueOf("tri://127.0.0.1:8080?foo=bar");
+            Connection connect = connectionManager.connect(url);
+        }
+
+        Consumer<Connection> consumer = new Consumer<Connection>() {
+            @Override
+            public void accept(Connection connection) {
+                try {
+                    Assertions.assertEquals("empty", connection.getUrl().getProtocol());
+                } catch (Exception e) {
+                    Assertions.assertEquals("tri", connection.getUrl().getProtocol());
+                }
+
+            }
+        };
+
+        connectionManager.forEachConnection(consumer);
+    }
+
+}
+
diff --git a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/api/SingleProtocolConnectionManagerTest.java b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/api/SingleProtocolConnectionManagerTest.java
new file mode 100644
index 0000000..077b3ec
--- /dev/null
+++ b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/api/SingleProtocolConnectionManagerTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.remoting.api;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.extension.ExtensionLoader;
+import org.apache.dubbo.remoting.RemotingException;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.Field;
+import java.util.Map;
+import java.util.function.Consumer;
+
+public class SingleProtocolConnectionManagerTest {
+
+    private ConnectionManager connectionManager = ExtensionLoader.getExtensionLoader(ConnectionManager.class).getExtension("single");
+
+    @Test
+    public void testConnect() throws Exception {
+        URL url = URL.valueOf("empty://127.0.0.1:8080?foo=bar");
+        Connection connect = connectionManager.connect(url);
+        Assertions.assertNotNull(connect);
+        Field protocolsField = connectionManager.getClass().getDeclaredField("connections");
+        protocolsField.setAccessible(true);
+        Map protocolMap = (Map) protocolsField.get(connectionManager);
+        Assertions.assertNotNull(protocolMap.get(url.getAddress()));
+        connect.close();
+    }
+
+    @Test
+    public void testForEachConnection() throws RemotingException {
+        URL url = URL.valueOf("empty://127.0.0.1:8080?foo=bar");
+        Connection connect = connectionManager.connect(url);
+
+        {
+            Consumer<Connection> consumer1 = new Consumer<Connection>() {
+                @Override
+                public void accept(Connection connection) {
+                    Assertions.assertEquals( "empty", connection.getUrl().getProtocol());
+                }
+            };
+
+            connectionManager.forEachConnection(consumer1);
+        }
+
+        {
+            Consumer<Connection> consumer2 = new Consumer<Connection>() {
+                @Override
+                public void accept(Connection connection) {
+                    Assertions.assertNotEquals( "not-empty", connection.getUrl().getProtocol());
+                }
+            };
+
+            connectionManager.forEachConnection(consumer2);
+        }
+
+    }
+}