You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by im...@apache.org on 2022/06/15 01:52:19 UTC

[incubator-shenyu] branch master updated: [type:Integration Test] Add mqtt-plugin Integration Test (#3553)

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

impactcn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new bdf75419d [type:Integration Test] Add mqtt-plugin Integration Test (#3553)
bdf75419d is described below

commit bdf75419d310d7d8409207aaa3cdbd500e18e609
Author: 尔等同学 <37...@users.noreply.github.com>
AuthorDate: Wed Jun 15 09:52:14 2022 +0800

    [type:Integration Test] Add mqtt-plugin Integration Test (#3553)
    
    * add mqtt plugin test
    
    * fix CI
---
 .../shenyu-integrated-test-http/pom.xml            |  8 +++
 .../test/http/combination/MqttPluginTest.java      | 65 ++++++++++++++++++++++
 2 files changed, 73 insertions(+)

diff --git a/shenyu-integrated-test/shenyu-integrated-test-http/pom.xml b/shenyu-integrated-test/shenyu-integrated-test-http/pom.xml
index 231ff8175..6c4ccbe49 100644
--- a/shenyu-integrated-test/shenyu-integrated-test-http/pom.xml
+++ b/shenyu-integrated-test/shenyu-integrated-test-http/pom.xml
@@ -154,6 +154,14 @@
         </dependency>
         <!-- apache shenyu rewrite plugin end-->
 
+        <!-- apache shenyu mqtt plugin start-->
+        <dependency>
+            <groupId>org.apache.shenyu</groupId>
+            <artifactId>shenyu-spring-boot-starter-plugin-mqtt</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <!-- apache shenyu mqtt plugin end-->
+
         <dependency>
             <groupId>org.apache.shenyu</groupId>
             <artifactId>shenyu-integrated-test-common</artifactId>
diff --git a/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/MqttPluginTest.java b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/MqttPluginTest.java
new file mode 100644
index 000000000..1fac23cce
--- /dev/null
+++ b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/MqttPluginTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.shenyu.integrated.test.http.combination;
+
+import org.apache.shenyu.common.dto.PluginData;
+import org.apache.shenyu.integratedtest.common.AbstractPluginDataInit;
+import org.apache.shenyu.plugin.mqtt.handler.MqttPluginDataHandler;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public final class MqttPluginTest extends AbstractPluginDataInit {
+
+    @Test
+    public void setup() throws IOException, InterruptedException {
+        MqttPluginDataHandler mqttPluginDataHandler = new MqttPluginDataHandler();
+        final PluginData enablePluginData = new PluginData("pluginId", "pluginName", "{\n"
+                + "  \"port\": 9500,"
+                + "  \"bossGroupThreadCount\": 1,"
+                + "  \"maxPayloadSize\": 65536,"
+                + "  \"workerGroupThreadCount\": 12,"
+                + "  \"userName\": \"shenyu\","
+                + "  \"password\": \"shenyu\","
+                + "  \"isEncryptPassword\": false,"
+                + "  \"encryptMode\": \"\","
+                + "  \"leakDetectorLevel\": \"DISABLED\""
+                + "}", "0", true);
+        mqttPluginDataHandler.handlerPlugin(enablePluginData);
+        Thread.sleep(3000);
+        assertTrue(isPortUsing());
+    }
+
+    private boolean isPortUsing() {
+        boolean flag = false;
+        try {
+            InetAddress address = InetAddress.getByName("127.0.0.1");
+            Socket socket = new Socket(address, 9500);
+            flag = true;
+        } catch (Exception ignored) {
+
+        }
+        return flag;
+
+    }
+
+}