JMeter share setUp Thread Group variables with normal Thread Group - jmeter

Imagine I have a simple test plan, like so:
setUp Thread Group
-- Http Request
---- JSON Extractor
Thread Group
-- Http Request
tearDown Thread Group
-- Http Request
By default, the variables extracted in the setUp Thread Group will not be accessible within the ordinary Thread Group nor the tearDown Thread Group. The variables' contents are different for each user and cannot be precomputed and loaded into the test plan. It is not possible to simulate the correct load using a single user.
How can I access each thread's setUp variables from within the corresponding Thread Group proper and tearDown?

JMeter Variables scope is limited to current Thread Group only, if you need to pass some data between different Thread Groups you need to convert JMeter Variables into JMeter Properties:
use __setProperty() function to set a JMeter Property in i.e. setUp Thread Group
use __P() function or __property() function to read the property value in another Thread Group.
More information: Knit One Pearl Two: How to Use Variables in Different Thread Groups

You stated in comments
5000 distributed threads.. transferring multiple variables...
Maybe JDBC Requests will help you to save(insert) variable to database and get(select) variable and delete/update variable wherever you are in test.

Related

How to pass one variable of a thread group extracted from JSON extractor into another thread group as request header value in JMeter?

Eg:
I have token grneration api in a thread group and the token generated in this request need to be sent as header value HTTP header manager for the api request present in another thread group
If thread groups are being run sequentially you can use __setProperty() function in 1st Thread Group to convert the JMeter Variable holding the token into a JMeter Property. JMeter Properties are global and can be accessed by all threads no matter in which thread group they are and JMeter Variables are local to the thread. In 2nd Thread Group the property can be read using __P() function
If thread groups are being run in parallel - use Inter-Thread Communication Plugin

JMeter - if controllers on thread group

Is it anyway I can have an if controller above a thread group, like:
TestPlan
-> If controller
----> Thread Group
I.e I just want to execute the if controller once so I can avoid unnecessary execution in the Thread Group?
You can add to Thread group in Number of Threads field get value from property, as:
${__P(GroupANumberOfThreads,0)}
So if you don't have property, for example don't send -JGroupANumberOfThreads=1 in CLI mode Thread group won't get executed
There are following options:
Put everything inside the Thread Group under the If Controller, this way no Samplers will be executed if the condition is not met, but the Thread Group will be still started and all threads will kick off
Set number of threads in the Thread Group to 0, it can be done using __if() function (member of JMeter Custom Functions plugin bundle, can be installed using JMeter Plugins Manager)
You can also consider running your JMeter test using Taurus tool as the wrapper, Taurus provides possibility to completely disable arbitrary test element (including thread groups) using simple declarative YAML syntax

Define a value in JSR223 Assertion and Access it from User Defined Variables in a Different Thread

Simply this is what I want help with,
Using Jmeter -
Set a variable in the JSR223 Assertion in the 1st thread
Access that value in a different threads User Defined Variables
Thanks in advance
JMeter Variables are local to the current thread only therefore you won't be able to access the value outside the current thread (virtual user) context.
As per JMeter Documentation:
Properties are not the same as variables. Variables are local to a thread; properties are common to all threads
So if you need to make some variable "global" you can convert it into a property like:
props.put('foo', 'bar')
in the JSR223 Assertion
Once done you should be able to access the value using __P() function as ${__P(foo,)} where required
You can also use __setProperty() function instead of setting the value in the JSR223 Assertion.
More information on JMeter Functions concept: Apache JMeter Functions - An Introduction
You can use below method:
props.put("var","value"); // set property in 1st thread group
props.get("var"); // get property in 2nd thread group
Alternatively you can user "Inter-Thread Communication" plugins in JMeter.

JMeter - Passing the number of threads to multiple thread groups

I have a file where I specify the number of threads for each Thread Group.
My goal is to run concurrently all Thread Groups with the number of threads read from the file.
My current algorithm: I have the first Thread Group in the Test Plan called Setup.
I read the data file to the local variables.
With the BeanShell Sampler, I convert those variables into the properties variables.
In each Thread Group, the number of threads is defined via the properties variable.
If I run the Thread Groups consecutively, there are no problems.
But I need to run them in parallel. I imagine that the Thread Group can try to run before the Setup group finishes reading the number of threads for that group. Then that group will never run.
I appreciate any thoughts and suggestions.
You can define the number of threads via JMeter properties in at least 2 more ways:
In user.properties file (the file is located in JMeter's "bin" folder, JMeter restart will be required to pick the properties up)
threads=100
Or you can do the same via -J command-line argument, i.e. start JMeter as:
jmeter -Jthreads=100 -n -t ....
In your Thread Groups you can refer the property via __P() function like:
${__P(threads)}
It is also possible to have "default" value which will be used in case of "threads" property will not be defined:
${__P(threads,50)}
References:
Full list of command-line options
Apache JMeter Properties Customization Guide
My current algorithm: I have the first Thread Group in the Test Plan
called Setup. I read the data file to the local variables. With the
BeanShell Sampler, I convert those variables into the properties
variables. In each Thread Group, the number of threads is defined via
the properties variable.
You could use Property File Reader. This will get loaded before any thread group starts. So you would not face any issue.
If you do not like Property File Reader, whatever you do - reading the data file and converting them into properties - do that in setUp Thread Group.
It will get executed before any thread group starts

Dependency among multiple thread groups in JMeter

I have set up a load test plan with multiple thread group, i.e. -
Registration (50% of the threads)
Place Order (10% of the threads)
Some more operations (remaining threads)
Herein if Registration thread does not succeeds than I don't want to execute remaining thread groups. In case of a single thread group I can use if controller and discard samples if one sample fails but how do I achieve it when I am using multiple thread groups.
JMeter Variables scope is limited to current Thread Group only, if you want to use If Controller basing on the condition which is set in another Thread Group - you should be using JMeter Properties instead (JMeter Properties scope is global for the whole JVM). See How to Use Variables in Different Thread Groups article for details on converting JMeter Variables into JMeter Properties.
You may also find InterThread Communication plugins useful when it comes to passing data between thread groups and setting up dependencies.
However, given your scenario you either need to pass the whole thread context (cookies, cache, whatever) which might be tricky so it would be much better putting all the samplers under the same Thread Group and use Throughput Controller, Switch Controller or Weighted Switch Controller, whatever matches your scenario the closest way. See Running JMeter Samplers with Defined Percentage Probability guide for more information.

Resources