jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1212891 - in /jmeter/trunk: src/functions/org/apache/jmeter/functions/ xdocs/ xdocs/usermanual/
Date Sat, 10 Dec 2011 21:48:20 GMT
Author: pmouawad
Date: Sat Dec 10 21:48:19 2011
New Revision: 1212891

URL: http://svn.apache.org/viewvc?rev=1212891&view=rev
Log:
Added new function machineIP
Factored with machineNam
Removed synchronized as not needed

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

Added: jmeter/trunk/src/functions/org/apache/jmeter/functions/AbstractHostIPName.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/functions/org/apache/jmeter/functions/AbstractHostIPName.java?rev=1212891&view=auto
==============================================================================
--- jmeter/trunk/src/functions/org/apache/jmeter/functions/AbstractHostIPName.java (added)
+++ jmeter/trunk/src/functions/org/apache/jmeter/functions/AbstractHostIPName.java Sat Dec
10 21:48:19 2011
@@ -0,0 +1,83 @@
+/*
+ * 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.samplers.SampleResult;
+import org.apache.jmeter.samplers.Sampler;
+import org.apache.jmeter.threads.JMeterVariables;
+import org.apache.jmeter.util.JMeterUtils;
+
+abstract class AbstractHostIPName extends AbstractFunction {
+
+    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;
+
+    public AbstractHostIPName() {
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public String execute(SampleResult previousResult, Sampler currentSampler)
+            throws InvalidVariableException {
+
+        /*
+         * boolean fullHostName = false; if (((CompoundFunction) values[0])
+         * .execute() .toLowerCase() .equals("true")) { fullHostName = true; }
+         */
+
+        String value = compute();
+
+        if (values.length >= 1){// we have a variable name
+            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) {
+                    vars.put(varName, value);
+                }
+            }
+        }
+        return value;
+
+    }
+
+    abstract protected String compute();
+
+	/** {@inheritDoc} */
+    @Override
+    public synchronized void setParameters(Collection<CompoundVariable> parameters)
throws InvalidVariableException {
+        checkParameterCount(parameters, 0, 1);
+        values = parameters.toArray();
+    }
+
+    /** {@inheritDoc} */
+    public List<String> getArgumentDesc() {
+        return desc;
+    }
+}

Propchange: jmeter/trunk/src/functions/org/apache/jmeter/functions/AbstractHostIPName.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jmeter/trunk/src/functions/org/apache/jmeter/functions/MachineIP.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/functions/org/apache/jmeter/functions/MachineIP.java?rev=1212891&view=auto
==============================================================================
--- jmeter/trunk/src/functions/org/apache/jmeter/functions/MachineIP.java (added)
+++ jmeter/trunk/src/functions/org/apache/jmeter/functions/MachineIP.java Sat Dec 10 21:48:19
2011
@@ -0,0 +1,43 @@
+/*
+ * 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 org.apache.jmeter.util.JMeterUtils;
+
+/**
+ * Return Machine IP
+ */
+public class MachineIP extends AbstractHostIPName {
+
+    private static final String KEY = "__machineIP"; //$NON-NLS-1$
+
+    public MachineIP() {
+    }
+
+	@Override
+	protected String compute() {
+		return JMeterUtils.getLocalHostIP();
+	}
+	
+    /** {@inheritDoc} */
+    @Override
+    public String getReferenceKey() {
+        return KEY;
+    }
+}

Propchange: jmeter/trunk/src/functions/org/apache/jmeter/functions/MachineIP.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jmeter/trunk/src/functions/org/apache/jmeter/functions/MachineName.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/functions/org/apache/jmeter/functions/MachineName.java?rev=1212891&r1=1212890&r2=1212891&view=diff
==============================================================================
--- jmeter/trunk/src/functions/org/apache/jmeter/functions/MachineName.java (original)
+++ jmeter/trunk/src/functions/org/apache/jmeter/functions/MachineName.java Sat Dec 10 21:48:19
2011
@@ -18,72 +18,26 @@
 
 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.samplers.SampleResult;
-import org.apache.jmeter.samplers.Sampler;
-import org.apache.jmeter.threads.JMeterVariables;
 import org.apache.jmeter.util.JMeterUtils;
 
-public class MachineName extends AbstractFunction {
-
-    private static final List<String> desc = new LinkedList<String>();
+/**
+ * Return Machine Host
+ */
+public class MachineName extends AbstractHostIPName {
 
     private static final String KEY = "__machineName"; //$NON-NLS-1$
 
-    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;
-
     public MachineName() {
     }
 
-    /** {@inheritDoc} */
-    @Override
-    public synchronized String execute(SampleResult previousResult, Sampler currentSampler)
-            throws InvalidVariableException {
-
-        /*
-         * boolean fullHostName = false; if (((CompoundFunction) values[0])
-         * .execute() .toLowerCase() .equals("true")) { fullHostName = true; }
-         */
-
-        String machineName = JMeterUtils.getLocalHostName();
-
-        if (values.length >= 1){// we have a variable name
-            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) {
-                    vars.put(varName, machineName);
-                }
-            }
-        }
-        return machineName;
-
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    public synchronized void setParameters(Collection<CompoundVariable> parameters)
throws InvalidVariableException {
-        checkParameterCount(parameters, 0, 1);
-        values = parameters.toArray();
-    }
-
+	@Override
+	protected String compute() {
+		return JMeterUtils.getLocalHostName();
+	}
+	
     /** {@inheritDoc} */
     @Override
     public String getReferenceKey() {
         return KEY;
     }
-
-    /** {@inheritDoc} */
-    public List<String> getArgumentDesc() {
-        return desc;
-    }
 }

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1212891&r1=1212890&r2=1212891&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Sat Dec 10 21:48:19 2011
@@ -196,6 +196,7 @@ This behaviour can be changed with prope
 <li>Bug 52006 - Create a function RandomString to generate random Strings</li>
 <li>Bug 52016 - It would be useful to support Jexl2</li>
 <li>__char() function now supports octal values</li>
+<li>New function __machineIP returning IP address</li>
 </ul>
 
 <h3>I18N</h3>

Modified: jmeter/trunk/xdocs/usermanual/functions.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/functions.xml?rev=1212891&r1=1212890&r2=1212891&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/functions.xml (original)
+++ jmeter/trunk/xdocs/usermanual/functions.xml Sat Dec 10 21:48:19 2011
@@ -89,6 +89,7 @@ and need to be referenced using the __P 
         <!-- 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="#__machineIP">machineIP</a></td><td>get
the local machine IP address</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>
@@ -468,7 +469,7 @@ Examples:<br></br>
 	</p>
 </component>
 
-<component index="&sect-num;.5.6" name="__machineName">
+<component index="&sect-num;.5.6a" name="__machineName">
 <description><p>The machineName function returns the local host name</p></description>
 
 <properties>
@@ -477,6 +478,15 @@ Examples:<br></br>
 </properties>
 </component>
 
+<component index="&sect-num;.5.6b" name="__machineIP">
+<description><p>The machineIP function returns the local IP address</p></description>
+
+<properties>
+        <property name="Variable Name" required="No">A reference name for reusing the
value
+                computed by this function.</property>
+</properties>
+</component>
+
 <component index="&sect-num;.5.7" name="__javaScript">
 <description>
 <p>



Mime
View raw message