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

dataroaring pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 62a03ec24c [feature](regression) add http test action (#17567)
62a03ec24c is described below

commit 62a03ec24c21ec299ca805891b1fcbbd9721c66f
Author: AlexYue <yj976240...@gmail.com>
AuthorDate: Thu Mar 9 15:13:04 2023 +0800

    [feature](regression) add http test action (#17567)
---
 .../doris/regression/action/HttpCliAction.groovy   | 52 +++++++++++++++----
 .../framework/src/main/groovy/suite.gdsl           |  3 +-
 .../suites/demo_p0/httpTest_action.groovy          | 58 ++++++++++++++++++++++
 3 files changed, 101 insertions(+), 12 deletions(-)

diff --git 
a/regression-test/framework/src/main/groovy/org/apache/doris/regression/action/HttpCliAction.groovy
 
b/regression-test/framework/src/main/groovy/org/apache/doris/regression/action/HttpCliAction.groovy
index 7fe00c38a4..6cb3434955 100644
--- 
a/regression-test/framework/src/main/groovy/org/apache/doris/regression/action/HttpCliAction.groovy
+++ 
b/regression-test/framework/src/main/groovy/org/apache/doris/regression/action/HttpCliAction.groovy
@@ -36,6 +36,7 @@ class HttpCliAction implements SuiteAction {
     private String uri
     private String body
     private String result
+    private String op
     private Closure check
     SuiteContext context
 
@@ -67,6 +68,18 @@ class HttpCliAction implements SuiteAction {
         this.body = body
     }
 
+    void op(Closure<String> opSupplier) {
+        this.op = bodySupplier.call()
+    }
+
+    void op(String op) {
+        this.op = op
+    }
+
+    void result(Object result) {
+        this.result = result
+    }
+
     @Override
     void run() {
         try {
@@ -74,24 +87,41 @@ class HttpCliAction implements SuiteAction {
                 uri = "http://$endpoint"; + uri
                 log.info("url : " + uri)
                 log.info("body: " + body)
-                HttpPost httpPost = new HttpPost(uri)
-                StringEntity requestEntity = new StringEntity(
-                        body,
-                        ContentType.APPLICATION_JSON);
-                httpPost.setEntity(requestEntity)
-                client.execute(httpPost).withCloseable { resp ->
-                    resp.withCloseable {
-                        String respJson = 
EntityUtils.toString(resp.getEntity())
-                        def respCode = resp.getStatusLine().getStatusCode()
-                        return new ActionResult(respCode, respJson)
+                log.info("op: " + op)
+
+                if (op == "get") {
+                    HttpGet httpGet = new HttpGet(uri)
+
+                    client.execute(httpGet).withCloseable { resp ->
+                        resp.withCloseable {
+                            String respJson = 
EntityUtils.toString(resp.getEntity())
+                            def respCode = resp.getStatusLine().getStatusCode()
+                            return new ActionResult(respCode, respJson)
+                        }
+                    }
+                } else {
+                    HttpPost httpPost = new HttpPost(uri)
+                    StringEntity requestEntity = new StringEntity(
+                            body,
+                            ContentType.APPLICATION_JSON);
+                    httpPost.setEntity(requestEntity)
+
+                    client.execute(httpPost).withCloseable { resp ->
+                        resp.withCloseable {
+                            String respJson = 
EntityUtils.toString(resp.getEntity())
+                            def respCode = resp.getStatusLine().getStatusCode()
+                            return new ActionResult(respCode, respJson)
+                        }
                     }
                 }
             }
+            log.info("result:${result}".toString())
+            log.info("this.result:${this.result}".toString())
             if (check != null) {
                 check.call(result.respCode, result.body)
             } else {
                 if (this.result != null) {
-                    Assert.assertEquals(this.result, result.body)
+                    Assert.assertEquals(this.result, result)
                 }
             }
         } catch (Throwable t) {
diff --git a/regression-test/framework/src/main/groovy/suite.gdsl 
b/regression-test/framework/src/main/groovy/suite.gdsl
index 7b50692038..da55904de8 100644
--- a/regression-test/framework/src/main/groovy/suite.gdsl
+++ b/regression-test/framework/src/main/groovy/suite.gdsl
@@ -78,7 +78,8 @@ contributor([suiteContext]) {
         if (enclosingCall("check") ||
                 (!enclosingCall("test") &&
                         !enclosingCall("explain") &&
-                        !enclosingCall("streamLoad"))) {
+                        !enclosingCall("streamLoad") &&
+                        !enclosingCall("httpTest"))) {
             // bind other suite method and field
             def suiteClass = findClass(suiteClassName)
             delegatesTo(suiteClass)
diff --git a/regression-test/suites/demo_p0/httpTest_action.groovy 
b/regression-test/suites/demo_p0/httpTest_action.groovy
new file mode 100644
index 0000000000..4eda6aba35
--- /dev/null
+++ b/regression-test/suites/demo_p0/httpTest_action.groovy
@@ -0,0 +1,58 @@
+// 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.
+
+import org.codehaus.groovy.runtime.IOGroovyMethods
+
+suite("http_test_action") {
+    String[][] backends = sql """ show backends """
+    assertTrue(backends.size() > 0)
+    String backendId;
+    def backendIdToBackendIP = [:]
+    def backendIdToBackendBrpcPort = [:]
+    for (String[] backend in backends) {
+        if (backend[9].equals("true")) {
+            backendIdToBackendIP.put(backend[0], backend[2])
+            backendIdToBackendBrpcPort.put(backend[0], backend[6])
+        }
+    }
+
+    backendId = backendIdToBackendIP.keySet()[0]
+    def getMetricsMethod = { check_func ->
+        httpTest {
+            endpoint backendIdToBackendIP.get(backendId) + ":" + 
backendIdToBackendBrpcPort.get(backendId)
+            uri "/brpc_metrics"
+            op "get"
+            check check_func
+        }
+    }
+
+    getMetricsMethod.call() {
+        respCode, body ->
+            logger.info("test ttl expired resp Code {}", 
"${respCode}".toString())
+            assertEquals("${respCode}".toString(), "200")
+            String out = "${body}".toString()
+            def strs = out.split('\n')
+            Boolean flag = false;
+            for (String line in strs) {
+                if (line.contains("bthread_count")) {
+                    flag = true;
+                    break;
+                }
+            }
+            assertTrue(flag);
+    }
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to