I have JDBC request, what give me 10 values. Also i have ThreadGroup from 10 user. I need launch HTTP request in my service, but for different user i need different value from me JDBC. How can i do that?
Define "Variable Name" in the JDBC Request sampler like:
It will give you the following JMeter Variables (observable by the Debug Sampler):
foo_1=xxx
foo_2=yyy
foo_3=zzz
...
foo_#=10
Now you can access a different variable with the different JMeter virtual user using __threadNum() and __V() functions combination like:
${__V(foo_${__threadNum},)}
More information: Here’s What to Do to Combine Multiple JMeter Variables
Related
I am currently designing a test case for multiple users testing using jmeter and I kind of need some help.
Here's the scenario:
Suppose I have 2 different login portals with 500 different users on each portal. I want to do login, access getExamSchedule, startExam, getListQuestion, getOneQuestion, submitOneQuestion and finishExam so I create one new thread group for each request. Each thread has 2 samplers (1 for portal A, 2 for portal B).
My question is how am I supposed to pass the multiple generated tokens from login thread so that I can access the rest of the thread with different tokens. And also each http request has some response I need to extract to be used on another thread. I tried to extract the tokens and the responses to csv file but somehow it didn't work. Let me know if there's any best practice for this scenario. Thank you in advance!
so I create one new thread group for each request - normally you should create separate/different Thread Groups only for new logical groups of virtual users, for your use case I think everything could be in one Thread Group.
As per JMeter Documentation:
Properties are not the same as variables. Variables are local to a thread; properties are common to all threads, and need to be referenced using the __P or __property function.
So if you really need to pass values across different Thread Groups - you can take a look at following solutions:
__setProperty(), __threadNum() and __P() functions combination like:
To set the property:
${__setProperty(token_${__threadNum},${jmeter-variable-holding-the-token},)}
To read the property: ${__P(token_${__threadNum},)}
Use Inter-Thread Communication Plugin
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.
I am performing login test with multiple concurrent users.
I have created a JDBC request to get username and password from patient
table. and then Created a Test.CSV file using same data with the help of
BeanShell assertion.
Now pass this file name in CSV dataset configTest.csv.
I am able to login with multiple users concurrently but facing an issue:
when I am running the test first time. The file is not available at the same location because it is being created after the execution of thread group.
If file is not there I am getting this in log: File Test.csv must exist and be readable.
To execute the same process, What I am doing is, keeping the JDBC request is different test plan. Firstly executing that test plan and then proceeding to the login.
I want to execute and keep both requests is the same test plan.
one more thing If I am using the different thread group for these requests in the same test plan, Still facing the same issue.
Jmeter execution order is:-
0-Configuration elements
1-Pre-Processors
2-Timers
3-Sampler
4-Post-Processors (unless SampleResult is null)
5-Assertions (unless SampleResult is null)
6-Listeners (unless SampleResult is null)
Based on above, it is evident that "csv data config" will be executed first before the JDBC sampler.
What I can think of, if you want to get the username/pwd in the same Thread Group then you can set username and password as properties using __setProperty() and fetch it using __property(). For this, use JSR223 Post Process after JDBC.
You can also use any of the other know post processor/scripting language, it is just groovy is better for performance test.
Apache Groovy - Why and How You Should Use It
Hope it helps.
The reason is that CSV Data Set Config is a Configuration Element and according to test elements Execution Order it is being initialised before anything else.
I would suggest going for __CSVRead() function instead, JMeter functions are evaluated at the time they're being called so the Test.csv file will exist at the time you will be getting credentials from it. See Apache JMeter Functions - An Introduction to get familiarized with JMeter Functions concept.
Also be aware that according to JMeter Best Practices it is recommended to switch to JSR223 Test Elements from Beanshell or other scripting languages.
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.
I'd like to stress test an REStful API with JMeter with different parameterization and capture the response time depending on the number of users and parameters used for the REST call:
| 10 User | 100 Users | 1000 Users
Parameters A |‾‾‾‾‾‾‾‾‾|‾‾‾‾‾‾‾‾‾‾‾|‾‾‾‾‾‾‾‾‾‾‾‾
Parameters B |‾‾‾‾‾‾‾‾‾|‾‾‾‾‾‾‾‾‾‾‾|‾‾‾‾‾‾‾‾‾‾‾‾
Parameters C |‾‾‾‾‾‾‾‾‾|‾‾‾‾‾‾‾‾‾‾‾|‾‾‾‾‾‾‾‾‾‾‾‾
So my HTTP Request is always the same, except for the Parameters and the number of users. My current (poor) approach is a thread group with a hardcoded number of threads for each combination of users and parameters. But i assume there is better approach available, with utilizing of variables.
Any suggestions on a clean implementation?
Edit: Basically i'm trying to achieve the following nested for loops.
for (param in parameters) {
for (numReq in users) {
executeRequest(param, numReq)
// execute *numReq* simultaneous requests with the parameters of param
}
}
JMeter Thread Groups are initialized during JMeter startup so unfortunately you won't be able to use JMeter Variables as they're being read and applied a little bit after.
However you can go for JMeter Properties instead. For instance, you can define number of users using __P() function like :
${__P(threads,)}
and then you will be able to define threads number via -J command-line argument like:
jmeter -Jthreads=100 -n -t test.jmx -l result.jtl
See Apache JMeter Properties Customization Guide for more information on JMeter properties and ways of working with them.
If you're using JMeter Plugins you can also consider trying out i.e. Stepping Thread Group instead