I have multiple test CSV files (approx. 20 files with a million records (just one column of IDs) in each file) in a folder. I want to run a performance test using this data.
To loop through the files, I have made progress but I am stuck at one issue. First I will explain what I have accomplished so far and then the issue I am running into.
- Added a BeanShell sampler (script is below) under Thread Group.
It creates file variables with file paths as values.
e.g.file_1 = /Users/Code/JMeter-Campaign/data/file_1.txt
import java.io.*;
File fileDir = new File("/Users/Code/JMeter-Campaign/data");
File[] fList = fileDir.listFiles();
int counter = 1;
for (File file:fList) {
if (! file.isHidden()) {
vars.put("file_" + counter, file.getAbsolutePath());
log.info("file_" + counter + "=" + vars.get("file_" + counter));
counter++;
}
}
- Add
ForEach
controller to loop. Fields and values are below.
Input variable prefix : file
Start index for loop : 0
Output variable name: USER_FILE
Add _ before number - checked
Added Beanshell Preprocessor as a child of
ForEach
controller. Converts vars in props.props.put("UserFile", vars.get("USER_FILE"));
Added CSV Data Set config as a child of
ForEach
controller.
Filename : ${__P(UserFile,)}
Delimeter: ,
First, I am testing a simple scenario - 3 files (file_1, file_2 and file_3) with 1 record in each.
It's looping through all 3 files (debugged using log.info, debug sampler, view results tree) however the data is coming from the last file only. So for file_1, data is from file_3
Also observer in the jmeter.log, jmeter.services.FileServer always points to the 3rd file.
Is there a better way to parameterize test CSV files? I want to my run the test with all records in the first file and then second file and so on. This will prevent server side caching.