You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by mc...@apache.org on 2017/06/07 13:26:37 UTC

svn commit: r1797920 - in /jmeter/trunk: src/core/org/apache/jmeter/engine/PreCompiler.java src/core/org/apache/jmeter/threads/JMeterContext.java src/core/org/apache/jmeter/threads/JMeterContextService.java xdocs/changes.xml

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 =================== -->



Re: svn commit: r1797920 - in /jmeter/trunk: src/core/org/apache/jmeter/engine/PreCompiler.java src/core/org/apache/jmeter/threads/JMeterContext.java src/core/org/apache/jmeter/threads/JMeterContextService.java xdocs/changes.xml

Posted by Philippe Mouawad <ph...@gmail.com>.
Hello Maxime,
I commited some changes on the feature to try to lock JMeterVariables as
unmodifiable.

Would it be possible to test and also to add a JMX based Unit Test that
checks replacement works ?

Have a look at
    <antcall target="batchtest">
...
    </antcall>

Thanks

On Fri, Jun 9, 2017 at 1:26 PM, Maxime Chassagneux <
maxime.chassagneux@gmail.com> wrote:

> Hello,
>
> I use this patch from 2-3 months without bugs.
> In fact it's impossible to access to the new shared JMeterVariables
> variables
> in a executed nide of JMeter.
> This field is null and only set for the client side instance.
>
> May be it's possible to improve this patch, rather than revert it ?
>
> 2017-06-09 7:10 GMT+02:00 Philippe Mouawad <ph...@gmail.com>:
>
> > 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, <mc...@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.
> >
>



-- 
Cordialement.
Philippe Mouawad.

Re: svn commit: r1797920 - in /jmeter/trunk: src/core/org/apache/jmeter/engine/PreCompiler.java src/core/org/apache/jmeter/threads/JMeterContext.java src/core/org/apache/jmeter/threads/JMeterContextService.java xdocs/changes.xml

Posted by Maxime Chassagneux <ma...@gmail.com>.
Hello,

I use this patch from 2-3 months without bugs.
In fact it's impossible to access to the new shared JMeterVariables variables
in a executed nide of JMeter.
This field is null and only set for the client side instance.

May be it's possible to improve this patch, rather than revert it ?

2017-06-09 7:10 GMT+02:00 Philippe Mouawad <ph...@gmail.com>:

> 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, <mc...@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.
>

Re: svn commit: r1797920 - in /jmeter/trunk: src/core/org/apache/jmeter/engine/PreCompiler.java src/core/org/apache/jmeter/threads/JMeterContext.java src/core/org/apache/jmeter/threads/JMeterContextService.java xdocs/changes.xml

Posted by Philippe Mouawad <ph...@gmail.com>.
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, <mc...@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.