Design and Implementation of a Distributed Load‑Testing Framework Using HttpRequestBase in FunTester
This article outlines the planning, design, and Java implementation of a distributed load‑testing framework called FunTester, focusing on two test‑case schemes (case transmission and execution), an HttpRequestBase‑based demo, case creation, transmission, execution, and the complete FunRequest class code.
In recent work planning, a distributed load‑testing framework has been scheduled, and the FunTester project already provides several features needed for distributed performance testing.
HttpRequestBase‑Based Load‑Testing Scenario
The author discusses a simple scenario that uses a single or multiple fixed HttpRequestBase objects. Although this approach lacks parameterization, upstream/downstream calls, and pre/post processing, it offers easy case transmission, direct execution via the framework, good compatibility, and the ability to extract functional test cases for reuse.
Demo Implementation
The demo is divided into three parts: request line, request headers, and request body. An example shows how to build a HttpPost request, but because the POST entity cannot be copied directly, a custom intermediate object is created.
public static void main(String[] args) throws UnsupportedEncodingException {
HttpPost httpPost = getHttpPost("http://localhost:12345/test/qps");
httpPost.addHeader(getHeader("token", "324u2u09uweidlxnvldfsad"));
httpPost.setEntity(new StringEntity(getJson("name=FunTester").toString(), DEFAULT_CHARSET));
}Using fastJSON for serialization, the author demonstrates converting the request to JSON and back, then executing it and printing the response.
INFO-> 当前用户:oker,工作目录:/Users/oker/IdeaProjects/funtester/,系统编码格式:UTF-8,系统Mac OS X版本:10.16
WARN-> 响应体非json格式,已经自动转换成json格式!
INFO-> 请求uri:http://localhost:12345/test/qps , 耗时:236 ms , HTTPcode: 200
...The initial POST copy fails, so a custom FunRequest object is introduced to encapsulate the request and enable proper serialization.
public static void main(String[] args) {
HttpPost httpPost = getHttpPost("http://localhost:12345/post");
httpPost.addHeader(getHeader("token", "324u2u09uweidlxnvldfsad"));
httpPost.setEntity(new StringEntity(getJson("name=FunTester").toString(), DEFAULT_CHARSET));
httpPost.addHeader(HttpClientConstant.ContentType_JSON);
JSONObject httpResponse = getHttpResponse(httpPost);
output(httpResponse);
FunRequest funRequest = FunRequest.initFromRequest(httpPost);
HttpRequestBase request = funRequest.getRequest();
JSONObject httpResponse1 = getHttpResponse(request);
output(httpResponse1);
String s = JSON.toJSONString(funRequest);
HttpRequestBase httpRequestBase = FunRequest.initFromString(s).getRequest();
JSONObject httpResponse2 = getHttpResponse(httpRequestBase);
output(httpResponse2);
}Case Creation
Cases are simple HttpRequestBase objects wrapped by com.funtester.httpclient.FunRequest. The article provides a static method to generate a FunRequest instance and shows how to serialize it to a JSON string.
static FunRequest getCase001() {
HttpPost httpPost = getHttpPost("http://localhost:12345/post");
httpPost.addHeader(getHeader("token", "324u2u09uweidlxnvldfsad"));
httpPost.setEntity(new StringEntity(getJson("name=FunTester").toString(), DEFAULT_CHARSET));
httpPost.addHeader(HttpClientConstant.ContentType_JSON);
return FunRequest.initFromRequest(httpPost);
}Case Transmission
After converting a case to a string, it can be uploaded to a master service via a POST API, which then distributes the case to slave services (currently a Spring Boot implementation) for execution.
static boolean updateCase() {
HttpPost httpPost = getHttpPost("http://localhost:12345/updatecase");
httpPost.addHeader(getHeader("token", "324u2u09uweidlxnvldfsad"));
JSONObject json = getJson("name=FunTester");
json.put("FunTester", getCase002());
httpPost.setEntity(new StringEntity(json.toString(), DEFAULT_CHARSET));
httpPost.addHeader(HttpClientConstant.ContentType_JSON);
JSONObject httpResponse = getHttpResponse(httpPost);
return isRight(httpResponse);
}Case Execution
On the slave side, cases are parsed and executed either as single HttpRequestBase objects or as a list of objects handled by a multithreaded RequestThreadTimes model.
static void executeCase(CaseBase caseBase) {
FunRequest funRequest = caseBase.getFunRequest();
int thread = caseBase.getThread();
int times = caseBase.getTimes();
int runup = caseBase.getRunup();
String name = caseBase.getName();
RequestThreadTimes requestThreadTimes = new RequestThreadTimes(funRequest.getRequest(), times);
Concurrent concurrent = new Concurrent(requestThreadTimes, thread, name);
Constant.RUNUP_TIME = runup * 1.0;
concurrent.start();
}Full FunRequest Code
The article concludes with the complete source code of the FunRequest class, which encapsulates request type, URL components, headers, parameters, JSON bodies, response handling, conversion to cURL commands, and utilities for cloning and serialization.
Overall, the post provides a practical guide for building, transmitting, and executing distributed HTTP‑based performance test cases in Java.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
