jakarta-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: [JMeter] Contribution: Adding a function
Date Tue, 21 Sep 2010 10:27:41 GMT
On 21 September 2010 08:35, Jens Müller <jens_0@hotmail.com> wrote:
>
> Hi,
>
> I needed a new JMeter function to be able to access the name of the current sampler from
the Header Manager.
>
> I wanted to share it, maybe you can add it to the development branch:

Code additions are normally provided via the bug-tracking system, i.e. Bugzilla.

https://issues.apache.org/bugzilla/enter_bug.cgi?product=JMeter

If you create an enhancement request you can add the code to it as an
attachment.
If you do so, please include the standard AL header in the file.

Thanks!

> 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.JMeterContextService;
>
> /**
>  * Function to return the name of the current sampler.
>  */
> public class SamplerName extends AbstractFunction {
>
>     private static final String KEY = "__samplerName"; //$NON-NLS-1$
>
>     private static final List<String> desc = new LinkedList<String>();
>
>     /** {@inheritDoc} */
>     @Override
>     public String execute(SampleResult previousResult, Sampler currentSampler)
>             throws InvalidVariableException {
>         return JMeterContextService.getContext().getCurrentSampler().getName();
>     }
>
>     /** {@inheritDoc} */
>     @Override
>     public void setParameters(Collection<CompoundVariable> parameters)
>             throws InvalidVariableException {
>         checkParameterCount(parameters, 0, 0);
>     }
>
>     /** {@inheritDoc} */
>     @Override
>     public String getReferenceKey() {
>         return KEY;
>     }
>
>     /** {@inheritDoc} */
>     public List<String> getArgumentDesc() {
>         return desc;
>     }
> }
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: dev-help@jakarta.apache.org
>
>

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


Mime
View raw message