From 926f9e882ade6c20ec08b791a88a5726492ddf7f Mon Sep 17 00:00:00 2001 From: Philippe Mouawad Date: Mon, 4 Feb 2019 20:19:53 +0000 Subject: [PATCH] Bug 63055 Don't rename SampleResult Label when test is running in Functional mode or property subresults.disable_renaming=true. Implemented by Artem Fedorov (artem.fedorov at blazemeter.com) and contributed by BlazeMeter. This closes #439 Bugzilla Id: 63055 git-svn-id: https://svn.apache.org/repos/asf/jmeter/trunk@1852943 13f79535-47bb-0310-9956-ffa450edef68 Former-commit-id: 1a404502428559231c2d8dee35c097e96bf2c90a --- bin/jmeter.properties | 13 +++++++++ .../apache/jmeter/samplers/SampleResult.java | 20 +++++++++++--- .../jmeter/samplers/TestSampleResult.java | 27 +++++++++++++++++++ xdocs/changes.xml | 1 + xdocs/usermanual/properties_reference.xml | 5 ++++ 5 files changed, 62 insertions(+), 4 deletions(-) diff --git a/bin/jmeter.properties b/bin/jmeter.properties index 51842f8a7b..a98af29351 100644 --- a/bin/jmeter.properties +++ b/bin/jmeter.properties @@ -576,6 +576,11 @@ sampleresult.timestamp.start=true # Set this to <= 0 to disable the background thread #sampleresult.nanoThreadSleep=5000 +# Since version 5.0 JMeter has a new SubResult Naming Policy which numbers subresults by default +# This property if set to true discards renaming policy. This can be required if you're using JMeter for functional testing. +# Defaults to: false +#subresults.disable_renaming=false + #--------------------------------------------------------------------------- # Upgrade property #--------------------------------------------------------------------------- @@ -1320,3 +1325,11 @@ jmeter.reportgenerator.apdex_tolerated_threshold=1500 # Switch that allows using Local documentation opened in JMeter GUI # By default we use Online documentation opened in Browser #help.local=false + +#--------------------------------------------------------------------------- +# Documentation generation +#--------------------------------------------------------------------------- + +# Path to XSL file used to generate Schematic View of Test Plan +# When empty, JMeter will use the embedded one in src/core/org/apache/jmeter/gui/action/schematic.xsl +#docgeneration.schematic_xsl= \ No newline at end of file diff --git a/src/core/org/apache/jmeter/samplers/SampleResult.java b/src/core/org/apache/jmeter/samplers/SampleResult.java index a9df618f40..71e1bfe8a6 100644 --- a/src/core/org/apache/jmeter/samplers/SampleResult.java +++ b/src/core/org/apache/jmeter/samplers/SampleResult.java @@ -32,6 +32,7 @@ import java.util.concurrent.TimeUnit; import org.apache.jmeter.assertions.AssertionResult; import org.apache.jmeter.gui.Searchable; +import org.apache.jmeter.testelement.TestPlan; import org.apache.jmeter.threads.JMeterContext.TestLogicalAction; import org.apache.jmeter.util.JMeterUtils; import org.apache.jorphan.util.JOrphanUtils; @@ -96,7 +97,9 @@ public class SampleResult implements Serializable, Cloneable, Searchable { * @see #setDataType(java.lang.String) */ public static final String BINARY = "bin"; // $NON-NLS-1$ - + + private static final boolean DISABLE_SUBRESULTS_RENAMING = JMeterUtils.getPropDefault("subresults.disable_renaming", false); + // List of types that are known to be binary private static final String[] BINARY_TYPES = { "image/", //$NON-NLS-1$ @@ -614,8 +617,17 @@ public class SampleResult implements Serializable, Cloneable, Searchable { * the {@link SampleResult} to be added */ public void addSubResult(SampleResult subResult) { - addSubResult(subResult, true); + addSubResult(subResult, isRenameSampleLabel()); } + + /** + * @return true if TestPlan is in functional mode or property subresults.disable_renaming is true + * @see https://bz.apache.org/bugzilla/show_bug.cgi?id=63055 + */ + protected final boolean isRenameSampleLabel() { + return !(TestPlan.getFunctionalMode() || DISABLE_SUBRESULTS_RENAMING); + } + /** * Add a subresult and adjust the parent byte count and end-time. * @@ -652,7 +664,7 @@ public class SampleResult implements Serializable, Cloneable, Searchable { * the {@link SampleResult} to be added */ public void addRawSubResult(SampleResult subResult){ - storeSubResult(subResult, true); + storeSubResult(subResult, isRenameSampleLabel()); } /** @@ -676,7 +688,7 @@ public class SampleResult implements Serializable, Cloneable, Searchable { * the {@link SampleResult} to be added */ public void storeSubResult(SampleResult subResult) { - storeSubResult(subResult, true); + storeSubResult(subResult, isRenameSampleLabel()); } /** diff --git a/test/src/org/apache/jmeter/samplers/TestSampleResult.java b/test/src/org/apache/jmeter/samplers/TestSampleResult.java index 2300e5d3fe..e4e08f312e 100644 --- a/test/src/org/apache/jmeter/samplers/TestSampleResult.java +++ b/test/src/org/apache/jmeter/samplers/TestSampleResult.java @@ -26,6 +26,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import org.apache.jmeter.junit.JMeterTestCase; +import org.apache.jmeter.testelement.TestPlan; import org.apache.jmeter.util.Calculator; import org.apache.jmeter.util.LogRecordingDelegatingLogger; import org.apache.jorphan.test.JMeterSerialTest; @@ -344,5 +345,31 @@ public class TestSampleResult implements JMeterSerialTest { Thread.sleep(ms); return System.currentTimeMillis() - start; } + + @Test + public void testCompareSampleLabels() { + final boolean prevValue = TestPlan.getFunctionalMode(); + TestPlan plan = new TestPlan(); + plan.setFunctionalMode(true); + try { + SampleResult result = new SampleResult(); + result.setStartTime(System.currentTimeMillis()); + result.setSampleLabel("parent label"); + + SampleResult subResult = new SampleResult(); + subResult.setStartTime(System.currentTimeMillis()); + subResult.setSampleLabel("subResult label"); + + result.addSubResult(subResult); + assertEquals("subResult label", subResult.getSampleLabel()); + + plan.setFunctionalMode(false); + subResult.setSampleLabel("parent label"); + result.addRawSubResult(subResult); + assertEquals("parent label-0", subResult.getSampleLabel()); + } finally { + plan.setFunctionalMode(prevValue); + } + } } diff --git a/xdocs/changes.xml b/xdocs/changes.xml index 1dda5873e5..1faecf8975 100644 --- a/xdocs/changes.xml +++ b/xdocs/changes.xml @@ -100,6 +100,7 @@ containing a fix to this issue, we decided to remove it. If you still needed, yo

Controllers

diff --git a/xdocs/usermanual/properties_reference.xml b/xdocs/usermanual/properties_reference.xml index 4126993617..66caa73d9b 100644 --- a/xdocs/usermanual/properties_reference.xml +++ b/xdocs/usermanual/properties_reference.xml @@ -732,6 +732,11 @@ JMETER-SERVER Set this to a value less than zero to disable the background thread.
Defaults to: 5000 + + Since version 5.0 JMeter has a new SubResult Naming Policy which numbers subresults by default
+ This property if set to true discards renaming policy. This can be required if you're using JMeter for functional testing.
+ Defaults to: false +