Simulation method and device for database request
Through the combination of database middleware and rules engine, the problem of insufficient support for database protocols by existing mock tools is solved, simulation of database requests and dirty data avoidance is realized, simplifying the preparation of the test environment and improving the testing efficiency.
Patent Information
- Application Number
- CN202411315240.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-19
- Publication Date
- 2025-01-07
AI Technical Summary
The lack of support for database protocols in existing mock tools leads to difficulties in database request simulation, dirty data problems and resource consumption in product development and testing.
Receive database requests for application services through database middleware, parse operation types and execution statements, and determine whether business processing logic is included. If included, use the rule engine to match the simulation data, build simulation return results, avoid direct connection with the database, and reduce shadow library and Use of shadow table.
The simulation of database requests is realized, which avoids dirty data problems and resource consumption, simplifies the preparation of the test environment, and improves the testing efficiency.
Smart Images

Figure CN119271693A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of database technology, and in particular to a method and device for simulating database requests. Background Art
[0002] Mock can be used in software development and testing to simulate system components or services, facilitating development, testing, and debugging, especially in microservice architectures, client-server applications, and systems that need to interact with external APIs. Current interface management tools such as postman and apifox already have built-in mock functions, which mainly support http / https protocols to simulate related functions of traditional http interfaces and restful-style interfaces. As open source mock tools, moco and powermock provide support for socket protocols and grpc interfaces, respectively.
[0003] However, the various existing mock tools currently lack support for database protocols, which results in the following limitations when conducting product development and testing support:
[0004] 1) Network requests often have a long call chain. In addition to common HTTP, GRPC and other interfaces, database requests are also an important part of the chain. If the database request cannot be mocked, when the test environment database table structure is backward, the database request will directly report an error; or, when the data in the test environment database table is insufficient or does not meet business requirements, the call chain cannot continue to move forward;
[0005] 2) Write requests will bring a large amount of dirty data to the test environment database, and it is necessary to use a shadow library or shadow table to replace the test environment database to avoid the generation of dirty data, data unique index conflicts and other problems. However, the shadow library or shadow table requires too much investment in the early preparation process, and for the unique index, a new shadow table needs to be created every time the playback is played back to meet the needs, which not only complicates the playback link, but also increases resource consumption. Summary of the invention
[0006] In view of the above problems, embodiments of the present application are proposed to provide a method and device for simulating database requests that overcome the above problems or at least partially solve the above problems.
[0007] According to a first aspect of an embodiment of the present application, a method for simulating a database request is provided, which includes:
[0008] The database middleware receives the database request of the application service, parses the database request based on the database protocol, and obtains the operation type of the database command and the database execution statement;
[0009] According to the operation type, determine whether the database execution statement contains business processing logic;
[0010] If it contains business processing logic, the database execution statement is passed to the rule engine, and the rule engine matches the database execution statement with the preset matching rules to obtain matching simulation data;
[0011] The matched simulation data is returned to the construction module, and the construction module constructs a simulation return result corresponding to the database request based on the matched simulation data to return to the application service.
[0012] Optionally, the method further comprises:
[0013] Start the database middleware, establish a connection with the database, and build a database instance session to request the database; wherein the database middleware is started according to a preset configuration file or the database information transmitted by the dependent service; the database middleware establishes a connection with the database based on the database protocol, and the application service accesses the database via the database middleware.
[0014] Optionally, the database protocol predefines the message format of the database request;
[0015] The database middleware receives the database request of the application service, parses the database request based on the database protocol, and obtains the operation type of the database command and the database execution statement, further including:
[0016] The database middleware receives a database request of the application service; the database request includes a request message;
[0017] The request message of the database request is parsed based on the database protocol, and the operation type of the database command and the database execution statement contained in the database request are obtained according to the message format.
[0018] Optionally, according to the operation type, determining whether the database execution statement contains business processing logic further includes:
[0019] Determine whether the operation type is a preset operation type;
[0020] If it is a preset operation type, make sure that the database execution statement contains business processing logic.
[0021] Optionally, if the database execution statement does not contain business processing logic, the method further includes:
[0022] Access the database according to the database execution statement and return the corresponding database results.
[0023] Optionally, passing the database execution statement to a rule engine, and the rule engine matching the database execution statement with a preset matching rule, to obtain matching simulation data further includes:
[0024] The rule engine matches the database execution statement with the preset matching rules, and determines the matching simulation data based on the preset multiple simulation data; the preset matching rules include request matching, statement matching and / or field matching; the matching simulation data includes data value and data type.
[0025] Optionally, returning the matched simulation data to the construction module, and the construction module constructing a simulation return result corresponding to the database request according to the matched simulation data further includes:
[0026] The construction module converts the data type in the matched simulation data into the data type required for the simulation return result according to the data type contained in the matched simulation data, and constructs the simulation return result corresponding to the database request based on the converted matched simulation data.
[0027] Optionally, the database comprises a relational database.
[0028] According to a second aspect of an embodiment of the present application, a simulation device for a database request is provided, comprising:
[0029] Database middleware is used to receive database requests from application services, parse the database requests based on the database protocol, obtain the operation type of the database command and the database execution statement; determine whether the database execution statement contains business processing logic according to the operation type;
[0030] The rule engine is used to match the database execution statement with the preset matching rules to obtain matching simulation data if it contains business processing logic;
[0031] The construction module is used to construct a simulation return result corresponding to the database request according to the matched simulation data, so as to return it to the application service.
[0032] According to a third aspect of an embodiment of the present application, there is provided a computing device, comprising: a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus;
[0033] The memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute the operation corresponding to the simulation method of the database request.
[0034] According to a fourth aspect of an embodiment of the present application, a computer storage medium is provided, wherein at least one executable instruction is stored in the storage medium, and the executable instruction enables a processor to execute an operation corresponding to the simulation method requested by the above-mentioned database.
[0035] According to a fifth aspect of an embodiment of the present application, a computer program product is provided, comprising at least one executable instruction, wherein the executable instruction enables a processor to execute operations corresponding to the simulation method such as the above-mentioned database request.
[0036] According to the simulation method and device for database requests provided by the present application, direct connection between the application service to be tested and the database is avoided through the database middleware. There is no need to pay attention to the language used by the application service and the database framework used, and the application service code is not invaded. Pre-operations such as connecting to the database are implemented, database requests are obtained for parsing, database execution statements are intercepted, simulation data is matched for them, and simulation return data is constructed to realize simulation of database requests. During the entire process, there is no need to pay attention to the table structure and data in the table of the database of the tested environment, nor is there any need to prepare shadow libraries, shadow tables, etc. to avoid dirty data problems caused by write requests.
[0037] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present application. Also, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:
[0039] Figure 1 A flowchart of a method for simulating a database request according to an embodiment of the present application is shown;
[0040] Figure 2 A schematic diagram of the architecture of application services and various simulation services is shown;
[0041] Figure 3 A flowchart of a method for simulating a database request according to another embodiment of the present application is shown;
[0042] Figure 4 A schematic diagram of the structure of a simulation device for database request according to an embodiment of the present application is shown;
[0043] Figure 5A schematic diagram of the structure of a computing device according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0044] The exemplary embodiments of the present application will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present application and to fully convey the scope of the present application to those skilled in the art.
[0045] First, the terms involved in one or more embodiments of the present application are explained.
[0046] MySQL protocol: The protocol used by the MySQL database management system for communication between the access client and the MySQL server. It defines how the access client establishes a connection with the MySQL server, sends queries, and receives results.
[0047] Database: A system for storing, managing, and retrieving data that organizes data in a structured way so that it can be efficiently queried and managed.
[0048] Middleware: Computer software used to connect different software components or applications in a distributed application, providing communication and data management services for different parts of the distributed system so that applications can interoperate.
[0049] Microservice: A software development technology - a variation of the service-oriented architecture (SOA) architectural style that divides a single application into a group of small services that coordinate and cooperate with each other to provide ultimate value to users. Each service runs in its own independent process, and services communicate with each other using lightweight communication mechanisms (usually using http or grpc protocols).
[0050] HTTP / HTTPS: HTTP (HyperText Transfer Protocol) and HTTPS (HyperText Transfer Protocol Secure) are protocols used to transfer data between a client and a server.
[0051] gRPC: gRPC (gRPC Remote Procedure Calls) is an open source remote procedure call system that is based on HTTP / 2 protocol transmission.
[0052] Mock: refers to creating virtual objects or behaviors to simulate real objects or behaviors for use during development and testing, helping developers isolate parts of the system and perform unit and integration testing without relying on the system's external dependencies.
[0053] ResultSet: An interface or object used to store data returned from a database query and is used to represent query results when executing SQL queries (such as SELECT statements). ResultSet provides a series of methods to access and manipulate these results.
[0054] Figure 1 A flowchart of a method for simulating a database request according to an embodiment of the present application is shown. Figure 1 As shown, the method comprises the following steps:
[0055] Step S101: The database middleware receives a database request of an application service, parses the database request based on a database protocol, and obtains an operation type of a database command and a database execution statement.
[0056] In this embodiment, the database middleware establishes a connection with the database based on the database protocol, performs a series of operations such as authentication, and does not require the application service to be tested (which may include various application services) to be directly connected to the database. Based on the database middleware, it is not necessary to consider the language used by the application service implementation and the database framework used, and application services in various languages and different databases can be connected.
[0057] Based on the information of the database, the database middleware can establish a connection with the database, perform authentication, create a connection pool, etc., so that it has the ability to directly replace the database instance to connect to the application service. The database middleware directly connects with the application service and can receive the database request of the application service. The database request can be parsed based on the database protocol, and the operation type of the database command and the database execution statement can be parsed from the request message of the database request. The database execution statement is the specific SQL statement requested by the application service. The operation type of the database command is used to distinguish different database operations, such as query request operation, connection management request operation, system management request operation, pre-processing request operation, etc.
[0058] Step S102: Determine whether the database execution statement contains business processing logic according to the operation type.
[0059] Based on the operation type of the database command, it is possible to further distinguish whether the database execution statement contains business processing logic. For example, the connection management request operation and the system management request operation are irrelevant to the business, do not involve business processing logic, and will not affect the execution of specific businesses in the application service. The database middleware can directly pass it to the database instance, execute the corresponding data execution statement, and return the execution result to the application service. If the operation type is a query request operation, the data required by the business needs to be returned, that is, the database execution statement involves business processing logic. In order to ensure the execution of subsequent businesses, the data required by the business needs to be returned. This embodiment simulates the database request based on the database protocol to meet business needs, avoiding the problem of dirty data or shadow libraries, shadow tables, etc. due to the inability of the data in the database to meet business needs.
[0060] Whether the database execution statement contains business processing logic can be judged by the operation type, such as pre-setting the association between different operation types and business processing logic, such as the query request operation and the business processing logic. By judging the operation type, it can be determined whether the database execution statement contains business processing logic. If it contains business processing logic, step S103 is executed. If it does not contain business processing logic, the database instance can be directly transparently transmitted, and the database execution statement can be executed to obtain the execution result and returned to the application service through the database middleware.
[0061] Step S103, if it contains business processing logic, the database execution statement is passed to the rule engine, and the rule engine matches the database execution statement with the preset matching rule to obtain matching simulation data.
[0062] When it is determined that the database execution statement contains business processing logic, it is necessary to mock the corresponding simulation data for the application service based on the database execution statement to ensure the requirements of the application service.
[0063] Specifically, when it is determined that the database execution statement contains business processing logic, the database middleware passes the database execution statement to the rule engine, and the rule engine performs rule matching based on the database execution statement. The preset matching rules can be set according to different business processing logics, such as setting different preset matching rules according to the field name, data table name, conditions, etc. related to the business processing logic. The preset matching rules can use regular expressions to facilitate query matching based on database execution statements. The preset matching rules are set according to the specific implementation situation and are not limited here.
[0064] The preset matching rules also include simulation data corresponding to the preset matching rules, such as preset matching rule 1 corresponding to simulation data 1, preset matching rule 2 corresponding to simulation data 2, etc. Simulation data is the data required by the business processing logic. The simulation data can be pre-built. The simulation data can be built based on the data in the database, or the required simulation data can be built according to the business processing logic. For example, when the database does not contain field 1, but the business processing logic needs to use field 1, the requirements of the business processing logic can be met by building simulation data for field 1. Simulation data can contain multiple data, and the value of each data is set according to the requirements of the business processing logic, which is not limited here.
[0065] The rule engine matches the database execution statement according to the preset matching rules. When the database execution statement matches a preset matching rule, the simulation data corresponding to the preset matching rule is the execution result after executing the database execution statement required by the business processing logic.
[0066] Step S104, returning the matched simulation data to the construction module, which constructs a simulation return result corresponding to the database request based on the matched simulation data and returns it to the application service.
[0067] After the rule engine matches the database execution statement with the preset matching rule and obtains the matched simulation data, the matched simulation data can be returned to the construction module. The construction module can be constructed according to the matched simulation data to obtain the simulation return result, wherein the simulation return result needs to be constructed according to the database request. For example, if the database request is for a certain object information, the simulation data contains the object information, wherein the simulated object information is consistent with the data type of each object information in the database. If the simulation data contains simulation data of time type, the data type of time in the database is datetime, and the data type of the simulation data of the time type of the simulation data is also datetime, then, according to the time type required in the simulation return result ResultSet, the datetime format of the simulation data of the time type in the simulation data needs to be converted to String format, etc. The specific data type conversion of the simulation data is set according to the specific implementation situation and is not limited here.
[0068] After the data type conversion, the converted matching simulation data is stored in the simulation return result ResultSet. The construction module returns the ResultSet to the application service so that the business that initiates the database request in the application service can execute the corresponding business processing logic according to the simulation return result ResultSet, so that the test can be executed normally.
[0069] This embodiment can avoid direct connection between the application service being tested and the database by using database middleware, directly obtain database requests from the application service, such as the original TCP message of the database request, etc., and can also complete a series of pre-operations with the database including connection handshake, client response and identity authentication, without paying attention to the language used by the application service and the database framework used, and will not cause intrusion into the code of the application service. After the database middleware receives the database request, it can intercept the database execution statement before executing it by parsing the database request, and the rule engine will match it with the preset matching rules to filter out the matching simulation data, avoiding the verification of the database table structure and the writing of dirty data. The matching simulation data is reconstructed and returned to the simulation return result required by the application service, thereby realizing the mock simulation of the database protocol, without the need to prepare shadow libraries, shadow tables, etc. during testing, which is more convenient for the testing of application services.
[0070] Furthermore, in this embodiment, the database includes a relational database. To facilitate a better understanding of the present application, the relational database is described using MySQL as an example. Figure 2 As shown, the database middleware, rule engine and return structure (i.e., construction module) together constitute mysql mock server (data simulation service for MySQL database) to implement data simulation based on database protocol. The database middleware is based on MySQL protocol to implement handshake and authentication with MySQL database to avoid direct connection between the tested application service and database. The database middleware receives mysql request of application service, parses it, and determines the request containing business processing logic, that is, determines the business-related request, so that the pre-processed business request can be sent to the rule engine, and the rule engine matches the business request with the preset matching rule, that is, Figure 2 As shown in the figure, match the match case and mock cases (preset matching rules and multiple mock data), return the matched mock case (mock data) to the return structure, and the return structure builds a simulated return result according to the matched mock case. Finally, mysql mock is returned to the application service, that is, the simulated return result of the mysql database is returned. Figure 2In addition to the data simulation of the database, it also includes the mock simulation of the http / https protocol and the grpc interface. The application service sends an http request to the http mock server. The http mock server matches according to the match case, mock cases, etc., and returns the http mock return to the application service. The application service sends a grpc request to the grpc mock server. The grpc mock server matches according to the match case, mock cases, etc., and returns it to the application service. The grpcmock return. The above http mock sever and grpc mock sever can use the existing mock simulation tools, which are not explained in detail here. The http mock server, grpc mock server and mysql mock server together form a mock server, which provides http mock, grpc mock and mysql mock for the application service to ensure that the application service to be tested can be tested conveniently and quickly. The above is an example, which is set according to the implementation situation and is not limited here.
[0071] According to the simulation method of database request provided by the present application, direct connection between the application service to be tested and the database is avoided through the database middleware. There is no need to pay attention to the language used by the application service and the database framework used, and the application service code is not invaded. Pre-operations such as connecting to the database are implemented, database requests are obtained for parsing, database execution statements are intercepted, simulation data is matched for them, and simulation return data is constructed to realize simulation of database requests. During the entire process, there is no need to pay attention to the table structure and data in the table of the database of the tested environment, nor is there any need to prepare shadow libraries, shadow tables, etc. to avoid dirty data problems caused by write requests.
[0072] Figure 3 A flowchart of a method for simulating a database request according to an embodiment of the present application is shown. Figure 3 As shown, the method comprises the following steps:
[0073] Step S301, start the database middleware, establish a connection with the database, build a database instance session, and request the database.
[0074] The database middleware can be started according to a preset configuration file or a dependent service. When the database middleware is started, the preset configuration file or the external dependent service will pass the database information related to the database middleware. The database information includes information such as the database address, port, name, password, etc., so that the database middleware can complete operations such as connection and authentication with the database based on the database protocol and according to the above database information. The database middleware can create a connection pool, so that it has the ability to directly replace the database instance to connect to the application service. The application services to be tested access the database through the database middleware to avoid direct access to the database. Each application service can receive the mock data of the database returned by the database middleware, that is, the data required for the test, to complete the test, etc.
[0075] The database includes various relational databases, such as MySQL database, etc. For ease of understanding of this application, the following description takes MySQL database as an example, but is not limited to this. For example, the database middleware establishes a connection with the MySQL database based on the MySQL protocol, performs authentication, etc., and builds a MySQL connection pool to replace the direct connection between the MySQL database instance and the application service.
[0076] Step S302: the database middleware receives the database request of the application service, parses the request message of the database request based on the database protocol, and obtains the operation type of the database command and the database execution statement contained in the database request according to the message format.
[0077] The database middleware receives the database request of the application service, and the database request includes a request message, such as a TCP request message. The request message is constructed based on the message format of the database request predefined by the database protocol. After receiving the database request, the database middleware parses the request message of the database request based on the database protocol. Taking the MySQL protocol as an example, the MySQL protocol defines that the request message includes three parts of the structure, namely the message length (3 bytes), which is used to indicate the length of the message content, excluding the length of the message sequence number; the sequence number (1 byte), which is used to identify the order of the message. Payload, which is the actual message content, wherein different types of messages have different contents. By parsing the request message, the payload can be obtained, and the operation type of the database command and the database execution statement can be determined according to the command byte at the first position. The operation types of the database command include ordinary request (command byte is 3), ping operation (command byte is 14), prepare operation (command byte is 22), etc. The database execution statement is the SQL statement required to be executed in the application service, which can be obtained through the payload. The above is an example for explanation. The specific settings will be based on the implementation situation and are not limited here.
[0078] The database middleware receives database requests from application services and intercepts database execution statements to avoid direct execution of database execution statements, execution failures caused by problems such as insufficient database data, and inability of application service calls to continue execution.
[0079] Step S303: determine whether the operation type is a preset operation type.
[0080] After parsing the operation type of the database command, the database middleware can further determine whether the operation type is a preset operation type. If the operation type is determined to be the preset operation type, it can be determined that the database execution statement contains business processing logic, and step S305 is executed. Otherwise, it can be determined that the database execution statement does not contain business processing logic, and step S304 is executed.
[0081] The preset operation type is set according to the implementation situation and is determined by analyzing specific requests. For example, system management requests (such as set requests, etc.) and connection management requests (such as ping requests, etc.) are requests that do not contain business processing logic, while ordinary requests include query requests, update requests, delete requests, etc., which contain business logic processing. The preset operation type includes the operation type of ordinary requests. The above is an example, which is set according to the implementation situation and is not limited here.
[0082] Step S304, access the database according to the database execution statement, and return the corresponding database result.
[0083] When it is determined that the operation type is not the preset operation type, that is, the database execution statement does not contain business processing logic, the database middleware can pass the database execution statement directly to the database instance. The database execution statement can directly access the database and obtain the corresponding execution completion database result. Based on the database middleware, the database result can be returned to the application service so that the application service can execute subsequent service functions according to the database result.
[0084] Step S305, passing the database execution statement to the rule engine, the rule engine matches the database execution statement with the preset matching rule, and determines the matching simulation data based on the preset multiple simulation data.
[0085] When the operation type is determined to be a preset operation type, that is, the database execution statement contains business processing logic, the required data needs to be provided to the application service according to the business processing logic. This embodiment uses a mock method to simulate the data required by the database request of the application service to meet the needs of the application service.
[0086] Specifically, preset matching rules are set in advance based on the business processing logic of the application service. The preset matching rules may include multiple different matching rules such as request matching, statement matching, field matching, etc. For example, the preset matching rules include identifiers for distinguishing different rules, http / grpc request interface paths, or request messages of database requests, request methods of http / grpc requests, such as get / post methods, or database execution statements of database requests; conditional matching rules (regular matching, etc. may be used); headers and bodies returned by http / grpc requests, or data values and data types of database fields of database requests (i.e., simulated data may be recorded in a two-dimensional array format). The above are examples, which are set according to the implementation situation and are not limited here.
[0087] The simulation data corresponds to the preset matching rules. Different preset matching rules correspond to different simulation data. The rule engine matches the multiple simulation data through the preset matching rules to obtain the matching simulation data. Specifically, the database middleware passes the database execution statement to the rule engine. The rule engine matches the database execution statement with the above preset matching rules, and selects the matching simulation data by matching the request message and the database execution statement. It further matches according to the conditions to determine the matching simulation data. The matching simulation data includes data values and data types for the subsequent construction of simulation return results.
[0088] Step S306, returning the matched simulation data to the construction module, the construction module converts the data type in the matched simulation data into the data type required for the simulation return result according to the data type contained in the matched simulation data, and constructs the simulation return result corresponding to the database request based on the converted matched simulation data.
[0089] After the rule engine obtains the matched simulation data, it returns the matched simulation data to the construction module, and the construction module is constructed according to the matched simulation data. The data type in the simulation data is created based on the data type of the database. When constructing the simulation return result, the data type of the matched simulation data needs to be converted. For example, the matched simulation data contains multiple fields, namely, the identification id (data type bigint), name (data type varchar), age (data type int), time (data type datetime) and other fields. The body part of the mock case simulation data is (1, "xx", "10", "2024-8-29"), and the header part stores the field name and data type number of each field, id (bigint, 3), name (varchar, 253), age (int, 3), enter_time (datetime, 7). According to the data type number of each field in the simulation data, each field value is forcibly converted to the data type corresponding to the application service language, such as varchar (3) is converted to String, datetime (7) is converted to String, bigint (3) is converted to Int32, etc., and then the simulation return result ResultSet is constructed based on the field name, field data type, and converted field value. The above is an example for explanation. The specific settings will be based on the implementation situation and are not limited here.
[0090] Based on mock data, when a certain field is missing from the database, simulation can help the database solve the problem of data structure asynchrony. It can also obtain the data required by the application service through simulation data to avoid problems such as missing data in the database. The simulated return results can bypass the database requesting the test environment, avoid errors that may be caused by field asynchrony, reduce the manpower and time costs required for test environment preparation, and ensure the smooth progress of the test work.
[0091] According to the simulation method of database request provided by the present application, the database is connected to the database based on the database middleware, and the database request of the application service is received. The database execution statement of the database request containing the business processing logic can be intercepted, and the simulation data can be matched through the rule engine to build a simulation return result to the application service, so as to solve the problems of asynchronous data structure and missing data in the test environment, and also reduce the various manpower and time costs required for the preparation of the test environment database. Furthermore, for database requests that do not contain business processing logic, the database middleware can directly pass it to the database instance for execution and return the corresponding database execution result. The whole process will not invade the code of the application service, which is more convenient and quick.
[0092] Figure 4FIG. 1 is a schematic diagram showing the structure of a simulation device for database request provided by an embodiment of the present application. Figure 4 As shown, the device comprises:
[0093] The database middleware 410 is used to receive the database request of the application service through the database middleware, parse the database request based on the database protocol, obtain the operation type of the database command and the database execution statement; and determine whether the database execution statement contains business processing logic according to the operation type;
[0094] The rule engine 420 is used to match the database execution statement with the preset matching rules to obtain matching simulation data if the business processing logic is included;
[0095] The construction module 430 is used to construct a simulation return result corresponding to the database request according to the matched simulation data, and return it to the application service.
[0096] Optionally, the database middleware 410 is also used to start and establish a connection with the database, build a database instance session, and request the database; wherein the database middleware is started according to a preset configuration file or relies on database information transmitted by the service; the database middleware establishes a connection with the database based on the database protocol, and the application service accesses the database via the database middleware.
[0097] Optionally, the database protocol predefines the message format of the database request;
[0098] The database middleware 410 is also used for:
[0099] Receiving a database request for an application service; the database request includes a request message;
[0100] The request message of the database request is parsed based on the database protocol, and the operation type of the database command and the database execution statement contained in the database request are obtained according to the message format.
[0101] Optionally, the database middleware 410 is further used for:
[0102] Determine whether the operation type is a preset operation type;
[0103] If it is a preset operation type, make sure that the database execution statement contains business processing logic.
[0104] Optionally, the database middleware 410 is further used for:
[0105] Access the database according to the database execution statement and return the corresponding database results.
[0106] Optionally, the rule engine 420 is further configured to:
[0107] The database execution statement is matched with the preset matching rules, and the matching simulation data is determined based on the preset multiple simulation data; the preset matching rules include request matching, statement matching and / or field matching; the matching simulation data includes data value and data type.
[0108] Optionally, the construction module 430 is further used to:
[0109] According to the data type contained in the matched simulation data, the data type in the matched simulation data is converted into the data type required for the simulation return result, and the simulation return result corresponding to the database request is constructed based on the converted matched simulation data.
[0110] Optionally, the database comprises a relational database.
[0111] The description of each module above refers to the corresponding description in the method embodiment and will not be repeated here.
[0112] According to the simulation device for database requests provided by the present application, direct connection between the application service to be tested and the database is avoided through the database middleware. There is no need to pay attention to the language used by the application service and the database framework used, and the application service code is not invaded. Pre-operations such as connecting to the database are implemented, database requests are obtained for parsing, database execution statements are intercepted, simulation data is matched for them, and simulation return data is constructed to realize simulation of database requests. During the entire process, there is no need to pay attention to the table structure and data in the table of the database of the tested environment, nor is there any need to prepare shadow libraries, shadow tables, etc. to avoid dirty data problems caused by write requests.
[0113] The present application also provides a non-volatile computer storage medium, which stores at least one executable instruction, and the executable instruction can execute the operation corresponding to the simulation method of the database request in any of the above method embodiments.
[0114] The present application also provides a computer program product, which includes at least one executable instruction or computer program, and the executable instruction or computer program can enable a processor to execute operations corresponding to the simulation method of the database request in any of the above method embodiments.
[0115] Figure 5 A schematic diagram of the structure of a computing device according to an embodiment of the present application is shown. The specific embodiment of the present application does not limit the specific implementation of the computing device.
[0116] like Figure 5 As shown, the computing device may include: a processor (processor) 502 , a communications interface (Communications Interface) 504 , a memory (memory) 506 , and a communication bus 508 .
[0117] in:
[0118] The processor 502 , the communication interface 504 , and the memory 506 communicate with each other via a communication bus 508 .
[0119] The communication interface 504 is used to communicate with other devices such as clients or other servers.
[0120] The processor 502 is used to execute the program 510, and specifically can execute the relevant steps in the above-mentioned database request simulation method embodiment.
[0121] Specifically, the program 510 may include program codes, which include computer operation instructions.
[0122] The processor 502 may be a central processing unit (CPU), or an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the present application. The one or more processors included in the computing device may be processors of the same type, such as one or more CPUs; or processors of different types, such as one or more CPUs and one or more ASICs.
[0123] The memory 506 is used to store the program 510. The memory 506 may include a high-speed RAM memory, and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory.
[0124] The program 510 can be specifically used to enable the processor 502 to execute the simulation method of the database request in any of the above-mentioned method embodiments. The specific implementation of each step in the program 510 can refer to the corresponding description in the corresponding steps and units in the above-mentioned simulation embodiment of the database request, which will not be repeated here. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working process of the above-described devices and modules can refer to the corresponding process description in the above-mentioned method embodiment, which will not be repeated here.
[0125] The algorithm or display provided here is not inherently related to any specific computer, virtual system or other device. Various general systems can also be used together with the teaching based on this. According to the above description, it is obvious to construct the structure required for this type of system. In addition, the application is not directed to any specific programming language either. It should be understood that various programming languages can be utilized to realize the content of the application described here, and the above description of specific languages is to disclose the preferred embodiment of the application.
[0126] In the description provided herein, a large number of specific details are described. However, it is understood that the embodiments of the present application can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this description.
[0127] Similarly, it should be understood that in order to streamline the present application and help understand one or more of the various inventive aspects, in the above description of the exemplary embodiments of the present application, the various features of the present application are sometimes grouped together into a single embodiment, figure, or description thereof. However, the disclosed method should not be interpreted as reflecting the following intention: the claimed application requires more features than the features clearly stated in each claim. More specifically, as reflected in the claims below, the inventive aspects are less than all the features of the single embodiment disclosed above. Therefore, the claims following the specific embodiment are hereby expressly incorporated into the specific embodiment, wherein each claim itself serves as a separate embodiment of the present application.
[0128] Those skilled in the art will appreciate that the modules in the devices in the embodiments may be adaptively changed and arranged in one or more devices different from the embodiments. The modules or units or components in the embodiments may be combined into one module or unit or component, and in addition they may be divided into a plurality of submodules or subunits or subcomponents. Except that at least some of such features and / or processes or units are mutually exclusive, all features disclosed in this specification (including the accompanying claims, abstracts and drawings) and all processes or units of any method or device disclosed in this manner may be combined in any combination. Unless otherwise expressly stated, each feature disclosed in this specification (including the accompanying claims, abstracts and drawings) may be replaced by an alternative feature providing the same, equivalent or similar purpose.
[0129] In addition, those skilled in the art will appreciate that, although some embodiments herein include certain features included in other embodiments but not other features, the combination of features of different embodiments is meant to be within the scope of the present application and form different embodiments. For example, in the claims below, any one of the claimed embodiments may be used in any combination.
[0130] The various component embodiments of the present application can be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. It should be understood by those skilled in the art that a microprocessor or digital signal processor (DSP) can be used in practice to implement some or all functions of some or all components of the present application. The present application can also be implemented as a device or apparatus program (e.g., computer program and computer program product) for executing a part or all of the methods described herein. Such a program implementing the present application can be stored on a computer-readable medium, or can have the form of one or more signals. Such a signal can be downloaded from an Internet website, or provided on a carrier signal, or provided in any other form.
[0131] It should be noted that the above embodiments illustrate the present application rather than limit the present application, and that those skilled in the art may design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference symbol between brackets shall not be constructed as a limitation on the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "one" or "an" preceding an element does not exclude the presence of multiple such elements. The present application may be implemented by means of hardware including several different elements and by means of a suitably programmed computer. In a unit claim that lists several devices, several of these devices may be embodied by the same hardware item. The use of the words first, second, and third, etc. does not indicate any order. These words may be interpreted as names. The steps in the above embodiments, unless otherwise specified, should not be understood as limitations on the order of execution.
Claims
1. A method for simulating a database request, comprising: The database middleware receives the database request of the application service, parses the database request based on the database protocol, and obtains the operation type of the database command and the database execution statement; Determining, according to the operation type, whether the database execution statement contains business processing logic; If the business processing logic is included, the database execution statement is passed to the rule engine, and the rule engine matches the database execution statement with the preset matching rule to obtain matching simulation data; The matched simulation data is returned to the construction module, and the construction module constructs a simulation return result corresponding to the database request according to the matched simulation data, and returns it to the application service.
2. The method according to claim 1, wherein: The method further comprises: Start the database middleware, establish a connection with the database, and build a database instance session to request the database; wherein the database middleware is started according to a preset configuration file or relies on database information transmitted by a service; the database middleware establishes a connection with the database based on a database protocol, and the application service accesses the database via the database middleware.
3. The method according to claim 1, wherein: The database protocol predefines the message format of the database request; The step of receiving the database request of the application service by the database middleware, parsing the database request based on the database protocol, and obtaining the operation type of the database command and the database execution statement further includes: The database middleware receives a database request for an application service; the database request includes a request message; The request message of the database request is parsed based on the database protocol, and the operation type of the database command and the database execution statement contained in the database request are obtained according to the message format.
4. The method according to claim 1, wherein: The step of determining, according to the operation type, whether the database execution statement includes business processing logic further includes: Determining whether the operation type is a preset operation type; If it is a preset operation type, it is determined that the database execution statement includes business processing logic.
5. The method according to any one of claims 1 to 4, wherein: If the database execution statement does not contain business processing logic, the method further includes: Access the database according to the database execution statement and return the corresponding database result.
6. The method according to any one of claims 1 to 5, wherein: The step of passing the database execution statement to a rule engine, and having the rule engine match the database execution statement with a preset matching rule to obtain matching simulation data further includes: The rule engine matches the database execution statement with the preset matching rules, and determines the matching simulation data based on the preset multiple simulation data; the preset matching rules include request matching, statement matching and / or field matching; the matching simulation data includes data value and data type.
7. The method according to any one of claims 1 to 6, wherein: The step of returning the matched simulation data to the construction module, and constructing a simulation return result corresponding to the database request according to the matched simulation data by the construction module, further comprises: The construction module converts the data type in the matched simulation data into the data type required for the simulation return result according to the data type contained in the matched simulation data, and constructs the simulation return result corresponding to the database request based on the converted matched simulation data.
8. The method according to any one of claims 1 to 7, wherein: The database comprises a relational database.
9. A simulation device for database request, comprising: The database middleware is used to receive a database request of an application service, parse the database request based on a database protocol, obtain an operation type of a database command and a database execution statement; and determine whether the database execution statement contains business processing logic according to the operation type; A rule engine, for matching the database execution statement with a preset matching rule to obtain matching simulation data if the business processing logic is included; A construction module is used to construct a simulation return result corresponding to the database request according to the matched simulation data, so as to return it to the application service.
10. A computing device comprising: A processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus; The memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute an operation corresponding to the simulation method of the database request according to any one of claims 1-8.
11. A computer storage medium, wherein at least one executable instruction is stored in the storage medium, and wherein the executable instruction enables a processor to execute operations corresponding to the method for simulating a database request according to any one of claims 1 to 8.
12. A computer program product, comprising at least one executable instruction, wherein the executable instruction enables a processor to execute operations corresponding to the method for simulating a database request according to any one of claims 1 to 8.