You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@jakarta.apache.org by se...@apache.org on 2010/09/23 23:28:12 UTC

svn commit: r1000632 - in /jakarta/jmeter/trunk: src/functions/org/apache/jmeter/functions/SamplerName.java xdocs/changes.xml xdocs/usermanual/functions.xml

Author: sebb
Date: Thu Sep 23 21:28:12 2010
New Revision: 1000632

URL: http://svn.apache.org/viewvc?rev=1000632&view=rev
Log:
Bug 49975 - New function returning the name of the current sampler

Added:
    jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/SamplerName.java   (with props)
Modified:
    jakarta/jmeter/trunk/xdocs/changes.xml
    jakarta/jmeter/trunk/xdocs/usermanual/functions.xml

Added: jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/SamplerName.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/SamplerName.java?rev=1000632&view=auto
==============================================================================
--- jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/SamplerName.java (added)
+++ jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/SamplerName.java Thu Sep 23 21:28:12 2010
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jmeter.functions;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.jmeter.engine.util.CompoundVariable;
+import org.apache.jmeter.functions.AbstractFunction;
+import org.apache.jmeter.functions.InvalidVariableException;
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jmeter.samplers.Sampler;
+import org.apache.jmeter.threads.JMeterVariables;
+import org.apache.jmeter.util.JMeterUtils;
+import org.apache.jorphan.logging.LoggingManager;
+import org.apache.log.Logger;
+
+/**
+ * Function to return the name of the current sampler.
+ */
+public class SamplerName extends AbstractFunction {
+
+    private static final Logger log = LoggingManager.getLoggerForClass();
+
+    private static final String KEY = "__samplerName"; //$NON-NLS-1$
+
+	private static final List<String> desc = new LinkedList<String>();
+
+    static {
+        // desc.add("Use fully qualified host name: TRUE/FALSE (Default FALSE)");
+        desc.add(JMeterUtils.getResString("function_name_paropt")); //$NON-NLS-1$
+    }
+
+    private Object[] values;
+
+	/** {@inheritDoc} */
+	@Override
+	public String execute(SampleResult previousResult, Sampler currentSampler)
+			throws InvalidVariableException {
+		// return JMeterContextService.getContext().getCurrentSampler().getName();
+		String name = "";
+		if (currentSampler != null) { // will be null if function is used on TestPlan
+		    name = currentSampler.getName();
+		}
+		log.info("execute: ***********************************************");
+		if (values.length > 0){
+            JMeterVariables vars = getVariables();
+            if (vars != null) {// May be null if function is used on TestPlan
+                String varName = ((CompoundVariable) values[0]).execute().trim();
+                if (varName.length() > 0) {
+                    log.info("name="+name+", varName="+varName+".");
+                    vars.put(varName, name);
+                }
+            }
+		}
+        return name;
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	public synchronized void setParameters(Collection<CompoundVariable> parameters)
+			throws InvalidVariableException {
+        checkParameterCount(parameters, 0, 1);
+        values = parameters.toArray();
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	public String getReferenceKey() {
+		return KEY;
+	}
+
+	/** {@inheritDoc} */
+	public List<String> getArgumentDesc() {
+		return desc;
+	}
+}

Propchange: jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/SamplerName.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/SamplerName.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: jakarta/jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/changes.xml?rev=1000632&r1=1000631&r2=1000632&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/changes.xml (original)
+++ jakarta/jmeter/trunk/xdocs/changes.xml Thu Sep 23 21:28:12 2010
@@ -131,6 +131,7 @@ To override the default local language f
 
 <h3>Functions</h3>
 <ul>
+<li>Bug 49975 - New function returning the name of the current sampler</li>
 </ul>
 
 <h3>I18N</h3>

Modified: jakarta/jmeter/trunk/xdocs/usermanual/functions.xml
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/usermanual/functions.xml?rev=1000632&r1=1000631&r2=1000632&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/usermanual/functions.xml (original)
+++ jakarta/jmeter/trunk/xdocs/usermanual/functions.xml Thu Sep 23 21:28:12 2010
@@ -88,6 +88,7 @@ and need to be referenced using the __P 
         <tr><th>Type of function</th><th>Name</th><th>Comment</th></tr>
         <!-- N.B. the leading space is needed to ensure the content is processed -->
         <tr><td>Information</td><td> <a href="#__threadNum">threadNum</a></td><td>get thread number</td></tr>
+        <tr><td>Information</td><td> <a href="#__samplerName">samplerName</a></td><td>get the sampler name (label)</td></tr>
         <tr><td>Information</td><td> <a href="#__machineName">machineName</a></td><td>get the local machine name</td></tr>
         <tr><td>Information</td><td> <a href="#__time">time</a></td><td>return current time in various formats</td></tr>
         <tr><td>Information</td><td> <a href="#__log">log</a></td><td>log (or display) a message (and return the value)</td></tr>
@@ -1115,6 +1116,25 @@ A reference name - refName - for reusing
 <p>The file name, encoding and reference name parameters are resolved every time the function is executed.</p>
 </component>
 
+<component index="&sect-num;.5.27" name="__samplerName">
+
+<description>
+    <p>
+    The samplerName function returns the name (i.e. label) of the current sampler.
+    </p>
+    <note>
+    The function does not work on the Test Plan or in Configuration elements
+    as these don't have an associated sampler. 
+    </note>
+</description>
+
+<properties>
+        <property name="Variable Name" required="No">
+A reference name - refName - for reusing the value created by this function. Stored values are of the form ${refName}.
+        </property>
+</properties>
+</component>
+
 </subsection>
 
 <subsection name="&sect-num;.6 Pre-defined Variables" anchor="predefinedvars">



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@jakarta.apache.org
For additional commands, e-mail: notifications-help@jakarta.apache.org