Hello Maxime, I am not sure this commit is a good idea. JMeterVariables are usually available per Thread and each VU (Thread) manipulates his own copy. Here you introduce a shared static JMeterVariables which is not thread safe. I think this will introduce bugs and I am not fond of the new API.
Regards On Wed, Jun 7, 2017 at 3:26 PM, <mchassagn...@apache.org> wrote: > Author: mchassagneux > Date: Wed Jun 7 13:26:36 2017 > New Revision: 1797920 > > URL: http://svn.apache.org/viewvc?rev=1797920&view=rev > Log: > Allow to use variables ( from User Defined Variables only ) in all > listeners in slave mode > Bugzilla Id: 57962 > > Modified: > jmeter/trunk/src/core/org/apache/jmeter/engine/PreCompiler.java > jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterContext.java > jmeter/trunk/src/core/org/apache/jmeter/threads/ > JMeterContextService.java > jmeter/trunk/xdocs/changes.xml > > 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=1797920& > r1=1797919&r2=1797920&view=diff > ============================================================ > ================== > --- jmeter/trunk/src/core/org/apache/jmeter/engine/PreCompiler.java > (original) > +++ jmeter/trunk/src/core/org/apache/jmeter/engine/PreCompiler.java Wed > Jun 7 13:26:36 2017 > @@ -28,6 +28,7 @@ import org.apache.jmeter.testelement.Tes > import org.apache.jmeter.testelement.TestPlan; > import org.apache.jmeter.threads.JMeterContextService; > import org.apache.jmeter.threads.JMeterVariables; > +import org.apache.jmeter.visualizers.backend.Backend; > import org.apache.jorphan.collections.HashTree; > import org.apache.jorphan.collections.HashTreeTraverser; > import org.slf4j.Logger; > @@ -61,7 +62,7 @@ public class PreCompiler implements Hash > /** {@inheritDoc} */ > @Override > public void addNode(Object node, HashTree subTree) { > - if(isRemote && node instanceof ResultCollector) > + if(isRemote && (node instanceof ResultCollector || node > instanceof Backend)) > { > try { > replacer.replaceValues((TestElement) node); > @@ -69,10 +70,8 @@ public class PreCompiler implements Hash > log.error("invalid variables", e); > } > } > - if (isRemote) { > - return; > - } > - if(node instanceof TestElement) > + > + if(!isRemote && node instanceof TestElement) > { > try { > replacer.replaceValues((TestElement) node); > @@ -86,14 +85,24 @@ public class PreCompiler implements Hash > replacer.setUserDefinedVariables(args); > JMeterVariables vars = new JMeterVariables(); > vars.putAll(args); > - JMeterContextService.getContext().setVariables(vars); > + // 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) { > ((Arguments)node).setRunningVersion(true); > Map<String, String> args = ((Arguments) > node).getArgumentsAsMap(); > replacer.addVariables(args); > - JMeterContextService.getContext().getVariables(). > putAll(args); > + // Don't store User Defined Variables in the context for > client side > + if (isRemote) { > + JMeterContextService.getClientVariable().putAll(args); > + } else { > + JMeterContextService.getContext().getVariables(). > putAll(args); > + } > } > } > > > Modified: jmeter/trunk/src/core/org/apache/jmeter/threads/ > JMeterContext.java > URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/ > apache/jmeter/threads/JMeterContext.java?rev= > 1797920&r1=1797919&r2=1797920&view=diff > ============================================================ > ================== > --- jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterContext.java > (original) > +++ jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterContext.java > Wed Jun 7 13:26:36 2017 > @@ -79,7 +79,8 @@ public class JMeterContext { > * @return a pointer to the JMeter variables. > */ > public JMeterVariables getVariables() { > - return variables; > + // If context variable is null ( Client side ) return client > variables > + return (variables == null) ? JMeterContextService.getClientVariable() > : variables; > } > > public void setVariables(JMeterVariables vars) { > > Modified: jmeter/trunk/src/core/org/apache/jmeter/threads/ > JMeterContextService.java > URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/ > apache/jmeter/threads/JMeterContextService.java?rev= > 1797920&r1=1797919&r2=1797920&view=diff > ============================================================ > ================== > --- jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterContextService.java > (original) > +++ jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterContextService.java > Wed Jun 7 13:26:36 2017 > @@ -46,6 +46,10 @@ public final class JMeterContextService > > //@GuardedGy("this") > private static int totalThreads = 0; > + > + //@GuardedGy("this") > + private static JMeterVariables variables = null; > + > > /** > * Private constructor to prevent instantiation. > @@ -162,6 +166,22 @@ public final class JMeterContextService > numberOfThreadsStarted = 0; > numberOfThreadsFinished = 0; > } > + > + /** > + * Get all variables accessible for JMeter client in a distributed > test (exclusively test plan and user defined variables ) > + * @return variables available for JMeter client > + */ > + public static JMeterVariables getClientVariable() { > + return variables; > + } > + > + /** > + * Set variables for JMeter client in a distributed test > + * @param var {@link JMeterVariables} > + */ > + public static void setClientVariable(JMeterVariables var) { > + variables = var; > + } > > public static class ThreadCounts { > > > Modified: jmeter/trunk/xdocs/changes.xml > URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes. > xml?rev=1797920&r1=1797919&r2=1797920&view=diff > ============================================================ > ================== > --- jmeter/trunk/xdocs/changes.xml [utf-8] (original) > +++ jmeter/trunk/xdocs/changes.xml [utf-8] Wed Jun 7 13:26:36 2017 > @@ -195,6 +195,7 @@ Summary > <li><bug>57958</bug>Fix transaction sample not generated if thread > stops/restarts. Implemented by Artem Fedorov (artem at blazemeter.com) > and contributed by BlazeMeter Ltd.</li> > <li><bug>61050</bug>Handle uninitialized RessourceBundle more > gracefully, when calling <code>JMeterUtils#getResString</code>.</li> > <li><bug>61100</bug>Invalid GC Log Filename on Windows</li> > + <li><bug>57962</bug>Allow to use variables ( from User Defined > Variables only ) in all listeners in slave mode</li> > </ul> > > <!-- =================== Thanks =================== --> > > > -- Cordialement. Philippe Mouawad.