Bug 60729 - RandomVariableConfig should allow minimum==maximum
Summary: RandomVariableConfig should allow minimum==maximum
Status: RESOLVED FIXED
Alias: None
Product: JMeter - Now in Github
Classification: Unclassified
Component: Main (show other bugs)
Version: 3.1
Hardware: All All
: P2 normal (vote)
Target Milestone: ---
Assignee: JMeter issues mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-13 18:45 UTC by Rainer Jung
Modified: 2017-02-13 21:24 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rainer Jung 2017-02-13 18:45:58 UTC
Currently RandomVariableConfig checks for maximum > minimum and complains otherwise. I have a situation where I create random values using RandomVariableConfig in some given range and sometimes I need that range to be exactly one number.

E.g. the random value could be the number of products you want to buy but for a simple base test you always want only one product. I retrieve minimum and maximum from JMeter variables and it would be trivial to set both to "1" to get that behavior.

Unfortunately RandomVariableConfig only accepts minimum < maximum, not minimum == maximum. Note that the Random math still works for minimum == maximum, because range = maximum - minimum + 1 would be 1 and we would generate minimum + randGen.nextInt(range) = minimum + randGen.nextInt(1) = minimum + 0 = minimum (== maximum), which would be the expected result.

The docs do not mention the condition on minimum and maximum, so there's no docs change involved.

I'm going to apply the following (trivial) patch unless someone opposes:

Index: components/org/apache/jmeter/config/RandomVariableConfig.java
===================================================================
--- components/org/apache/jmeter/config/RandomVariableConfig.java       (revision 1782826)
+++ components/org/apache/jmeter/config/RandomVariableConfig.java       (working copy)
@@ -91,8 +91,8 @@
         final String maxAsString = getMaximumValue();
         long maximum = NumberUtils.toLong(maxAsString);
         long rangeL=maximum-minimum+1; // This can overflow
-        if (minimum >= maximum){
-            log.error("maximum({}) must be > minimum({})", maxAsString, minAsString);
+        if (minimum > maximum){
+            log.error("maximum({}) must be >= minimum({})", maxAsString, minAsString);
             range=0;// This is used as an error indicator
             return;
         }

Regards,

Rainer
Comment 2 Rainer Jung 2017-02-13 19:34:35 UTC
Thanks. I'm in the middle of preparing tests. I'll include the fixes fpor the other two comparisons.
Comment 3 Rainer Jung 2017-02-13 19:37:26 UTC
Actzually these do not need changing. range comes from rangeL which was set to rangeL=maximum-minimum+1, so for minimum==maximum range is and should be 1. So comparing against 0 (which is used as a special marker value) is fine.
Comment 4 Rainer Jung 2017-02-13 20:10:36 UTC
Will be part of version 3.2:

Author: rjung
Date: Mon Feb 13 20:07:52 2017
New Revision: 1782848

URL: http://svn.apache.org/viewvc?rev=1782848&view=rev
Log:
Allow minimum == maximum in Random Variable Config Element.

Bugzilla Id: 60729

Modified:
    jmeter/trunk/src/components/org/apache/jmeter/config/RandomVariableConfig.java
Comment 5 UbikLoadPack support 2017-02-13 20:27:27 UTC
(In reply to Rainer Jung from comment #4)
> Will be part of version 3.2:
> 
> Author: rjung
> Date: Mon Feb 13 20:07:52 2017
> New Revision: 1782848
> 
> URL: http://svn.apache.org/viewvc?rev=1782848&view=rev
> Log:
> Allow minimum == maximum in Random Variable Config Element.
> 
> Bugzilla Id: 60729
> 
> Modified:
>    
> jmeter/trunk/src/components/org/apache/jmeter/config/RandomVariableConfig.
> java

Hi Rainer, 
Can't this fix break existing test plans ? I don't think so but you've investigated it more than me.
Maybe a note in incompatible changes would be useful in this case.
Thanks for patch and fix.
Comment 6 Rainer Jung 2017-02-13 20:58:54 UTC
> Hi Rainer, 
> Can't this fix break existing test plans ? I don't think so but you've
> investigated it more than me.
> Maybe a note in incompatible changes would be useful in this case.
> Thanks for patch and fix.

Behavior before that change: when minimum==maximum you got an error in the log, but the test plan proceeded without the defined variable being set to any value.

So yes, it can break plans and I will add a note, but I think just not setting the variable when minimum==maximum is wrong. Thus the fix.
Comment 7 Rainer Jung 2017-02-13 21:24:42 UTC
Author: rjung
Date: Mon Feb 13 21:23:23 2017
New Revision: 1782880

URL: http://svn.apache.org/viewvc?rev=1782880&view=rev
Log:
Add info about BZ 60729 (the Random Variable
Config Element should allow minimum==maximum)
to changes.

Modified:
    jmeter/trunk/xdocs/changes.xml
Comment 8 The ASF infrastructure team 2022-09-24 20:38:07 UTC
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/4278