1 18 19 package org.apache.jmeter.testelement.property; 20 21 import org.apache.jmeter.engine.util.CompoundVariable; 22 import org.apache.jmeter.testelement.TestElement; 23 import org.apache.jmeter.threads.JMeterContext; 24 import org.apache.jmeter.threads.JMeterContextService; 25 26 29 public class FunctionProperty extends AbstractProperty 30 { 31 CompoundVariable function; 32 int testIteration = -1; 33 String cacheValue; 34 35 public FunctionProperty(String name, CompoundVariable func) 36 { 37 super(name); 38 function = func; 39 } 40 41 public FunctionProperty() 42 { 43 super(); 44 } 45 46 public void setObjectValue(Object v) 47 { 48 if (v instanceof CompoundVariable && !isRunningVersion()) 49 { 50 function = (CompoundVariable) v; 51 } 52 else 53 { 54 cacheValue = v.toString(); 55 } 56 } 57 58 public boolean equals(Object o) 59 { 60 if (o instanceof FunctionProperty) 61 { 62 if (function != null) 63 { 64 return function.equals(((JMeterProperty) o).getObjectValue()); 65 } 66 } 67 return false; 68 } 69 70 76 public String getStringValue() 77 { 78 log.debug("Calling getStringValue from FunctionProperty"); 79 log.debug("boogedy boogedy"); 80 JMeterContext ctx = JMeterContextService.getContext(); if (!isRunningVersion() 82 || !ctx.isSamplingStarted()) 83 { 84 log.debug("Not running version, return raw function string"); 85 return function.getRawParameters(); 86 } 87 else 88 { 89 log.debug("Running version, executing function"); 90 int iter = 91 ctx.getVariables().getIteration(); 92 if (iter < testIteration) 93 { 94 testIteration = -1; 95 } 96 if (iter > testIteration || cacheValue == null) 97 { 98 testIteration = iter; 99 cacheValue = function.execute(); 100 } 101 return cacheValue; 102 } 103 } 104 105 108 public Object getObjectValue() 109 { 110 return function; 111 } 112 113 public Object clone() 114 { 115 FunctionProperty prop = (FunctionProperty) super.clone(); 116 prop.cacheValue = cacheValue; 117 prop.testIteration = testIteration; 118 prop.function = function; 119 return prop; 120 } 121 122 125 public void recoverRunningVersion(TestElement owner) 126 { 127 cacheValue = null; 128 } 129 } 130 | Popular Tags |