Author: sebb
Date: Thu Mar 27 08:50:47 2008
New Revision: 641859

URL: http://svn.apache.org/viewvc?rev=641859&view=rev
Log:
intSum and longSum reference parameters are now optional

Modified:
    jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/IntSum.java
    jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/LongSum.java
    jakarta/jmeter/trunk/test/src/org/apache/jmeter/functions/PackageTest.java
    jakarta/jmeter/trunk/xdocs/changes.xml
    jakarta/jmeter/trunk/xdocs/usermanual/functions.xml

Modified: 
jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/IntSum.java
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/IntSum.java?rev=641859&r1=641858&r2=641859&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/IntSum.java 
(original)
+++ jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/IntSum.java 
Thu Mar 27 08:50:47 2008
@@ -45,7 +45,7 @@
        static {
                desc.add(JMeterUtils.getResString("intsum_param_1")); 
//$NON-NLS-1$
                desc.add(JMeterUtils.getResString("intsum_param_2")); 
//$NON-NLS-1$
-               desc.add(JMeterUtils.getResString("function_name_param")); 
//$NON-NLS-1$
+               desc.add(JMeterUtils.getResString("function_name_paropt")); 
//$NON-NLS-1$
        }
 
        private Object[] values;
@@ -83,8 +83,14 @@
                        sum += Integer.parseInt(((CompoundVariable) 
values[i]).execute());
                }
 
-               String totalString = Integer.toString(sum);
-               if (vars != null){// vars will be null on TestPlan
+        try {
+            sum += Integer.parseInt(varName);
+            varName = null; // there is no variable name
+        } catch (NumberFormatException ignored) {
+        }
+
+        String totalString = Integer.toString(sum);
+               if (vars != null && varName != null){// vars will be null on 
TestPlan
                        vars.put(varName, totalString);
                }
 
@@ -98,7 +104,7 @@
         * @see Function#setParameters(Collection)
         */
        public synchronized void setParameters(Collection parameters) throws 
InvalidVariableException {
-               checkMinParameterCount(parameters, 3);
+               checkMinParameterCount(parameters, 2);
                values = parameters.toArray();
        }
 

Modified: 
jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/LongSum.java
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/LongSum.java?rev=641859&r1=641858&r2=641859&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/LongSum.java 
(original)
+++ jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/LongSum.java 
Thu Mar 27 08:50:47 2008
@@ -44,7 +44,7 @@
        static {
                desc.add(JMeterUtils.getResString("longsum_param_1")); 
//$NON-NLS-1$
                desc.add(JMeterUtils.getResString("longsum_param_2")); 
//$NON-NLS-1$
-               desc.add(JMeterUtils.getResString("function_name_param")); 
//$NON-NLS-1$
+               desc.add(JMeterUtils.getResString("function_name_paropt")); 
//$NON-NLS-1$
        }
 
        private Object[] values;
@@ -82,8 +82,14 @@
                        sum += Long.parseLong(((CompoundVariable) 
values[i]).execute());
                }
 
+        try {
+            sum += Long.parseLong(varName);
+            varName = null; // there is no variable name
+        } catch (NumberFormatException ignored) {
+        }
+        
                String totalString = Long.toString(sum);
-               if (vars != null){// vars will be null on TestPlan
+               if (vars != null && varName != null){// vars will be null on 
TestPlan
                        vars.put(varName, totalString);
                }
 
@@ -97,7 +103,7 @@
         * @see Function#setParameters(Collection)
         */
        public synchronized void setParameters(Collection parameters) throws 
InvalidVariableException {
-               checkMinParameterCount(parameters, 3);
+               checkMinParameterCount(parameters, 2);
                values = parameters.toArray();
        }
 

Modified: 
jakarta/jmeter/trunk/test/src/org/apache/jmeter/functions/PackageTest.java
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/test/src/org/apache/jmeter/functions/PackageTest.java?rev=641859&r1=641858&r2=641859&view=diff
==============================================================================
--- jakarta/jmeter/trunk/test/src/org/apache/jmeter/functions/PackageTest.java 
(original)
+++ jakarta/jmeter/trunk/test/src/org/apache/jmeter/functions/PackageTest.java 
Thu Mar 27 08:50:47 2008
@@ -906,9 +906,11 @@
     
     public void sumTest() throws Exception {
        IntSum is = new IntSum();
-       checkInvalidParameterCounts(is,3);
+       checkInvalidParameterCounts(is,2);
        checkSum(is,"3", new String[]{"1","2"});
-       checkSum(is,"1", new String[]{"-1","1","1","1","-1","0"});
+        checkSumNoVar(is,"3", new String[]{"1","2"});
+       checkSum(is,"1", new String[]{"-1","1","1","1","-2","1"});
+        checkSumNoVar(is,"1", new String[]{"-1","1","1","1","-2","1"});
        String maxIntVal = Integer.toString(Integer.MAX_VALUE);
        String minIntVal = Integer.toString(Integer.MIN_VALUE);
        checkSum(is,maxIntVal, new String[]{maxIntVal,"0"});
@@ -917,9 +919,11 @@
        is = null; // prevent accidental use below
        
        LongSum ls = new LongSum();
-       checkInvalidParameterCounts(ls,3);
+       checkInvalidParameterCounts(ls,2);
        checkSum(ls,"3", new String[]{"1","2"});
        checkSum(ls,"1", new String[]{"-1","1","1","1","-1","0"});
+        checkSumNoVar(ls,"3", new String[]{"1","2"});
+        checkSumNoVar(ls,"1", new String[]{"-1","1","1","1","-1","0"});
        String maxIntVal_1 = Long.toString(1+(long)Integer.MAX_VALUE);
        checkSum(ls,maxIntVal, new String[]{maxIntVal,"0"});
        checkSum(ls,maxIntVal_1, new String[]{maxIntVal,"1"}); // no wrap-round 
check
@@ -939,5 +943,14 @@
        func.setParameters(parms);
        assertEquals(value,func.execute(null,null));
        assertEquals(value,vars.getObject("Result"));           
+    }
+    // Perform a sum and check the results
+    private void checkSumNoVar(AbstractFunction func, String value, String [] 
addends)  throws Exception {
+        Collection parms = new LinkedList();
+        for (int i=0; i< addends.length; i++){
+            parms.add(new CompoundVariable(addends[i]));
+        }
+        func.setParameters(parms);
+        assertEquals(value,func.execute(null,null));
     }
 }

Modified: jakarta/jmeter/trunk/xdocs/changes.xml
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/changes.xml?rev=641859&r1=641858&r2=641859&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/changes.xml (original)
+++ jakarta/jmeter/trunk/xdocs/changes.xml Thu Mar 27 08:50:47 2008
@@ -71,6 +71,8 @@
 All existing JMeter functions conform to this restriction.
 To revert to earlier behaviour, comment or change the properties 
classfinder.functions.* in jmeter.properties.
 </li>
+<li>The reference value parameter for intSum() is now optional. 
+As a consequence, if a variable name is used, it must not be a valid 
integer.</li>
 </ul>
 
 <h4>Bug fixes</h4>

Modified: jakarta/jmeter/trunk/xdocs/usermanual/functions.xml
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/usermanual/functions.xml?rev=641859&r1=641858&r2=641859&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/usermanual/functions.xml (original)
+++ jakarta/jmeter/trunk/xdocs/usermanual/functions.xml Thu Mar 27 08:50:47 2008
@@ -302,15 +302,24 @@
 </component>
 
 <component index="&sect-num;.5.4a" name="__intSum">
-<description><p>The intsum function can be used to compute the sum of two or 
more integer values.
-</p></description>
+<description>
+<p>
+The intSum function can be used to compute the sum of two or more integer 
values.
+</p>
+<note>
+JMeter Versions 2.3.1 and earlier required the reference name to be present.
+The reference name is now optional, but it must not be a valid integer.
+</note>
+</description>
 
 <properties>
         <property name="First argument" required="Yes">The first int 
value.</property>
         <property name="Second argument" required="Yes">The second int 
value.</property>
         <property name="nth argument" required="No">The nth int 
value.</property>
-        <property name="last argument" required="Yes">A reference name for 
reusing the value
-                computed by this function.</property>
+        <property name="last argument" required="No">A reference name for 
reusing the value computed by this function. 
+                If specified, the reference name must contain at least one 
non-numeric character otherwise it will
+                be treated as another int value to be added.
+        </property>
 </properties>
 </component>
 
@@ -322,8 +331,10 @@
         <property name="First argument" required="Yes">The first long 
value.</property>
         <property name="Second argument" required="Yes">The second long 
value.</property>
         <property name="nth argument" required="No">The nth long 
value.</property>
-        <property name="last argument" required="Yes">A reference name for 
reusing the value
-                computed by this function.</property>
+        <property name="last argument" required="No">A reference name for 
reusing the value computed by this function. 
+                If specified, the reference name must contain at least one 
non-numeric character otherwise it will
+                be treated as another long value to be added.
+        </property>
 </properties>
 </component>
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to