I want to create a simple load tester that posts a file to a service
endpoint.
Are there any existing samples that have all the best-practices in place
and that also does this in a group of threads?
As a starting point, can you guys critique my method that posts a file
please.
I am creating a single instance of the client that I will pass to this
function:
CloseableHttpClient httpClient = HttpClients.createDefault();
private static int PostToApi(CloseableHttpClient httpClient, File xmlFile)
throws IOException {
HttpPost httpPost = new HttpPost("http://localhost:8090/a/b/c/");
httpPost.setEntity(new FileEntity(xmlFile, "text/xml,
application/xml"));
CloseableHttpResponse response = httpClient.execute(httpPost);
int responseCode = 0;
try {
BufferedReader reader = new BufferedReader(new
InputStreamReader(response.getEntity().getContent()));
String line = "";
while ((line = reader.readLine()) != null) {
System.out.println(line);
if(line.equals("OK")) {
responseCode = 1;
}
}
} finally {
response.close();
}
return responseCode;
}
What can I do to make this more stable and fast/effecient etc?
This is for load testing and it will be called thousands of times per
second hopefully so I want some advice on how to clean it up.