@@ -32,7 +32,7 @@ public class ElasticSearchMetric {
3232 private boolean allResHeaders ;
3333
3434 public ElasticSearchMetric (SampleResult sr , String testMode , String timeStamp , int buildNumber ,
35- boolean parseReqHeaders , boolean parseResHeaders , Set <String > fields ) {
35+ boolean parseReqHeaders , boolean parseResHeaders , Set <String > fields ) {
3636 this .sampleResult = sr ;
3737 this .esTestMode = testMode .trim ();
3838 this .esTimestamp = timeStamp .trim ();
@@ -45,9 +45,8 @@ public ElasticSearchMetric(SampleResult sr, String testMode, String timeStamp, i
4545
4646 /**
4747 * This method returns the current metric as a Map(String, Object) for the provided sampleResult
48- *
49- * @param context
50- * BackendListenerContext
48+ *
49+ * @param context BackendListenerContext
5150 * @return a JSON Object as Map(String, Object)
5251 */
5352 public Map <String , Object > getMetric (BackendListenerContext context ) throws Exception {
@@ -74,27 +73,27 @@ public Map<String, Object> getMetric(BackendListenerContext context) throws Exce
7473 addFilteredJSON ("TestStartTime" , JMeterContextService .getTestStartTime ());
7574 addFilteredJSON ("SampleStartTime" , sdf .format (new Date (this .sampleResult .getStartTime ())));
7675 addFilteredJSON ("SampleEndTime" , sdf .format (new Date (this .sampleResult .getEndTime ())));
77- addFilteredJSON ("Timestamp" , sdf . format ( new Date ( this .sampleResult .getTimeStamp ()) ));
76+ addFilteredJSON ("Timestamp" , this .sampleResult .getTimeStamp ());
7877 addFilteredJSON ("InjectorHostname" , InetAddress .getLocalHost ().getHostName ());
7978
8079 // Add the details according to the mode that is set
8180 switch (this .esTestMode ) {
82- case "debug" :
83- addDetails ();
84- break ;
85- case "error" :
86- addDetails ();
87- break ;
88- case "info" :
89- if (!this .sampleResult .isSuccessful ())
81+ case "debug" :
82+ addDetails ();
83+ break ;
84+ case "error" :
9085 addDetails ();
91- break ;
92- default :
93- break ;
86+ break ;
87+ case "info" :
88+ if (!this .sampleResult .isSuccessful ())
89+ addDetails ();
90+ break ;
91+ default :
92+ break ;
9493 }
9594
9695 addAssertions ();
97- addElapsedTime (sdf );
96+ addElapsedTime ();
9897 addCustomFields (context );
9998 parseHeadersAsJsonProps (this .allReqHeaders , this .allResHeaders );
10099
@@ -103,7 +102,6 @@ public Map<String, Object> getMetric(BackendListenerContext context) throws Exce
103102
104103 /**
105104 * This method adds all the assertions for the current sampleResult
106- *
107105 */
108106 private void addAssertions () {
109107 AssertionResult [] assertionResults = this .sampleResult .getAssertionResults ();
@@ -133,31 +131,27 @@ private void addAssertions() {
133131 * This method adds the ElapsedTime as a key:value pair in the JSON object. Also, depending on whether or not the
134132 * tests were launched from a CI tool (i.e Jenkins), it will add a hard-coded version of the ElapsedTime for results
135133 * comparison purposes
136- *
137- * @param sdf
138- * SimpleDateFormat
139134 */
140- private void addElapsedTime (SimpleDateFormat sdf ) {
135+ private void addElapsedTime () {
141136 Date elapsedTime ;
142137
143138 if (this .ciBuildNumber != 0 ) {
144139 elapsedTime = getElapsedTime (true );
145140 addFilteredJSON ("BuildNumber" , this .ciBuildNumber );
146141
147142 if (elapsedTime != null )
148- addFilteredJSON ("ElapsedTimeComparison" , sdf . format ( elapsedTime ));
143+ addFilteredJSON ("ElapsedTimeComparison" , elapsedTime . getTime ( ));
149144 }
150145
151146 elapsedTime = getElapsedTime (false );
152147 if (elapsedTime != null )
153- addFilteredJSON ("ElapsedTime" , sdf . format ( elapsedTime ));
148+ addFilteredJSON ("ElapsedTime" , elapsedTime . getTime ( ));
154149 }
155150
156151 /**
157152 * Methods that add all custom fields added by the user in the Backend Listener's GUI panel
158153 *
159- * @param context
160- * BackendListenerContext
154+ * @param context BackendListenerContext
161155 */
162156 private void addCustomFields (BackendListenerContext context ) {
163157 Iterator <String > pluginParameters = context .getParameterNamesIterator ();
@@ -180,7 +174,6 @@ private void addCustomFields(BackendListenerContext context) {
180174
181175 /**
182176 * Method that adds the request and response's body/headers
183- *
184177 */
185178 private void addDetails () {
186179 addFilteredJSON ("RequestHeaders" , this .sampleResult .getRequestHeaders ());
@@ -195,52 +188,50 @@ private void addDetails() {
195188 * all headers into different ElasticSearch document properties by passing "true" This is a work-around the native
196189 * behaviour of JMeter where variables are not accessible within the backend listener.
197190 *
198- * @param allReqHeaders
199- * boolean to determine if the user wants to separate ALL request headers into different ES JSON
200- * properties.
201- * @param allResHeaders
202- * boolean to determine if the user wants to separate ALL response headers into different ES JSON
203- * properties.
204- *
205- * NOTE: This will be fixed as soon as a patch comes in for JMeter to change the behaviour.
191+ * @param allReqHeaders boolean to determine if the user wants to separate ALL request headers into different ES JSON
192+ * properties.
193+ * @param allResHeaders boolean to determine if the user wants to separate ALL response headers into different ES JSON
194+ * properties.
195+ * <p>
196+ * NOTE: This will be fixed as soon as a patch comes in for JMeter to change the behaviour.
206197 */
207198 private void parseHeadersAsJsonProps (boolean allReqHeaders , boolean allResHeaders ) {
208199 LinkedList <String []> headersArrayList = new LinkedList <String []>();
209-
210- if (allReqHeaders ) {
211- headersArrayList .add (this .sampleResult .getRequestHeaders ().split ("\n " ));
212- }
213200
214- if (allResHeaders ) {
215- headersArrayList .add (this .sampleResult .getResponseHeaders ().split ("\n " ));
216- }
217-
218- if (!allReqHeaders && !allResHeaders ) {
219- headersArrayList .add (this .sampleResult .getRequestHeaders ().split ("\n " ));
220- headersArrayList .add (this .sampleResult .getResponseHeaders ().split ("\n " ));
221- }
201+ if (allReqHeaders ) {
202+ headersArrayList .add (this .sampleResult .getRequestHeaders ().split ("\n " ));
203+ }
204+
205+ if (allResHeaders ) {
206+ headersArrayList .add (this .sampleResult .getResponseHeaders ().split ("\n " ));
207+ }
208+
209+ if (!allReqHeaders && !allResHeaders ) {
210+ headersArrayList .add (this .sampleResult .getRequestHeaders ().split ("\n " ));
211+ headersArrayList .add (this .sampleResult .getResponseHeaders ().split ("\n " ));
212+ }
222213
223- for (String [] lines : headersArrayList ) {
224- for (int i = 0 ; i < lines .length ; i ++) {
225- String [] header = lines [i ].split (":" ,2 );
214+ for (String [] lines : headersArrayList ) {
215+ for (int i = 0 ; i < lines .length ; i ++) {
216+ String [] header = lines [i ].split (":" , 2 );
226217
227218 // if not all res/req headers and header contains special X-tag
228219 if (!allReqHeaders && !allResHeaders && header .length > 1 ) {
229220 if (header [0 ].startsWith ("X-es-backend" )) {
230221 this .json .put (header [0 ].replaceAll ("X-es-backend-" , "" ).trim (), header [1 ].trim ());
231- }
232- }
233-
222+ }
223+ }
224+
234225 if ((allReqHeaders || allResHeaders ) && header .length > 1 ) {
235- this .json .put (header [0 ].trim (), header [1 ].trim ());
236- }
237- }
226+ this .json .put (header [0 ].trim (), header [1 ].trim ());
227+ }
228+ }
238229 }
239230 }
240231
241232 /**
242233 * Adds a given key-value pair to JSON if the key is contained in the field filter or in case of empty field filter
243- *
234+ *
244235 * @param key
245236 * @param value
246237 */
@@ -255,8 +246,7 @@ private void addFilteredJSON(String key, Object value) {
255246 * build comparison in Kibana. By doing this, the user is able to set the X-axis of his graph to this date and split
256247 * the series by build numbers. It allows him to overlap test results and see if there is regression or not.
257248 *
258- * @param forBuildComparison
259- * boolean to determine if there is CI (continuous integration) or not
249+ * @param forBuildComparison boolean to determine if there is CI (continuous integration) or not
260250 * @return The elapsed time in YYYY-MM-dd HH:mm:ss format
261251 */
262252 public Date getElapsedTime (boolean forBuildComparison ) {
0 commit comments