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

jooks 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 5ba8e13c2 [type:Integration Test] add integrated-test of 
logging-rocketmq-plugin (#3672)
5ba8e13c2 is described below

commit 5ba8e13c2c3cf330bb30924190ca6a97fb112283
Author: 尔等同学 <[email protected]>
AuthorDate: Wed Jul 6 23:54:15 2022 +0800

    [type:Integration Test] add integrated-test of logging-rocketmq-plugin 
(#3672)
    
    * add addRocketMqTest
    
    * add license
    
    * fix ci
    
    * fix workflow
    
    * add clean plugin method
    
    * update rocketmq image
---
 .../shenyu-integrated-test-http/config/broker.conf | 23 ++++++
 .../shenyu-integrated-test-http/docker-compose.yml | 43 ++++++++++-
 .../shenyu-integrated-test-http/pom.xml            |  8 ++
 .../test/http/combination/RocketMqPluginTest.java  | 88 ++++++++++++++++++++++
 4 files changed, 161 insertions(+), 1 deletion(-)

diff --git 
a/shenyu-integrated-test/shenyu-integrated-test-http/config/broker.conf 
b/shenyu-integrated-test/shenyu-integrated-test-http/config/broker.conf
new file mode 100644
index 000000000..6f7c02497
--- /dev/null
+++ b/shenyu-integrated-test/shenyu-integrated-test-http/config/broker.conf
@@ -0,0 +1,23 @@
+# 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.
+
+brokerName = shenyu-broker
+brokerId = 0
+deleteWhen = 04
+fileReservedTime = 48
+brokerRole = ASYNC_MASTER 
+flushDiskType = ASYNC_FLUSH
+autoCreateTopicEnable=true
\ No newline at end of file
diff --git 
a/shenyu-integrated-test/shenyu-integrated-test-http/docker-compose.yml 
b/shenyu-integrated-test/shenyu-integrated-test-http/docker-compose.yml
index 8f7b9912b..8616dfb3a 100644
--- a/shenyu-integrated-test/shenyu-integrated-test-http/docker-compose.yml
+++ b/shenyu-integrated-test/shenyu-integrated-test-http/docker-compose.yml
@@ -81,7 +81,7 @@ services:
         limits:
           memory: 2048M
     environment:
-      - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket          
+      - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket
     depends_on:
       shenyu-admin:
         condition: service_healthy
@@ -128,6 +128,47 @@ services:
       timeout: 2s
       retries: 30
 
+  shenyu-rocketmq:
+    image: apache/rocketmq:4.9.3
+    container_name: shenyu-rocketmq
+    restart: always
+    depends_on:
+      shenyu-integrated-test-http:
+        condition: service_healthy
+    ports:
+      - "9876:9876"
+    environment:
+      JAVA_OPT_EXT: "-server -Xms1g -Xmx1g"
+    volumes:
+      - ./logs:/root/logs
+    command: sh mqnamesrv
+    networks:
+      shenyu:
+        aliases:
+          -  shenyu-rocketmq
+
+  shenyu-rmqbroker:
+    image: apache/rocketmq:4.9.3
+    container_name: shenyu-rmqbroker
+    restart: always
+    depends_on:
+      - shenyu-rocketmq
+    ports:
+      - 10909:10909
+      - 10911:10911
+    volumes:
+      - ./logs:/root/logs
+      - ./store:/root/store
+      - ./config/broker.conf:/opt/rocketmq-4.4.0/conf/broker.conf
+    command: sh mqbroker  -c /opt/rocketmq-4.4.0/conf/broker.conf
+    environment:
+      NAMESRV_ADDR: "shenyu-rocketmq:9876"
+      JAVA_OPT_EXT: "-server -Xms1g -Xmx1g -Xmn1g"
+    networks:
+      shenyu:
+        aliases:
+          - shenyu-rmqbroker
+
 networks:
   shenyu:
     name: shenyu
diff --git a/shenyu-integrated-test/shenyu-integrated-test-http/pom.xml 
b/shenyu-integrated-test/shenyu-integrated-test-http/pom.xml
index 7aeace73e..0266f5b57 100644
--- a/shenyu-integrated-test/shenyu-integrated-test-http/pom.xml
+++ b/shenyu-integrated-test/shenyu-integrated-test-http/pom.xml
@@ -178,6 +178,14 @@
         </dependency>
         <!--shenyu logging-elasticsearch plugin end-->
 
+        <!--shenyu logging-rocketmq plugin start-->
+        <dependency>
+            <groupId>org.apache.shenyu</groupId>
+            
<artifactId>shenyu-spring-boot-starter-plugin-logging-rocketmq</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <!--shenyu logging-rocketmq 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/RocketMqPluginTest.java
 
b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/RocketMqPluginTest.java
new file mode 100644
index 000000000..84d92b8f2
--- /dev/null
+++ 
b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/RocketMqPluginTest.java
@@ -0,0 +1,88 @@
+/*
+ * 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.common.enums.PluginEnum;
+import org.apache.shenyu.common.utils.GsonUtils;
+import org.apache.shenyu.integratedtest.common.AbstractPluginDataInit;
+import org.apache.shenyu.plugin.logging.common.entity.ShenyuRequestLog;
+import org.apache.shenyu.plugin.logging.rocketmq.config.LogCollectConfig;
+import 
org.apache.shenyu.plugin.logging.rocketmq.client.RocketMQLogCollectClient;
+import org.apache.shenyu.plugin.logging.rocketmq.constant.LoggingConstant;
+import 
org.apache.shenyu.plugin.logging.rocketmq.utils.RocketLogCollectConfigUtils;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+
+public final class RocketMqPluginTest extends AbstractPluginDataInit {
+
+    private final RocketMQLogCollectClient rocketMQLogCollectClient = new 
RocketMQLogCollectClient();
+
+    private final PluginData pluginData = new PluginData();
+
+    private final Properties properties = new Properties();
+
+    private final List<ShenyuRequestLog> logs = new ArrayList<>();
+
+    private final ShenyuRequestLog shenyuRequestLog = new ShenyuRequestLog();
+
+    @BeforeEach
+    public void setup() throws IOException {
+        String pluginResult = initPlugin(PluginEnum.LOGGING_ROCKETMQ.getName(),
+                "{\"topic\":\"rocket-mq-test\", 
\"namesrvAddr\":\"shenyu-rocketmq:9876\", 
\"producerGroup\":\"shenyu-plugin-logging-rocketmq\"}");
+        assertThat(pluginResult, is("success"));
+    }
+
+    @Test
+    public void testPass() {
+        final LogCollectConfig.GlobalLogConfig globalLogConfig = 
GsonUtils.getInstance().fromJson(pluginData.getConfig(), 
LogCollectConfig.GlobalLogConfig.class);
+        properties.setProperty(LoggingConstant.TOPIC, "shenyu-access-logging");
+        properties.setProperty(LoggingConstant.NAMESERVER_ADDRESS, 
"shenyu-rocketmq:9876");
+        properties.setProperty(LoggingConstant.PRODUCER_GROUP, 
"shenyu-plugin-logging-rocketmq");
+
+        shenyuRequestLog.setClientIp("0.0.0.0");
+        shenyuRequestLog.setPath("org/apache/shenyu/plugin/logging");
+        logs.add(shenyuRequestLog);
+
+        String msg = "";
+        RocketLogCollectConfigUtils.setGlobalConfig(globalLogConfig);
+        rocketMQLogCollectClient.initProducer(properties);
+        try {
+            rocketMQLogCollectClient.consume(logs);
+        } catch (Exception e) {
+            msg = "false";
+        }
+        Assertions.assertEquals(msg, "");
+        rocketMQLogCollectClient.close();
+    }
+
+    @AfterAll
+    public static void clean() throws IOException {
+        cleanPluginData(PluginEnum.LOGGING_ROCKETMQ.getName());
+    }
+}

Reply via email to