Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -67,31 +68,60 @@ 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 {
def result = HttpClients.createDefault().withCloseable { client ->
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) {
Expand Down
3 changes: 2 additions & 1 deletion regression-test/framework/src/main/groovy/suite.gdsl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
58 changes: 58 additions & 0 deletions regression-test/suites/demo_p0/httpTest_action.groovy
Original file line number Diff line number Diff line change
@@ -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);
}
}