How can I get a random set of variables in Jmeter?
For example, I set lat, long and city for New York
and lat, long and city for Los Angeles.
I need to post those parameters in random way, so it will be for all the set and not only one parameter for each, so when it takes the first lat and long, it will also use New York as the city.
This can be done in at least 2 ways:
Using CSV DataSet Config:
put the 3 variables separated by ';' in a CSV file
use CSV Data Set Config element and put in variables:
variables : lat,long,city
Delimiter : ;
Sharing Mode : Thread Group
Then as you use a certain number of Threads, each one will pick a different value for the triplet and it should be fine.
Using Redis Data Set:
Insert in a Redis Set the triplet as 1 value using ; separator
Configure Redis Data Set:
Use Random_Keep
; as separator
Related
i am using JMeter BeanShell Preprocessor to generate unique date value in each iteration. I am using two (2) users for my load test on database . for user 1 the date value generating as expected but when the user change to 2 then date variable value reset to default. what should i do to prevent the reset of date variable value as on insertion i am facing violation of unique key constraint error.[enter image description here](https://i.stack.imgur.com/euEc9.png)
i have mentioned in the screen shot what I tried . I need help to solve my problem
Don't post code as images
Don't use Beanshell, since JMeter 3.1 you should be using JSR223 Test Elements and Groovy language for scripting
Your problem is that both users are adding 1 day to the date and if the database is configured that way it doesn't allow the same dates - the insert or update will fail.
I don't know the details of your test scenario but you could consider adding current iteration number and/or current virtual user number to the date from the User Defined Variables, the relevant functions are:
vars.getIteration() - for the iteration number
ctx.getThreadNum() - for the user number
However the best option would be pre-generating the list of dates somewhere in setUp Thread Group
Example Groovy code:
def now = new Date()
1.upto(200000,{index ->
def date = now.plus(index)
new File('dates.csv') << date.format('yyyy-MM-dd') << System.getProperty('line.separator')
})
And then use CSV Data Set Config to read the generated dates from the dates.csv file in your main Thread Group
Given you have 2 users and 100k iterations which means that the last date would be 2570-08-11 so make sure it matches your requirements and the database is capable of accepting the date such far in the future
My dataset has multiple variables each with different values. I am already filtering in my Datasets and Charts/Tables. I need to be able to filter again in my expression.
I want only the values from one variable. I need to filter out the other variables so I can focus only on the values from one variable.
Value=(Fields!VALUE.Value) when Fields!VARIABLE.Value = "ABCD"
Obviously the logic above does not work but I am looking for something similar that does work.
Value is an integer
Fields!VALUE.Value is an integer
Fields!VARIABLE.Value is a string
ABCD is the variable name I want to get the value from.
For example.
I have two variables ABCD and EFGH. I only want the value from ABCD but not from EFGH. I need to filter out EFGH.
Like there are lots of values in array
{"profile":"qa","job":"active","status":"green"}
{"profile":"dba","job":"non-active","status":"yellow"}
So there are multiple rows like this, I want to fetch profile and job of all the arrays randomly and it should be like that, if profile is selected as qa randomly say by regular expression post processor, then job value should also be "active" i.e
Same for dba profile, that if dba is fetched , then job value should be non active
Can this be achieved using regular expression for random fetch??i. giving match no as 0
As you are dealing with JSON responses, hence would recommend you to use JSON extractor post processor as $..['job','profile'] and set Match number to 0. This way you can extract values from array in one go.
You can use this variable name highlighted in subsequent requests like - ${entryJson}
For Regular expression you can use profile": "(.?)" and job": "(.?)"
in two of the expressions but using zero will return different values for each run.
In Jmeter , I have created a DB connection with Oracle, and executing below query.
select address , city , zip from table where city='Delhi';
Now this is giving result as:
212 Kamla nagar Delhi 11011
Now I want to use this into 3 variable using regular expression and pass all these 3 parameters to another soap request.
I tried to use regular expression as (\d+) but it only stored value in variable 1.
How to extract values and use them in another request?
you can use JDBC preprocessor and from which you use either Variable names or Result variable name
The ones you specify in the Variable names box map to individual columns returned by your query and these you can access by saying columnVariable_{index}.
OR
The one you specify in the Result variable name contains the entire result set and in practice this is a list of maps to values. The above syntax will obviously not work in this case. you will have to access it by BeanShell and create variables.
...and then you can use these variables as ${name_1}, ${city_1}, ${zip_1} in soap request to access value from DB. or as ${name}, ${city}, ${zip} if you use Result variable name object
Configure your JDBC Sampler as follows:
i.e. add the next line to "Variable Names" input:
address, city, zip
You will be able to access the extracted values as:
${address_1}
${city_1}
${zip_1}
later in the script. 1 stands for Result Set row, i.e. if there will be 2 rows in JDBC response - ${address_1} will stand for 1st row address, ${address_2} - for 2nd row address, etc.
See Debugging JDBC Sampler Results in JMeter article for details.
Hi i am designing a data generation job.
my job is something like this
tRowGenerate --> tMap --> tFileOutputDelimited.
Lets say my tRowGenerate produces 5 columns with 2 records. I want to iterate for this records i.e for each record I want to iterate certain number of times.
for record 1 iterate 5 times to produce further data.
for record 2 iterate 3 times to produce further data.
Please suggest how to apply this multiply by xi logic. where xi for each record can change.
Thanks!
If you want to loop on the data generated from the tRowGenerator you can use a tLoop where you put the call to your business rule to determine the number of loops or when stop looping.
An example job might look like:
Logic of flow:
row1 is a main connection taking the generated values to the tFlowtoIterate that stores them in global variables;
the iterate link activates the tLoop that can use the values stored in the global vars to activate your business rule (to have the number of loops or tho ask if continue or stop);
the tLoop activate the tJavaFlex that uses the stored global vars to produce the output you like and pass it to the tFileOutputDelimited with a main link (row2).
You have to activate the append flag on the tFileOutputDelimited to keep the data from the different loops. If you need you can add a tFileDelete at the beginning to empty the output file before a new processing round.