Database operation test method, device, storage medium and computer equipment
By listening to the application call instruction information to obtain functions, obtain instruction information and call chain information, determine the database operation type and master-slave attributes, the problem of failure to effectively test application database operations in the existing technology is solved, and a database operation testing method with resource saving and cost reduction is realized.
Patent Information
- Application Number
- CN202211054127.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-31
- Publication Date
- 2025-05-13
- Estimated Expiration
- 2042-08-31
AI Technical Summary
The existing technology failed to effectively test whether the application's database operations on the master-slave database comply with the master-slave read-write separation configuration before the application was launched, resulting in unreasonable database operations that may occur after the application is launched, increasing resource consumption and maintenance costs.
By listening to the call instruction information of the application to be tested, obtaining the instruction information and call chain information, determining the read and write operation type of the target database access instruction and the master and slave properties of the database, and matching it to obtain the test results.
You can test the application's database read and write operations without building a database for testing, saving resources and reducing costs.
Smart Images

Figure CN115328799B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of application testing technology, and in particular to a database operation testing method, device, storage medium and computer equipment. Background Art
[0002] When storing data in a database, a master database and a slave database are usually configured. The master database supports write operations, and in some cases, read operations, while the slave database supports read-only operations. Applications can read data stored in the slave database or write data to the master database.
[0003] Currently, the database operations performed by the application are not tested before the application goes online, resulting in the inability to test whether the database operations performed by the application on the master-slave database comply with the master-slave read-write separation configuration. In order to avoid unreasonable database operations causing alarms in the production environment after the application goes online, the application's database operations need to be tested. During testing, since there is currently no ready-made database available for testing, before testing, the database administrator needs to perform operations such as database configuration and data synchronization to build a testable database. After the construction is completed, the application's database operations are tested using the constructed database. However, testing the application's database operations in the aforementioned manner not only requires a lot of resources, but also has high maintenance costs. Summary of the invention
[0004] The purpose of this application is to solve at least one of the above-mentioned technical defects, especially the technical defects of the prior art that consumes a lot of resources and has high maintenance costs.
[0005] In a first aspect, an embodiment of the present application provides a database operation testing method, the method comprising:
[0006] In the case of monitoring the application to be tested calling the instruction information acquisition function, obtaining the instruction information returned by the instruction information acquisition function, and obtaining the call chain information corresponding to the instruction information acquisition function in this call; the instruction information acquisition function is used to obtain the instruction information of the database access instruction;
[0007] Determining the read / write operation type of the target database access instruction according to the instruction information returned by the instruction information acquisition function, wherein the target database access instruction is a database access instruction corresponding to the instruction information;
[0008] Determining a master-slave property of a target database based on the call chain information, the target database being the database to be accessed by the target database access instruction, the master-slave property of the target database being used to determine a type of read and write operations allowed by the target database;
[0009] The master-slave attribute of the target database and the read-write operation type of the target database access instruction are matched to obtain a test result.
[0010] In one embodiment, the step of determining the read / write operation type of the target database access instruction according to the instruction information returned by the instruction information acquisition function includes:
[0011] Extracting the operation tag in the target database access instruction from the instruction information returned by the instruction information acquisition function;
[0012] If the operation tag is a selection tag, determining that the read / write operation type of the target database access instruction is a read operation type;
[0013] If the operation tag is an insert tag, an update tag, or a delete tag, it is determined that the read-write operation type of the target database access instruction is a write operation type.
[0014] In one embodiment, the step of determining the master-slave attribute of the target database based on the call chain information includes:
[0015] Extracting annotation information corresponding to each level of calling functions from the call chain information;
[0016] If the annotation information corresponding to at least one level of calling function includes preset read-only annotation information, determining that the master-slave attribute of the target database is a slave database;
[0017] If the annotation information corresponding to at least one level of calling function includes preset write annotation information, it is determined that the master-slave attribute of the target database is the master database.
[0018] In one of the embodiments, the master-slave attribute of the target database is a master database or a slave database, and the read-write operation type of the target database access instruction is a read operation type or a write operation type;
[0019] The step of matching the master-slave attribute of the target database with the read-write operation type of the target database access instruction to obtain the test result includes:
[0020] If the master-slave attribute of the target database is a slave database and the read-write operation type of the target database access instruction is a write operation type, a database operation exception prompt is thrown and a conflict test result is generated.
[0021] In one embodiment, the step of matching the master-slave attribute of the target database with the read-write operation type of the target database access instruction to obtain the test result further includes:
[0022] If the master-slave attribute of the target database is a master database, and the read-write operation type of the target database access instruction is a read operation type, a pre-configured processing method is obtained, and processing is performed according to the processing method and the test result is generated according to the processing method; the processing method is an exception throwing processing, a log generation processing or no processing.
[0023] In one embodiment, before the step of obtaining the instruction information returned by the instruction information obtaining function and obtaining the call chain information corresponding to the instruction information obtaining function in this call when monitoring the application to be tested calling the instruction information obtaining function, the method further includes:
[0024] A test function is inserted into the application to be tested by using a program instrumentation technology, so as to monitor whether the application to be tested calls the instruction information acquisition function through the test function.
[0025] In one embodiment, the step of inserting a test function into the application to be tested by using program instrumentation technology includes:
[0026] The test function is inserted at a specified position of the application to be tested by using a program stub technology, and the specified position is a position that enables the test function and the instruction information acquisition function to run in the same thread.
[0027] In a second aspect, an embodiment of the present application further provides a database operation test device, the device comprising:
[0028] An information acquisition module is used to acquire the instruction information returned by the instruction information acquisition function and acquire the call chain information corresponding to the instruction information acquisition function in this call when monitoring the application to be tested calling the instruction information acquisition function; the instruction information acquisition function is used to acquire the instruction information of the database access instruction;
[0029] a read / write operation type determination module, configured to determine the read / write operation type of the target database access instruction according to the instruction information returned by the instruction information acquisition function, wherein the target database access instruction is a database access instruction corresponding to the instruction information;
[0030] A master-slave attribute determination module, used to determine the master-slave attribute of a target database based on the call chain information, the target database being the database to be accessed by the target database access instruction, the master-slave attribute of the target database being used to determine the type of read and write operations allowed by the target database;
[0031] The test result acquisition module is used to match the master-slave attribute of the target database with the read-write operation type of the target database access instruction to obtain the test result.
[0032] In a third aspect, an embodiment of the present application provides a storage medium, in which computer-readable instructions are stored. When the computer-readable instructions are executed by one or more processors, the one or more processors execute the steps of the database operation testing method described in any of the above embodiments.
[0033] In a fourth aspect, an embodiment of the present application provides a computer device, including: one or more processors, and a memory;
[0034] The memory stores computer-readable instructions, and when the computer-readable instructions are executed by the one or more processors, the steps of the database operation testing method described in any of the above embodiments are executed.
[0035] In the database operation test method, device, storage medium and computer equipment provided by the embodiment of the present application, it is monitored whether the application to be tested calls the instruction information acquisition function. If it is monitored that the application to be tested calls the instruction information acquisition function, the instruction information returned by the instruction information acquisition function and the call chain information of the instruction information acquisition function in this call process are obtained, and the read and write operation type of the target database access instruction is determined according to the instruction information, and the master-slave attribute of the database to be accessed by the target database access instruction is determined according to the call chain information, and the database operation test result of the application to be tested is obtained based on the read and write operation type and the master-slave attribute. In this way, the database read and write operation of the application can be tested without specially building a read-write separation database for testing, thereby saving database resources and reducing costs. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0037] Figure 1 A schematic diagram of a flow chart of a database operation test method in one embodiment;
[0038] Figure 2 It is a structural schematic diagram of a database operation test device in one embodiment;
[0039] Figure 3 FIG. 1 is a schematic diagram of the structure of a computer device in an embodiment. DETAILED DESCRIPTION
[0040] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0041] In one embodiment, the present application provides a database operation test method. The following embodiment takes the method applied to a server as an example for explanation. It can be understood that the server executing the database operation test method can be a single server or a server cluster composed of multiple servers, and the present application does not make any specific restrictions on this. Figure 1 As shown, the method specifically comprises the following steps:
[0042] S102, when monitoring the application to be tested calling the instruction information acquisition function, obtain the instruction information returned by the instruction information acquisition function, and obtain the call chain information corresponding to the instruction information acquisition function in this call; the instruction information acquisition function is used to obtain the instruction information of the database access instruction.
[0043] The application to be tested can obtain the instruction information of the database access instruction by calling the instruction information acquisition function, and the instruction information includes but is not limited to the operation label, operation object and operation condition of the database access instruction. In one embodiment, the instruction information acquisition function can be the getBoundSql() function of the MappedStatement class. In other words, the server can monitor whether the application to be tested calls the getBoundSql() function, and when the application to be tested calls the function, the server can obtain the instruction information returned by the getBoundSql() function and the call chain information corresponding to the getBoundSql() function in the local call.
[0044] The call chain information reflects the calling hierarchy relationship of the instruction information acquisition function in this calling process, and records the function information corresponding to each level of the calling function in this calling process, such as the function name of each level of the calling function, the class name corresponding to each level of the calling function, etc. In one embodiment, the server can call the Thread.currentThread().getStackTrace() function to obtain the call chain information of the instruction information acquisition function in this calling process.
[0045] S104: Determine the read / write operation type of the target database access instruction according to the instruction information returned by the instruction information acquisition function, wherein the target database access instruction is a database access instruction corresponding to the instruction information.
[0046] In the case of monitoring the application to be tested calling the instruction information acquisition function, since the parameter returned by the instruction information acquisition function is the instruction information of the database access instruction, the server can determine the read / write operation type of the database access instruction (i.e., the target database access instruction) corresponding to the instruction information according to the instruction information returned by the instruction information acquisition function. The read / write operation type is used to reflect whether the operation performed by the target database access instruction on the database is a read operation or a write operation.
[0047] S106, determining the master-slave attribute of a target database based on the call chain information, wherein the target database is a database to be accessed by the target database access instruction, and the master-slave attribute of the target database is used to determine the read and write operation types allowed by the target database.
[0048] In the case of monitoring the application to be tested calling the instruction information acquisition function, the server can determine the master-slave attribute of the database to be accessed by the target database access instruction based on the acquired call chain information, that is, determine whether the database to be accessed by the target database access instruction (i.e., the target database) is the master database or the slave database based on the call chain information. Since the types of read and write operations allowed by the master and slave databases are different, the slave database only supports read operations, the master database supports write operations, and in some cases, the master database also supports read operations, therefore, the types of read and write operations allowed by the target database can be determined based on the master-slave attribute of the target database.
[0049] S108, matching the master-slave attribute of the target database with the read-write operation type of the target database access instruction to obtain a test result.
[0050] After obtaining the master-slave attribute of the target database and the read-write operation type of the target database access instruction, the server can match the master-slave attribute of the target database and the read-write operation type of the target database access instruction to obtain a test result. The test result can be used to reflect whether the application to be tested performs unreasonable database read-write operations. Further, if the application to be tested performs unreasonable database read-write operations, the test result can also include the unreasonable database read-write operation type.
[0051] In this application, it is possible to monitor whether the application to be tested calls the instruction information acquisition function. If it is monitored that the application to be tested calls the instruction information acquisition function, the instruction information returned by the instruction information acquisition function and the call chain information of the instruction information acquisition function during this call are obtained, and the read and write operation type of the target database access instruction is determined according to the instruction information, and the master-slave attribute of the database to be accessed by the target database access instruction is determined according to the call chain information, and the database operation test result of the application to be tested is obtained based on the read and write operation type and the master-slave attribute. In this way, the database read and write operations of the application can be tested without specially building a database for testing, thereby saving resources and reducing costs.
[0052] In one embodiment, the step of determining the read / write operation type of the target database access instruction according to the instruction information returned by the instruction information acquisition function includes:
[0053] Extracting the operation tag in the target database access instruction from the instruction information returned by the instruction information acquisition function;
[0054] If the operation tag is a selection tag, determining that the read / write operation type of the target database access instruction is a read operation type;
[0055] If the operation tag is an insert tag, an update tag, or a delete tag, it is determined that the read-write operation type of the target database access instruction is a write operation type.
[0056] Specifically, when determining the read-write operation type of the target database access instruction, the server can extract the operation tag of the target database access instruction from the instruction information returned by the instruction information acquisition function. The operation tag can be a selection tag "select", an insert tag "insert", an update tag "update" or a delete tag "delete". If the extracted operation tag is a selection tag, it can be determined that the target database access instruction is only used to obtain data in the target database, and does not involve adding, deleting or modifying the data in the target database, that is, it does not involve write operations, so it can be determined that the read-write operation type of the target database access instruction is a read operation type. When the extracted operation tag is an insert tag, an update tag or a delete tag, it can be determined that the execution of the target database access instruction will add, delete or modify the data in the target database, that is, the target database access instruction involves database write operations during the execution process, so it can be determined that the read-write operation type of the target database access instruction is a write operation type.
[0057] In the embodiment of the present application, by extracting the operation tag of the target database access instruction from the instruction information, the read and write operation type of the target database access instruction can be quickly determined according to the operation tag. At the same time, there is no need to specially build a database for testing, nor is there a need to determine the read and write operation type of the target database access instruction based on the data change of the database, thereby further saving resources and reducing costs.
[0058] In one embodiment, the step of determining the master-slave attribute of the target database based on the call chain information includes:
[0059] Extracting annotation information corresponding to each level of calling functions from the call chain information;
[0060] If the annotation information corresponding to at least one level of calling function includes preset read-only annotation information, determining that the master-slave attribute of the target database is a slave database;
[0061] If the annotation information corresponding to at least one level of calling function includes preset write annotation information, the master-slave attribute of the target database is determined to be the master database.
[0062] The call chain information records the function information corresponding to each level of the calling function, and the function information corresponding to each level of the calling function includes the annotation information of the calling function. For example, in the current calling process of the instruction information acquisition function, the application to be tested first calls function A, and calls function B in function A, and then calls the instruction information acquisition function in function B. Then the call chain information includes at least the annotation information corresponding to function A and the annotation information corresponding to function B.
[0063] The server can extract the annotation information corresponding to the calling functions at all levels from the calling information, and determine whether the target database is configured with read-only / write-only read-write attributes based on the annotation information corresponding to the calling functions at all levels, and then determine the master-slave attributes of the database based on the read-write attributes. Specifically, if the annotation information corresponding to at least one level of calling functions includes preset read-only annotation information, it can be determined that the target database is configured with a read-only attribute, and the target database is a slave database. If the annotation information corresponding to at least one level of calling functions includes preset write annotation information, it can be determined that the target database supports write operations, and the target database is a master database. It can be understood that the specific content of the preset read-only annotation information and the preset write annotation information can be determined according to actual conditions, and the present application does not impose specific restrictions on this. In one example, the read-only annotation information can be "READ" and the write annotation information can be "WRITE".
[0064] In the embodiment of the present application, by extracting annotation information corresponding to each level of calling functions from the call chain information, the master and slave data of the target database can be quickly determined based on the annotation information.
[0065] In one embodiment, the master-slave attribute of the target database is a master database or a slave database, and the read-write operation type of the target database access instruction is a read operation type or a write operation type;
[0066] The step of matching the master-slave attribute of the target database with the read-write operation type of the target database access instruction to obtain the test result includes:
[0067] If the master-slave attribute of the target database is a slave database and the read-write operation type of the target database access instruction is a write operation type, a database operation exception prompt is thrown and a conflict test result is generated.
[0068] Specifically, if the master-slave property of the target database is a slave database, it indicates that the target database only supports read-only operations. If the read-write operation type of the target database access instruction is a write operation type, the target database access instruction will not be successfully executed, and there is a conflict between the target database access instruction and the target database. In this case, the server can simulate the database to throw an exception to block the test behavior, and generate a conflict test result to indicate that there is a conflict between the target database access instruction and the target database. In one embodiment, the server can call the ProcessController.throwsImmediately() function to throw a database operation exception prompt. In this way, the database operation test can be completed without specially building a testable database, thereby further saving resources and reducing costs.
[0069] In one embodiment, the step of matching the master-slave attribute of the target database with the read-write operation type of the target database access instruction to obtain the test result further includes:
[0070] If the master-slave attribute of the target database is a master database, and the read-write operation type of the target database access instruction is a read operation type, a pre-configured processing method is obtained, and processing is performed according to the processing method and the test result is generated according to the processing method; the processing method is an exception throwing processing, a log generation processing or no processing.
[0071] Specifically, since the master database can determine whether to support read operations based on the configuration of the R&D personnel, when the master-slave attribute of the target database is the master database and the read-write operation type of the target database access instruction is a read operation type, the server can obtain the pre-configured processing method to determine whether the target database access instruction needs to be executed without processing, generate a corresponding log, or throw an exception. After determining the processing method, the server can process according to the determined processing method and generate corresponding test results. For example, when the pre-configured processing method is to throw an exception, the server can throw an exception and generate a conflict test result; when the pre-configured processing method is not to process, the server can generate a non-conflict test result; when the pre-configured processing method is to generate a log, the server can generate a conflict test result or a non-conflict test result according to the test configuration.
[0072] In this embodiment, when the master-slave attribute of the target database is the master database, and the read-write operation type of the target database access instruction is the read operation type, the server can process and generate test results according to the pre-configured processing method. In this way, the actual operation of the application to be tested after it is officially put into use can be simulated to perform testing, so that the test results are more accurate.
[0073] In one embodiment, before the step of obtaining the instruction information returned by the instruction information obtaining function and obtaining the call chain information corresponding to the instruction information obtaining function in this call, the method further includes:
[0074] A test function is inserted into the application to be tested by using a program instrumentation technology, so as to monitor whether the application to be tested calls the instruction information acquisition function through the test function.
[0075] It can be understood that the present application can implement the insertion of test functions through any type of program instrumentation technology. In one embodiment, the program instrumentation technology can be JVM-Sandbox (Java Virtual Machine Sandbox) technology.
[0076] In one of the embodiments, the test function can be used to monitor whether the application to be tested calls the instruction information acquisition function, and execute the steps of the database operation test method described in any of the above embodiments. In order to ensure that the test function can accurately obtain the call chain information of the instruction information acquisition function during this call when monitoring the application to be tested calling the instruction information acquisition function, in this application, the program stub technology can be used to insert the test function at the specified position of the application to be tested, and the specified position is the position where the test function and the instruction information acquisition function run in the same thread.
[0077] The following is a description of a database operation testing device provided in an embodiment of the present application. The database operation testing device described below and the database operation testing method described above can be referenced to each other.
[0078] In one embodiment, the present application provides a database operation testing device 200. Figure 2 As shown, the device 200 specifically includes an information acquisition module 210, a read / write operation type determination module 220, a master-slave attribute determination module 230 and a test result acquisition module 240, wherein:
[0079] The information acquisition module 210 is used to acquire the instruction information returned by the instruction information acquisition function and acquire the call chain information corresponding to the instruction information acquisition function in this call when monitoring the application to be tested calling the instruction information acquisition function; the instruction information acquisition function is used to acquire the instruction information of the database access instruction;
[0080] A read / write operation type determination module 220, configured to determine the read / write operation type of the target database access instruction according to the instruction information returned by the instruction information acquisition function, wherein the target database access instruction is a database access instruction corresponding to the instruction information;
[0081] A master-slave attribute determination module 230, configured to determine the master-slave attribute of a target database based on the call chain information, wherein the target database is the database to be accessed by the target database access instruction, and the master-slave attribute of the target database is used to determine the type of read and write operations allowed by the target database;
[0082] The test result acquisition module 240 is used to match the master-slave attribute of the target database with the read-write operation type of the target database access instruction to obtain the test result.
[0083] In one embodiment, the read / write operation type determination module 220 includes an operation label extraction unit, a first type determination unit, and a second type determination unit. The operation label extraction unit is used to extract the operation label in the target database access instruction from the instruction information returned by the instruction information acquisition function. The first type determination unit is used to determine that the read / write operation type of the target database access instruction is a read operation type when the operation label is a select label. The second type determination unit is used to determine that the read / write operation type of the target database access instruction is a write operation type when the operation label is an insert label, an update label, or a delete label.
[0084] In one embodiment, the master-slave attribute determination module 230 includes an annotation information extraction unit, a first attribute determination unit, and a second attribute determination unit. The annotation information extraction unit is used to extract annotation information corresponding to each level of calling functions from the call chain information. The first attribute determination unit is used to determine that the master-slave attribute of the target database is a slave database when the annotation information corresponding to at least one level of calling functions includes preset read-only annotation information. The second attribute determination unit is used to determine that the master-slave attribute of the target database is a master database when the annotation information corresponding to at least one level of calling functions includes preset write annotation information.
[0085] In one embodiment, the master-slave attribute of the target database is a master database or a slave database, and the read-write operation type of the target database access instruction is a read operation type or a write operation type. The test result acquisition module 240 includes a first test result generation unit, which is used to throw a database operation exception prompt and generate a conflict test result when the master-slave attribute of the target database is a slave database and the read-write operation type of the target database access instruction is a write operation type.
[0086] In one embodiment, the test result acquisition module 240 also includes a second test result generation unit, which is used to obtain a pre-configured processing method when the master-slave attribute of the target database is a master database and the read and write operation type of the target database access instruction is a read operation type, and to process according to the processing method and generate the test result according to the processing method; the processing method is to throw an exception, generate a log, or do no processing.
[0087] In one embodiment, the apparatus 200 further includes a function insertion module, which is used to insert a test function into the application to be tested using a program instrumentation technique, so as to monitor whether the application to be tested calls the instruction information acquisition function through the test function.
[0088] In one embodiment, the function insertion module includes a first insertion unit, which is used to insert the test function at a specified position of the application to be tested using program instrumentation technology, and the specified position is a position where the test function and the instruction information acquisition function run in the same thread.
[0089] In one embodiment, the present application also provides a storage medium storing computer-readable instructions. When the computer-readable instructions are executed by one or more processors, the one or more processors execute the steps of the database operation testing method described in any one of the above embodiments.
[0090] In one embodiment, the present application further provides a computer device having computer-readable instructions stored therein, which, when executed by one or more processors, causes the one or more processors to execute the steps of the database operation test method described in any one of the above embodiments.
[0091] Indicatively, Figure 3 The internal structure diagram of a computer device provided in an embodiment of the present application is shown in FIG. 1 . In one example, the computer device may be a server. Figure 3 The computer device 900 includes a processing component 902, which further includes one or more processors, and a memory resource represented by a memory 901, for storing instructions executable by the processing component 902, such as an application. The application stored in the memory 901 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 902 is configured to execute instructions to perform the steps of the database operation test method described in any of the above embodiments.
[0092] The computer device 900 may further include a power supply component 903 configured to perform power management of the computer device 900, a wired or wireless network interface 904 configured to connect the computer device 900 to a network, and an input / output (I / O) interface 905. The computer device 900 may operate based on an operating system stored in the memory 901, such as Windows Server TM, Mac OS X TM, Unix TM, Linux TM, Free BSD TM or the like.
[0093] Those skilled in the art will understand that the internal structure of the computer device shown in the present application is merely a block diagram of a partial structure related to the scheme of the present application, and does not constitute a limitation on the computer device to which the scheme of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0094] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply that there is any such actual relationship or order between these entities or operations. Moreover, the term "include", "comprise" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, article or equipment including a series of elements not only includes those elements, but also includes other elements not clearly listed, or also includes elements inherent to such process, method, article or equipment. In the absence of more restrictions, the elements defined by the sentence "including one..." do not exclude the existence of other identical elements in the process, method, article or equipment including the elements. Herein, "one", "one", "said", "the" and "it" may also include plural forms, unless the context clearly indicates another way. A plurality refers to at least two cases, such as 2, 3, 5 or 8, etc. "And / or" includes any and all combinations of the relevant listed items.
[0095] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The various embodiments can be combined as needed, and the same or similar parts can refer to each other.
[0096] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A database operation testing method, characterized in that: The method comprises: In the case of monitoring the application to be tested calling the instruction information acquisition function, obtaining the instruction information returned by the instruction information acquisition function, and obtaining the call chain information corresponding to the instruction information acquisition function in this call; the instruction information acquisition function is used to obtain the instruction information of the database access instruction; Determining the read / write operation type of the target database access instruction according to the instruction information returned by the instruction information acquisition function, wherein the target database access instruction is a database access instruction corresponding to the instruction information; Determining a master-slave property of a target database based on the call chain information, the target database being the database to be accessed by the target database access instruction, the master-slave property of the target database being used to determine a type of read and write operations allowed by the target database; Matching the master-slave attribute of the target database with the read-write operation type of the target database access instruction to obtain a test result; The step of determining the read / write operation type of the target database access instruction according to the instruction information returned by the instruction information acquisition function includes: Extracting the operation tag in the target database access instruction from the instruction information returned by the instruction information acquisition function; If the operation tag is a selection tag, determining that the read / write operation type of the target database access instruction is a read operation type; If the operation tag is an insert tag, an update tag or a delete tag, determining that the read / write operation type of the target database access instruction is a write operation type; The step of determining the master-slave attribute of the target database based on the call chain information includes: Extracting annotation information corresponding to each level of calling functions from the call chain information; If the annotation information corresponding to at least one level of calling function includes preset read-only annotation information, determining that the master-slave attribute of the target database is a slave database; If the annotation information corresponding to at least one level of calling function includes preset write annotation information, the master-slave attribute of the target database is determined to be the master database.
2. The method according to claim 1, characterized in that The master-slave attribute of the target database is a master database or a slave database, and the read-write operation type of the target database access instruction is a read operation type or a write operation type; The step of matching the master-slave attribute of the target database with the read-write operation type of the target database access instruction to obtain the test result includes: If the master-slave attribute of the target database is a slave database and the read-write operation type of the target database access instruction is a write operation type, a database operation exception prompt is thrown and a conflict test result is generated.
3. The method according to claim 2, characterized in that The step of matching the master-slave attribute of the target database with the read-write operation type of the target database access instruction to obtain the test result further includes: If the master-slave attribute of the target database is a master database, and the read-write operation type of the target database access instruction is a read operation type, a pre-configured processing method is obtained, and processing is performed according to the processing method and the test result is generated according to the processing method; the processing method is an exception throwing processing, a log generation processing or no processing.
4. The method according to claim 1, characterized in that: Before the steps of obtaining the instruction information returned by the instruction information obtaining function and obtaining the call chain information corresponding to the instruction information obtaining function in the current call, the method further includes: A test function is inserted into the application to be tested by using a program instrumentation technology, so as to monitor whether the application to be tested calls the instruction information acquisition function through the test function.
5. The method according to claim 4, characterized in that The step of inserting a test function into the application to be tested by using program instrumentation technology includes: The test function is inserted at a specified position of the application to be tested by using a program stub technology, and the specified position is a position that enables the test function and the instruction information acquisition function to run in the same thread.
6. A database operation test device, characterized in that: The device comprises: An information acquisition module is used to acquire the instruction information returned by the instruction information acquisition function and acquire the call chain information corresponding to the instruction information acquisition function in this call when monitoring the application to be tested calling the instruction information acquisition function; the instruction information acquisition function is used to acquire the instruction information of the database access instruction; A read / write operation type determination module, configured to determine the read / write operation type of a target database access instruction according to the instruction information returned by the instruction information acquisition function, wherein the target database access instruction is a database access instruction corresponding to the instruction information; A master-slave attribute determination module, used to determine the master-slave attribute of a target database based on the call chain information, the target database being the database to be accessed by the target database access instruction, the master-slave attribute of the target database being used to determine the type of read and write operations allowed by the target database; A test result acquisition module, used for matching the master-slave attribute of the target database with the read-write operation type of the target database access instruction to obtain a test result; Wherein, the read-write operation type determination module includes: An operation tag extraction unit, used to extract the operation tag in the target database access instruction from the instruction information returned by the instruction information acquisition function; A first type determination unit, configured to determine, when the operation tag is a selection tag, that the read / write operation type of the target database access instruction is a read operation type; A second type determination unit, configured to determine, when the operation tag is an insert tag, an update tag, or a delete tag, that the read / write operation type of the target database access instruction is a write operation type; The master-slave attribute determination module includes: An annotation information extraction unit, used to extract annotation information corresponding to each level of calling functions from the call chain information; A first attribute determination unit, configured to determine that the master-slave attribute of the target database is a slave database when the annotation information corresponding to at least one level of calling function includes preset read-only annotation information; The second attribute determination unit is used to determine that the master-slave attribute of the target database is the master database when the annotation information corresponding to at least one level of calling function includes preset write annotation information.
7. A storage medium, characterized in that: The storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by one or more processors, the one or more processors execute the steps of the database operation testing method according to any one of claims 1 to 5.
8. A computer device, characterized in that: include: one or more processors, and memory; The memory stores computer-readable instructions, and when the computer-readable instructions are executed by the one or more processors, the steps of the database operation testing method according to any one of claims 1 to 5 are performed.
Citation Information
Patent Citations
Method and device for splitting database reading and writing
CN103793432A
Data source read-write separation method and device and computer readable storage medium
CN110837531A