Data recovery method, device, equipment, medium and product
By combining the proxy module and the rollback module, the processing instructions for interface test data are automatically recorded and executed in reverse order, which solves the problem of time-consuming manual recovery of test data in the existing technology and realizes automated recovery and efficient testing of interface test data.
Patent Information
- Application Number
- CN202511075929.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-01
- Publication Date
- 2025-11-14
AI Technical Summary
In interface testing involving CRUD operations, existing technologies require manual recovery of test data, which is time-consuming, affects testing efficiency, and may interfere with other testers.
The proxy module obtains interface call requests, records the state of thread-local variables and stores data processing information, and uses the rollback module to generate and execute reverse data restoration instructions to achieve automated restoration of interface test data.
It improved testing efficiency, avoided interference with other testers, and ensured data consistency.
Smart Images

Figure CN120950307A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a data recovery method, apparatus, device, medium, and product. Background Technology
[0002] In a typical web backend system, an Application Programming Interface (API) interacts with a database to implement a specific business function. It processes the data according to predetermined rules and returns the results to the consumer. During this process, the API's handling of database data essentially involves four operations: querying, adding, modifying, and deleting. While querying does not change the data's state or attributes, the other three operations do. This nature means that for an API involving add, delete, and modify operations, when repeatedly testing a specific application scenario, after the initial successful or partially successful call, subsequent tests using the same request parameters will not yield the expected results because the data's state or attributes have changed.
[0003] Therefore, for interfaces involving CRUD operations, it is often necessary to recreate the test data or restore the data to its original state after each execution. This requires testers to be familiar with the data creation process and table structure, and is time-consuming, which impacts testing efficiency. Therefore, there is an urgent need for a way to automatically restore test data. Summary of the Invention
[0004] This invention provides a data recovery method, apparatus, device, medium, and product that conditionally enables automated recovery of interface test data and improves testing efficiency.
[0005] In a first aspect, embodiments of this disclosure provide a data recovery method, including:
[0006] The proxy module obtains test interface call requests, determines the corresponding thread local variable state based on the test interface call requests, executes the data processing instructions corresponding to the test interface call requests according to the thread local variable state, and stores the corresponding data processing information based on the operation type of the data processing instructions.
[0007] When a data recovery request is received, the rollback module generates a corresponding data recovery instruction based on the data processing information and executes the data recovery instruction in reverse order of the execution of the data processing instructions.
[0008] Secondly, embodiments of this disclosure provide a data recovery apparatus, comprising:
[0009] The proxy module is used to obtain test interface call requests, determine the corresponding thread local variable state based on the test interface call requests, execute the data processing instructions corresponding to the test interface call requests according to the thread local variable state, and store the corresponding data processing information based on the operation type of the data processing instructions.
[0010] The rollback module is used to generate a corresponding data restoration instruction based on the data processing information when a data restoration request is received, and to execute the data restoration instruction in reverse order of the execution of the data processing instructions.
[0011] Thirdly, embodiments of this disclosure provide an electronic device, including:
[0012] At least one processor; and
[0013] A memory that is communicatively connected to at least one processor; wherein,
[0014] The memory stores a computer program that can be executed by at least one processor, such that the at least one processor can perform a data recovery method provided in the first aspect embodiment described above.
[0015] Fourthly, embodiments of this disclosure provide a computer-readable storage medium storing computer instructions that, when executed by a processor, implement the data restoration method provided in the first aspect of the embodiments described above.
[0016] Fifthly, this disclosure provides a computer program product, which includes a computer program that, when executed by a processor, implements a data restoration method provided in the first aspect of the embodiments described above.
[0017] An embodiment of the present invention provides a data recovery method, apparatus, device, medium, and product, comprising: acquiring a test interface call request through a proxy module; determining the corresponding thread local variable state based on the test interface call request; executing a data processing instruction corresponding to the test interface call request according to the thread local variable state; and storing corresponding data processing information based on the operation type of the data processing instruction.
[0018] The rollback module, upon receiving a data recovery request, generates a corresponding data recovery instruction based on the data processing information and executes the instruction in reverse order of execution. This technical solution conditionally enables automated recovery of interface test data and improves testing efficiency.
[0019] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description
[0020] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0021] Figure 1 This is a flowchart of a data restoration method provided in Embodiment 1 of the present invention;
[0022] Figure 2 This is a schematic diagram of the structure of a data recovery device provided in Embodiment 1 of the present invention;
[0023] Figure 3 This is a flowchart of a data restoration method provided in Embodiment 2 of the present invention;
[0024] Figure 4 This is a schematic diagram of the structure of a data recovery device provided in Embodiment 3 of the present invention;
[0025] Figure 5 This is a schematic diagram of the structure of an electronic device provided in Embodiment 4 of the present invention. Detailed Implementation
[0026] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0027] It should be noted that the terms "first," "second," and "target," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0028] The existing data recovery methods have the following drawbacks:
[0029] 1. It lacks flexibility, as it uses a single test activity as the basic unit. A single test activity includes the execution of multiple test cases, and data rollback is only possible after all test cases have been executed.
[0030] 2. This may interfere with other testers. Reverting to the backup data will also revert the test data of other personnel.
[0031] Therefore, embodiments of the present invention provide a data recovery method to solve the above-mentioned technical problems.
[0032] Example 1
[0033] Figure 1 This is a flowchart of a data recovery method provided in Embodiment 1 of the present invention. This embodiment is applicable to the situation of data recovery of interface test data. The method can be executed by a data recovery device, which can be implemented in hardware and / or software.
[0034] Figure 2 This is a schematic diagram of the structure of a data recovery device provided in Embodiment 1 of the present invention, as shown below. Figure 2As shown, the proxy module includes an HTTP request interception unit corresponding to Hypertext Transfer Protocol (HTTP) requests, an SQL interception unit corresponding to Structured Query Language (SQL) requests, and a data snapshot storage unit. The rollback module includes a reverse SQL generation unit and a rollback execution unit. Both the HTTP request interception unit and the SQL interception unit perform data interception and identification operations. The HTTP request interception unit initially identifies whether the test data corresponding to the test interface call request is the data to be rolled back. The SQL interception unit identifies the Data Manipulation Language (DML) SQL commands within the test interface call request for the test data to be rolled back. The data snapshot storage unit captures a data snapshot before DML execution, storing information such as operation type, table name, and old data for rollback. The reverse SQL generation unit automatically generates reverse SQL based on the DML type and snapshot data. The rollback execution unit executes the reverse SQL in reverse order during data restoration to ensure data consistency.
[0035] like Figure 1 As shown, the method includes:
[0036] S101. Obtain the test interface call request through the proxy module, determine the corresponding thread local variable state based on the test interface call request, execute the data processing instruction corresponding to the test interface call request according to the thread local variable state, and store the corresponding data processing information based on the operation type of the data processing instruction.
[0037] In this embodiment, the test interface call request can be understood as an interface used to test the system's interaction with other external systems, as well as the interfaces between various sub-modules within the system. The focus of the test is to check the correctness of the interface parameter transmission, the correctness of the interface function implementation, the correctness of the output results, and the completeness and rationality of the fault tolerance handling for various abnormal situations. The thread-local variable state indicates whether the received test data to be processed belongs to custom test data, to confirm whether SQL interception identification should be executed subsequently. The data processing instruction can be understood as the processing instructions for the test data within the test interface call request, which are SQL statements. SQL is a database query and programming language used to access data and query, update, and manage relational database systems. The operation types of data processing instructions include query and editing types, with editing types including adding, deleting, and modifying. Data processing information can be understood as information related to the data processing instructions, including at least the corresponding operation type, the table name of the database table containing the test data, and the data being processed.
[0038] Specifically, the proxy module obtains test interface call requests, verifies them, and sets the thread-local variable status to either yes or no based on the verification result. Subsequent snapshot storage and rollback are only executed when the thread-local variable status is yes. The module executes the data processing instructions corresponding to the test interface call requests and processes the corresponding test data based on the operation type of the instructions. Then, the data processing information for operations of add, delete, and modify types is stored in the corresponding data snapshot storage unit.
[0039] S102. Upon receiving a data restoration request, the rollback module generates a corresponding data restoration instruction based on the data processing information and executes the data restoration instruction in reverse order of execution of the data processing instructions.
[0040] In this embodiment, a data restoration request can be understood as a request to restore the test data corresponding to the snapshot storage process performed through the proxy module. A data restoration instruction can be understood as a reverse SQL statement corresponding to a data processing instruction. It instructs the test data to be rolled back to the original data or the data before the last edit; rollback refers to restoring the data's attributes or state to the state before a series of SQL operations were executed.
[0041] Specifically, the rollback module, upon receiving a data restoration request, retrieves the data processing information of the test data targeted by the data restoration request from the data snapshot storage unit. Based on the operation type corresponding to the data processing information and the saved processing data, it generates the corresponding reverse SQL statement, i.e., the data restoration instruction, and executes the data restoration instruction in reverse order of the data processing instruction execution order.
[0042] This invention provides a data recovery method, comprising: acquiring a test interface call request through a proxy module; determining the corresponding thread-local variable state based on the test interface call request; executing the data processing instruction corresponding to the test interface call request according to the thread-local variable state; and storing corresponding data processing information based on the operation type of the data processing instruction; and generating a corresponding data recovery instruction based on the data processing information through a rollback module when a data recovery request is received, and executing the data recovery instruction in reverse order of execution of the data processing instructions. This technical solution automatically records the executed SQL statements during interface operation and allows for one-click rollback of the data state after interface execution, facilitating rapid retesting; it conditionally enables automated recovery of interface test data, avoiding interference with other requests and other testers, ensuring data consistency before and after recovery, and improving testing efficiency.
[0043] Example 2
[0044] Figure 3This is a flowchart of a data recovery method provided in Embodiment 2 of the present invention. This embodiment is a further optimization of any of the above embodiments and can be applied to the situation of data recovery of interface test data. The method can be executed by a data recovery device, which can be implemented in hardware and / or software.
[0045] like Figure 3 As shown, the method includes:
[0046] S201. Obtain the test interface call request through the proxy module and determine the current interception flag in the request header of the test interface call request.
[0047] In this embodiment, the current interception identifier can be understood as the custom intercept_id parameter in the request header of the test interface call request.
[0048] Specifically, when the proxy module receives an interface call request, it checks whether the request header contains the intercept_id parameter.
[0049] S202. Compare the current interception identifier with the preset interception identifier deployed in the proxy module.
[0050] In this embodiment, the preset interception identifier is the custom parameter INTERCEPT_ID that is included in the command line when the proxy module starts.
[0051] Specifically, if the request header of the test interface call request contains the current interception identifier, the current interception identifier intercept_id is compared with the preset interception identifier INTERCEPT_ID deployed in the proxy module to obtain the comparison result, which includes whether they match or do not match.
[0052] S203. If the comparison results are consistent, set the thread-local variable state of the processing thread corresponding to the test interface call request to "yes".
[0053] In this embodiment, if the comparison result is consistent, the state of a thread-local variable is set to "yes".
[0054] When SQL operations are required, the state of thread-local variables determines whether to intercept the SQL statement to be executed in that request. This ensures that SQL interception is only enabled for interface requests specified by the tester, avoiding interference with other users.
[0055] S204. If the comparison result is inconsistent, set the thread-local variable state of the processing thread corresponding to the test interface call request to no.
[0056] In this embodiment, if the comparison result is inconsistent, the state of a thread-local variable is set to "No". It is understood that the request header of the test interface call request may not contain the current interception identifier. In this case, the state of a thread-local variable is also set to "No".
[0057] In this embodiment, steps S201-S204 are as follows: Figure 2 The HTTP request interception unit in the proxy module shown is executed.
[0058] S205. When the state of the thread-local variable is yes, determine the operation type of the data processing instruction corresponding to the test interface call request.
[0059] In this embodiment, SQL interception and identification are performed when the state of the thread-local variable is "yes".
[0060] Specifically, when the thread-local variable is in a certain state, the SQL statement is intercepted through a Java Database Connectivity (JDBC) proxy. The operation type corresponding to the SQL statement is then determined. The operation type includes add, delete, modify, and query.
[0061] S206. If the operation type is query, execute the data processing instruction.
[0062] In this embodiment, the query class is the query operation SELECT.
[0063] Specifically, if the operation type is a SELECT operation, since it does not change the state and attributes of the test data, no processing is required, and the data processing instructions are executed directly to perform the query.
[0064] S207. If the operation type is editing, based on the editing type of the data processing instruction, store the corresponding data processing information and execute the data processing instruction.
[0065] In this embodiment, the edit class refers to the editing operation that changes the state and attributes of the test data; the edit class is also a DML type. The edit types of the edit class include INSERT, DELETE, and UPDATE.
[0066] Specifically, if the operation type is DML, different editing types correspond to different filtering conditions and data processing. Understandably, DML statements require packaging using data snapshot storage units. Therefore, based on the editing type of the data processing instructions, it is necessary to store the necessary data processing information and execute the data processing instructions to facilitate subsequent restoration of the original state using reverse SQL operations.
[0067] In this embodiment, steps S205-S207 are performed as follows: Figure 2 The SQL interception unit and the data snapshot storage unit in the agent module shown are executed together.
[0068] Optionally, based on the edit type of the data processing instruction, the corresponding data processing information is stored and the data processing instruction is executed, including:
[0069] S2071. If the editing type of the data processing instruction is "add", store the primary key value of the data to be inserted in the data processing instruction to the corresponding data snapshot storage unit, and execute the data processing instruction.
[0070] In this embodiment, if the editing type of the data processing instruction for the test data is "add," the INSERT statement to be executed contains all the field names and corresponding values to be inserted. However, the DELETE operation used to roll back the INSERT operation does not require all the field information. Therefore, only the primary key value of the data to be inserted needs to be stored in the corresponding data snapshot storage unit. It is understood that the INSERT operation type and the table name of the database table containing the test data also need to be stored so that the subsequent rollback module can execute the corresponding DELETE operation in the corresponding database table. After the data snapshot storage unit is completed, the INSERT type data processing instruction is executed.
[0071] S2072. If the editing type of the data processing instruction is deletion, store the deletion filter conditions and all field values of the data to be deleted in the data processing instruction to the corresponding data snapshot storage unit, and execute the data processing instruction.
[0072] In this embodiment, the deletion filter criteria can be understood as the conditions used to query data to be deleted. The data to be deleted is the content in the test data that needs to be removed.
[0073] Specifically, if the data processing instruction for the test data is a delete operation, the DELETE statement to be executed typically only contains some field values as filter conditions. However, the INSERT operation used to roll back the DELETE operation requires all field values of the data to be deleted. Therefore, before executing the original DELETE statement, it is necessary to query the data to be deleted based on the deletion filter conditions in the original DELETE statement and save all field values of the data to be deleted to the data snapshot storage unit. Understandably, it is also necessary to store the DELETE operation type and the table name of the database table where the test data resides, so that the subsequent rollback module can execute the corresponding INSERT operation in the corresponding database table. After completing the storage in the data snapshot storage unit, the DELETE type data processing instruction is executed.
[0074] For example, a database table stores four fields: abcd. The data processing command is `delete * from table where a = 1`, which means deleting all four fields (a, b, c, d) from rows where a = 1. However, when constructing a reverse SQL statement, the values of all fields from rows where a = 1 are needed. Therefore, before executing `DELETE`, a query filtering operation needs to be performed first, and then the delete filter conditions `select a, b, c, d where a = 1` and all fields of the filtered data to be deleted need to be saved.
[0075] S2073. If the editing type of the data processing instruction is modification, store the modification filter conditions and the current value of the data to be modified in the data processing instruction to the corresponding data snapshot storage unit, and execute the data processing instruction.
[0076] In this embodiment, modifying the filter criteria can be understood as using conditions to query the data to be modified. The data to be modified is the content in the test data that needs to be changed.
[0077] Specifically, if the data processing instruction's editing type is "modify," the UPDATE statement to be executed contains the names of the fields to be modified and their values after modification, but generally does not include the values before modification. Therefore, before executing the original UPDATE statement, it is necessary to query the current values of the fields to be modified based on the modification filter conditions in the original UPDATE statement and save them to the data snapshot storage unit. Understandably, it is also necessary to store the UPDATE operation type and the table name of the database table containing the test data, so that the rollback module can execute the corresponding UPDATE operation in the corresponding database table later. After completing the storage in the data snapshot storage unit, the UPDATE type data processing instruction is executed.
[0078] For example, in the test data, the value of field 'b' is 3, and we need to change it to 5. The data processing command is `update table set b = 5 where a = 1`. Therefore, before executing the UPDATE statement, we need to perform a query filtering operation to query and save the original value of 'b' (3). This is so that we can later construct a reverse SQL statement `update table set b = 3 where a = 1` using the original value of 'b' (3) and the operation type UPDATE.
[0079] S208. When a data recovery request is received, the rollback module reads the data recovery information corresponding to the data recovery request from the corresponding data snapshot storage unit. The data recovery information includes at least the operation type, table name, and data to be rolled back.
[0080] In this embodiment, the data to be rolled back can be understood as the modification information of the original data. The table name can be understood as the name identifier of the database table where the test data is located.
[0081] Specifically, when the rollback module receives a data recovery request, it sequentially reads information such as the operation type, table name, and data to be rolled back from the data snapshot storage unit.
[0082] In this embodiment, step S208 is performed as follows: Figure 2 The reverse SQL generation unit in the agent module shown is executed.
[0083] S209. Based on the operation type, generate the corresponding data restoration instructions, and execute the generated data restoration instructions one by one in reverse order of the execution order of the data processing instructions to realize the restoration of interface test data.
[0084] In this embodiment, step S209 is performed as follows: Figure 2 The reverse SQL generation unit and the rollback execution unit in the agent module shown are executed together.
[0085] Specifically, the reverse SQL generation unit generates corresponding reverse SQL statements sequentially based on different operation types. Reverse SQL can roll back data to its state and attributes before the original SQL execution. Then, the rollback execution unit executes the generated reverse SQL statements one by one in reverse order. To ensure data consistency, the reversed SQL statements need to be encapsulated into a transaction. After the rollback transaction succeeds, the data and statements stored in the data snapshot storage unit and the reverse SQL generation unit are cleared. At this point, the data has been restored to its state before the interface call, and the interface can be called again using the exact same request message parameters as before.
[0086] Optionally, based on the operation type, generate corresponding data recovery instructions, including:
[0087] S2091. If the operation type is "add", generate the corresponding data restoration instruction based on the primary key value in the data to be rolled back.
[0088] In this embodiment, if the operation type is insert, that is, the original SQL statement in the interface is INSERT, the corresponding DELETE type data restoration instruction is generated using the data to be rolled back (the primary key value of the data to be inserted) stored in the data snapshot storage unit: DELETE FROM TABLE WHERE KEY = VALUE.
[0089] S2092. If the operation type is deletion, generate the corresponding data restoration instruction based on all field values of the data to be deleted in the data to be rolled back.
[0090] In this embodiment, if the operation type is deletion, that is, the original SQL in the interface is DELETE, the corresponding INSERT type data recovery instruction is generated using the data to be rolled back (all field values of the data to be deleted) stored in the data snapshot storage unit: INSERT INTO TABLE(COLUMN1,COLUMN2,...)VALUES(VALUE1,VALUE2,...).
[0091] S2093. If the operation type is modification, generate the corresponding data restoration instruction based on the current value of the data to be modified in the data to be rolled back.
[0092] In this embodiment, if the operation type is modification, that is, the original SQL in the interface is UPDATE, the corresponding UPDATE type data restoration instruction is generated by using the data to be rolled back (the primary key value of the original data and the current value of the data to be modified) stored in the data snapshot storage unit: UPDATE TABLE SET COLUMN1=VALUE1,COLUMN2=VALUE2,...WHERE KEY=VALUE.
[0093] This invention provides a data recovery method, comprising: acquiring a test interface call request through a proxy module; determining the current interception identifier in the request header of the test interface call request; comparing the current interception identifier with a preset interception identifier deployed in the proxy module; if the comparison result is consistent, setting the thread-local variable state of the processing thread corresponding to the test interface call request to "yes"; if the comparison result is inconsistent, setting the thread-local variable state of the processing thread corresponding to the test interface call request to "no"; if the thread-local variable state is "yes", determining the operation type of the data processing instruction corresponding to the test interface call request; if the operation type is query type, executing the data processing instruction; if the operation type is edit type, storing the corresponding data processing information and executing the data processing instruction based on the edit type of the data processing instruction; and, through a rollback module, reading the data recovery information corresponding to the data recovery request from the corresponding data snapshot storage unit when a data recovery request is received, the data recovery information including at least the operation type, table name, and data to be rolled back; generating corresponding data recovery instructions based on the operation type, and executing the generated data recovery instructions one by one in reverse order of the execution order of the data processing instructions to realize interface test data recovery. The above technical solution is simple to operate and highly flexible. After calling a single interface, if testers find certain problems and need to retest the scenario, they only need to start the rollback command to immediately and automatically generate and execute the reverse SQL statement. There is no need to recreate the test data required for the test scenario, nor is there a need to wait for other test cases to be executed before rolling back, and it will not interfere with other testers. The reverse SQL statement generation method proposed in this embodiment of the invention, which relies on data snapshot storage, stores the necessary data information before executing DML type statements in the application interface. This data is used as filtering conditions or attribute values when constructing the reverse SQL statement. The SQL interception operation has thread isolation. Users can specify parameters when starting the proxy module to process the specified interface call request without interfering with other requests or other testers, which facilitates timely feedback to developers.
[0094] For example, let's take some application scenarios as examples:
[0095] A certain application system has a container deregistration interface. The request message contains the parameter: container number (idWltNo). The function of this interface is:
[0096] 1. Use the container number from the request parameters as a query condition to search the container master table (dcep_acc_per_wlt_info). If it exists, proceed to the next step; otherwise, return an error. The query SQL statement is: Select * from dcep_acc_per_wlt_info where idWltNo = xx;
[0097] 2. Write a portion of the container number from the request parameters in the master table into the deregistered container table (dcep_acc_per_wlt_info_can). The SQL statement for this write is: Insert into dcep_acc_per_wlt_info_can(column1,column2,...)values select column1,column2,...from dcep_acc_per_wlt_info where idWltNo=xx;
[0098] 3. Delete the container number from the request parameters in the master table. The SQL statement for deletion is: Delete from dcep_acc_per_wlt_info where idWltNo=xx;
[0099] When testers create a container ID 'a' for this interface, they call the interface once. Assuming the database operation succeeds (container 'a' is deleted from the container master table and inserted into the deregistered container table), the interface responds with an unknown exception. In this case, testers need to retest the scenario to confirm if the interface has a defect. However, if a request is initiated with the same container ID 'a', since container 'a' no longer in the container master table, the program will throw an error at the beginning, making it impossible to reproduce the previous scenario. Without using this invention, testers would need to recreate the container ID.
[0100] Using this invention, the operating steps for the tester are as follows:
[0101] 1. Deploy the tool to the application test server, start the agent program, and include the intercept_id parameter in the startup command;
[0102] 2. Include an `id` parameter in the request header of the container deregistration API call to initiate the API call. The proxy program identifies the header of each request; if the `intercept_id` parameter matches, it intercepts the SQL operation of that request and stores a data snapshot. If there is no `id` parameter or it does not match, it does not intercept the request.
[0103] 3. After completing an API call, if the scenario needs to be retested, the tester starts the rollback program. The rollback program automatically generates a reverse SQL statement and encapsulates it into a transaction for execution.
[0104] 4. Testers can retest the scenario using the same request message parameters as the previous API call, without needing to create new test data.
[0105] Example 3
[0106] Figure 4 This is a schematic diagram of the structure of a data recovery device provided in Embodiment 3 of the present invention. Figure 4 As shown, the device includes:
[0107] The proxy module 31 is used to obtain test interface call requests, determine the corresponding thread local variable state based on the test interface call requests, execute the data processing instructions corresponding to the test interface call requests according to the thread local variable state, and store the corresponding data processing information based on the operation type of the data processing instructions.
[0108] The rollback module 32 is used to generate a corresponding data restoration instruction based on the data processing information when a data restoration request is received, and to execute the data restoration instruction in reverse order of the execution of the data processing instructions.
[0109] The data recovery device used in this technical solution can conditionally and automatically recover interface test data and improve testing efficiency.
[0110] Optionally, the proxy module 31 is specifically used for:
[0111] Used to determine the current interception identifier in the request header of the test interface call request;
[0112] The current interception identifier is compared with the preset interception identifier deployed in the proxy module;
[0113] If the comparison results are consistent, the thread-local variable state of the processing thread corresponding to the test interface call request will be set to yes;
[0114] If the comparison results are inconsistent, the thread-local variable state of the processing thread corresponding to the test interface call request is set to no.
[0115] Optionally, the proxy module 31 includes:
[0116] An operation type determination unit is used to determine the operation type of the data processing instruction corresponding to the test interface call request when the state of the thread local variable is yes.
[0117] The first processing unit is configured to execute the data processing instruction if the operation type is a query type.
[0118] The second processing unit is configured to, if the operation type is an editing type, store the corresponding data processing information and execute the data processing instruction based on the editing type of the data processing instruction.
[0119] Optionally, the second processing unit is specifically used for:
[0120] If the editing type of the data processing instruction is "add", the primary key value of the data to be inserted in the data processing instruction is stored in the corresponding data snapshot storage unit, and the data processing instruction is executed.
[0121] If the editing type of the data processing instruction is deletion, the deletion filter conditions and all field values of the data to be deleted in the data processing instruction are stored in the corresponding data snapshot storage unit, and the data processing instruction is executed.
[0122] If the editing type of the data processing instruction is modification, the modification filter conditions and the current value of the data to be modified in the data processing instruction are stored in the corresponding data snapshot storage unit, and the data processing instruction is executed.
[0123] Optionally, the rollback module 32 includes:
[0124] The information reading unit is used to read the data restoration information corresponding to the data restoration request from the corresponding data snapshot storage unit when a data restoration request is received. The data restoration information includes at least the operation type, table name, and data to be rolled back.
[0125] The rollback execution unit is used to generate corresponding data restoration instructions based on the operation type, and execute the generated data restoration instructions one by one in reverse order of the execution order of the data processing instructions to realize the restoration of interface test data.
[0126] Optionally, the rollback execution unit is specifically used for:
[0127] If the operation type is an add operation, a corresponding data restoration instruction is generated based on the primary key value in the data to be rolled back.
[0128] If the operation type is deletion, a corresponding data restoration instruction is generated based on all field values of the data to be deleted in the data to be rolled back;
[0129] If the operation type is modification, a corresponding data restoration instruction is generated based on the current value of the data to be modified in the data to be rolled back.
[0130] The data recovery device provided in the embodiments of the present invention can execute the data recovery method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the method.
[0131] Example 4
[0132] Figure 5This is a schematic diagram of the structure of an electronic device provided in Embodiment 4 of the present invention. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (such as helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.
[0133] like Figure 5 As shown, the electronic device 40 includes at least one processor 41 and a memory, such as a read-only memory (ROM) 42 or a random access memory (RAM) 43, communicatively connected to the at least one processor 41. The memory stores computer programs executable by the at least one processor. The processor 41 can perform various appropriate actions and processes based on the computer program stored in the ROM 42 or loaded into the RAM 43 from storage unit 48. The RAM 43 may also store various programs and data required for the operation of the electronic device 40. The processor 41, ROM 42, and RAM 43 are interconnected via a bus 44. An input / output (I / O) interface 45 is also connected to the bus 44.
[0134] Multiple components in electronic device 40 are connected to I / O interface 45, including: input unit 46, such as keyboard, mouse, etc.; output unit 47, such as various types of monitors, speakers, etc.; storage unit 48, such as disk, optical disk, etc.; and communication unit 49, such as network card, modem, wireless transceiver, etc. Communication unit 49 allows electronic device 40 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0135] Processor 41 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 41 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 41 performs the various methods and processes described above, such as data recovery methods.
[0136] In some embodiments, the data recovery method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 48. In some embodiments, part or all of the computer program may be loaded and / or mounted on electronic device 40 via ROM 42 and / or communication unit 49. When the computer program is loaded into RAM 43 and executed by processor 41, one or more steps of the data recovery method described above may be performed. Alternatively, in other embodiments, processor 41 may be configured to perform the data recovery method by any other suitable means (e.g., by means of firmware).
[0137] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0138] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0139] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0140] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0141] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or computing systems that include middleware components (e.g., application servers), or computing systems that include frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0142] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through a communication network. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.
[0143] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.
[0144] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A data recovery method, characterized in that, include: The proxy module obtains test interface call requests, determines the corresponding thread local variable state based on the test interface call requests, executes the data processing instructions corresponding to the test interface call requests according to the thread local variable state, and stores the corresponding data processing information based on the operation type of the data processing instructions. When a data recovery request is received, the rollback module generates a corresponding data recovery instruction based on the data processing information and executes the data recovery instruction in reverse order of the execution of the data processing instructions.
2. The method according to claim 1, characterized in that, The process of determining the corresponding thread-local variable state based on the test interface call request includes: Determine the current interception flag in the request header of the test interface call request; The current interception identifier is compared with the preset interception identifier deployed in the proxy module; If the comparison results are consistent, the thread-local variable state of the processing thread corresponding to the test interface call request will be set to yes; If the comparison results are inconsistent, the thread-local variable state of the processing thread corresponding to the test interface call request is set to no.
3. The method according to claim 1, characterized in that, The step of executing the data processing instruction corresponding to the test interface call request based on the thread-local variable state, and storing the corresponding data processing information based on the operation type of the data processing instruction, includes: If the state of the thread-local variable is yes, determine the operation type of the data processing instruction corresponding to the test interface call request; If the operation type is a query, execute the data processing instruction; If the operation type is an editing type, based on the editing type of the data processing instruction, the corresponding data processing information is stored and the data processing instruction is executed.
4. The method according to claim 3, characterized in that, The editing type based on the data processing instruction, storing the corresponding data processing information and executing the data processing instruction, includes: If the editing type of the data processing instruction is "add", the primary key value of the data to be inserted in the data processing instruction is stored in the corresponding data snapshot storage unit, and the data processing instruction is executed. If the editing type of the data processing instruction is deletion, the deletion filter conditions and all field values of the data to be deleted in the data processing instruction are stored in the corresponding data snapshot storage unit, and the data processing instruction is executed. If the editing type of the data processing instruction is modification, the modification filter conditions and the current value of the data to be modified in the data processing instruction are stored in the corresponding data snapshot storage unit, and the data processing instruction is executed.
5. The method according to claim 1, characterized in that, Upon receiving a data restoration request, generating a corresponding data restoration instruction based on the data processing information, and executing the data restoration instruction in reverse order of the execution of the data processing instructions, includes: Upon receiving a data recovery request, the corresponding data recovery information corresponding to the data recovery request is read from the corresponding data snapshot storage unit. The data recovery information includes at least the operation type, table name, and data to be rolled back. Based on the operation type, a corresponding data restoration instruction is generated, and the generated data restoration instructions are executed one by one in reverse order of the execution order of the data processing instructions to realize the restoration of interface test data.
6. The method according to claim 5, characterized in that, The step of generating corresponding data restoration instructions based on the operation type includes: If the operation type is an add operation, a corresponding data restoration instruction is generated based on the primary key value in the data to be rolled back. If the operation type is deletion, a corresponding data restoration instruction is generated based on all field values of the data to be deleted in the data to be rolled back; If the operation type is modification, a corresponding data restoration instruction is generated based on the current value of the data to be modified in the data to be rolled back.
7. A data recovery device, characterized in that, include: The proxy module is used to obtain test interface call requests, determine the corresponding thread local variable state based on the test interface call requests, execute the data processing instructions corresponding to the test interface call requests according to the thread local variable state, and store the corresponding data processing information based on the operation type of the data processing instructions. The rollback module is used to generate a corresponding data restoration instruction based on the data processing information when a data restoration request is received, and to execute the data restoration instruction in reverse order of the execution of the data processing instructions.
8. An electronic device, characterized in that, include: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform a data recovery method according to any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that, when executed by a processor, implement a data restoration method according to any one of claims 1-6.
10. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements a data restoration method according to any one of claims 1-6.