Service call simulation method and device, storage medium and electronic device
By adding mock policy tables and inserting mock components into the target service's database, flexible mock testing of the target service is achieved, solving the problem of poor deployment flexibility of existing mock services and improving the flexibility of service mock testing.
Patent Information
- Application Number
- CN202210112035.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-29
- Publication Date
- 2025-05-06
- Estimated Expiration
- 2042-01-29
AI Technical Summary
The existing mock services are less flexible when deploying, and cannot mock the specific business process intermediate links of the interface, and it is difficult to switch to the official server.
Add a mock policy table in the target service's database and insert the mock component into the target service. The simulation policy table includes a call processing policy associated with the target location of the target service, and the simulation component carries execution data corresponding to the call processing policy. When a target call request is received, the request is intercepted and the request is responded to according to the processing policy in the simulated policy table.
It realizes mock testing of service calls to any target location in the target service, improves the flexibility of service simulation testing, and solves the problem of poor mock service deployment flexibility.
Smart Images

Figure CN114546840B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of testing, and in particular to a method and device for simulating service calls, a storage medium and an electronic device. Background Art
[0002] When performing web interface call testing, if you want to quickly test various scenarios, you usually deploy a Mock service and use the Mock service to simulate and return various required simulation results.
[0003] Mock refers to the use of Mock objects to simulate behaviors that are difficult to construct and obtain during the test process. For example, when performing a call test, the system to be called has not yet been developed and deployed. At this time, it is necessary to use mock operations to simulate the behavior of the called system, such as: simulating the return of the interface, simulating the timeout return of the interface, simulating other return scenarios, etc.
[0004] However, the existing mock services can usually only mock the entire interface of the system, and cannot perform mock operations on the intermediate links of the specific business process of the interface. Moreover, since the mock service is deployed independently of the tested system, it is usually only possible to use the mock service and it is difficult to switch to the official server. In other words, the existing mock service can only operate according to the deployed solution, and has poor flexibility.
[0005] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention
[0006] The embodiments of the present invention provide a method and device for simulating service calls, a storage medium and an electronic device, so as to at least solve the technical problem of poor flexibility in mock service deployment.
[0007] According to one aspect of an embodiment of the present invention, a simulation method for service call is provided, comprising: in a case where a simulation policy table is added to a database of the target service, inserting a simulation component into the target service, wherein the simulation policy table includes a call processing policy associated with a target location of the target service, and the simulation component carries execution data corresponding to the call processing policy; in a case where the target location of the target service receives a target call request, intercepting the target call request; querying the target processing policy associated with the target location in the simulation policy table; and in a case where the target processing policy is in an enabled state, calling the target execution data corresponding to the target processing policy in the simulation component to respond to the target call request in accordance with the target processing policy.
[0008] According to another aspect of an embodiment of the present invention, a simulation device for service call is also provided, including: an insertion unit, for inserting a simulation component into the target service when a simulation policy table is added to the database of the target service, wherein the simulation policy table includes a call processing policy associated with a target location of the target service, and the simulation component carries execution data corresponding to the call processing policy; an interception unit, for intercepting the target call request when a target call request is received at the target location of the target service; a query unit, for querying the target processing policy associated with the target location in the simulation policy table; and a calling unit, for calling the target execution data corresponding to the target processing policy in the simulation component when the target processing policy is in an enabled state, so as to respond to the target call request in accordance with the target processing policy.
[0009] According to another aspect of the embodiments of the present invention, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the above-mentioned service call simulation method at runtime.
[0010] According to another aspect of an embodiment of the present invention, there is provided an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to execute the above-mentioned service call simulation method through the computer program.
[0011] In an embodiment of the present invention, a simulation component is inserted into the target service when a simulation strategy table is added to the database of the target service. The simulation strategy table includes a call processing strategy associated with the target location of the target service. The simulation component carries execution data corresponding to the call processing strategy. When a target call request is received at the target location of the target service, the target call request is intercepted, the target processing strategy associated with the target location is queried in the simulation strategy table, and when the target processing strategy is enabled, the target execution data corresponding to the target processing strategy in the simulation component is called to respond to the target call request in accordance with the target processing strategy. By inserting the simulation component into the target service and adding the simulation strategy table to the database of the target service, when a call request is received at the target location of the target service, the target processing strategy associated with the target location is queried in the simulation strategy table, and when the target processing strategy is enabled, the target execution data in the simulation component is called to respond to the call request received at the target location in accordance with the target processing strategy. The purpose of realizing simulation testing of service calls to any target location in the target service through the inserted simulation component and the simulation strategy table is achieved, thereby achieving the technical effect of improving the flexibility of service simulation testing, and further solving the technical problem of poor flexibility of mock service deployment. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0013] Figure 1 is a schematic diagram of an application environment of an optional service call simulation method according to an embodiment of the present invention;
[0014] Figure 2 is a flow chart of an optional service call simulation method according to an embodiment of the present invention;
[0015] Figure 3 is a flow chart of an optional service call simulation method according to an embodiment of the present invention;
[0016] Figure 4 is a flow chart of an optional service call simulation method according to an embodiment of the present invention;
[0017] Figure 5 is a schematic structural diagram of an optional service call simulation device according to an embodiment of the present invention;
[0018] Figure 6 It is a schematic diagram of the structure of an optional electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0019] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0020] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0021] According to one aspect of an embodiment of the present invention, a method for simulating a service call is provided. Optionally, the method for simulating a service call can be applied to, but is not limited to, Figure 1 In the environment shown. The terminal device 102 exchanges data with the server 112 through the network 110. The terminal device 102 is not limited to running an application corresponding to the server 112. Before the application goes online, it is not limited to performing a server simulation test through the server 112 to ensure the normal operation of the application service. The server 112 includes a database 114 and a processing engine 116. The database 114 is used to store data. The processing engine 116 processes the data stored in the database 114 by responding to the processing instruction to obtain the corresponding processing result, and stores the processing result in the database 114.
[0022] The simulation of the service call performed by the processing engine in the server 112 and 116 is not limited to being implemented by sequentially executing S102 to S108. Insert the simulation component into the target service. In the case where a simulation policy table is added to the database of the target service, insert the simulation component into the target service, the simulation policy table includes a call processing policy associated with the target location of the target service, and the simulation component carries execution data corresponding to the call processing policy. Intercept the target call request. In the case where a target call request is received at the target location of the target service, intercept the target call request. Query the target processing policy. Query the target processing policy associated with the target location in the simulation policy table. Call the target execution data. When the target processing policy is in an enabled state, call the target execution data corresponding to the target processing policy in the simulation component to respond to the target call request according to the target processing policy.
[0023] Optionally, in this embodiment, the terminal device may be a terminal device configured with a target client, which may include but is not limited to at least one of the following: a mobile phone (such as an Android phone, an IOS phone, etc.), a laptop, a tablet computer, a PDA, a MID (Mobile Internet Devices), a PAD, a desktop computer, a smart TV, etc. The target client may be a video client, an instant messaging client, a browser client, an education client, etc. The network may include but is not limited to: a wired network, a wireless network, wherein the wired network includes: a local area network, a metropolitan area network and a wide area network, and the wireless network includes: Bluetooth, WIFI and other networks that realize wireless communication. The server may be a single server, or a server cluster consisting of multiple servers, or a cloud server. The above is only an example, and this embodiment does not make any limitation to this.
[0024] As an optional implementation, Figure 2As shown, the simulation method of the above service call includes:
[0025] S202, when a simulation strategy table is added to the database of the target service, inserting a simulation component into the target service, wherein the simulation strategy table includes a call processing strategy associated with a target location of the target service, and the simulation component carries execution data corresponding to the call processing strategy;
[0026] S204, when a target call request is received at a target location of a target service, intercepting the target call request;
[0027] S206, searching the simulation strategy table for a target processing strategy associated with the target location;
[0028] S208, when the target processing strategy is in an enabled state, calling the target execution data corresponding to the target processing strategy in the simulation component to respond to the target calling request according to the target processing strategy.
[0029] The target service is the service to be called in the service simulation test, that is, the service that responds to the call request. The call request is not limited to the call request initiated by other services, but can also be the call request initiated by the previous process of the target service. The target location can be the call location of the interface corresponding to the target service, or the call location of any step in the interface processing flow.
[0030] The simulation strategy table is associated with the simulation component. The simulation strategy table is used to record the processing strategy of the simulation test of each call location, and the simulation component is used to record the execution data corresponding to the processing strategy. The processing strategy corresponding to the call location and the status of the processing strategy are determined by querying the simulation strategy table. When the processing strategy is enabled, the execution data corresponding to the processing strategy is called from the simulation component to perform the service simulation test of the call location.
[0031] The simulation component is not limited to the mock component, and the corresponding simulation strategy table is not limited to the mock strategy table. After the mock strategy table is added to the database of the target service, the mock component is inserted into the target service, so as to perform simulation test of the target service through the mock strategy table and the mock component.
[0032] When service A calls server B and performs simulation test on service B, it is not limited to the following: Figure 3As shown. Add the mock strategy table to the database of service B, and insert the compressed package of the mock component into service B. Write the location where service B needs to perform simulation testing and the corresponding processing strategy into the mock strategy table. When service A initiates a call to the interface of service B, when it is at the target location, query the target processing strategy corresponding to the target location in the mock strategy table. When the target processing strategy is in the startup state, determine to respond to the call request of the target location according to the target processing strategy.
[0033] In an embodiment of the present application, a simulation component is inserted into the target service when a simulation policy table is added to the database of the target service. The simulation policy table includes a call processing policy associated with the target location of the target service. The simulation component carries execution data corresponding to the call processing policy. When a target call request is received at the target location of the target service, the target call request is intercepted, the target processing policy associated with the target location is queried in the simulation policy table, and when the target processing policy is enabled, the target execution data corresponding to the target processing policy in the simulation component is called to respond to the target call request in accordance with the target processing policy. By inserting the simulation component in the target service and adding the simulation policy table to the database of the target service, when a call request is received at the target location of the target service, the target processing policy associated with the target location is queried in the simulation policy table, and when the target processing policy is enabled, the target execution data in the simulation component is called to respond to the call request received at the target location in accordance with the target processing policy. The purpose of realizing simulation testing of service calls to any target location in the target service through the inserted simulation component and the simulation policy table is achieved, thereby achieving the technical effect of improving the flexibility of service simulation testing, and further solving the technical problem of poor flexibility of mock service deployment.
[0034] As an optional implementation manner, the above-mentioned querying the target processing strategy associated with the target position in the simulation strategy table includes:
[0035] In the case where the target location is a target interface of the target service, querying the simulation policy table for an interface processing policy associated with the target interface;
[0036] In the case where the target location is a target process of a target interface of a target service, a process processing policy associated with the target process of the target interface is queried in the simulation policy table.
[0037] Optionally, the target processing strategy corresponding to the target position is queried in the simulation strategy table according to the target position. When the target position is the target interface, the target processing strategy is the interface processing strategy of the target interface corresponding to the entire interface, and when the target position is any process of the target interface, the target processing strategy is the process processing strategy corresponding to the target process.
[0038] The interface processing strategy is the processing strategy of the entire process corresponding to the interface. Figure 3 Taking service B as an example, when step 1, step 2 and step 3 are steps corresponding to different processes of the same interface, when the target position is an interface, the interface processing strategy corresponding to the interface is searched in the mock strategy table; when the target position is the process position corresponding to step 2, the process processing strategy corresponding to step 2 is searched in the mock strategy table.
[0039] In the embodiment of the present application, by providing a processing strategy in the policy table that can perform simulation tests for an interface and any process of the interface, flexible simulation tests for service calls are implemented, thereby improving the flexibility of service simulation tests.
[0040] As an optional implementation, the inserting of the simulation component into the target service includes: inserting the simulation component into a database directory of the target service.
[0041] The simulation component is not limited to being inserted into the database directory of the target service, so that any interface in the entire target service and the processing strategy of the process in any interface added to the policy table can realize the call of the compressed execution data in the compressed package of the simulation component.
[0042] As an optional implementation, after calling the target execution data corresponding to the target processing strategy in the simulation component, the method further includes:
[0043] S1, searching a simulation strategy table for a first processing strategy corresponding to a first target position;
[0044] S2, adjusting the first processing strategy from an enabled state to a disabled state, wherein the disabled state is used to indicate that the processing strategy is in a disabled state.
[0045] When a stop instruction is received to stop the simulation test of the first target position, the first processing strategy corresponding to the first target position is searched in the simulation strategy table, and the simulation test of the first target position is closed by adjusting the first processing strategy to an invalid state.
[0046] The status of the processing strategy recorded in the simulation strategy table is not limited to including an on state and an off state. When the processing strategy is in the on state, it is used to instruct the target location to enable simulation testing and respond to the call of the target location according to the target processing strategy. When the processing strategy is in the off state, it is used to instruct the target location to turn off simulation testing and respond to the call of the target location according to the normal processing flow of the target location.
[0047] In the embodiment of the present application, the simulation test of the target location can be turned off by simply adjusting the status of the processing strategy in the strategy table to an invalid state, and the status adjustment of the processing strategy of each target location is relatively independent and does not affect the status of the processing strategy of other locations. At the same time, there is no need to make any changes or adjustments to the simulation components, which is convenient to operate and more flexible.
[0048] As an optional implementation, after calling the target execution data corresponding to the target processing strategy in the simulation component, the method further includes:
[0049] S1, remove the simulated component inserted in the target service;
[0050] S2, when the simulation component is removed, all processing strategies in the simulation strategy table are adjusted to an invalid state.
[0051] When all processing strategies need to be invalidated, the states of all strategies can be adjusted in the strategy table in sequence, instead of adjusting the states of the processing strategies in the strategy table in sequence. All processing strategies in the simulation strategy table can also be adjusted to invalid states by removing the simulation component inserted into the target service from the target service.
[0052] In an embodiment of the present application, the simulation component is registered in the target service in an inserted manner to implement simulation testing of the target service, and no code changes are required for the target service itself, thereby achieving simple plug-in operation.
[0053] As an optional implementation, the above-mentioned intercepting target call request includes:
[0054] S1, creating a target call object of the same type as the call object at the target location in the simulation component, wherein the target call request is used to request to call the call object at the target location, and the target call object carries an annotation indicating that the call priority is higher than the call object at the target location;
[0055] S2, using the target call object to respond to the target call request, so as to intercept the call request of the target location and respond to the target call request.
[0056] The call request received by the target service is not limited to high-priority proxy or aspect-oriented programming function to achieve high-priority proxy. It is not limited to the @Primary annotation in the Spring framework to achieve static proxy of the original process. In the mock component, declare a target call object of the same type as the call object at the target location, and add the @Primary annotation to the target call object. The Spring framework will give priority to injecting the target call object with the @Primary annotation. The target call request is intercepted through the target call object, thereby realizing the call simulation test of the target location.
[0057] As an optional implementation, the above-mentioned intercepting target call request includes:
[0058] S1, when the target service enables the aspect-oriented programming (AOP) function, the aspect interception condition corresponding to the aspect-oriented programming (AOP) function is carried in the simulation component, wherein when the call request received by the target service meets the aspect interception condition, the aspect-oriented programming (AOP) function intercepts the call request, and the aspect interception condition includes a location condition indicating that the receiving location of the call request is the target location;
[0059] S2, intercept the target call request through aspect-oriented programming (AOP) function.
[0060] The aspect-oriented programming function is not limited to the Spring AOP aspect-oriented programming to achieve dynamic interception of target call requests. Spring AOP can intercept call requests that meet the aspect conditions. Similarly, simulation test operations can be performed at these interception locations according to the configured processing strategy. Similarly, the simulation test operation can be used to instruct the execution of the original process at the target location.
[0061] Take service A calling service B and performing simulation test on service B as an example. The service simulation test process is not limited to the following: Figure 4 shown.
[0062] S402, service B receives the call request;
[0063] S404, the mock component intercepts the call request at the target location;
[0064] S406, querying the target processing strategy of the target location in the mock strategy table;
[0065] S408, determining whether the target processing strategy is enabled; if it is enabled, executing S410, otherwise executing S412;
[0066] S410, responding to the call request according to the target processing strategy;
[0067] S412, executing the original processing logic of the target position.
[0068] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should know that the present invention is not limited by the described action sequence, because according to the present invention, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present invention.
[0069] According to another aspect of the embodiment of the present invention, a service call simulation device for implementing the service call simulation method is also provided. Figure 5 As shown, the device comprises:
[0070] Insertion unit 502, used to insert the simulation component into the target service when a simulation strategy table is added to the database of the target service, wherein the simulation strategy table includes a call processing strategy associated with a target location of the target service, and the simulation component carries execution data corresponding to the call processing strategy;
[0071] An interception unit 504 is used to intercept the target call request when the target location of the target service receives the target call request;
[0072] A query unit 506, configured to query a target processing strategy associated with a target position in a simulation strategy table;
[0073] The calling unit 508 is used to call the target execution data corresponding to the target processing strategy in the simulation component when the target processing strategy is in an enabled state, so as to respond to the target calling request according to the target processing strategy.
[0074] Optionally, the query unit 506 includes:
[0075] A first query module, for querying an interface processing policy associated with a target interface in a simulation policy table when the target location is a target interface of a target service;
[0076] The second query module is used to query the process processing strategy associated with the target process of the target interface in the simulation strategy table when the target location is the target process of the target interface of the target service.
[0077] Optionally, the above-mentioned insertion unit is also used to insert the simulation component into the database directory of the target service.
[0078] Optionally, the simulation device for calling the above-mentioned service also includes an invalidation unit, which is used to search for a first processing strategy corresponding to a first target position in a simulation strategy table after calling the target execution data corresponding to the target processing strategy in the simulation component; and adjust the first processing strategy from an enabled state to an invalid state, wherein the invalid state is used to indicate that the processing strategy is in an unenabled state.
[0079] Optionally, the simulation device for calling the above-mentioned service also includes a removal unit, which is used to remove the simulation component inserted in the target service after calling the target execution data corresponding to the target processing strategy in the simulation component; when the simulation component is removed, all processing strategies in the simulation strategy table are adjusted to an invalid state.
[0080] Optionally, the interception unit 504 includes:
[0081] The first interception module is used to create a target call object of the same type as the call object of the target location in the simulation component, wherein the target call request is used to request to call the call object of the target location, and the target call object carries an annotation indicating that the call priority is higher than the call object of the target location; the target call object is used to respond to the target call request to intercept the call request of the target location to respond to the target call request.
[0082] Optionally, the interception unit 504 includes:
[0083] The second interception module is used to carry the aspect interception conditions corresponding to the aspect oriented programming AOP function in the simulation component when the target service enables the aspect oriented programming AOP function, wherein when the call request received by the target service meets the aspect interception conditions, the aspect oriented programming AOP function intercepts the call request, and the aspect interception conditions include a location condition indicating that the receiving location of the call request is the target location; the target call request is intercepted by the aspect oriented programming AOP function.
[0084] In an embodiment of the present application, a simulation component is inserted into the target service when a simulation policy table is added to the database of the target service. The simulation policy table includes a call processing policy associated with the target location of the target service. The simulation component carries execution data corresponding to the call processing policy. When a target call request is received at the target location of the target service, the target call request is intercepted, the target processing policy associated with the target location is queried in the simulation policy table, and when the target processing policy is enabled, the target execution data corresponding to the target processing policy in the simulation component is called to respond to the target call request in accordance with the target processing policy. By inserting the simulation component in the target service and adding the simulation policy table to the database of the target service, when a call request is received at the target location of the target service, the target processing policy associated with the target location is queried in the simulation policy table, and when the target processing policy is enabled, the target execution data in the simulation component is called to respond to the call request received at the target location in accordance with the target processing policy. The purpose of realizing simulation testing of service calls to any target location in the target service through the inserted simulation component and the simulation policy table is achieved, thereby achieving the technical effect of improving the flexibility of service simulation testing, and further solving the technical problem of poor flexibility of mock service deployment.
[0085] According to another aspect of the embodiment of the present invention, an electronic device for implementing the above-mentioned service call simulation method is also provided. The electronic device may be Figure 1 The terminal device or server shown in the figure. This embodiment is described by taking the electronic device as a server as an example. Figure 6 As shown, the electronic device includes a memory 602 and a processor 604. The memory 602 stores a computer program, and the processor 604 is configured to execute the steps in any of the above method embodiments through the computer program.
[0086] Optionally, in this embodiment, the electronic device may be located in at least one network device among a plurality of network devices of a computer network.
[0087] Optionally, in this embodiment, the processor may be configured to perform the following steps through a computer program:
[0088] S1, inserting a simulation component into the target service when a simulation strategy table is added to the database of the target service, wherein the simulation strategy table includes a call processing strategy associated with a target location of the target service, and the simulation component carries execution data corresponding to the call processing strategy;
[0089] S2, when receiving a target call request at a target location of a target service, intercepting the target call request;
[0090] S3, querying the target processing strategy associated with the target position in the simulation strategy table;
[0091] S4, when the target processing strategy is in an enabled state, calling the target execution data corresponding to the target processing strategy in the simulation component to respond to the target calling request according to the target processing strategy.
[0092] Alternatively, a person skilled in the art may understand that: Figure 6 The structure shown is for illustration only, and the electronic device may also be a smart phone (such as an Android phone, an IOS phone, etc.), a tablet computer, a PDA, a mobile Internet device (Mobile Internet Devices, MID), a PAD, and other terminal devices. Figure 6 The structure of the electronic device is not limited. Figure 6 More or fewer components (such as network interfaces, etc.) as shown in, or with Figure 6 Different configurations are shown.
[0093] Among them, the memory 602 can be used to store software programs and modules, such as the program instructions / modules corresponding to the service call simulation method and device in the embodiment of the present invention. The processor 604 executes various functional applications and data processing by running the software programs and modules stored in the memory 602, that is, realizing the above-mentioned service call simulation method. The memory 602 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 602 may further include a memory remotely arranged relative to the processor 604, and these remote memories may be connected to the terminal via a network. Examples of the above-mentioned networks include but are not limited to the Internet, corporate intranets, local area networks, mobile communication networks and combinations thereof. Among them, the memory 602 can be specifically but not limited to being used to store simulation components, simulation strategy tables and other information. As an example, Figure 6 As shown, the memory 602 may include but is not limited to the insertion unit 502, interception unit 504, query unit 506 and calling unit 508 in the service call simulation device. In addition, it may also include but is not limited to other module units in the service call simulation device, which will not be repeated in this example.
[0094] Optionally, the transmission device 606 is used to receive or send data via a network. Specific examples of the network may include a wired network and a wireless network. In one example, the transmission device 606 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices and routers via a network cable so as to communicate with the Internet or a local area network. In one example, the transmission device 606 is a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0095] In addition, the electronic device further comprises: a display 608 for displaying the simulation strategy table; and a connection bus 610 for connecting various module components in the electronic device.
[0096] In other embodiments, the terminal device or server may be a node in a distributed system, wherein the distributed system may be a blockchain system, and the blockchain system may be a distributed system formed by connecting the multiple nodes through network communication. Among them, the nodes may form a peer-to-peer (P2P, Peer To Peer) network, and any form of computing device, such as a server, terminal and other electronic devices, may become a node in the blockchain system by joining the peer-to-peer network.
[0097] According to one aspect of the present application, a computer program product or computer program is provided, the computer program product or computer program including computer instructions, the computer instructions being stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device performs the methods provided in various optional implementations of the simulation aspects of the above-mentioned service call. The computer program is configured to execute the steps of any of the above-mentioned method embodiments when it is run.
[0098] Optionally, in this embodiment, the computer-readable storage medium may be configured to store a computer program for performing the following steps:
[0099] S1, inserting a simulation component into the target service when a simulation strategy table is added to the database of the target service, wherein the simulation strategy table includes a call processing strategy associated with a target location of the target service, and the simulation component carries execution data corresponding to the call processing strategy;
[0100] S2, when receiving a target call request at a target location of a target service, intercepting the target call request;
[0101] S3, querying the target processing strategy associated with the target position in the simulation strategy table;
[0102] S4, when the target processing strategy is in an enabled state, calling the target execution data corresponding to the target processing strategy in the simulation component to respond to the target calling request according to the target processing strategy.
[0103] Optionally, in this embodiment, a person of ordinary skill in the art may understand that all or part of the steps in the various methods of the above embodiments may be completed by instructing hardware related to the terminal device through a program, and the program may be stored in a computer-readable storage medium, and the storage medium may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, etc.
[0104] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0105] If the integrated units in the above embodiments are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above computer-readable storage medium. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling one or more computer devices (which can be personal computers, servers or network devices, etc.) to perform all or part of the steps of the methods described in various embodiments of the present invention.
[0106] In the above embodiments of the present invention, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0107] In the several embodiments provided in the present application, it should be understood that the disclosed client can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0108] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0109] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0110] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A method for simulating a service call, characterized in that: include: In the case where a simulation strategy table is added to the database of the target service, inserting a simulation component into the target service, wherein the simulation strategy table includes a call processing strategy associated with a target location of the target service, and the simulation component carries execution data corresponding to the call processing strategy; In a case where a target invocation request is received at the target location of the target service, intercepting the target invocation request; Querying the target processing strategy associated with the target position in the simulation strategy table; In the case where the target processing strategy is in an enabled state, calling the target execution data corresponding to the target processing strategy in the simulation component to respond to the target calling request according to the target processing strategy; The step of querying the target processing strategy associated with the target position in the simulation strategy table includes: In the case where the target location is a target interface of the target service, querying the simulation strategy table for an interface processing strategy associated with the target interface, the interface processing strategy being a processing strategy for the entire process corresponding to the interface; In the case where the target location is the target process of the target interface of the target service, the process processing policy associated with the target process of the target interface is queried in the simulation strategy table, and the process processing policy is the processing strategy corresponding to the steps corresponding to different processes of the same interface.
2. The method according to claim 1, characterized in that The inserting the simulation component into the target service comprises: In the database catalog of the target service, the simulation component is inserted.
3. The method according to claim 1, characterized in that After calling the target execution data corresponding to the target processing strategy in the simulation component, the method further includes: Searching the simulation strategy table for a first processing strategy corresponding to the first target position; The first processing strategy is adjusted from the enabled state to a disabled state, wherein the disabled state is used to indicate that the processing strategy is in a disabled state.
4. The method according to claim 3, characterized in that After calling the target execution data corresponding to the target processing strategy in the simulation component, the method further includes: removing the simulation component inserted in the target service; When the simulation component is removed, all processing strategies in the simulation strategy table are adjusted to the invalid state.
5. The method according to claim 1, characterized in that The intercepting of the target call request comprises: Creating a target call object of the same type as the call object at the target location in the simulation component, wherein the target call request is used to request to call the call object at the target location, and the target call object carries an annotation indicating that the call priority is higher than the call object at the target location; The target call object is used to respond to the target call request, so as to intercept the call request of the target location and respond to the target call request.
6. The method according to claim 1, characterized in that The intercepting of the target call request comprises: In the case where the target service enables the aspect-oriented programming (AOP) function, the aspect interception condition corresponding to the aspect-oriented programming (AOP) function is carried in the simulation component, wherein when the call request received by the target service satisfies the aspect interception condition, the aspect-oriented programming (AOP) function intercepts the call request, and the aspect interception condition includes a location condition indicating that the receiving location of the call request is the target location; The target call request is intercepted by the aspect-oriented programming (AOP) function.
7. A service call simulation device, characterized in that: include: An insertion unit, configured to insert a simulation component into a target service when a simulation strategy table is added to a database of the target service, wherein the simulation strategy table includes a call processing strategy associated with a target location of the target service, and the simulation component carries execution data corresponding to the call processing strategy; An interception unit, configured to intercept the target call request when a target call request is received at the target location of the target service; A query unit, configured to query the simulation strategy table for a target processing strategy associated with the target position; a calling unit, configured to call target execution data corresponding to the target processing strategy in the simulation component when the target processing strategy is in an enabled state, so as to respond to the target calling request according to the target processing strategy; The query unit comprises: A first query module is used to query the interface processing strategy associated with the target interface in the simulation strategy table when the target location is a target interface of the target service, wherein the interface processing strategy is a processing strategy for the entire process corresponding to the interface; The second query module is used to query the process processing strategy associated with the target process of the target interface of the target service in the simulation strategy table when the target location is the target process of the target interface of the target service. The process processing strategy is the processing strategy corresponding to the steps corresponding to different processes of the same interface.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored program, wherein the program executes the method described in any one of claims 1 to 6 when executed.
9. An electronic device, comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to execute the method according to any one of claims 1 to 6 through the computer program.
Citation Information
Patent Citations
Interface data simulation method and device, storage medium and electronic equipment
CN109739656A
Interface call test method and device and computer readable storage medium
CN110990205A
Automatic Mock method and device based on traffic, equipment and storage medium
CN113938473A