Pages

Monday, 30 January 2017

JMeter - Config Element - "CSV Data Set Config"

Test Data set-up is a common requirement for any non-functional test. Unique and bulk test data helps to simulate the real-time scenario in Performance Testing. Those test data either need to be generated or get it from the server log. Now, the next question will be How we can use external Test Data for Non-Functional Testing using Apache JMeter?

Apache JMeter has an element that allows you to use external test data sets in a CSV or txt format. That element is called “CSV Data Set Config” element. It is used to read lines from a file and split them into variables. It is well suited to handle large numbers of variables and is also useful for testing with random and unique values.

Generating unique or random values at run-time is expensive in terms of CPU and memory, so just create the data in advance for the test. If necessary, the "random" data from the file can be used in conjunction with a run-time parameter to create different sets of values from each run - e.g. using concatenation - which is much cheaper than generating everything at run-time.

How to add "CSV Data Set Config" element?
You can follow the below steps:
1. Select "Test Plan" node
2. Right click on "Test Plan" node
3. Mouse hover "Add"
4. Mouse hover "Config Element"
5. Click "CSV Data Set Config"
Apache Jmeter - CSV Data Set Config

Generally, the CSV Data Set Config element is added under the Test Plan, so that parameter value can be used globally. In case having more than one Thread Group with the different CSV fileyou need to either add CSV Data Set Config element under respective Thread Group or create a set of files, one for each thread. 
For example: paramFile1.csvparamFile2.csvparamFile3.csv..... Use the filename paramFile${__threadNum}.csv and set the "Sharing mode" to "Current thread".

By default, the file is only opened once, and each thread will use a different line from the file (when Sharing Mode having All threads value). However, the order in which lines are passed to threads depends on the order in which they execute, which may vary between iterations. Lines are read at the start of each test iteration. The file name and mode are resolved in the first iteration.

How to remove "CSV Data Set Config" element?
You can follow the below steps:
1. Select "CSV Data Set Config" node
2. Right click on "CSV Data Set Config" node
3. Click "Remove" (Mouse) or "Delete" button from keyboard
4. Click "Yes"
Apache Jmeter - CSV Data Set Config


How can we use of "CSV Data Set Config" element?
Let's say you have four variables UserID, password, productID, orderID in paramFile.csv. Now refer to the below GIF:
Apache Jmeter - CSV Data Set Config

What are the attributes of "CSV Data Set Config" element?
"CSV Data Set Config" has below attributes:
a. Name: To provide "CSV Data Set Config" name
b. Comments: To provide comments (if any)
c.  File Name: Name or relative path of the file to be read. If the file(s) is/are stored in Apache JMeter bin folder then the only name is enough (with extension) otherwise give full path along with file name. Relative file names are resolved with respect to the path of the active test plan. For distributed testing, the CSV file must be stored on the server host system in the correct relative directory to where the JMeter server is started. Absolute file names are also supported, but note that they are unlikely to work in remote mode unless the remote server has the same directory structure. If the same physical file is referenced in two different ways - e.g. csvdata.txt and ./csvdata.txt - then these are treated as different files. If the OS does not distinguish between upper and lower case, csvData.TXT would also be opened separately.
d. File Encoding: The encoding to be used to read the file, if not the platform default
e. Variable Names (comma-delimited): List of variable names separated by the comma. JMeter supports CSV header lines: if the variable name field empty, then the first line of the file is read and interpreted as the list of column names. The names must be separated by the delimiter character. They can be quoted using double-quotes.
JMeter allows values to be quoted; this allows the value to contain a delimiter. If "allow quoted data" is enabled, a value may be enclosed in double-quotes. These are removed. To include double-quotes within a quoted field, use two double-quotes. 
For Example: 1,"2,3","4""5" will be treated as
a. 1
b. 2,3
c. 4"5
f.  Delimiter"\t" or "," can be used as a delimiter. Delimiter to be used to split the records in the file. If there are fewer values on the line than there are variables the remaining variables are not updated - so they will retain their previous value (if any)
g. Allow quoted data?Whether the CSV file allows values to be quoted? If this option enabled (True), then the values can be enclosed in "" (double quote) allowing values to contain a delimiter
h. Recycle on EOF: To make the file re-read from the beginning on reaching the end of file (EOF). The default value is true. 
i.  Stop thread on EOF: This option will stop the thread if reaches to end of file (EOF). The default value is false.
Note: If "Recycle on EOF"is false and "Stop thread on EOF" is false, then on reaching the end of the file, all the variables are set to last line values.
If "Recycle on EOF" is false and "Stop thread on EOF" is true, then on reaching the end of file thread will stop.
j. Sharing Mode: There are 4 sharing modes options.
1. All Threads: The file will be shared between all the threads. This is a default value.
2. Current Thread Group: Each file is opened once for each thread group in which the element appears
3. Current thread - Each file is opened separately for each thread
4. Edit: all threads sharing the same identifier share the same file. So for example, if you have 4 thread groups, you could use a common id for two or more of the groups to share the file between them. Or you could use the thread number to share the file between the same thread numbers in different thread groups.

Next Topic:
Apache JMeter - "DNS Cache Manager" Element

Previous Topic:
Apache JMeter - "Counter"

Related Topics:

2 comments:

  1. Could you please explain the sharing mode with example, it will be more helpful.

    Thanks,
    Pawan

    ReplyDelete
    Replies
    1. Hi Pawan,

      Please refer below link:

      http://perfmatrix.blogspot.in/2017/04/understand-practically-sharing-mode-of-CSV-data-set-config.html

      Delete