【发布时间】:2016-09-09 10:59:37
【问题描述】:
我正在尝试在使用HttpClient 版本4.5 的类上编写测试。我写的测试真的很慢,所以我试图隔离问题。我可以编写一个测试来证明我的问题:
public class RequeteurRESTTest extends LocalServerTestBase {
private String startServer(String urlSuffix, HttpRequestHandler handler) throws Exception{
this.serverBootstrap.registerHandler(urlSuffix, handler);
HttpHost target = start();
String serverUrl = "http://localhost:" + target.getPort();
return serverUrl;
}
@Test
public void testCase() throws Exception{
String baseURL = startServer("/api", new HttpRequestHandler() {
@Override
public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
response.setStatusCode(HttpStatus.SC_OK);
}
});
HttpClient httpClient;
httpClient = HttpClients.custom().build();
HttpGet method = new HttpGet(baseURL + "/api");
HttpResponse response = httpClient.execute(method);
}
}
我遇到的问题是指令:
httpClient.execute(method)
执行需要 10 秒。这很慢,但我不明白为什么这么慢。我是否在测试中犯了任何错误,或者忘记了什么?
【问题讨论】:
-
它执行正确吗?即您的被测服务器是否被调用?
-
处理程序被正确调用,是的
标签: performance testing apache-httpclient-4.x