Can we use use ThreadGroup inside a ThreadGroup - jmeter

Can we use use ThreadGroup inside a ThreadGroup?
I know that we can run it simultaneously but can we run a threadgroup inside a thread group is what i need to know.

No you cannot by design.
#schtever answer is related to Java thread group, not jmeter thread group.
Why do you want to do that ?

Yes. One of the constructors for a ThreadGroup takes a parent ThreadGroup as a parameter. See http://docs.oracle.com/javase/7/docs/api/java/lang/ThreadGroup.html.

Related

How to run two thread groups consecutively in a loop

Is there any way to run two ThreadGroup consecutively in a loop for a certain amount of time? I am writing a test scenario in which I have to create a task for multiple users and then fulfill this task by them. Therefore, I decided to divide the scenario into two thread groups, because it needs one user to create a task and many users to complete it. Everything works fine, but the problem arises when I try to run the test in several iterations.
I tried to check Run Test Group consecutively check-box, but tests instead of performing alternately, e.g.
ThreadGroup 1
ThreadGroup 2
ThreadGroup 1
ThreadGroup 2
perform as follows
ThreadGroup 1
ThreadGroup 1
ThreadGroup 2
ThreadGroup 2
Is it possible to somehow make thread groups execute alternately? I would be very grateful for any advice.
If you want to run multiple iterations you need to let thread group 2 know that the task is ready and let thread group 1 know that the task is compete and it's ok to generate a new task.
There are 2 approaches of passing data between Thread Groups:
__setProperty() function to create/update a value in one Thread Group and __P() function to read the value in another Thread Group
Inter-Thread Communication Plugin, see SynchronizationExample.jmx for reference implementation

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

How to perform teardown for a specific Thread Group

is there a way to create a teardown for a specific Thread Group in Jmeter? That is, the object "tearDown Thread Group" seems to be executed at the end of each Thread Group in the test. It's possible to bind a tearDown only with a single Thread Group? If not, is there an other object to insert in the Thread Group to achieve that?
JMeter executes Samplers upside down (or according to Logic Controllers) so it's sufficient to put your "teardown" logic to the "bottom" of the Thread Group and the relevant Samplers will be executed "last".
Few more hints:
If you need to run your main logic for several iterations - put it under the Loop Controller
If you need to run your main logic for specific time - put it under the Runtime Controller
If you need to pass some data between Thread Groups you can use Inter-Thread Communication Plugin

Run certain ThreadGroup (or just an action) periodically

I've got pretty similar problem as the one explained in this tread.
The problem is that my TestPlan has got several Thread Groups,
which are run consecutively (that is required).
Therefore, I cannot use the suggested solution of 'Add another Thread Group & Constant timer' as this would only work if I unchecked 'Run Thread Groups consecutively'.
So, I need to trigger my 'Take_access_token' thread either every 30min or before every other Thread Group.
I was thinking on applying some of the controllers:
Module or Interleave, but looks like they can apply only to the Sampler execution logic, and not the thread groups.
I'm sure jMeter has to have something.
What am i missing?)
Thanks for any help.
What can I understand from this question is that you want to trigger your thread groups consecutively but before that Take_acess_token should generate some token which will be used by other thread groups.
So my suggestion to achieve this requirement is shown in below snapshot
First apply token thread group with 1 user 1 iteration which will generate token and then save it to property to use it in another thread group then next thread group will perform some activity and once control will come out of this group it'll again enter into another thread group to generate token and similarly do this for other also
Hope this approach should help you!!
Disable "Take Access Token" threadgroup
Add a simple controller under "Take Access Token" threadgroup
Move all the samplers to newly added Simple controller
Now you can add "Module Controller" in start of each of your thread group
Set path to your simple controller in these module controllers
This can solve your issue without any duplication of code.

Getting the number of users / threads in a thread group

In JMeter, I have a test plan with a thread group. The thread group has number of threads and a loop count which can be set in the gui.
Is there anyway I can figure out dynamically what they have being set so I can pass them to variable?
Thanks.
Use BeanShell PostProcessor with following code:
vars.put("threads", Integer.toString(prev.getAllThreads()));
Or maybe you just looking for this: http://code.google.com/p/jmeter-plugins/wiki/ActiveThreadsOverTime
You can parametrize the thread count defining a property like
${__P(users, 1)}
and if you run the test plan from command line, you can specify its value as -Jusers=XX. If, instead, you run the test from JMeter gui, to verify the text plan for example, the users property assume the default value of 1.
Don't forget to reference the property in the thread count, with ${users}.
You should parameterize your thread count at TestPlan level settings, then use that parameter (variable) both in ThreadGroup and Listener.
If the value varies and you want to pass it from command line use __P() function instead of variable.

Resources