You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2018/03/24 20:16:35 UTC
svn commit: r1827674 - in /jmeter/trunk:
src/components/org/apache/jmeter/visualizers/backend/
src/core/org/apache/jmeter/report/processor/
src/core/org/apache/jmeter/report/utils/
src/core/org/apache/jmeter/samplers/ src/core/org/apache/jmeter/save/ s...
Author: pmouawad
Date: Sat Mar 24 20:16:35 2018
New Revision: 1827674
URL: http://svn.apache.org/viewvc?rev=1827674&view=rev
Log:
Bug 62209 InfluxBackendListenerClient: First Assertion Failure Message must be sent if error code and response code are empty or ok
Bugzilla Id: 62209
Added:
jmeter/trunk/src/core/org/apache/jmeter/report/utils/
jmeter/trunk/src/core/org/apache/jmeter/report/utils/MetricUtils.java (with props)
Modified:
jmeter/trunk/src/components/org/apache/jmeter/visualizers/backend/ErrorMetric.java
jmeter/trunk/src/core/org/apache/jmeter/report/processor/ErrorsSummaryConsumer.java
jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleResult.java
jmeter/trunk/src/core/org/apache/jmeter/save/CSVSaveService.java
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
jmeter/trunk/test/src/org/apache/jmeter/report/processor/ErrorsSummaryConsumerTest.java
jmeter/trunk/xdocs/changes.xml
Modified: jmeter/trunk/src/components/org/apache/jmeter/visualizers/backend/ErrorMetric.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/visualizers/backend/ErrorMetric.java?rev=1827674&r1=1827673&r2=1827674&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/visualizers/backend/ErrorMetric.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/visualizers/backend/ErrorMetric.java Sat Mar 24 20:16:35 2018
@@ -18,6 +18,8 @@
package org.apache.jmeter.visualizers.backend;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.jmeter.report.utils.MetricUtils;
import org.apache.jmeter.samplers.SampleResult;
/**
@@ -40,8 +42,15 @@ public class ErrorMetric {
}
public ErrorMetric(SampleResult result) {
- responseCode = result.getResponseCode();
- responseMessage = result.getResponseMessage();
+ if (MetricUtils.isSuccessCode(responseCode) ||
+ (StringUtils.isEmpty(responseCode) &&
+ !StringUtils.isEmpty(result.getFirstAssertionFailureMessage()))) {
+ responseCode = MetricUtils.ASSERTION_FAILED;
+ responseMessage = result.getFirstAssertionFailureMessage();
+ } else {
+ responseCode = result.getResponseCode();
+ responseMessage = result.getResponseMessage();
+ }
}
/**
Modified: jmeter/trunk/src/core/org/apache/jmeter/report/processor/ErrorsSummaryConsumer.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/report/processor/ErrorsSummaryConsumer.java?rev=1827674&r1=1827673&r2=1827674&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/report/processor/ErrorsSummaryConsumer.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/report/processor/ErrorsSummaryConsumer.java Sat Mar 24 20:16:35 2018
@@ -20,6 +20,7 @@ package org.apache.jmeter.report.process
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.report.core.Sample;
+import org.apache.jmeter.report.utils.MetricUtils;
import org.apache.jmeter.samplers.SampleSaveConfiguration;
import org.apache.jmeter.util.JMeterUtils;
@@ -39,7 +40,6 @@ public class ErrorsSummaryConsumer exten
SampleSaveConfiguration.ASSERTION_RESULTS_FAILURE_MESSAGE_PROP,
true);
- static final String ASSERTION_FAILED = "Assertion failed"; //$NON-NLS-1$
private static final Long ZERO = Long.valueOf(0);
private long errorCount = 0L;
@@ -90,10 +90,10 @@ public class ErrorsSummaryConsumer exten
String responseMessage = sample.getResponseMessage();
String key = responseCode + (!StringUtils.isEmpty(responseMessage) ?
"/" + StringEscapeUtils.escapeJson(StringEscapeUtils.escapeHtml4(responseMessage)) : "");
- if (isSuccessCode(responseCode) ||
+ if (MetricUtils.isSuccessCode(responseCode) ||
(StringUtils.isEmpty(responseCode) &&
!StringUtils.isEmpty(sample.getFailureMessage()))) {
- key = ASSERTION_FAILED;
+ key = MetricUtils.ASSERTION_FAILED;
if (ASSERTION_RESULTS_FAILURE_MESSAGE) {
String msg = sample.getFailureMessage();
if (!StringUtils.isEmpty(msg)) {
@@ -133,29 +133,6 @@ public class ErrorsSummaryConsumer exten
}
}
- /**
- * Determine if the HTTP status code is successful or not i.e. in range 200
- * to 399 inclusive
- *
- * @param codeAsString
- * status code to check
- * @return whether in range 200-399 or not
- *
- * FIXME Duplicates HTTPSamplerBase#isSuccessCode but it's in http
- * protocol
- */
- static boolean isSuccessCode(String codeAsString) {
- if (StringUtils.isNumeric(codeAsString)) {
- try {
- int code = Integer.parseInt(codeAsString);
- return code >= 200 && code <= 399;
- } catch (NumberFormatException ex) {
- return false;
- }
- }
- return false;
- }
-
/*
* (non-Javadoc)
*
Added: jmeter/trunk/src/core/org/apache/jmeter/report/utils/MetricUtils.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/report/utils/MetricUtils.java?rev=1827674&view=auto
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/report/utils/MetricUtils.java (added)
+++ jmeter/trunk/src/core/org/apache/jmeter/report/utils/MetricUtils.java Sat Mar 24 20:16:35 2018
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.jmeter.report.utils;
+
+import org.apache.commons.lang3.StringUtils;
+
+/**
+ * @since 4.1
+ */
+public class MetricUtils {
+ public static final String ASSERTION_FAILED = "Assertion failed"; //$NON-NLS-1$
+
+ /**
+ *
+ */
+ private MetricUtils() {
+ super();
+ }
+
+ /**
+ * Determine if the HTTP status code is successful or not i.e. in range 200
+ * to 399 inclusive
+ *
+ * @param codeAsString
+ * status code to check
+ * @return whether in range 200-399 or not
+ */
+ public static boolean isSuccessCode(String codeAsString) {
+ if (StringUtils.isNumeric(codeAsString)) {
+ try {
+ int code = Integer.parseInt(codeAsString);
+ return isSuccessCode(code);
+ } catch (NumberFormatException ex) {
+ return false;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * @param code Response code
+ * @return true if code is between 200 and 399 included
+ */
+ public static boolean isSuccessCode(int code) {
+ return code >= 200 && code <= 399;
+ }
+}
Propchange: jmeter/trunk/src/core/org/apache/jmeter/report/utils/MetricUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jmeter/trunk/src/core/org/apache/jmeter/report/utils/MetricUtils.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleResult.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleResult.java?rev=1827674&r1=1827673&r2=1827674&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleResult.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleResult.java Sat Mar 24 20:16:35 2018
@@ -1517,4 +1517,23 @@ public class SampleResult implements Ser
public void setIgnore() {
this.ignore = true;
}
+
+ /**
+ * @return String first non null assertion failure message
+ */
+ public String getFirstAssertionFailureMessage() {
+ String message = null;
+ AssertionResult[] results = getAssertionResults();
+
+ if (results != null) {
+ // Find the first non-null message
+ for (AssertionResult result : results) {
+ message = result.getFailureMessage();
+ if (message != null) {
+ break;
+ }
+ }
+ }
+ return message;
+ }
}
Modified: jmeter/trunk/src/core/org/apache/jmeter/save/CSVSaveService.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/save/CSVSaveService.java?rev=1827674&r1=1827673&r2=1827674&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/save/CSVSaveService.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/save/CSVSaveService.java Sat Mar 24 20:16:35 2018
@@ -41,7 +41,6 @@ import javax.swing.table.DefaultTableMod
import org.apache.commons.collections.map.LinkedMap;
import org.apache.commons.lang3.CharUtils;
import org.apache.commons.lang3.StringUtils;
-import org.apache.jmeter.assertions.AssertionResult;
import org.apache.jmeter.reporters.ResultCollector;
import org.apache.jmeter.samplers.SampleEvent;
import org.apache.jmeter.samplers.SampleResult;
@@ -837,19 +836,7 @@ public final class CSVSaveService {
}
if (saveConfig.saveAssertionResultsFailureMessage()) {
- String message = null;
- AssertionResult[] results = sample.getAssertionResults();
-
- if (results != null) {
- // Find the first non-null message
- for (AssertionResult result : results) {
- message = result.getFailureMessage();
- if (message != null) {
- break;
- }
- }
- }
-
+ String message = sample.getFirstAssertionFailureMessage();
if (message != null) {
text.append(message);
} else {
Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java?rev=1827674&r1=1827673&r2=1827674&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java (original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java Sat Mar 24 20:16:35 2018
@@ -65,6 +65,7 @@ import org.apache.jmeter.protocol.http.u
import org.apache.jmeter.protocol.http.util.HTTPConstantsInterface;
import org.apache.jmeter.protocol.http.util.HTTPFileArg;
import org.apache.jmeter.protocol.http.util.HTTPFileArgs;
+import org.apache.jmeter.report.utils.MetricUtils;
import org.apache.jmeter.samplers.AbstractSampler;
import org.apache.jmeter.samplers.Entry;
import org.apache.jmeter.samplers.SampleResult;
@@ -1669,7 +1670,7 @@ public abstract class HTTPSamplerBase ex
* @return whether in range 200-399 or not
*/
protected boolean isSuccessCode(int code) {
- return code >= 200 && code <= 399;
+ return MetricUtils.isSuccessCode(code);
}
protected static String encodeBackSlashes(String value) {
Modified: jmeter/trunk/test/src/org/apache/jmeter/report/processor/ErrorsSummaryConsumerTest.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/report/processor/ErrorsSummaryConsumerTest.java?rev=1827674&r1=1827673&r2=1827674&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/report/processor/ErrorsSummaryConsumerTest.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/report/processor/ErrorsSummaryConsumerTest.java Sat Mar 24 20:16:35 2018
@@ -19,6 +19,7 @@ package org.apache.jmeter.report.process
import org.apache.jmeter.report.core.Sample;
import org.apache.jmeter.report.core.SampleMetadata;
+import org.apache.jmeter.report.utils.MetricUtils;
import org.apache.jmeter.save.CSVSaveService;
import org.junit.Assert;
import org.junit.Test;
@@ -46,7 +47,7 @@ public class ErrorsSummaryConsumerTest {
ErrorsSummaryConsumer.getErrorKey(sample));
sample = new Sample(0, metadata, new String[] { "true", "200", "", "" });
- Assert.assertEquals(ErrorsSummaryConsumer.ASSERTION_FAILED, ErrorsSummaryConsumer.getErrorKey(sample));
+ Assert.assertEquals(MetricUtils.ASSERTION_FAILED, ErrorsSummaryConsumer.getErrorKey(sample));
sample = new Sample(0, metadata, new String[] { "false", "500", "Server Error", "FailureMessage" });
Assert.assertEquals("500/Server Error", ErrorsSummaryConsumer.getErrorKey(sample));
Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1827674&r1=1827673&r2=1827674&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Sat Mar 24 20:16:35 2018
@@ -100,6 +100,7 @@ this behaviour, set <code>httpclient.res
<h3>Listeners</h3>
<ul>
<li><bug>62195</bug>Save Responses to a file : Improve component and UI. Contributed by Ubik Load Pack (support at ubikloadpack.com)</li>
+ <li><bug>62209</bug>InfluxBackendListenerClient: First Assertion Failure Message must be sent if error code and response code are empty or ok</li>
</ul>
<h3>Timers, Assertions, Config, Pre- & Post-Processors</h3>