Apache Jmeter read SQL variables from csv file

jhon.smith

Need to load test a Oracle database the requirement is to fire sql queries concurrently to the database reading the varaibles from a CSV file is this feasible ?

Have a CSV file with values like

Name        Email
Justin      [email protected]
George      [email protected]
...
Micheal     [email protected]

And then have 10,20,30 users fire of queries like

select name,phone,city
from address
where name = <<feild1-from-csv>>
and email = <<feild2-from-csv>>
...
Dmitri T

I'd suggest splitting your test logic into 2 separate pieces:

  1. Load information from CSV and store it as JMeter variables
  2. Execute SQL code against Oracle using variables from point 1

In regards to implementation I'd suggest to use 2 separate Thread Groups, the first one will be loading stuff from CSV, the second one will be doing actual testing.

Important: don't forget to check "Run Thread Groups Consecutively" box at TestPlan level to assure that second thread group runs after first one.

Example configuration of 1st thread group:

  1. Counter

    • Start - 1
    • Increment - 1
    • Reference name - counter
  2. CSV Data Set Config

    • Filename - path to your csv file
    • Variable names - name, email
    • Delimiter - if you're using TAB - "\t", if comma - "," without quotes
    • Allow quoted data - False
    • Recycle on EOF - False
    • Stop thread on EOF - True
    • Sharing mode - All Threads
  3. Beanshell Sampler (this one is optional, JMeter 2.10 is smart enough to store variables for you but I prefer to control everything myself)

Code for Beanshell sampler shoud look as follows:

props.put("name" + vars.get("counter"), vars.get("name"));

props.put("email" + vars.get("counter"), vars.get("email"));

It fetches current "name" variable and stores it as name + counter property.

So given 3 lines is CSV file you'll have following properties:

name1=Justin
[email protected]
name2=George 
[email protected]
name3=Micheal
[email protected]

You can use Debug Sampler to see JMeter Variables and Properties values

After that in second thread group you can refer stored properties as:

${__P(name1,)}

or

${__property(name1,,)}

in your JDBC Request Sampler.

Both should work.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Jmeter : Read data (numbers) from CSV file in Jmeter

Using Apache Commons CSV to read file starting from the second line

How to read a csv file for variables and dictionaries from different columns?

Read csv file in SQL

JMeter 3.3: Cannot read variables from file - Typed variable declaration : Class: Wini not found in namespace

JMeter - How to use few sets of variables from csv file in one post request?

JMeter- extract multiple variables from JSON response and save it in CSV file

JMeter- extract 'id' variables from JSON response and save it in CSV file and use it in tear down thread

How to read CSV file using Apache file?

CSV Data Set : Parameterize URL variables in JMeter - wrong CSV file

Read variables from file and replace

Jmeter skips alternate row from CSV file

Pick random path from CSV file in JMeter

SQL - read from XML variables

Apache beam read csv file and groupbykey

how to make zone config file for bind9 in ansible with a template and read variables from a csv file?

How to read from a CSV file

Read CSV file from package

Read csv file from url

How to put specific parameters as independent variables into csv-file in JMeter?

Writing Variables using Beanshell Sampler in JMeter into a txt/csv file

Read CSV and write to BigQuery from Apache Beam

Getting Duplicate while trying to read CSV file with Apache Common CSV

How to make JMeter read unique values from a csv

Jmeter Run SQL script from file

I have used CSV file in Jmeter script. Now I want if data is Not read from CSV file then it will pick some Default Value. How to do this?

Read a file from GCS in Apache Beam

psql - read SQL file and output to CSV

How to dereference environment variables read from file?