Right now, I'm making processing of large volumes of data, if not big data. Processing large data is limited in the number of times it can be tested per day, so
I want that environment even in my house, I wondered if I could do something with jMeter. just made it.
JMeter is a multifunctional and high-performance request sending app, By default, there is no "function that converts CSV to JSON".
However, by running the Script when sending "** BeanPreProcesser **", There is a function that can be controlled in various ways.
Roughly do this. -Set the receiving variable in the HTTP request
-Use Bean PreProcessor to create a JSON string and assign it to the receiving variable
・ Send HTTP request with jMeter
First, set the HTTP request transmission settings normally. Create an HTTP header manager, Set Content-Type to ** application / json **
First, normally, enter the target address in the target server or path.
Then put "** variable to store the result of the script **" in the request This time I named it ** $ {post_data} **
Then right-click to create BeanPreProcessor and create a JSON string.
BeanPreProcessor is written in Java, so if you are used to it, it's easy to use. It seems that JSON serialization and deserialization are also possible by loading the library in jMeter ヾ (.> ﹏ <.) ノ ✧ *.
The processing content is as you can see. Loop the CSV line by line
request.json
"csv list":[{
"Hogehoge":"CSV 1st column"
"somehow":"CSV 2nd column"
"foo":"CSV 3rd column"
}
{
"Hogehoge":"CSV 1st column"
"somehow":"CSV 2nd column"
"foo":"CSV 3rd column"
}]
...
Make a JSON like this!
BeanShellPreProcessor.java
//▼-----------BeanPreProcessor processing started-------------▼
log.info("BeanShell PreProcessor start");
StringBuilder requestBody = new StringBuilder();
//Make a JSON start
requestBody.append("{\r\n");
//Line breaks are also reflected properly ヾ(¡>﹏<¡)No ✧*。
//Start creating list object
requestBody.append("\"requestCSV\":[\r\n");
//Read CSV file
BufferedReader reader = new BufferedReader(new FileReader(new File("C:\\csvFileForBatche\\06YAMAGAcopied.CSV")));
String line;
//Loop line by line
boolean secondLoopFlg = false;
while ((line = reader.readLine()) != null) {
//Divide the read CSV with commas
String[] params = line.split(",");
if(secondLoopFlg){
requestBody.append(",\r\n");
}
requestBody.append("{\r\n");
//Create CSV parameters for each item
requestBody.append("\"countryPublicOrgCd\":\"").append(params[0]).append("\",\r\n");
requestBody.append("\"zipcodePare\":").append(params[1]).append(",\r\n");
requestBody.append("\"zipcode\":").append(params[2]).append(",\r\n");
requestBody.append("\"prefNameKana\":").append(params[3]).append(",\r\n");
requestBody.append("\"cityNameKana\":").append(params[4]).append(",\r\n");
requestBody.append("\"streetNameKana\":").append(params[5]).append(",\r\n");
requestBody.append("\"prefNameKanji\":").append(params[6]).append(",\r\n");
requestBody.append("\"cityNameKanji\":").append(params[7]).append(",\r\n");
requestBody.append("\"streetNameKanji\":").append(params[8]).append(",\r\n");
requestBody.append("\"var1\": \"").append(params[9]).append("\",\r\n");
requestBody.append("\"var2\": \"").append(params[10]).append("\",\r\n");
requestBody.append("\"var3\": \"").append(params[11]).append("\",\r\n");
requestBody.append("\"var4\": \"").append(params[12]).append("\",\r\n");
requestBody.append("\"var5\": \"").append(params[13]).append("\",\r\n");
requestBody.append("\"var6\": \"").append(params[14]).append("\"\r\n");
//Close object
requestBody.append("}\r\n");
secondLoopFlg = true;
}
//Close JSON object
requestBody.append("]\r\n");
requestBody.append("}\r\n");
//Close file
reader.close();
//Assign to a variable prepared by the request
vars.put("post_data", requestBody.toString());
// ▲-----------BeanPreProcessor processing started-------------▲
log.info("BeanShell PreProcessor start");
I will actually send a request in this state
We were able to send CSV to 30,000 requests b
reference Sending Complete JSON Data from the CSV file in one request in JMeter https://stackoverflow.com/questions/32628934/sending-complete-json-data-from-the-csv-file-in-one-request-in-jmeter
receiving json and deserializing as List of object at spring mvc controller https://stackoverflow.com/questions/23012841/receiving-json-and-deserializing-as-list-of-object-at-spring-mvc-controller
Recommended Posts