mstover1    2003/06/04 17:13:40

  Modified:    src/core/org/apache/jmeter/engine/util CompoundVariable.java
                        ReplaceStringWithFunctions.java
               src/core/org/apache/jmeter/resources messages.properties
                        messages_de.properties messages_ja.properties
                        messages_no.properties
               src/core/org/apache/jmeter/util JMeterUtils.java
  Added:       src/functions/org/apache/jmeter/functions Random.java
  Log:
  New Random Function
  Efficiency improvements to variable resolution
  
  Revision  Changes    Path
  1.12      +23 -20    
jakarta-jmeter/src/core/org/apache/jmeter/engine/util/CompoundVariable.java
  
  Index: CompoundVariable.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/engine/util/CompoundVariable.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- CompoundVariable.java     2 Jun 2003 00:34:44 -0000       1.11
  +++ CompoundVariable.java     5 Jun 2003 00:13:40 -0000       1.12
  @@ -99,11 +99,12 @@
        private Map varMap = new HashMap();
   
       static Map functions = new HashMap();
  -    private boolean hasFunction, hasStatics, hasUnknowns;
  +    private boolean hasFunction, isDynamic;
       private String staticSubstitution;
       private Perl5Util util = new Perl5Util();
       private Perl5Compiler compiler = new Perl5Compiler();
       private static final String unescapePattern = "[\\\\]([${}\\,])";
  +    private String permanentResults = "";
       
       LinkedList compiledComponents = new LinkedList();
   
  @@ -133,9 +134,8 @@
       public CompoundVariable()
       {
        super();
  +        isDynamic = true;
           hasFunction = false;
  -        hasStatics = false;
  -        hasUnknowns = false;
           staticSubstitution = "";
       }
       
  @@ -149,10 +149,17 @@
   
        public String execute() 
        {
  -             JMeterContext context = JMeterContextService.getContext();
  -             SampleResult previousResult = context.getPreviousResult();
  -             Sampler currentSampler = context.getCurrentSampler();
  -             return execute( previousResult, currentSampler );
  +        if(isDynamic)
  +        {
  +             JMeterContext context = JMeterContextService.getContext();
  +             SampleResult previousResult = context.getPreviousResult();
  +             Sampler currentSampler = context.getCurrentSampler();
  +             return execute( previousResult, currentSampler );
  +        }
  +        else
  +        {
  +            return permanentResults;
  +        }
        }
       
       /**
  @@ -173,6 +180,7 @@
           {
               return "";
           }
  +        boolean testDynamic = false;
           StringBuffer results = new StringBuffer();
           Iterator iter = compiledComponents.iterator();
           while (iter.hasNext())
  @@ -181,6 +189,7 @@
               log.debug("executing object: " + item);
               if (item instanceof Function)
               {
  +                testDynamic = true;
                   try
                   {
                       results.append(
  @@ -194,6 +203,7 @@
               }
               else if (item instanceof SimpleVariable)
               {
  +                testDynamic = true;
                        results.append( ((SimpleVariable) item).toString() );   
               }
               else
  @@ -201,6 +211,11 @@
                   results.append(item);
               }
           }
  +        if(!testDynamic)
  +        {
  +            isDynamic = false;
  +            permanentResults = results.toString();
  +        }
           return results.toString();
       }
   
  @@ -220,7 +235,6 @@
       public void clear()
       {
           hasFunction = false;
  -        hasStatics = false;
           compiledComponents.clear();
           staticSubstitution = "";
       }
  @@ -481,17 +495,6 @@
       public boolean hasFunction()
       {
           return hasFunction;
  -    }
  -
  -     public boolean hasStatics()
  -    {
  -        return hasStatics;
  -    }
  -
  -
  -    public String getStaticSubstitution()
  -    {
  -        return staticSubstitution;
       }
   
       /**
  
  
  
  1.2       +0 -5      
jakarta-jmeter/src/core/org/apache/jmeter/engine/util/ReplaceStringWithFunctions.java
  
  Index: ReplaceStringWithFunctions.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/engine/util/ReplaceStringWithFunctions.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ReplaceStringWithFunctions.java   5 May 2003 17:23:01 -0000       1.1
  +++ ReplaceStringWithFunctions.java   5 Jun 2003 00:13:40 -0000       1.2
  @@ -11,7 +11,6 @@
   import org.apache.jmeter.functions.InvalidVariableException;
   import org.apache.jmeter.testelement.property.FunctionProperty;
   import org.apache.jmeter.testelement.property.JMeterProperty;
  -import org.apache.jmeter.testelement.property.StringProperty;
   
   /**
    * @author ano ano
  @@ -40,10 +39,6 @@
           if (getMasterFunction().hasFunction())
           {
               newValue = new FunctionProperty(prop.getName(), 
getMasterFunction().getFunction());
  -        }
  -        else if (getMasterFunction().hasStatics())
  -        {
  -            newValue = new StringProperty(prop.getName(), 
getMasterFunction().getStaticSubstitution());
           }
           return newValue;
       }
  
  
  
  1.42      +2 -0      
jakarta-jmeter/src/core/org/apache/jmeter/resources/messages.properties
  
  Index: messages.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/resources/messages.properties,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- messages.properties       4 Jun 2003 14:31:43 -0000       1.41
  +++ messages.properties       5 Jun 2003 00:13:40 -0000       1.42
  @@ -286,6 +286,8 @@
   mailer_attributes_panel=Mailing attributes
   duration_assertion_input_error=Please enter a valid positive integer.
   function_name_param=Name of function.  Used to store values for use elsewhere in 
the testplan.
  +minimum_param=The minimum value allowed for a range of values
  +maximum_param=The maximum value allowed for a range of values
   user_parameters_title=User Parameters
   user=User
   user_parameters_table=Parameters
  
  
  
  1.34      +2 -0      
jakarta-jmeter/src/core/org/apache/jmeter/resources/messages_de.properties
  
  Index: messages_de.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/resources/messages_de.properties,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- messages_de.properties    4 Jun 2003 14:31:43 -0000       1.33
  +++ messages_de.properties    5 Jun 2003 00:13:40 -0000       1.34
  @@ -355,3 +355,5 @@
   test_configuration=Test Configuration
   test =Test
   ldap_testing_title= LDAP Request
  +minimum_param=The minimum value allowed for a range of values
  +maximum_param=The maximum value allowed for a range of values
  \ No newline at end of file
  
  
  
  1.30      +2 -0      
jakarta-jmeter/src/core/org/apache/jmeter/resources/messages_ja.properties
  
  Index: messages_ja.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/resources/messages_ja.properties,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- messages_ja.properties    4 Jun 2003 14:31:43 -0000       1.29
  +++ messages_ja.properties    5 Jun 2003 00:13:40 -0000       1.30
  @@ -349,3 +349,5 @@
   test_configuration=Test Configuration
   test =Test
   ldap_testing_title= LDAP Request
  +minimum_param=The minimum value allowed for a range of values
  +maximum_param=The maximum value allowed for a range of values
  \ No newline at end of file
  
  
  
  1.30      +2 -0      
jakarta-jmeter/src/core/org/apache/jmeter/resources/messages_no.properties
  
  Index: messages_no.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/resources/messages_no.properties,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- messages_no.properties    4 Jun 2003 14:31:43 -0000       1.29
  +++ messages_no.properties    5 Jun 2003 00:13:40 -0000       1.30
  @@ -341,3 +341,5 @@
   test_configuration=Test Configuration
   test =Test
   ldap_testing_title= LDAP Request
  +minimum_param=The minimum value allowed for a range of values
  +maximum_param=The maximum value allowed for a range of values
  \ No newline at end of file
  
  
  
  1.23      +3 -2      jakarta-jmeter/src/core/org/apache/jmeter/util/JMeterUtils.java
  
  Index: JMeterUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/util/JMeterUtils.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- JMeterUtils.java  4 Jun 2003 14:31:43 -0000       1.22
  +++ JMeterUtils.java  5 Jun 2003 00:13:40 -0000       1.23
  @@ -97,7 +97,7 @@
    */
   public class JMeterUtils implements UnitTestManager
   {
  -        private static final String VERSION="20030604";
  +        private static final String VERSION="1.9.RC20030604";
           private static PatternCacheLRU patternCache = new PatternCacheLRU(1000,new 
Perl5Compiler());
   
        transient private static Logger log =
  @@ -977,6 +977,7 @@
                return VERSION;
        }
   }
  +
   
   
   
  
  
  
  1.1                  
jakarta-jmeter/src/functions/org/apache/jmeter/functions/Random.java
  
  Index: Random.java
  ===================================================================
  /*
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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.Serializable;
  import java.util.Collection;
  import java.util.LinkedList;
  import java.util.List;
  
  import org.apache.jmeter.engine.util.CompoundVariable;
  import org.apache.jmeter.samplers.SampleResult;
  import org.apache.jmeter.samplers.Sampler;
  import org.apache.jmeter.threads.JMeterVariables;
  import org.apache.jmeter.util.JMeterUtils;
  
  /**
   * Provides a Random function which returns a random integer between
   * a min (first argument) and a max (seceond argument).
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Jonathan Kwadzo</a>
   * @version $Id: Random.java,v 1.1 2003/06/05 00:13:40 mstover1 Exp $
   */
  public class Random extends AbstractFunction implements Serializable
  {
  
        private static final List desc = new LinkedList();
        private static final String KEY = "__Random";
  
        static
        {
                desc.add(JMeterUtils.getResString("minimum_param"));
                desc.add(JMeterUtils.getResString("maximum_param"));
                desc.add(JMeterUtils.getResString("function_name_param"));
        }
  
        private CompoundVariable varName,minimum,maximum;
  
  
      /**
       * No-arg constructor.
       */
        public Random() {}
  
      /**
       * Clone this Add object.
       *
       * @return A new Add object.
       */
        public Object clone()
        {
                Random newRandom = new Random();
                return newRandom;
        }
  
        /**
         * Execute the function.
         *
         * @see Function#execute(SampleResult, Sampler)
         */
        public synchronized String execute(SampleResult previousResult, Sampler 
currentSampler)
                        throws InvalidVariableException
        {
  
                JMeterVariables vars = getVariables();
  
                int min = Integer.parseInt(minimum.execute());
                int max = Integer.parseInt(maximum.execute());
          
                int rand = (int)Math.round(min + Math.random()*(max-min));
  
                String randString = Integer.toString(rand);
                vars.put(varName.execute(), randString);
  
                return randString;
  
        }
  
        /**
         * Set the parameters for the function.
         *
         * @see Function#setParameters(Collection)
         */
        public void setParameters(Collection parameters)
                        throws InvalidVariableException
        {
                Object[] values = parameters.toArray();
  
                if ( values.length < 3 ) {
                        throw new InvalidVariableException();
                }
          else
          {
              varName = (CompoundVariable)values[2];
              minimum = (CompoundVariable)values[0];
              maximum = (CompoundVariable)values[1];
          }
  
        }
  
        /**
         * Get the invocation key for this function.
         *
         * @see Function#getReferenceKey()
         */
        public String getReferenceKey() {
                return KEY;
        }
  
        /**
         * Get the description of this function.
         *
         * @see Function#getArgumentDesc()
         */
        public List getArgumentDesc() {
                return desc;
        }
  
  }
  
  
  

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

Reply via email to