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

jinrongtong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-e2e.git


The following commit(s) were added to refs/heads/master by this push:
     new 47d3165   [ISSUE #3] Add description to README.md and optimized code 
(#4)
47d3165 is described below

commit 47d316508ee01cd62c3e4bdbbc837b75375a8ad4
Author: yueya <[email protected]>
AuthorDate: Thu Nov 24 16:16:06 2022 +0800

     [ISSUE #3] Add description to README.md and optimized code (#4)
    
    * Modify the method of reading a local property file
    
    (cherry picked from commit 66c85b5482124d6e6b446fa03996619a219eb57e)
    
    * Modify README.md
    
    (cherry picked from commit 0c77d6a9087381f068b3c49d9ec80da1d86a2347)
    
    * remove some useless annotations
    
    (cherry picked from commit ae501bb4432fe13bcb2755a4cb86d5dba6b08570)
---
 README.md                                          |  36 +++++++
 .../org/apache/rocketmq/frame/ResourceInit.java    | 117 ++++++++++++++-------
 2 files changed, 116 insertions(+), 37 deletions(-)

diff --git a/README.md b/README.md
index 875be46..c1081e8 100644
--- a/README.md
+++ b/README.md
@@ -3,3 +3,39 @@
 
 RocketMQ E2E Test
 
+### Test Case Coverage
+* Message Type
+  * Normal message
+  * Transaction message
+  * Order message
+  * Delay message
+* Producer
+  * Sync Send 
+  * Async Send
+* PushConsumer
+* SimpleConsumer
+  * Order/Delay/Transaction/Normal
+  * Sync receive/Async receive
+  * Sync ack/Async ack
+* Client init
+  * Parameter settings
+* Message
+  * Tag 
+  * Body 
+  * Key
+  * User property
+* Filter
+  * Tag
+  * Sql
+* Retry
+  * Normal message
+  * Order message
+  
+#### How to start
+```angular2html
+mvn clean test -B -Dgroups=smoke -Dcluster=DefaultCluster
+```
+##### Options
+* `ALL_IP` : not required, default is null 
+* `cluster`: not required, default `DefaultCluster`
+* `groups`: param of junit5, 
`src/main/java/org/apache/rocketmq/enums/TESTSET.java`
\ No newline at end of file
diff --git a/src/main/java/org/apache/rocketmq/frame/ResourceInit.java 
b/src/main/java/org/apache/rocketmq/frame/ResourceInit.java
index 7f9255a..2a8b237 100644
--- a/src/main/java/org/apache/rocketmq/frame/ResourceInit.java
+++ b/src/main/java/org/apache/rocketmq/frame/ResourceInit.java
@@ -23,8 +23,9 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.InetSocketAddress;
 import java.net.Socket;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Properties;
-import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.lang3.exception.ExceptionUtils;
 import org.apache.rocketmq.account.Account;
 import org.apache.rocketmq.util.MQAdmin;
@@ -45,22 +46,26 @@ public class ResourceInit {
     protected static String endPoint = null;
     protected static String namesrvAddr = null;
     protected static Boolean aclEnable = null;
+    protected static String ALL_IP;
     protected static String cluster;
-    protected static MQAdmin mqAdmin;
+    protected static List<String> nameserverIpList = new ArrayList<>();
+    protected static List<String> brokerIpList = new ArrayList<>();
+    protected static List<String> proxyIpList = new ArrayList<>();
+    protected static String nameserverPort = "9876";
+    protected static String endPointPort = "8081";
+    private static Properties properties = null;
 
     static {
         initResource();
         MQAdmin.initMQAdminExtInstance(namesrvAddr);
-        log.info("init process success");
+        log.info("Init process success");
     }
 
-    //Initializing the console
     private static void initResource() {
-        Properties properties = null;
         try {
             String env = System.getProperty("env", "daily");
             String region = System.getProperty("region", "daily");
-            InputStream inputStream = 
ResourceInit.class.getResourceAsStream(String.format("/env/%s/%s.conf", env, 
region));
+            InputStream inputStream = new 
FileInputStream(String.format("src/test/resources/env/%s/%s.conf", env, 
region));
             log.info("INIT - use config env:{}, config:{}", env, region);
             properties = configFileHelper.loadConfig(inputStream);
         } catch (Exception e) {
@@ -68,33 +73,85 @@ public class ResourceInit {
             log.info("INIT - execute error,exit the process");
             System.exit(0);
         }
+        // init endpoint and nameserver
+        initConnectionInfo();
+        initAcl();
 
-        endPoint = System.getProperty("endPoint", 
properties.getProperty("endPoint"));
-        namesrvAddr = System.getProperty("namesrvAddr", 
properties.getProperty("namesrvAddr"));
-        cluster = System.getProperty("cluster", 
properties.getProperty("cluster"));
-        aclEnable = Boolean.parseBoolean(System.getProperty("aclEnable", 
properties.getProperty("aclEnable", "false")));
+        String endPointIp = endPoint.substring(0, endPoint.indexOf(":"));
+        String endPointPort = endPoint.substring(endPoint.lastIndexOf(":") + 
1);
+        checkConnection(endPointIp, endPointPort);
+
+        String namesrvAddrIp = namesrvAddr.substring(0, 
namesrvAddr.indexOf(":"));
+        String namesrvAddrPort = 
namesrvAddr.substring(namesrvAddr.lastIndexOf(":") + 1);
+        checkConnection(namesrvAddrIp, namesrvAddrPort);
 
+    }
+
+    private static void initAcl() {
+        aclEnable = Boolean.parseBoolean(System.getProperty("aclEnable", 
properties.getProperty("aclEnable", "false")));
         if (aclEnable) {
             String instanceUsername = System.getProperty("INSTANCE_USERNAME", 
properties.getProperty("INSTANCE_USERNAME"));
             String instancePassword = System.getProperty("INSTANCE_PASSWORD", 
properties.getProperty("INSTANCE_PASSWORD"));
             account = new Account(instanceUsername, instancePassword);
-            log.info("INIT - ENV [instanceUsername:{}, instancePassword:{}]", 
instanceUsername, instancePassword);
+            log.info("INIT - acl is enabled, [instanceUsername:{}, 
instancePassword:{}]", instanceUsername, instancePassword);
         } else {
+            log.info("INIT - acl is disabled");
             account = new Account(endPoint);
         }
-        String testDomain = endPoint.substring(0, endPoint.indexOf(":"));
-        String testPort = endPoint.substring(endPoint.lastIndexOf(":") + 1);
-        //tcp endpoint connect check
-        boolean isEndPointConnected = telnet(testDomain, 
Integer.parseInt(testPort), 5000);
-        if (!isEndPointConnected) {
-            log.error("INIT - TCP endpoint connectivity check: telnet {} {} 
==> timeout: {}, isConnected: false", testDomain, testPort, 5000);
+    }
+
+    private static void initConnectionInfo() {
+        ALL_IP = System.getProperty("ALL_IP", 
properties.getProperty("ALL_IP"));
+        if (ALL_IP != null) {
+            String[] allPodInfos = ALL_IP.split(",");
+            for (String podInfo : allPodInfos) {
+                if (podInfo.contains("nameserver")) {
+                    
nameserverIpList.add(podInfo.substring(podInfo.indexOf(":") + 1));
+                } else if (podInfo.contains("broker")) {
+                    brokerIpList.add(podInfo.substring(podInfo.indexOf(":") + 
1));
+                } else if (podInfo.contains("proxy")) {
+                    proxyIpList.add(podInfo.substring(podInfo.indexOf(":") + 
1));
+                }
+            }
+            if (proxyIpList.isEmpty()) {
+                if (brokerIpList.isEmpty()) {
+                    log.warn("INIT- Get broker from external is empty");
+                    endPoint = System.getProperty("endPoint", 
properties.getProperty("endPoint"));
+                } else {
+                    endPoint = brokerIpList.get(0) + ":" + endPointPort;
+                }
+            } else {
+                log.info("INIT- Use enable-proxy model or 4.x model");
+                endPoint = proxyIpList.get(0) + ":" + endPointPort;
+            }
+            if (nameserverIpList.isEmpty()) {
+                log.warn("INIT- Get nameserver from external is empty");
+                namesrvAddr = System.getProperty("namesrvAddr", 
properties.getProperty("namesrvAddr"));
+            } else {
+                namesrvAddr = nameserverIpList.get(0) + ":" + nameserverPort;
+            }
+        } else {
+            log.info("INIT- Get ALL_IP is null, use local info");
+            endPoint = System.getProperty("endPoint", 
properties.getProperty("endPoint"));
+            namesrvAddr = System.getProperty("namesrvAddr", 
properties.getProperty("namesrvAddr"));
+        }
+        cluster = System.getProperty("cluster", 
properties.getProperty("cluster"));
+        if (cluster == null) {
+            log.error("INIT- cluster is null, system exit");
+            System.exit(-1);
+        }
+        log.info("INIT- endPoint:{}, namesrvAddr:{}, cluster:{}", endPoint, 
namesrvAddr, cluster);
+    }
+
+    private static void checkConnection(String ip, String port) {
+        boolean isConnected = telnet(ip, Integer.parseInt(port), 5000);
+        if (!isConnected) {
+            log.error("INIT - check: telnet {} {} ==> timeout: {}, 
isConnected: false", ip, port, 5000);
             log.error("INIT - Warning, exit!!!");
             System.exit(0);
         } else {
-            log.info("INIT - TCP endpoint connectivity check: telnet {} {} ==> 
isConnected: true", testDomain, testPort);
+            log.info("INIT - check: telnet {} {} ==> isConnected: true", ip, 
port);
         }
-
-        log.info("INIT - ENV [endpoint:{}]", endPoint);
     }
 
     public static class SystemConfigFileHelper {
@@ -132,31 +189,17 @@ public class ResourceInit {
         }
     }
 
-    /**
-     * Generated md5
-     *
-     * @param className  className
-     * @param methodName methodName
-     * @return md5
-     */
-    protected static String getMD5Sum(String className, String methodName) {
-        String completeName = String.format("%s_%s", className, methodName);
-        return methodName + "_" + 
DigestUtils.md5Hex(completeName).substring(0, 6);
-    }
-
     public static boolean telnet(String hostname, int port, int timeout) {
         Socket socket = new Socket();
         boolean isConnected = false;
         try {
-            socket.connect(new InetSocketAddress(hostname, port), timeout); // 
connection
-            isConnected = socket.isConnected(); // Check the connectivity 
status using existing methods
+            socket.connect(new InetSocketAddress(hostname, port), timeout);
+            isConnected = socket.isConnected();
         } catch (IOException e) {
-            log.error("telnet test false");        // When the connection is 
disconnected, throw the exception directly, the exception can be captured
         } finally {
             try {
-                socket.close();   // Closing the connection
+                socket.close();
             } catch (IOException e) {
-                log.error("telnet test false");
             }
         }
         return isConnected;

Reply via email to