Coverage Report - kg.apc.jmeter.functions.FifoSize
 
Classes in this File Line Coverage Branch Coverage Complexity
FifoSize
100%
19/19
50%
2/4
1.4
 
 1  
 package kg.apc.jmeter.functions;
 2  
 
 3  
 import kg.apc.jmeter.modifiers.FifoMap;
 4  
 import org.apache.jmeter.engine.util.CompoundVariable;
 5  
 import org.apache.jmeter.functions.AbstractFunction;
 6  
 import org.apache.jmeter.functions.InvalidVariableException;
 7  
 import org.apache.jmeter.samplers.SampleResult;
 8  
 import org.apache.jmeter.samplers.Sampler;
 9  
 import org.apache.jmeter.threads.JMeterVariables;
 10  
 
 11  
 import java.util.Collection;
 12  
 import java.util.LinkedList;
 13  
 import java.util.List;
 14  
 
 15  
 public class FifoSize extends AbstractFunction {
 16  
 
 17  1
     private static final List<String> desc = new LinkedList<String>();
 18  
     private static final String KEY = "__fifoSize";
 19  
 
 20  
     static {
 21  1
         desc.add("FIFO queue name to get elements count");
 22  1
         desc.add("Name of variable in which to store the result (optional)");
 23  1
     }
 24  
 
 25  
     private Object[] values;
 26  
 
 27  4
     public FifoSize() {
 28  4
     }
 29  
 
 30  
     @Override
 31  
     public synchronized String execute(SampleResult previousResult, Sampler currentSampler)
 32  
             throws InvalidVariableException {
 33  1
         String fifoName = ((CompoundVariable) values[0]).execute();
 34  
 
 35  1
         int size = FifoMap.getInstance().length(fifoName);
 36  1
         String value = Integer.toString(size);
 37  
 
 38  1
         JMeterVariables vars = getVariables();
 39  1
         if (vars != null && values.length > 1) {
 40  1
             String varName = ((CompoundVariable) values[1]).execute().trim();
 41  1
             vars.put(varName, value);
 42  
         }
 43  
 
 44  1
         return value;
 45  
     }
 46  
 
 47  
     @Override
 48  
     public synchronized void setParameters(Collection<CompoundVariable> parameters) throws InvalidVariableException {
 49  2
         checkMinParameterCount(parameters, 1);
 50  2
         values = parameters.toArray();
 51  2
     }
 52  
 
 53  
     @Override
 54  
     public String getReferenceKey() {
 55  1
         return KEY;
 56  
     }
 57  
 
 58  
     @Override
 59  
     public List<String> getArgumentDesc() {
 60  1
         return desc;
 61  
     }
 62  
 }