apache / jmeter

Apache JMeter open-source load testing tool for analyzing and measuring the performance of a variety of services
https://jmeter.apache.org/
Apache License 2.0
7.98k stars 2.03k forks source link

[Enh/Patch] New Property function; upated comp ref. #1126

Closed asfimport closed 20 years ago

asfimport commented 20 years ago

tjsb (Bug 20771): This is a new function to return the value of a JMeter property.

Called as: ${__Property(user.dir)} for example.

It can be used in combination with the -J command-line option to supply run- time parameters without needing to edit the test script.

The update consists of one new file (Property.java) plus updates to the messages files and documentation for component_reference.xml

Severity: normal OS: other

asfimport commented 20 years ago

tjsb (migrated from Bugzilla): Created attachment Property.java: Property.java - new source file

Property.java ````java /* * ==================================================================== * 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 apache@apache.org. * * 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 * . * * $ID$ */ 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.util.JMeterUtils; /** * GetProperty (Function) * * @author default * * @version $Id$ * * Function to get a JMeter property * * Parameters: * - property name * - variable name (optional) * * Returns: * - the property value or the property name if not found * */ public class Property extends AbstractFunction implements Serializable { private static final List desc = new LinkedList(); private static final String KEY = "__property"; // Number of parameters expected - used to reject invalid calls private static final int MIN_PARAMETER_COUNT = 1; private static final int MAX_PARAMETER_COUNT = 2; static { desc.add(JMeterUtils.getResString("property_name_param")); desc.add(JMeterUtils.getResString("function_name_param")); } private Object[] values; public Property() {} public Object clone() { return new Property(); } public synchronized String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException { String propertyName = ((CompoundVariable)values[0]).execute(); String propertyValue = JMeterUtils.getPropDefault(propertyName,propertyName); if (values.length > 1) { String variableName = ((CompoundVariable)values[1]).execute(); getVariables().put(variableName,propertyValue); } return propertyValue; } public void setParameters(Collection parameters) throws InvalidVariableException { values = parameters.toArray(); if (( values.length < MIN_PARAMETER_COUNT ) || ( values.length > MAX_PARAMETER_COUNT )) { throw new InvalidVariableException("Parameter Count not between " +MIN_PARAMETER_COUNT+" & "+MAX_PARAMETER_COUNT); } } public String getReferenceKey() { return KEY; } public List getArgumentDesc() { return desc; } }````
asfimport commented 20 years ago

tjsb (migrated from Bugzilla): Created attachment cr_property.patch: [Patch] add property function details to component_reference

cr_property.patch ````diff Index: usermanual/component_reference.xml =================================================================== RCS file: /home/cvspublic/jakarta-jmeter/xdocs/usermanual/component_reference.xml,v retrieving revision 1.46 diff -u -r1.46 component_reference.xml --- usermanual/component_reference.xml 13 Jun 2003 14:51:51 -0000 1.46 +++ usermanual/component_reference.xml 13 Jun 2003 22:53:27 -0000 @@ -1512,6 +1512,18 @@ + +

The property function returns the value of a JMeter property. + If the property value cannot be found, it returns the property name.

+
+ + + The property name to be retrieved. + A reference name for reusing the value + computed by this function. + +
+ ````
asfimport commented 20 years ago

tjsb (migrated from Bugzilla): Created attachment messages.patch: Update messages files

messages.patch ````diff Index: messages.properties =================================================================== RCS file: /home/cvspublic/jakarta-jmeter/src/core/org/apache/jmeter/resources/messages.properties,v retrieving revision 1.47 diff -u -r1.47 messages.properties --- messages.properties 11 Jun 2003 15:38:32 -0000 1.47 +++ messages.properties 13 Jun 2003 22:57:20 -0000 @@ -375,4 +375,5 @@ starttime=StartTime endtime=EndTime scheduler=Scheduler -scheduler_configuration=Scheduler Configuration \ No newline at end of file +scheduler_configuration=Scheduler Configuration +property_name_param=Name of property \ No newline at end of file Index: messages_de.properties =================================================================== RCS file: /home/cvspublic/jakarta-jmeter/src/core/org/apache/jmeter/resources/messages_de.properties,v retrieving revision 1.39 diff -u -r1.39 messages_de.properties --- messages_de.properties 11 Jun 2003 15:38:33 -0000 1.39 +++ messages_de.properties 13 Jun 2003 22:57:22 -0000 @@ -364,4 +364,5 @@ starttime=StartTime endtime=EndTime scheduler=Scheduler -scheduler_configuration=Scheduler Configuration \ No newline at end of file +scheduler_configuration=Scheduler Configuration +property_name_param=Name of property \ No newline at end of file Index: messages_ja.properties =================================================================== RCS file: /home/cvspublic/jakarta-jmeter/src/core/org/apache/jmeter/resources/messages_ja.properties,v retrieving revision 1.35 diff -u -r1.35 messages_ja.properties --- messages_ja.properties 11 Jun 2003 15:38:33 -0000 1.35 +++ messages_ja.properties 13 Jun 2003 22:57:25 -0000 @@ -359,4 +359,5 @@ starttime=StartTime endtime=EndTime scheduler=Scheduler -scheduler_configuration=Scheduler Configuration \ No newline at end of file +scheduler_configuration=Scheduler Configuration +property_name_param=Name of property \ No newline at end of file Index: messages_no.properties =================================================================== RCS file: /home/cvspublic/jakarta-jmeter/src/core/org/apache/jmeter/resources/messages_no.properties,v retrieving revision 1.35 diff -u -r1.35 messages_no.properties --- messages_no.properties 11 Jun 2003 15:38:33 -0000 1.35 +++ messages_no.properties 13 Jun 2003 22:57:27 -0000 @@ -351,4 +351,5 @@ starttime=StartTime endtime=EndTime scheduler=Scheduler -scheduler_configuration=Scheduler Configuration \ No newline at end of file +scheduler_configuration=Scheduler Configuration +property_name_param=Name of property \ No newline at end of file ````
asfimport commented 20 years ago

tjsb (migrated from Bugzilla): Created attachment cr3.patch: Updated component_reference patch

cr3.patch ````diff Index: component_reference.xml =================================================================== RCS file: /home/cvspublic/jakarta-jmeter/xdocs/usermanual/component_reference.xml,v retrieving revision 1.46 diff -u -r1.46 component_reference.xml --- component_reference.xml 13 Jun 2003 14:51:51 -0000 1.46 +++ component_reference.xml 14 Jun 2003 16:49:46 -0000 @@ -1425,8 +1425,8 @@ - -

The intsum 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.

@@ -1481,7 +1481,15 @@ - The JavaScript expression to be executed. + The JavaScript expression to be executed. For example: +
    +
  • new Date() - return the current date and time
  • +
  • Math.floor(Math.random()*(${maxRandom}+1)) + - a random number between 0 and the variable maxRandom
  • +
  • ${minRandom}+Math.floor(Math.random()*(${maxRandom}-${minRandom}+1)) + - a random number between the variables minRandom and maxRandom
  • +
+
A reference name for reusing the value computed by this function.
@@ -1498,8 +1506,8 @@
- -

The CSVFile function returns a string from a CSV file (c.f. StringFromFile)

+ +

The CSVRead function returns a string from a CSV file (c.f. StringFromFile)

NOTE: A single instance of the file is opened and used for all threads.

@@ -1509,6 +1517,18 @@ 0 = first column, 1 = second etc. "next" - go to next line of file. + +
+ + +

The property function returns the value of a JMeter property. + If the property value cannot be found, it returns the property name.

+
+ + + The property name to be retrieved. + A reference name for reusing the value + computed by this function.
````
asfimport commented 20 years ago

tjsb (migrated from Bugzilla): Please note: the patch dated 06/14/03 16:58 supersedes the patch dated 06/13/03 22:58

It also fixes two spelling errors (intsum -> intSum, and CSVFile -> CSVRead) as well as adding some JavaScript examples. Sorry, should have submitted these separately.

asfimport commented 20 years ago

tjsb (migrated from Bugzilla): I think this bug may have been closed accidentally, as the new Property function does not seem to have made it into CVS.

The first 3 patches (6819, 6820 and 6821) are still relevant; they cover creating the new Property.java file, and updates to message resource files and component_reference.

asfimport commented 20 years ago

tjsb (migrated from Bugzilla): Thanks for updating CVS!