Coverage Report - kg.apc.jmeter.modifiers.FifoPopPreProcessor
 
Classes in this File Line Coverage Branch Coverage Complexity
FifoPopPreProcessor
86%
32/37
50%
3/6
1.385
 
 1  
 package kg.apc.jmeter.modifiers;
 2  
 
 3  
 import org.apache.jmeter.processor.PreProcessor;
 4  
 import org.apache.jmeter.testelement.AbstractTestElement;
 5  
 import org.apache.jmeter.testelement.TestStateListener;
 6  
 import org.apache.jmeter.threads.JMeterContextService;
 7  
 import org.apache.jmeter.threads.JMeterVariables;
 8  
 import org.apache.jmeter.util.JMeterUtils;
 9  
 import org.apache.jorphan.logging.LoggingManager;
 10  
 import org.apache.log.Logger;
 11  
 
 12  
 public class FifoPopPreProcessor extends AbstractTestElement
 13  
         implements PreProcessor, TestStateListener {
 14  
 
 15  1
     private static final Logger log = LoggingManager.getLoggerForClass();
 16  
 
 17  
     public static final String queueName = "FifoName";
 18  
     public static final String variableName = "Variable";
 19  
     public static final String TIMEOUT = "Timeout";
 20  
 
 21  16
     public FifoPopPreProcessor() {
 22  16
         setTimeout(Long.toString(JMeterUtils.getPropDefault(FifoMap.TIMEOUT_PROP, Long.MAX_VALUE)));
 23  16
     }
 24  
 
 25  
     public void testStarted() {
 26  2
         FifoMap.getInstance().clear();
 27  2
     }
 28  
 
 29  
     public void testStarted(String host) {
 30  1
         testStarted();
 31  1
     }
 32  
 
 33  
     public void testEnded() {
 34  2
         FifoMap.getInstance().clear();
 35  2
     }
 36  
 
 37  
     public void testEnded(String host) {
 38  1
         testEnded();
 39  1
     }
 40  
 
 41  
     public void process() {
 42  1
         String value = null;
 43  
         try {
 44  1
             Object valueObj = FifoMap.getInstance().pop(getQueueName(), getTimeoutAsLong());
 45  1
             if (valueObj != null) {
 46  0
                 value = valueObj.toString();
 47  
             }
 48  0
         } catch (InterruptedException ex) {
 49  0
             log.warn("Interrupted pop from queue " + getQueueName());
 50  0
             value = "INTERRUPTED";
 51  1
         }
 52  1
         final JMeterVariables vars = JMeterContextService.getContext().getVariables();
 53  1
         if (vars != null) {
 54  1
             vars.put(getVarName(), value);
 55  
         }
 56  1
     }
 57  
 
 58  
     public String getVarName() {
 59  3
         return getPropertyAsString(variableName);
 60  
     }
 61  
 
 62  
     private long getTimeoutAsLong() {
 63  1
         String timeout = getTimeout();
 64  1
         if (timeout.isEmpty()) {
 65  0
             return Long.MAX_VALUE;
 66  
         } else {
 67  1
             return Long.parseLong(timeout);
 68  
         }
 69  
     }
 70  
 
 71  
     public String getTimeout() {
 72  3
         return getPropertyAsString(TIMEOUT);
 73  
     }
 74  
 
 75  
     public String getQueueName() {
 76  3
         return getPropertyAsString(queueName);
 77  
     }
 78  
 
 79  
     public final void setTimeout(String atimeout) {
 80  20
         setProperty(TIMEOUT, atimeout);
 81  20
     }
 82  
 
 83  
     public void setVarName(String text) {
 84  3
         setProperty(variableName, text);
 85  3
     }
 86  
 
 87  
     public void setQueueName(String text) {
 88  3
         setProperty(queueName, text);
 89  3
     }
 90  
 }