Jmeter - Is it possible to pass query through variable - jmeter

Is it possible to pass query through variable? What I need is:
1. Get multiple queries from csv file.
2. Execute them one by one.
3. Store results

Yes you can do it by using CSV Data Set config and Bean shell post processor.
Step 1: Need to read queries from CSV file.
Step 2: Use JDBC request to query the database. I'm assuming that you already created database JDBC pool with the help of JDBC Connection Configuration
Step 3: Use Bean Shell post processor to save the results into a file.

To read queries from the file one by one you can use __StringFromFile() function like:
To store the output you can go for different options,
Save Responses to a file listener if query result is a simple/singe value
If your query result is more complex, i.e. you need to iterate the ResultSet object - you will need to do some scripting, check out Debugging JDBC Sampler Results in JMeter
If your query generates several JMeter Variables you can get them stored into .jtl results file via Sample Variables property.

Related

How Can i avoid repeated/duplicate test data or to avoid already executed data without deleting in CSV file?

We have a constrain in our application, For test data providing in JMeter execution (using CSV Data Set Config element) we are not supposed to provide duplicate test data and it won't accept in all the fields. So we kept unique test data (upto 8K data for 8k concurrent users) for all the fields in CSV format.
Here I have a manual intervention, After each test execution (i.e) 100 users, 1000 users up to 8000 users) we need to delete each row (WRT to users in thread group) in CSV file else the duplicate data will be fetching for next execution and result will be failed.
Here my questions is,
1. How Can i avoid repeated/duplicate test data or to avoid already executed data without deleting in CSV file.
2. During JMeter test execution with CSV files, How can we specify to take the data from the respective rows. For example 101th row, 1001th row & 7999th row (which contains 8000 rows of data)?
The easiest option will be using HTTP Simple Table Server, its READ command has KEEP=FALSE attribute so you will be able to feed your test with the unique data without having to physically remove it from the original CSV file.
You can install HTTP Simple Table Server plugin using JMeter Plugins Manager:
In general if your test doesn't need to be repeatable instead of keeping the data in the CSV file you can consider generating it on the fly using such JMeter Functions as:
__Random()
__RandomString()
__RandomDate()
__UUID()
etc.

Compare values/data using CSV data set config in JMeter

Trying to compare the data/count between source and destination tables (SQL) as below through using CSV config in JMeter. is it possible to implement this way?.
CSV config in JMeter
just want to compare the count between STAGING and DW for all tables. any thoughts on this..?
Just define Variable Names so JDBC Request sampler could store the query execution output into a JMeter Variable like:
In first JDBC Request sampler define "Variable Name" as result1 (replace "SQL Query" with the relevant JMeter Variable name holding the value from the CSV file)
In second JDBC Request sampler define "Variable Name" as result2
That's it, now you will have the count of rows returned from the first JDBC Request sampler as result1_1 and from the second as result2_1
Now you can compare the values using Response Assertion configured like:
in case of mismatch the relevant JDBC Request sampler will be marked as failed and you will be informed about the differences:
More information: Debugging JDBC Sampler Results in JMeter

JMeter- Reading One row of CSV file to Multiple rows of another csv file

How can I loop one csv file to another csv file in JMeter, where the first csv file contains all the login data and the other csv file contains the transaction data. I am supposed to run where 1 teller should process 30 transaction.
Go for __CSVRead() function.
You will not be able to use CSV Data Set Config as it is a Configuration Element and according to the JMeter Test Elements Execution Order all the configuration elements are being initialised at the very beginning of the test while your requirement is to read data based on user dynamically.
Check out How to Pick Different CSV Files at JMeter Runtime article for comprehensive information on using __CSVRead() function

how to login multiple users with different input in different threads in Jmeter using CSV data set config

How to login multiple users with different input in different threads in Jmeter using CSV data set config?
I have added CSV data set config but the thread is picking only the first entry and i m not able to see the responses for other user login
If you use CSV data set config which contains parameterized values which users(threads) will use while running script.
below is snapshot of jmeter of csv data set config which contain emp.csv file which contains values like,
nachiket,101,test
nikhil,102,test
harish,103,test
which are empname,empid,passwd respectively for 3 users.
if you run test with 3 users then thread1 will pick first and 2nd thread will pick 2nd val so on and you can repeat the file if it has less values than no of threads.
You need to provide enough loops/iterations as given one iteration only CSV Data Set Config will read only the first entry.
Try putting the request you want to parametrize under a Loop Controller, set enough loops and see whether it resolves your issue.
See Using CSV DATA SET CONFIG guide for more details.

How to set up a large amount of request data for a jMeter load test

I want to simulate a few hundred http request each with a different token and userId which I have in a database table.
What's the best way of setting up a jMeter load test to do this?
You can use JDBC Sampler to extract you data from DB to create a CSV and a JSR223 Sampler using groovy (add groovy-all.jar in jmeter/lib folder) to write the extracted values to a CSV file.
Then in the real plan , use CSV DataSet Config using the generated file.
Depending on how you want to use the dataset, you will play with Sharing mode attribute.
If you want to do both steps within the same plan you can use a Setup thread Group that will contain the JDBC Sampler part to write the CSV File, this will use 1 thread and then
the other part in regular Thread Group that will use the number of users you need.
One way is to put all your parameters into a csv file and use CSV Data Set Config in jmeter. Right click on the thread you have created - add- Config Element- CSV Data Set Config. Remember you need to set the Number of Threads(users) to match the number of users in your CSV file.

Resources