You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2017/06/11 20:13:21 UTC
svn commit: r1798400 -
/jmeter/trunk/src/core/org/apache/jmeter/engine/PreCompiler.java
Author: pmouawad
Date: Sun Jun 11 20:13:21 2017
New Revision: 1798400
URL: http://svn.apache.org/viewvc?rev=1798400&view=rev
Log:
Allow to use variables ( from User Defined Variables only ) in all listeners in slave mode
Try to make code of PreCompiler more readable
Bugzilla Id: 57962
Modified:
jmeter/trunk/src/core/org/apache/jmeter/engine/PreCompiler.java
Modified: jmeter/trunk/src/core/org/apache/jmeter/engine/PreCompiler.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/engine/PreCompiler.java?rev=1798400&r1=1798399&r2=1798400&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/engine/PreCompiler.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/engine/PreCompiler.java Sun Jun 11 20:13:21 2017
@@ -47,64 +47,88 @@ public class PreCompiler implements Hash
// In the latter case, only ResultCollectors are updated,
// as only these are relevant to the client, and updating
// other elements causes all sorts of problems.
- private final boolean isRemote; // skip certain processing for remote tests
+ private final boolean isClientSide; // skip certain processing for remote tests
public PreCompiler() {
replacer = new ValueReplacer();
- isRemote = false;
+ isClientSide = false;
}
public PreCompiler(boolean remote) {
replacer = new ValueReplacer();
- isRemote = remote;
+ isClientSide = remote;
}
/** {@inheritDoc} */
@Override
public void addNode(Object node, HashTree subTree) {
- if(isRemote && (node instanceof ResultCollector || node instanceof Backend))
- {
- try {
- replacer.replaceValues((TestElement) node);
- } catch (InvalidVariableException e) {
- log.error("invalid variables", e);
+ if(isClientSide) {
+ if(node instanceof ResultCollector || node instanceof Backend) {
+ try {
+ replacer.replaceValues((TestElement) node);
+ } catch (InvalidVariableException e) {
+ log.error("invalid variables in node {}", ((TestElement)node).getName(), e);
+ }
}
- }
- if(!isRemote && node instanceof TestElement)
- {
- try {
- replacer.replaceValues((TestElement) node);
- } catch (InvalidVariableException e) {
- log.error("invalid variables", e);
+ if (node instanceof TestPlan) {
+ JMeterVariables vars = createVars((TestPlan)node);
+ // Don't store variable of test plan in the context for client side
+ JMeterContextService.setClientVariables(vars);
}
- }
- if (node instanceof TestPlan) {
- ((TestPlan)node).prepareForPreCompile(); //A hack to make user-defined variables in the testplan element more dynamic
- Map<String, String> args = ((TestPlan) node).getUserDefinedVariables();
- replacer.setUserDefinedVariables(args);
- JMeterVariables vars = new JMeterVariables();
- vars.putAll(args);
- // Don't store variable of test plan in the context for client side
- if (isRemote) {
- JMeterContextService.setClientVariable(vars);
- } else {
- JMeterContextService.getContext().setVariables(vars);
+
+ if (node instanceof Arguments) {
+ // Don't store User Defined Variables in the context for client side
+ Map<String, String> args = createArgumentsMap((Arguments) node);
+ JMeterContextService.getClientVariables().putAll(args);
}
- }
- if (node instanceof Arguments) {
- ((Arguments)node).setRunningVersion(true);
- Map<String, String> args = ((Arguments) node).getArgumentsAsMap();
- replacer.addVariables(args);
- // Don't store User Defined Variables in the context for client side
- if (isRemote) {
- JMeterContextService.getClientVariable().putAll(args);
- } else {
+ } else {
+ if(node instanceof TestElement) {
+ try {
+ replacer.replaceValues((TestElement) node);
+ } catch (InvalidVariableException e) {
+ log.error("invalid variables in node {}", ((TestElement)node).getName(), e);
+ }
+ }
+
+ if (node instanceof TestPlan) {
+ JMeterVariables vars = createVars((TestPlan)node);
+ JMeterContextService.getContext().setVariables(vars);
+ }
+
+ if (node instanceof Arguments) {
+ Map<String, String> args = createArgumentsMap((Arguments) node);
JMeterContextService.getContext().getVariables().putAll(args);
}
}
}
+
+ /**
+ * Create Map of Arguments
+ * @param arguments {@link Arguments}
+ * @return {@link Map}
+ */
+ private Map<String, String> createArgumentsMap(Arguments arguments) {
+ arguments.setRunningVersion(true);
+ Map<String, String> args = arguments.getArgumentsAsMap();
+ replacer.addVariables(args);
+ return args;
+ }
+
+ /**
+ * Create variables for testPlan
+ * @param testPlan {@link JMeterVariables}
+ * @return {@link JMeterVariables}
+ */
+ private JMeterVariables createVars(TestPlan testPlan) {
+ testPlan.prepareForPreCompile(); //A hack to make user-defined variables in the testplan element more dynamic
+ Map<String, String> args = testPlan.getUserDefinedVariables();
+ replacer.setUserDefinedVariables(args);
+ JMeterVariables vars = new JMeterVariables();
+ vars.putAll(args);
+ return vars;
+ }
/** {@inheritDoc} */
@Override