You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jakarta.apache.org by Jens Müller <je...@hotmail.com> on 2010/09/21 09:35:22 UTC
[JMeter] Contribution: Adding a function
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:
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
RE: [JMeter] Contribution: Adding a function
Posted by Jens Müller <je...@hotmail.com>.
Better of course:
> public String execute(SampleResult previousResult, Sampler currentSampler)
> throws InvalidVariableException {
> return JMeterContextService.getContext().getCurrentSampler().getName();
> }
return currentSampler.getName();
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: dev-help@jakarta.apache.org
Re: [JMeter] Contribution: Adding a function
Posted by sebb <se...@gmail.com>.
On 21 September 2010 08:35, Jens Müller <je...@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