Skip to content

Commit 08c4a16

Browse files
committed
feat: add property to disable FunctionProperty caching
1 parent 69c1109 commit 08c4a16

4 files changed

Lines changed: 24 additions & 2 deletions

File tree

bin/jmeter.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,12 @@ csvdataset.file.encoding_list=UTF-8|UTF-16|ISO-8859-15|US-ASCII
10551055
# ORO PatternCacheLRU size
10561056
#oro.patterncache.size=1000
10571057

1058+
# Cache function execution during test execution
1059+
# By default, JMeter caches function properties, however, it might cause unexpected results
1060+
# when the component is shared across threads and the expression depends on the thread variables.
1061+
# The caching behaviour would likely change in the upcoming versions
1062+
#function.cache.per.iteration=true
1063+
10581064
#TestBeanGui
10591065
#
10601066
#propertyEditorSearchPath=null

src/core/src/main/java/org/apache/jmeter/testelement/property/FunctionProperty.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,24 @@
2121
import org.apache.jmeter.testelement.TestElement;
2222
import org.apache.jmeter.threads.JMeterContext;
2323
import org.apache.jmeter.threads.JMeterContextService;
24+
import org.apache.jmeter.util.JMeterUtils;
2425

2526
/**
2627
* Class that implements the Function property
2728
*/
2829
public class FunctionProperty extends AbstractProperty {
2930
private static final long serialVersionUID = 233L;
31+
private static final boolean FUNCTION_CACHE_PER_ITERATION =
32+
JMeterUtils.getPropDefault("function.cache.per.iteration", true);
3033

3134
private transient CompoundVariable function;
3235

3336
private int testIteration = -1;
3437

38+
/**
39+
* The cache will be removed in the subsequent releases.
40+
* For now, it is kept for backward compatibility.
41+
*/
3542
private String cacheValue;
3643

3744
public FunctionProperty(String name, CompoundVariable func) {
@@ -47,7 +54,7 @@ public FunctionProperty() {
4754
public void setObjectValue(Object v) {
4855
if (v instanceof CompoundVariable && !isRunningVersion()) {
4956
function = (CompoundVariable) v;
50-
} else {
57+
} else if (FUNCTION_CACHE_PER_ITERATION) {
5158
cacheValue = v.toString();
5259
}
5360
}
@@ -87,7 +94,7 @@ public String getStringValue() {
8794
log.debug("Not running version, return raw function string");
8895
return function.getRawParameters();
8996
}
90-
if(!ctx.isSamplingStarted()) {
97+
if (!FUNCTION_CACHE_PER_ITERATION || !ctx.isSamplingStarted()) {
9198
return function.execute();
9299
}
93100
log.debug("Running version, executing function");

xdocs/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ Summary
9797

9898
<h3>General</h3>
9999
<ul>
100+
<li>Added property <code>function.cache.per.iteration</code> to disable function property caching</li>
100101
</ul>
101102

102103
<ch_section>Non-functional changes</ch_section>

xdocs/usermanual/properties_reference.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,14 @@ JMETER-SERVER</source>
13391339
ORO PatternCacheLRU size.<br/>
13401340
Defaults to: <code>1000</code>
13411341
</property>
1342+
<property name="function.cache.per.iteration">
1343+
<p>Cache function execution during test execution.</p>
1344+
<p>By default, JMeter caches function properties during a test iteration, however,
1345+
it might cause unexpected results when a component is shared across threads and the expression depends on
1346+
the thread variables.</p>
1347+
<note>The caching behaviour would likely be disabled in the upcoming versions</note>
1348+
Defaults to: <code>true</code>
1349+
</property>
13421350
<property name="propertyEditorSearchPath">
13431351
TestBeanGui<br/>
13441352
Defaults to: <code>null</code>

0 commit comments

Comments
 (0)