Skip to content

Commit

Permalink
feat: add property to disable FunctionProperty caching
Browse files Browse the repository at this point in the history
  • Loading branch information
vlsi committed Apr 22, 2023
1 parent 50e2015 commit 7beaf41
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
6 changes: 6 additions & 0 deletions bin/jmeter.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
}
}
Expand Down Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions xdocs/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Summary

<h3>General</h3>
<ul>
<li>Added property <code>function.cache.per.iteration</code> to disable function property caching</li>
</ul>

<ch_section>Non-functional changes</ch_section>
Expand Down
8 changes: 8 additions & 0 deletions xdocs/usermanual/properties_reference.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,14 @@ JMETER-SERVER</source>
ORO PatternCacheLRU size.<br/>
Defaults to: <code>1000</code>
</property>
<property name="function.cache.per.iteration">
<p>Cache function execution during test execution.</p>
<p>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.</p>
<note>The caching behaviour would likely be disabled in the upcoming versions</note>
Defaults to: <code>true</code>
</property>
<property name="propertyEditorSearchPath">
TestBeanGui<br/>
Defaults to: <code>null</code>
Expand Down

0 comments on commit 7beaf41

Please sign in to comment.