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
Have you tried that patch? It looks other uses of range should be corrected as well: https://github.com/vlsi/jmeter/blob/7ebfa083afd0b4e2be069b2a8a654bc33fe761cf/src/components/org/apache/jmeter/config/RandomVariableConfig.java#L99-L99 and https://github.com/vlsi/jmeter/blob/7ebfa083afd0b4e2be069b2a8a654bc33fe761cf/src/components/org/apache/jmeter/config/RandomVariableConfig.java#L121.
Thanks. I'm in the middle of preparing tests. I'll include the fixes fpor the other two comparisons.
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.
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
(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.
> 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.
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
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/4278