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:57:38 UTC
svn commit: r1798405 - in /jmeter/trunk/src/core/org/apache/jmeter:
engine/ClientJMeterEngine.java engine/PreCompiler.java
threads/JMeterContext.java threads/JMeterContextService.java
threads/UnmodifiableJMeterVariables.java
Author: pmouawad
Date: Sun Jun 11 20:57:38 2017
New Revision: 1798405
URL: http://svn.apache.org/viewvc?rev=1798405&view=rev
Log:
Allow to use variables ( from User Defined Variables only ) in all listeners in slave mode
Try to secure exposed JMeterVariables
Bugzilla Id: 57962
Added:
jmeter/trunk/src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java (with props)
Modified:
jmeter/trunk/src/core/org/apache/jmeter/engine/ClientJMeterEngine.java
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
Modified: jmeter/trunk/src/core/org/apache/jmeter/engine/ClientJMeterEngine.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/engine/ClientJMeterEngine.java?rev=1798405&r1=1798404&r2=1798405&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/engine/ClientJMeterEngine.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/engine/ClientJMeterEngine.java Sun Jun 11 20:57:38 2017
@@ -112,7 +112,9 @@ public class ClientJMeterEngine implemen
HashTree testTree = test;
synchronized(testTree) {
- testTree.traverse(new PreCompiler(true)); // limit the changes to client only test elements
+ PreCompiler compiler = new PreCompiler(true);
+ testTree.traverse(compiler); // limit the changes to client only test elements
+ JMeterContextService.initClientSideVariables(compiler.getClientSideVariables());
testTree.traverse(new TurnElementsOn());
testTree.traverse(new ConvertListeners());
}
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=1798405&r1=1798404&r2=1798405&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:57:38 2017
@@ -48,6 +48,8 @@ public class PreCompiler implements Hash
// as only these are relevant to the client, and updating
// other elements causes all sorts of problems.
private final boolean isClientSide; // skip certain processing for remote tests
+
+ private JMeterVariables clientSideVariables;
public PreCompiler() {
replacer = new ValueReplacer();
@@ -72,15 +74,13 @@ public class PreCompiler implements Hash
}
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);
+ this.clientSideVariables = createVars((TestPlan)node);
}
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);
+ clientSideVariables.putAll(args);
}
} else {
@@ -139,4 +139,11 @@ public class PreCompiler implements Hash
@Override
public void processPath() {
}
+
+ /**
+ * @return the clientSideVariables
+ */
+ public JMeterVariables getClientSideVariables() {
+ return clientSideVariables;
+ }
}
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=1798405&r1=1798404&r2=1798405&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterContext.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterContext.java Sun Jun 11 20:57:38 2017
@@ -80,7 +80,9 @@ public class JMeterContext {
*/
public JMeterVariables getVariables() {
// If context variable is null ( Client side ) return client variables
- return (variables == null) ? JMeterContextService.getClientVariables() : variables;
+ return (variables != null) ?
+ variables :
+ JMeterContextService.getClientSideVariables();
}
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=1798405&r1=1798404&r2=1798405&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterContextService.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterContextService.java Sun Jun 11 20:57:38 2017
@@ -47,7 +47,7 @@ public final class JMeterContextService
//@GuardedGy("this")
private static int totalThreads = 0;
- private static JMeterVariables variables = null;
+ private static UnmodifiableJMeterVariables variables;
/**
@@ -169,19 +169,12 @@ public final class JMeterContextService
/**
* Get all variables accessible for JMeter client in a distributed test
* (only test plan and user defined variables)
+ * Note this is a read-only collection
* @return {@link JMeterVariables} available for JMeter client
*/
- public static JMeterVariables getClientVariables() {
+ public static JMeterVariables getClientSideVariables() {
return variables;
}
-
- /**
- * Set variables for JMeter client in a distributed test
- * @param var {@link JMeterVariables}
- */
- public static void setClientVariables(JMeterVariables var) {
- variables = var;
- }
public static class ThreadCounts {
@@ -197,4 +190,12 @@ public final class JMeterContextService
finishedThreads = finished;
}
}
+
+ /**
+ * Set variables for JMeter client in a distributed test (INTERNAL API)
+ * @param clientSideVariables {@link JMeterVariables}
+ */
+ public static void initClientSideVariables(JMeterVariables clientSideVariables) {
+ JMeterContextService.variables = new UnmodifiableJMeterVariables(clientSideVariables);
+ }
}
Added: jmeter/trunk/src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java?rev=1798405&view=auto
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java (added)
+++ jmeter/trunk/src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java Sun Jun 11 20:57:38 2017
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jmeter.threads;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+/**
+ * Readonly wrapper around {@link JMeterVariables}
+ * @since 3.3
+ */
+class UnmodifiableJMeterVariables extends JMeterVariables {
+ private JMeterVariables variables;
+ /**
+ *
+ */
+ public UnmodifiableJMeterVariables(JMeterVariables variables) {
+ this.variables = variables;
+ }
+ /**
+ * @return
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode() {
+ return variables.hashCode();
+ }
+ /**
+ * @return
+ * @see org.apache.jmeter.threads.JMeterVariables#getThreadName()
+ */
+ public String getThreadName() {
+ return variables.getThreadName();
+ }
+ /**
+ * @return
+ * @see org.apache.jmeter.threads.JMeterVariables#getIteration()
+ */
+ public int getIteration() {
+ return variables.getIteration();
+ }
+ /**
+ *
+ * @see org.apache.jmeter.threads.JMeterVariables#incIteration()
+ */
+ public void incIteration() {
+ throw new UnsupportedOperationException();
+ }
+ /**
+ * @param key
+ * @return
+ * @see org.apache.jmeter.threads.JMeterVariables#remove(java.lang.String)
+ */
+ public Object remove(String key) {
+ throw new UnsupportedOperationException();
+ }
+ /**
+ * @param key
+ * @param value
+ * @see org.apache.jmeter.threads.JMeterVariables#put(java.lang.String, java.lang.String)
+ */
+ public void put(String key, String value) {
+ throw new UnsupportedOperationException();
+ }
+ /**
+ * @param key
+ * @param value
+ * @see org.apache.jmeter.threads.JMeterVariables#putObject(java.lang.String, java.lang.Object)
+ */
+ public void putObject(String key, Object value) {
+ throw new UnsupportedOperationException();
+ }
+ /**
+ * @param vars
+ * @see org.apache.jmeter.threads.JMeterVariables#putAll(java.util.Map)
+ */
+ public void putAll(Map<String, ?> vars) {
+ throw new UnsupportedOperationException();
+ }
+ /**
+ * @param vars
+ * @see org.apache.jmeter.threads.JMeterVariables#putAll(org.apache.jmeter.threads.JMeterVariables)
+ */
+ public void putAll(JMeterVariables vars) {
+ throw new UnsupportedOperationException();
+ }
+ /**
+ * @param key
+ * @return
+ * @see org.apache.jmeter.threads.JMeterVariables#get(java.lang.String)
+ */
+ public String get(String key) {
+ return variables.get(key);
+ }
+ /**
+ * @param obj
+ * @return
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object obj) {
+ return variables.equals(obj);
+ }
+ /**
+ * @param key
+ * @return
+ * @see org.apache.jmeter.threads.JMeterVariables#getObject(java.lang.String)
+ */
+ public Object getObject(String key) {
+ return variables.getObject(key);
+ }
+ /**
+ * @return
+ * @see org.apache.jmeter.threads.JMeterVariables#getIterator()
+ */
+ public Iterator<Entry<String, Object>> getIterator() {
+ return variables.getIterator();
+ }
+ /**
+ * @return
+ * @see org.apache.jmeter.threads.JMeterVariables#entrySet()
+ */
+ public Set<Entry<String, Object>> entrySet() {
+ return variables.entrySet();
+ }
+ /**
+ * @return
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ return variables.toString();
+ }
+
+}
Propchange: jmeter/trunk/src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jmeter/trunk/src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Re: svn commit: r1798405 - in /jmeter/trunk/src/core/org/apache/jmeter:
engine/ClientJMeterEngine.java engine/PreCompiler.java threads/JMeterContext.java
threads/JMeterContextService.java threads/UnmodifiableJMeterVariables.java
Posted by sebb <se...@gmail.com>.
On 11 June 2017 at 21:57, <pm...@apache.org> wrote:
> Author: pmouawad
> Date: Sun Jun 11 20:57:38 2017
> New Revision: 1798405
>
> URL: http://svn.apache.org/viewvc?rev=1798405&view=rev
> Log:
> Allow to use variables ( from User Defined Variables only ) in all listeners in slave mode
> Try to secure exposed JMeterVariables
> Bugzilla Id: 57962
>
> Added:
> jmeter/trunk/src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java (with props)
> Modified:
> jmeter/trunk/src/core/org/apache/jmeter/engine/ClientJMeterEngine.java
> 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
>
> Modified: jmeter/trunk/src/core/org/apache/jmeter/engine/ClientJMeterEngine.java
> URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/engine/ClientJMeterEngine.java?rev=1798405&r1=1798404&r2=1798405&view=diff
> ==============================================================================
> --- jmeter/trunk/src/core/org/apache/jmeter/engine/ClientJMeterEngine.java (original)
> +++ jmeter/trunk/src/core/org/apache/jmeter/engine/ClientJMeterEngine.java Sun Jun 11 20:57:38 2017
> @@ -112,7 +112,9 @@ public class ClientJMeterEngine implemen
> HashTree testTree = test;
>
> synchronized(testTree) {
> - testTree.traverse(new PreCompiler(true)); // limit the changes to client only test elements
> + PreCompiler compiler = new PreCompiler(true);
> + testTree.traverse(compiler); // limit the changes to client only test elements
> + JMeterContextService.initClientSideVariables(compiler.getClientSideVariables());
> testTree.traverse(new TurnElementsOn());
> testTree.traverse(new ConvertListeners());
> }
>
> 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=1798405&r1=1798404&r2=1798405&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:57:38 2017
> @@ -48,6 +48,8 @@ public class PreCompiler implements Hash
> // as only these are relevant to the client, and updating
> // other elements causes all sorts of problems.
> private final boolean isClientSide; // skip certain processing for remote tests
> +
> + private JMeterVariables clientSideVariables;
>
> public PreCompiler() {
> replacer = new ValueReplacer();
> @@ -72,15 +74,13 @@ public class PreCompiler implements Hash
> }
>
> 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);
> + this.clientSideVariables = createVars((TestPlan)node);
> }
>
> 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);
> + clientSideVariables.putAll(args);
> }
>
> } else {
> @@ -139,4 +139,11 @@ public class PreCompiler implements Hash
> @Override
> public void processPath() {
> }
> +
> + /**
> + * @return the clientSideVariables
> + */
> + public JMeterVariables getClientSideVariables() {
> + return clientSideVariables;
> + }
> }
>
> 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=1798405&r1=1798404&r2=1798405&view=diff
> ==============================================================================
> --- jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterContext.java (original)
> +++ jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterContext.java Sun Jun 11 20:57:38 2017
> @@ -80,7 +80,9 @@ public class JMeterContext {
> */
> public JMeterVariables getVariables() {
> // If context variable is null ( Client side ) return client variables
> - return (variables == null) ? JMeterContextService.getClientVariables() : variables;
> + return (variables != null) ?
> + variables :
> + JMeterContextService.getClientSideVariables();
> }
>
> 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=1798405&r1=1798404&r2=1798405&view=diff
> ==============================================================================
> --- jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterContextService.java (original)
> +++ jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterContextService.java Sun Jun 11 20:57:38 2017
> @@ -47,7 +47,7 @@ public final class JMeterContextService
> //@GuardedGy("this")
> private static int totalThreads = 0;
>
> - private static JMeterVariables variables = null;
> + private static UnmodifiableJMeterVariables variables;
>
>
> /**
> @@ -169,19 +169,12 @@ public final class JMeterContextService
> /**
> * Get all variables accessible for JMeter client in a distributed test
> * (only test plan and user defined variables)
> + * Note this is a read-only collection
> * @return {@link JMeterVariables} available for JMeter client
> */
> - public static JMeterVariables getClientVariables() {
> + public static JMeterVariables getClientSideVariables() {
> return variables;
> }
> -
> - /**
> - * Set variables for JMeter client in a distributed test
> - * @param var {@link JMeterVariables}
> - */
> - public static void setClientVariables(JMeterVariables var) {
> - variables = var;
> - }
>
> public static class ThreadCounts {
>
> @@ -197,4 +190,12 @@ public final class JMeterContextService
> finishedThreads = finished;
> }
> }
> +
> + /**
> + * Set variables for JMeter client in a distributed test (INTERNAL API)
> + * @param clientSideVariables {@link JMeterVariables}
> + */
> + public static void initClientSideVariables(JMeterVariables clientSideVariables) {
> + JMeterContextService.variables = new UnmodifiableJMeterVariables(clientSideVariables);
> + }
> }
>
> Added: jmeter/trunk/src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java
> URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java?rev=1798405&view=auto
> ==============================================================================
> --- jmeter/trunk/src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java (added)
> +++ jmeter/trunk/src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java Sun Jun 11 20:57:38 2017
> @@ -0,0 +1,150 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one or more
> + * contributor license agreements. See the NOTICE file distributed with
> + * this work for additional information regarding copyright ownership.
> + * The ASF licenses this file to You under the Apache License, Version 2.0
> + * (the "License"); you may not use this file except in compliance with
> + * the License. You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + *
> + */
> +
> +package org.apache.jmeter.threads;
> +
> +import java.util.Iterator;
> +import java.util.Map;
> +import java.util.Map.Entry;
> +import java.util.Set;
> +
> +/**
> + * Readonly wrapper around {@link JMeterVariables}
> + * @since 3.3
> + */
> +class UnmodifiableJMeterVariables extends JMeterVariables {
This is a bit fragile.
If the parent class adds a new method that allows the variables to be
mutated, then it will have to be overridden here.
That's easy to overlook.
It might be better to use Composition.
> + private JMeterVariables variables;
> + /**
> + *
> + */
> + public UnmodifiableJMeterVariables(JMeterVariables variables) {
> + this.variables = variables;
> + }
> + /**
> + * @return
> + * @see java.lang.Object#hashCode()
> + */
> + public int hashCode() {
> + return variables.hashCode();
> + }
> + /**
> + * @return
> + * @see org.apache.jmeter.threads.JMeterVariables#getThreadName()
> + */
> + public String getThreadName() {
> + return variables.getThreadName();
> + }
> + /**
> + * @return
> + * @see org.apache.jmeter.threads.JMeterVariables#getIteration()
> + */
> + public int getIteration() {
> + return variables.getIteration();
> + }
> + /**
> + *
> + * @see org.apache.jmeter.threads.JMeterVariables#incIteration()
> + */
> + public void incIteration() {
> + throw new UnsupportedOperationException();
> + }
> + /**
> + * @param key
> + * @return
> + * @see org.apache.jmeter.threads.JMeterVariables#remove(java.lang.String)
> + */
> + public Object remove(String key) {
> + throw new UnsupportedOperationException();
> + }
> + /**
> + * @param key
> + * @param value
> + * @see org.apache.jmeter.threads.JMeterVariables#put(java.lang.String, java.lang.String)
> + */
> + public void put(String key, String value) {
> + throw new UnsupportedOperationException();
> + }
> + /**
> + * @param key
> + * @param value
> + * @see org.apache.jmeter.threads.JMeterVariables#putObject(java.lang.String, java.lang.Object)
> + */
> + public void putObject(String key, Object value) {
> + throw new UnsupportedOperationException();
> + }
> + /**
> + * @param vars
> + * @see org.apache.jmeter.threads.JMeterVariables#putAll(java.util.Map)
> + */
> + public void putAll(Map<String, ?> vars) {
> + throw new UnsupportedOperationException();
> + }
> + /**
> + * @param vars
> + * @see org.apache.jmeter.threads.JMeterVariables#putAll(org.apache.jmeter.threads.JMeterVariables)
> + */
> + public void putAll(JMeterVariables vars) {
> + throw new UnsupportedOperationException();
> + }
> + /**
> + * @param key
> + * @return
> + * @see org.apache.jmeter.threads.JMeterVariables#get(java.lang.String)
> + */
> + public String get(String key) {
> + return variables.get(key);
> + }
> + /**
> + * @param obj
> + * @return
> + * @see java.lang.Object#equals(java.lang.Object)
> + */
> + public boolean equals(Object obj) {
> + return variables.equals(obj);
> + }
> + /**
> + * @param key
> + * @return
> + * @see org.apache.jmeter.threads.JMeterVariables#getObject(java.lang.String)
> + */
> + public Object getObject(String key) {
> + return variables.getObject(key);
> + }
> + /**
> + * @return
> + * @see org.apache.jmeter.threads.JMeterVariables#getIterator()
> + */
> + public Iterator<Entry<String, Object>> getIterator() {
> + return variables.getIterator();
> + }
> + /**
> + * @return
> + * @see org.apache.jmeter.threads.JMeterVariables#entrySet()
> + */
> + public Set<Entry<String, Object>> entrySet() {
> + return variables.entrySet();
> + }
> + /**
> + * @return
> + * @see java.lang.Object#toString()
> + */
> + public String toString() {
> + return variables.toString();
> + }
> +
> +}
>
> Propchange: jmeter/trunk/src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java
> ------------------------------------------------------------------------------
> svn:eol-style = native
>
> Propchange: jmeter/trunk/src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java
> ------------------------------------------------------------------------------
> svn:mime-type = text/plain
>
>