当前位置:网站首页>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
边栏推荐
- Gartner announces emerging technology research: insight into the meta universe
- JSP learning 3
- How magical is the unsafe class used by all major frameworks?
- vim编辑器的实时操作
- RecyclerView advanced use - to realize drag and drop function of imitation Alipay menu edit page
- About JMeter startup flash back
- 无线鹅颈麦主播麦手持麦无线麦克风方案应当如何选择
- G008-hwy-cc-estor-04 Huawei Dorado V6 storage simulator configuration
- ∑GL-透视投影矩阵的推导
- 英语 | Day15、16 x 句句真研每日一句(从句断开、修饰)
猜你喜欢

Force buckle - 198 raid homes and plunder houses

Postman batch production body information (realize batch modification of data)

1959年高考数学真题

无线鹅颈麦主播麦手持麦无线麦克风方案应当如何选择

English | day15, 16 x sentence true research daily sentence (clause disconnection, modification)

TypeError: set_figure_params() got an unexpected keyword argument ‘figsize‘

vim编辑器的实时操作

Disk management and file system

Query the data from 2013 to 2021, and only query the data from 2020. The solution to this problem is carried out

Deepinv20 installation MariaDB
随机推荐
Public variables of robotframework
批量制造测试数据的思路,附源码
Dancenn: overview of byte self-developed 100 billion scale file metadata storage system
Selenium IDE and XPath installation of chrome plug-in
Disk management and file system
Ali developed three sides, and the interviewer's set of combined punches made me confused on the spot
JMeter setting environment variable supports direct startup by entering JMeter in any terminal directory
RecyclerView advanced use - to realize drag and drop function of imitation Alipay menu edit page
Gartner publie une étude sur les nouvelles technologies: un aperçu du métacosme
Detailed explanation of file operation (2)
Query the data from 2013 to 2021, and only query the data from 2020. The solution to this problem is carried out
Zhongang Mining: Fluorite Flotation Process
Solution of garbled code on idea console
Sail soft segmentation solution: take only one character (required field) of a string
Detailed explanation of gzip and gunzip decompression parameters
What is homebrew? And use
各大框架都在使用的Unsafe类,到底有多神奇?
Esxi encapsulated network card driver
MySQL master-slave replication
Nacos 详解,有点东西
