diff --git a/bin/jmeter.properties b/bin/jmeter.properties index 69b77d46bdf..e6d373fcb4e 100644 --- a/bin/jmeter.properties +++ b/bin/jmeter.properties @@ -1055,6 +1055,12 @@ csvdataset.file.encoding_list=UTF-8|UTF-16|ISO-8859-15|US-ASCII # ORO PatternCacheLRU size #oro.patterncache.size=1000 +# Cache function execution during test execution +# By default, JMeter caches function properties, however, it might cause unexpected results +# when the component is shared across threads and the expression depends on the thread variables. +# The caching behaviour would likely change in the upcoming versions +#function.cache.per.iteration=true + #TestBeanGui # #propertyEditorSearchPath=null diff --git a/src/core/src/main/java/org/apache/jmeter/testelement/property/FunctionProperty.java b/src/core/src/main/java/org/apache/jmeter/testelement/property/FunctionProperty.java index a4adf027747..0bfd45ada5b 100644 --- a/src/core/src/main/java/org/apache/jmeter/testelement/property/FunctionProperty.java +++ b/src/core/src/main/java/org/apache/jmeter/testelement/property/FunctionProperty.java @@ -21,17 +21,24 @@ import org.apache.jmeter.testelement.TestElement; import org.apache.jmeter.threads.JMeterContext; import org.apache.jmeter.threads.JMeterContextService; +import org.apache.jmeter.util.JMeterUtils; /** * Class that implements the Function property */ public class FunctionProperty extends AbstractProperty { private static final long serialVersionUID = 233L; + private static final boolean FUNCTION_CACHE_PER_ITERATION = + JMeterUtils.getPropDefault("function.cache.per.iteration", true); private transient CompoundVariable function; private int testIteration = -1; + /** + * The cache will be removed in the subsequent releases. + * For now, it is kept for backward compatibility. + */ private String cacheValue; public FunctionProperty(String name, CompoundVariable func) { @@ -47,7 +54,7 @@ public FunctionProperty() { public void setObjectValue(Object v) { if (v instanceof CompoundVariable && !isRunningVersion()) { function = (CompoundVariable) v; - } else { + } else if (FUNCTION_CACHE_PER_ITERATION) { cacheValue = v.toString(); } } @@ -87,7 +94,7 @@ public String getStringValue() { log.debug("Not running version, return raw function string"); return function.getRawParameters(); } - if(!ctx.isSamplingStarted()) { + if (!FUNCTION_CACHE_PER_ITERATION || !ctx.isSamplingStarted()) { return function.execute(); } log.debug("Running version, executing function"); diff --git a/xdocs/changes.xml b/xdocs/changes.xml index 508296c40ac..8feaeb0ef15 100644 --- a/xdocs/changes.xml +++ b/xdocs/changes.xml @@ -97,6 +97,7 @@ Summary
function.cache.per.iteration
to disable function property caching1000
+Cache function execution during test execution.
+By default, JMeter caches function properties during a test iteration, however, + it might cause unexpected results when a component is shared across threads and the expression depends on + the thread variables.
+true
+null