Skip to content

Commit ac0c90f

Browse files
Version 2.2.3 - RC2
1 parent 3d788d7 commit ac0c90f

File tree

1 file changed

+42
-12
lines changed

1 file changed

+42
-12
lines changed

src/main/java/io/github/delirius325/jmeter/backendlistener/elasticsearch/ElasticsearchBackend.java

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.apache.http.HttpStatus;
1616
import org.apache.http.entity.ContentType;
1717
import org.apache.http.nio.entity.NStringEntity;
18+
import org.apache.jmeter.assertions.AssertionResult;
1819
import org.apache.jmeter.config.Arguments;
1920
import org.apache.jmeter.samplers.SampleResult;
2021
import org.apache.jmeter.threads.JMeterContextService;
@@ -27,16 +28,17 @@
2728
import org.slf4j.LoggerFactory;
2829

2930
public class ElasticsearchBackend extends AbstractBackendListenerClient {
30-
private static final String BUILD_NUMBER = "BuildNumber";
31-
private static final String ES_SCHEME = "es.scheme";
32-
private static final String ES_HOST = "es.host";
33-
private static final String ES_PORT = "es.port";
34-
private static final String ES_INDEX = "es.index";
35-
private static final String ES_TIMESTAMP = "es.timestamp";
36-
private static final String ES_BULK_SIZE = "es.bulk.size";
37-
private static final String ES_TIMEOUT_MS = "es.timout.ms";
38-
private static final String ES_SAMPLE_FILTER = "es.sample.filter";
39-
private static final String ES_TEST_MODE = "es.test.mode";
31+
private static final String BUILD_NUMBER = "BuildNumber";
32+
private static final String ES_SCHEME = "es.scheme";
33+
private static final String ES_HOST = "es.host";
34+
private static final String ES_PORT = "es.port";
35+
private static final String ES_INDEX = "es.index";
36+
private static final String ES_TIMESTAMP = "es.timestamp";
37+
private static final String ES_BULK_SIZE = "es.bulk.size";
38+
private static final String ES_TIMEOUT_MS = "es.timout.ms";
39+
private static final String ES_SAMPLE_FILTER = "es.sample.filter";
40+
private static final String ES_TEST_MODE = "es.test.mode";
41+
private static final String ES_TRANSPORT_CLIENT = "es.transport.client";
4042
private static final long DEFAULT_TIMEOUT_MS = 200L;
4143
private static final Logger logger = LoggerFactory.getLogger(ElasticsearchBackend.class);
4244

@@ -60,6 +62,9 @@ public Arguments getDefaultParameters() {
6062
parameters.addArgument(ES_TIMEOUT_MS, Long.toString(DEFAULT_TIMEOUT_MS));
6163
parameters.addArgument(ES_SAMPLE_FILTER, null);
6264
parameters.addArgument(ES_TEST_MODE, "debug");
65+
//TODO. In future version - add the support for TransportClient as well for the possibility to choose the ElasticSearch version
66+
//parameters.addArgument(ES_TRANSPORT_CLIENT, "false");
67+
//parameters.addArgument(ES_TRANSPORT_VERSION, "6.2.0");
6368
return parameters;
6469
}
6570

@@ -191,6 +196,9 @@ public Map<String, Object> getElasticData(SampleResult sr, BackendListenerContex
191196
jsonObject.put("ThreadName", sr.getThreadName());
192197
jsonObject.put("URL", sr.getURL());
193198
jsonObject.put("Timestamp", sdf.format(new Date(sr.getTimeStamp())));
199+
jsonObject.put("StartTimeInMs", sr.getStartTime());
200+
jsonObject.put("EndTimeInMs", sr.getEndTime());
201+
jsonObject.put("ElapsedTimeInMs", System.currentTimeMillis() - sr.getStartTime());
194202
jsonObject.put(ElasticsearchBackend.BUILD_NUMBER, this.buildNumber);
195203

196204
// Add the details according to the mode that is set
@@ -199,15 +207,37 @@ public Map<String, Object> getElasticData(SampleResult sr, BackendListenerContex
199207
jsonObject = addDetails(sr, jsonObject);
200208
break;
201209
case "info":
202-
if(!sr.isResponseCodeOK()) {
210+
if(!sr.isSuccessful()) {
203211
jsonObject = addDetails(sr, jsonObject);
204212
}
205213
break;
214+
case "quiet":
215+
break;
206216
default:
207-
logger.warn("The parameter \"es.test.mode\" isn't set properly. Two modes are allowed: debug and info. Debug sends request and response details to ElasticSearch. Info only sends the details if the response is an error, it should be used in production.");
217+
logger.warn("The parameter \"es.test.mode\" isn't set properly. Three modes are allowed: debug ,info, and quiet.");
218+
logger.warn(" -- \"debug\": sends request and response details to ElasticSearch. Info only sends the details if the response has an error.");
219+
logger.warn(" -- \"info\": should be used in production");
220+
logger.warn(" -- \"quiet\": should be used if you don't care to have the details.");
208221
break;
209222
}
210223

224+
//all assertions
225+
AssertionResult[] assertionResults = sr.getAssertionResults();
226+
if(assertionResults != null) {
227+
Map<String, Object>[] assertionArray = new HashMap[assertionResults.length];
228+
Integer i = 0;
229+
for(AssertionResult assertionResult : assertionResults) {
230+
HashMap<String, Object> assertionMap = new HashMap<>();
231+
boolean failure = assertionResult.isFailure() || assertionResult.isError();
232+
assertionMap.put("failure", failure);
233+
assertionMap.put("failureMessage", assertionResult.getFailureMessage());
234+
assertionMap.put("name", assertionResult.getName());
235+
assertionArray[i] = assertionMap;
236+
i++;
237+
}
238+
jsonObject.put("AssertionResults", assertionArray);
239+
}
240+
211241
// If built from Jenkins, add the hard-c oded version to be able to compare response time
212242
// of two builds over the elapsed time
213243
if(this.buildNumber != 0) {

0 commit comments

Comments
 (0)