Bug 60729

Summary: RandomVariableConfig should allow minimum==maximum
Product: JMeter Reporter: Rainer Jung <rainer.jung>
Component: MainAssignee: JMeter issues mailing list <issues>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 3.1   
Target Milestone: ---   
Hardware: All   
OS: All   

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