From 04704265d8d2dde7b839c7f743538bad860f0f86 Mon Sep 17 00:00:00 2001 From: ByteYue Date: Wed, 8 Mar 2023 17:32:20 +0800 Subject: [PATCH] add http test action --- .../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(-) create mode 100644 regression-test/suites/demo_p0/httpTest_action.groovy 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 7fe00c38a45ff0..6cb343495572d0 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 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 7b50692038c23b..da55904de87e25 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 00000000000000..4eda6aba35cdf5 --- /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