当前位置:网站首页>Idea of batch manufacturing test data, with source code
Idea of batch manufacturing test data, with source code
2022-04-23 16:42:00 【Test development Kevin】
The core idea of creating data
In the work of performance testing , We often encounter the need to create data , This work can let the development students cooperate , But it must depend on the face of the development students ! encounter nice The development of students naturally work smoothly , But when you meet development students who don't cooperate well , Coordination and leadership are often needed to facilitate this , This is more troublesome ! This paper simulates the scenario of creating data through the example of circular batch inserting data , What is provided is the dry goods needed to make data SQL Code ! This article assumes that the reader understands the basic sql How to write statements and stored procedures .
The core idea of creating data is very simple : Is to write stored procedures , Loop insert data
Create data instance
Here through to mock Insert data into the database to do demo demonstration :
First , Create a table api_record2, The field information is as follows :
CREATE TABLE api_record2(
id INT(11) PRIMARY KEY AUTO_INCREMENT,
app_name VARCHAR(30) DEFAULT 'test',
host_ip VARCHAR(30),
access_time DATETIME,
method VARCHAR(10),
url VARCHAR(1000),
api_data VARCHAR(1000),
return_value VARCHAR(1000),
INDEX index_app_name ( app_name )
);
The specific meaning of field information will not be explained here ( I believe you can guess the meaning of naming by looking at it , If you have any questions, please leave a message ),id It's the primary key ,app_name Indexed .
The next step is to write stored procedures , The code is as follows :
DELIMITER ;;
DROP PROCEDURE IF EXISTS `insertdata`;
CREATE PROCEDURE insertdata()
BEGIN
DECLARE i INT;
SET i=1;
WHILE(i<=10)DO
INSERT INTO api_record2 (app_name,host_ip,access_time,method,url,api_data,return_value) VALUES (CONCAT('test',FLOOR( 1 + RAND() * (100 - 1))),'127.0.0.1',NOW(),'post','/yourapp_mock/func2','{"user":"kevin","pwd":"123",}','ok');
SET i=i+1;
END WHILE;
COMMIT; # If it's big data , It is suggested to add a layer of circulation , hold commit Put it on the outside of this layer of circulation , Not to fail , Roll back all
END;;
DELIMITER ;
CALL insertdata();
Stored procedure statement analysis
DELIMITER ;; sentence ;;
delimiter yes mysql Separator , stay mysql The default separator in the client is a semicolon , In general , On the client command line , If a line SQL Command to “;” ending , After returning , Will execute this command . For example, when creating a stored procedure , Functions, etc , At this time, you need to enter all a section of commands , Finally, execute it at one time , At this point, the interpreter needs to pass delimiter To deal with it , Replace the semicolon with another symbol , Such as :“//” or “;;”, This explains the semicolon in the command , Realize the one-time execution of this command , Otherwise, an error will be reported , Unable to execute .
DROP PROCEDURE IF EXISTS `insertdata` If stored procedure insertdata There is , Give up execution
CREATE PROCEDURE insertdata() Create stored procedure
BEGIN The transaction start
END End of transaction
COMMIT Transaction submission
WHILE(i<=10)DO
insert sql sentence
SET i=i+1;
END WHILE;
Batch insert data core : Circular insert 10 statement , Statement implementation is almost consistent with circular statements in other languages
insert In the sentence CONCAT('test',FLOOR( 1 + RAND() * (100 - 1))) Indicates that the application name is :test start +1-99 The random number , The main purpose is to explain how to insert random data
insert In the sentence NOW() Indicates to get the current time
CALL insertdata(); Execute stored procedures
This is a simple example , But it has clearly explained the ideas and specific methods of creating data , I believe you can combine your business to write more complex sql Statement and then insert operation ! Originality is not easy. , If the article helps you, you are welcome to like and forward !
版权声明
本文为[Test development Kevin]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231638236941.html
边栏推荐
- RAID磁盘阵列与RAID5的创建
- 1959年高考数学真题
- Phpstudy V8, a commonly used software for station construction 1 graphic installation tutorial (Windows version) super detailed
- Solution of garbled code on idea console
- Report FCRA test question set and answers (11 wrong questions)
- File system read and write performance test practice
- Esxi encapsulated network card driver
- logback的配置文件加载顺序
- Nacos detailed explanation, something
- 博士申请 | 厦门大学信息学院郭诗辉老师团队招收全奖博士/博后/实习生
猜你喜欢

Do you really understand the principle of code scanning login?

昆腾全双工数字无线收发芯片KT1605/KT1606/KT1607/KT1608适用对讲机方案

Change the icon size of PLSQL toolbar

Project framework of robot framework

Hypermotion cloud migration helped China Unicom. Qingyun completed the cloud project of a central enterprise and accelerated the cloud process of the group's core business system

MySQL master-slave replication

1959年高考数学真题

RecyclerView advanced use - to realize drag and drop function of imitation Alipay menu edit page

100 deep learning cases | day 41 - convolutional neural network (CNN): urbansound 8K audio classification (speech recognition)

How to build tiktok user trust and drive fan growth
随机推荐
New project of OMNeT learning
How magical is the unsafe class used by all major frameworks?
JMeter setting environment variable supports direct startup by entering JMeter in any terminal directory
Ali developed three sides, and the interviewer's set of combined punches made me confused on the spot
Loggie source code analysis source file module backbone analysis
Hypermotion cloud migration helped China Unicom. Qingyun completed the cloud project of a central enterprise and accelerated the cloud process of the group's core business system
G008-hwy-cc-estor-04 Huawei Dorado V6 storage simulator configuration
On the value, breaking and harvest of NFT project
Pycham connects to the remote server and realizes remote debugging
Detailed explanation of file operation (2)
Report FCRA test question set and answers (11 wrong questions)
Project framework of robot framework
[pyGame games] how did angry birds, a mobile game that became popular all over the world 10 years ago, dominate the list? Classic return
How to quickly batch create text documents?
Dlib of face recognition framework
5-minute NLP: text to text transfer transformer (T5) unified text to text task model
阿里研发三面,面试官一套组合拳让我当场懵逼
5分钟NLP:Text-To-Text Transfer Transformer (T5)统一的文本到文本任务模型
logback的配置文件加载顺序
深度学习100例 | 第41天-卷积神经网络(CNN):UrbanSound8K音频分类(语音识别)
