This is an automated email from the ASF dual-hosted git repository.
fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git
The following commit(s) were added to refs/heads/master by this push:
new 84fbdbb Strip results with subresults deeper in their hierarchy when
DataStripping is enabled
84fbdbb is described below
commit 84fbdbbf96704e00c9e6c905c4833c7e7006b2d0
Author: Felix Schumacher <[email protected]>
AuthorDate: Sat Aug 24 17:14:20 2019 +0200
Strip results with subresults deeper in their hierarchy when DataStripping
is enabled
SampleResults will now be stripped recursively up to a level of four when
DataStripping is enabled.
As Sonar nagged to widen the scope for readResolve to better support
inheritance and it made testing
possible, readResolve is now protected instead of private.
Bugzilla Id: 63674
---
.../jmeter/samplers/DataStrippingSampleSender.java | 21 ++--
.../samplers/TestDataStrippingSampleSender.java | 130 +++++++++++++++++++++
xdocs/changes.xml | 2 +
3 files changed, 146 insertions(+), 7 deletions(-)
diff --git
a/src/core/src/main/java/org/apache/jmeter/samplers/DataStrippingSampleSender.java
b/src/core/src/main/java/org/apache/jmeter/samplers/DataStrippingSampleSender.java
index 8fba027..6d185a9 100644
---
a/src/core/src/main/java/org/apache/jmeter/samplers/DataStrippingSampleSender.java
+++
b/src/core/src/main/java/org/apache/jmeter/samplers/DataStrippingSampleSender.java
@@ -92,12 +92,7 @@ public class DataStrippingSampleSender extends
AbstractSampleSender implements S
//Strip the response data before writing, but only for a successful
request.
SampleResult result = event.getResult();
if(stripAlsoOnError || result.isSuccessful()) {
- // Compute bytes before stripping
- stripResponse(result);
- // see Bug 57449
- for (SampleResult subResult : result.getSubResults()) {
- stripResponse(subResult);
- }
+ stripContent(result, 3);
}
if(decoratedSender == null)
{
@@ -113,6 +108,18 @@ public class DataStrippingSampleSender extends
AbstractSampleSender implements S
}
}
+ private void stripContent(SampleResult result, int level) {
+ if (level < 0) {
+ return;
+ }
+ // Compute bytes before stripping
+ stripResponse(result);
+ // see Bug 57449 and 63674
+ for (SampleResult subResult : result.getSubResults()) {
+ stripContent(subResult, level - 1);
+ }
+ }
+
/**
* Strip response but fill in bytes field.
* @param result {@link SampleResult}
@@ -129,7 +136,7 @@ public class DataStrippingSampleSender extends
AbstractSampleSender implements S
* @throws ObjectStreamException
* never
*/
- private Object readResolve() throws ObjectStreamException{
+ protected Object readResolve() throws ObjectStreamException{
if (isClientConfigured()) {
stripAlsoOnError = clientConfiguredStripAlsoOnError;
} else {
diff --git
a/src/core/src/test/java/org/apache/jmeter/samplers/TestDataStrippingSampleSender.java
b/src/core/src/test/java/org/apache/jmeter/samplers/TestDataStrippingSampleSender.java
new file mode 100644
index 0000000..8cef590
--- /dev/null
+++
b/src/core/src/test/java/org/apache/jmeter/samplers/TestDataStrippingSampleSender.java
@@ -0,0 +1,130 @@
+/*
+ * 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.samplers;
+
+import static java.lang.Boolean.FALSE;
+import static java.lang.Boolean.TRUE;
+import static org.junit.Assert.assertThat;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.jmeter.junit.JMeterTestCase;
+import org.apache.jmeter.util.JMeterUtils;
+import org.apache.jorphan.test.JMeterSerialTest;
+import org.hamcrest.CoreMatchers;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class TestDataStrippingSampleSender extends JMeterTestCase implements
JMeterSerialTest {
+
+ private static final String TEST_CONTENT = "Something important";
+
+ @Parameters(name = "is successful sample: {0}, expected content after
stripping: {1}, stripOnFailure: {2}")
+ public static Collection<Object[]> parameters() {
+ return Arrays.asList(
+ new Object[] {TRUE, "", TRUE},
+ new Object[] {TRUE, "", FALSE},
+ new Object[] {FALSE, "", TRUE},
+ new Object[] {FALSE, TEST_CONTENT, FALSE}
+ );
+ }
+
+ @Parameter(0) public Boolean successfulParent;
+ @Parameter(1) public String content;
+ @Parameter(2) public Boolean stripOnError;
+
+
+ @Test
+ public void testSampleOccurred() throws IOException {
+ Path props = Files.createTempFile("mydummy", ".properties");
+ JMeterUtils.loadJMeterProperties(props.toString());
+
JMeterUtils.getJMeterProperties().setProperty("sample_sender_strip_also_on_error",
stripOnError.toString());
+ SimpleSender nextSender = new SimpleSender();
+ DataStrippingSampleSender sut = new
DataStrippingSampleSender(nextSender);
+ sut.readResolve();
+ SampleResult sample = result(successfulParent.booleanValue(),
result(result(result())));
+ sut.sampleOccurred(event(sample));
+ assertResultsHaveContent(content, sample);
+ assertThat(sample, CoreMatchers.is(nextSender.getResult()));
+ }
+
+ private void assertResultsHaveContent(String content, SampleResult sample)
{
+ assertThat(sample.getResponseDataAsString(), CoreMatchers.is(content));
+ for (SampleResult subResult : sample.getSubResults()) {
+ assertResultsHaveContent(content, subResult);
+ }
+ }
+
+ private static SampleEvent event(SampleResult result) {
+ return new SampleEvent(result, "tg-one");
+ }
+
+ private static SampleResult result() {
+ return result(true);
+ }
+
+ private static SampleResult result(SampleResult... subResults) {
+ return result(true, subResults);
+ }
+
+ private static SampleResult result(boolean isSuccess, SampleResult...
subResults) {
+ SampleResult result = new SampleResult();
+ result.setSuccessful(isSuccess);
+ result.setResponseData(TEST_CONTENT, StandardCharsets.UTF_8.name());
+ for (SampleResult subResult : subResults) {
+ result.addSubResult(subResult);
+ }
+ return result;
+ }
+
+ private class SimpleSender implements SampleSender {
+
+ private SampleResult result;
+
+ public SampleResult getResult() {
+ return result;
+ }
+
+ @Override
+ public void testEnded() {
+ // nothing to implement here
+ }
+
+ @Override
+ public void testEnded(String host) {
+ // nothing to implement here
+ }
+
+ @Override
+ public void sampleOccurred(SampleEvent e) {
+ this.result = e.getResult();
+
+ }
+
+ }
+}
diff --git a/xdocs/changes.xml b/xdocs/changes.xml
index cb6713c..03d7195 100644
--- a/xdocs/changes.xml
+++ b/xdocs/changes.xml
@@ -173,6 +173,7 @@ to view the last release notes of version 5.1.1.
<li><bug>63423</bug>Selection of table rows in Aggregate Graph gets lost
too often</li>
<li><bug>63347</bug>View result tree: The search field is so small that
even a single character is not visible on Windows 7</li>
<li><bug>63433</bug>ListenerNotifier: Detected problem in Listener
NullPointerException if filename is null. Contributed by Ubik Load Pack
(support at ubikloadpack.com)</li>
+ <li><bug>63674</bug>Strip results with subresults deeper in their
hierarchy when DataStripping is enabled</li>
</ul>
<h3>Timers, Assertions, Config, Pre- & Post-Processors</h3>
@@ -230,6 +231,7 @@ to view the last release notes of version 5.1.1.
<li>Amer Ghazal (amerghazal at gmail.com)</li>
<li>Stefan Seide (stefan at trilobyte-se.de)</li>
<li>Havlicek Honza (havlicek.honza at gmail.com)</li>
+ <li>Pierre Astruc (pierre.astruc at evertest.com)</li>
</ul>
<p>
Apologies if we have omitted anyone else.