mstover1    2003/06/04 17:24:22

  Modified:    docs/usermanual component_reference.html
               src/functions/org/apache/jmeter/functions
                        StringFromFile.java
               xdocs/usermanual component_reference.xml
  Log:
  applying patch to StringFromFile and documentation for it from Sebastian Bazley
  
  Revision  Changes    Path
  1.38      +76 -4     jakarta-jmeter/docs/usermanual/component_reference.html
  
  Index: component_reference.html
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/docs/usermanual/component_reference.html,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- component_reference.html  4 Jun 2003 14:31:42 -0000       1.37
  +++ component_reference.html  5 Jun 2003 00:24:22 -0000       1.38
  @@ -12,7 +12,7 @@
                                <meta http-equiv="Content-Type" content="text/html; 
charset=iso-8859-1"/>
   
                                                                
  -                             <title>JMeter - User's Manual: Samplers</title>
  +                             <title>JMeter - User's Manual: Component 
Reference</title>
                  </head>
   
                  <body bgcolor="#ffffff" text="#000000" link="#525D76">
  @@ -156,7 +156,8 @@
                                        <li><a 
href="#__regexFunction">__regexFunction</a></li>
                                        <li><a href="#__counter">__counter</a></li>
                                        <li><a href="#__threadNum">__threadNum</a></li>
  -                                     <li><a href="#__sumInt">__sumInt</a></li>
  +                                     <li><a href="#__intsum">__intsum</a></li>
  +                                     <li><a 
href="#_StringFromFile">_StringFromFile</a></li>
                                </ul>
                </ul>
                                                                                       
                                                                                  
<table border="0" cellspacing="0" cellpadding="2" width="100%">
  @@ -3601,12 +3602,12 @@
                                                                                       
                                                                         <table 
border="0" cellspacing="0" cellpadding="2">
                <tr><td>
                  <font face="arial,helvetica,sanserif">
  -                      <a name="__sumInt"><h3>13.9.4 __sumInt</h3></a>
  +                      <a name="__intsum"><h3>13.9.4 __intsum</h3></a>
                  </font>
                </td></tr>
                                <tr><td>
                                                                                       
                                                                                 <p    
  >
  -                                                             The sumInt function 
can be used to compute the sum of two or more integer values.
  +                                                             The intsum function 
can be used to compute the sum of two or more integer values.
   
                                                </p>
                                                                                       
                                                                                       
                                           <p>
  @@ -3648,6 +3649,77 @@
                </tr>
                </table>
        </p>
  +                                                                     </td></tr>
  +             <tr><td><br/></td></tr>
  +      </table>
  +     <hr>
  +                                                                                    
                                                                         <table 
border="0" cellspacing="0" cellpadding="2">
  +             <tr><td>
  +               <font face="arial,helvetica,sanserif">
  +                      <a name="_StringFromFile"><h3>13.9.5 _StringFromFile</h3></a>
  +               </font>
  +             </td></tr>
  +                             <tr><td>
  +                                                                                    
                                                 
  +     
  +                                                                                    
         <p      >
  +                                                             
  +     The StringFromFile function can be used to read strings from a text file. 
  +     This is useful for running tests that require lots of variable data.
  +     For example when testing a banking application, 100s or 1000s of different 
account numbers might be required.
  +     
  +                                             </p>
  +                                                                     
  +     
  +                                                                                    
         <p      >
  +                                                             
  +     Each time it is called it reads the next line from the file.
  +     When the end of the file is reached, it will start reading again from the 
beginning.
  +     If there are multiple references to the function in a test script, each will 
open the file independently,
  +     even if the file names are the same.
  +     [If the value is to be used again elsewhere, use different variable names for 
each function call.]
  +     
  +                                             </p>
  +                                                                     
  +     
  +                                                                                    
         <p      >
  +                                                             If an error occurs 
opening or reading the file, then the function returns the string "**ERR**"
  +                                             </p>
  +                                                                     
  +
  +                                                                                    
                                                                                       
                                   <p>
  +     <b>Parameters</b>
  +     <table border="1" cellspacing="0" cellpadding="2">
  +     <tr><th>Attribute</th><th>Description</th><th>Required</th></tr>
  +                     <tr>
  +                     <td>First argument</td>
  +                     <td>                                            Path to the 
file name.
  +             (The path can be relative to the JMeter launch directory)
  +        
  +                     </td>
  +                     <td>
  +                                                                                    
 Yes
  +                                                             </td>
  +             </tr>
  +                     <tr>
  +                     <td>Second argument</td>
  +                     <td>                                            
  +             A reference name - refName - for reusing the value created by this 
function.
  +                     Stored values are of the form ${refName}.
  +        
  +                     </td>
  +                     <td>
  +                                                                                    
 No
  +                                                             </td>
  +             </tr>
  +             </table>
  +     </p>
  +                                                                                    
                                                                         <p      >
  +                                                             The file name 
parameter is resolved when the file is opened or re-opened.
  +                                             </p>
  +                                                                                    
                                                                         <p      >
  +                                                             The reference name 
parameter (if supplied) is resolved every time the function is executed.
  +                                             </p>
                                                                        </td></tr>
                <tr><td><br/></td></tr>
         </table>
  
  
  
  1.6       +113 -17   
jakarta-jmeter/src/functions/org/apache/jmeter/functions/StringFromFile.java
  
  Index: StringFromFile.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/functions/org/apache/jmeter/functions/StringFromFile.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- StringFromFile.java       3 May 2003 15:34:33 -0000       1.5
  +++ StringFromFile.java       5 Jun 2003 00:24:22 -0000       1.6
  @@ -1,3 +1,58 @@
  +/*
  + * ====================================================================
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 2001,2003 The Apache Software Foundation.  All rights
  + * reserved.
  + *
  + * Redistribution and use in source and binary forms, with or without
  + * modification, are permitted provided that the following conditions
  + * are met:
  + *
  + * 1. Redistributions of source code must retain the above copyright
  + * notice, this list of conditions and the following disclaimer.
  + *
  + * 2. Redistributions in binary form must reproduce the above copyright
  + * notice, this list of conditions and the following disclaimer in
  + * the documentation and/or other materials provided with the
  + * distribution.
  + *
  + * 3. The end-user documentation included with the redistribution,
  + * if any, must include the following acknowledgment:
  + * "This product includes software developed by the
  + * Apache Software Foundation (http://www.apache.org/)."
  + * Alternately, this acknowledgment may appear in the software itself,
  + * if and wherever such third-party acknowledgments normally appear.
  + *
  + * 4. The names "Apache" and "Apache Software Foundation" and
  + * "Apache JMeter" must not be used to endorse or promote products
  + * derived from this software without prior written permission. For
  + * written permission, please contact [EMAIL PROTECTED]
  + *
  + * 5. Products derived from this software may not be called "Apache",
  + * "Apache JMeter", nor may "Apache" appear in their name, without
  + * prior written permission of the Apache Software Foundation.
  + *
  + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  + * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  + * SUCH DAMAGE.
  + * ====================================================================
  + *
  + * This software consists of voluntary contributions made by many
  + * individuals on behalf of the Apache Software Foundation.  For more
  + * information on the Apache Software Foundation, please see
  + * <http://www.apache.org/>.
  + */
  +
   package org.apache.jmeter.functions;
   
   import java.io.BufferedReader;
  @@ -16,11 +71,34 @@
   import org.apache.log.Logger;
   
   
  -/*
  - * It appears that JMeter instantiates a new copy of each function for every 
reference in a Sampler
  - * or elsewhere.
  - */
   
  +/**
  + * StringFromFile (Function)
  + * 
  + * @author default
  + *
  + * @version $Id$
  + * 
  + * Function to read a String from a text file
  + * 
  + * Parameters:
  + *           - file name
  + *           - variable name (optional - defaults to StringFromFile_)
  + * 
  + * Returns:
  + *           - the next line from the file - or **ERR** if an error occurs
  + *           - value is also saved in the variable for later re-use.
  + * 
  + * Ensure that different variable names are used for each call to the function
  + * 
  + * 
  + * Notes:
  + * - JMeter instantiates a copy of each function for every reference in a Sampler
  + *   or elsewhere; each instance will open its own copy of the the file
  + * - the file name is resolved at file (re-)open time
  + * - the output variable name is resolved every time the function is invoked
  + * 
  + */
   public class StringFromFile extends AbstractFunction implements Serializable
   {
        transient private static Logger log = 
Hierarchy.getDefaultHierarchy().getLoggerFor(
  @@ -40,6 +118,7 @@
        private Object[] values;
        private BufferedReader myBread; // Buffered reader
        private boolean reopenFile=true; // Set from parameter list one day ...
  +     private String fileName; // needed for error messages
        
        public StringFromFile()
        {
  @@ -48,15 +127,21 @@
        public Object clone()
        {
                StringFromFile newReader = new StringFromFile();
  +             if (log.isDebugEnabled()){ // Skip expensive paramter creation ..
  +                     log.debug(this+"::StringFromFile.clone()",new 
Throwable("debug"));
  +             }
  +                     
                return newReader;
        }
   
  -     private void openFile( String fileName ){
  +     private void openFile(){
  +             fileName = ((CompoundVariable)values[0]).execute();
            try {
                        FileReader fis = new FileReader(fileName);
                        myBread = new BufferedReader(fis);
  +                     log.info("Opened "+fileName);
            } catch (Exception e) {
  -                     log.error("openFile",e);
  +                     log.error("Error in openFile "+fileName,e);
            }
        }
   
  @@ -68,44 +153,55 @@
                
                JMeterVariables vars = getVariables();
   
  -             String fileName = ((CompoundVariable)values[0]).execute();
  -             myName = ((CompoundVariable)values[1]).execute();
  -
  -             if(myBread == null)
  -        {
  -            openFile(fileName);
  -        } 
  -
  +             if (values.length >= 2) {
  +                     myName = ((CompoundVariable)values[1]).execute();
  +             }
  +             
                myValue="**ERR**";
                if (null != myBread) {// Did we open the file?
                  try {
                    String line = myBread.readLine();
                    if (line == null && reopenFile) { // EOF, re-open file
  +                     log.info("Reached EOF on "+fileName);
                                myBread.close();
  -                             openFile(fileName);
  +                             openFile();
                                line = myBread.readLine();
                    }
                    myValue = line;
                  } catch (Exception e) {
  -                 log.error("Token",e);
  +                 log.error("Error reading file "+fileName,e);
                  }
                }
                
                vars.put(myName,myValue);
  +
  +             log.debug(this+"::StringFromFile.execute() value " + myValue);
  +
                return myValue;
   
        }
   
       /* (non-Javadoc)
  +     * Parameters:
  +     * - file name
  +     * - variable name (optional)
  +     * 
         * @see org.apache.jmeter.functions.Function#setParameters(Collection)
         */
        public void setParameters(Collection parameters)
                throws InvalidVariableException {
                        
  +             log.debug(this+"::StringFromFile.setParameters()");
  +
                values = parameters.toArray();
                
  -             if ( values.length > 2 )
  +             if (( values.length > 2 ) || (values.length < 1)) {
                        throw new InvalidVariableException();
  +             }
  +             
  +             openFile();
  +             
  +             log.info("Variable name: "+ myName);
                        
        }
   
  
  
  
  1.36      +32 -3     jakarta-jmeter/xdocs/usermanual/component_reference.xml
  
  Index: component_reference.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/xdocs/usermanual/component_reference.xml,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- component_reference.xml   4 Jun 2003 14:31:45 -0000       1.35
  +++ component_reference.xml   5 Jun 2003 00:24:22 -0000       1.36
  @@ -2,7 +2,7 @@
   <document index="yes">
   
   <properties>
  -  <title>User's Manual: Samplers</title>
  +  <title>User's Manual: Component Reference</title>
   </properties>
   
   <body>
  @@ -1232,8 +1232,8 @@
   </description>
   </component>
   
  -<component index="13.9.4" name="__sumInt">
  -<description><p>The sumInt function can be used to compute the sum of two or more 
integer values.
  +<component index="13.9.4" name="__intsum">
  +<description><p>The intsum function can be used to compute the sum of two or more 
integer values.
   </p></description>
   
   <properties>
  @@ -1245,6 +1245,35 @@
   </properties>
   </component>
   
  +<component index="13.9.5" name="_StringFromFile">
  +<description>
  +     <p>
  +     The StringFromFile function can be used to read strings from a text file. 
  +     This is useful for running tests that require lots of variable data.
  +     For example when testing a banking application, 100s or 1000s of different 
account numbers might be required.
  +     </p>
  +     <p>
  +     Each time it is called it reads the next line from the file.
  +     When the end of the file is reached, it will start reading again from the 
beginning.
  +     If there are multiple references to the function in a test script, each will 
open the file independently,
  +     even if the file names are the same.
  +     [If the value is to be used again elsewhere, use different variable names for 
each function call.]
  +     </p>
  +     <p>If an error occurs opening or reading the file, then the function returns 
the string "**ERR**"</p>
  +</description>
  +
  +<properties>
  +        <property name="First argument" required="Yes">Path to the file name.
  +             (The path can be relative to the JMeter launch directory)
  +        </property>
  +        <property name="Second argument" required="No">
  +             A reference name - refName - for reusing the value created by this 
function.
  +                     Stored values are of the form ${refName}.
  +        </property>
  +</properties>
  +<p>The file name parameter is resolved when the file is opened or re-opened.</p>
  +<p>The reference name parameter (if supplied) is resolved every time the function 
is executed.</p>
  +</component>
   </section>
   </body>
   </document>
  
  
  

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

Reply via email to