Coverage Report - kg.apc.jmeter.functions.FifoGet
 
Classes in this File Line Coverage Branch Coverage Complexity
FifoGet
100%
21/21
50%
3/6
1.6
 
 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 FifoGet extends AbstractFunction {
 16  
 
 17  1
     private static final List<String> desc = new LinkedList<String>();
 18  
     private static final String KEY = "__fifoGet";
 19  
 
 20  
     static {
 21  1
         desc.add("FIFO queue name to get value");
 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 FifoGet() {
 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
         Object valueObj = FifoMap.getInstance().get(fifoName);
 36  1
         String value = null;
 37  1
         if (valueObj != null) {
 38  1
             value = valueObj.toString();
 39  
         }
 40  
 
 41  1
         JMeterVariables vars = getVariables();
 42  1
         if (vars != null && values.length > 1) {
 43  1
             String varName = ((CompoundVariable) values[1]).execute().trim();
 44  1
             vars.put(varName, value);
 45  
         }
 46  
 
 47  1
         return value;
 48  
     }
 49  
 
 50  
     @Override
 51  
     public synchronized void setParameters(Collection<CompoundVariable> parameters) throws InvalidVariableException {
 52  2
         checkMinParameterCount(parameters, 1);
 53  2
         values = parameters.toArray();
 54  2
     }
 55  
 
 56  
     @Override
 57  
     public String getReferenceKey() {
 58  1
         return KEY;
 59  
     }
 60  
 
 61  
     @Override
 62  
     public List<String> getArgumentDesc() {
 63  1
         return desc;
 64  
     }
 65  
 }