Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present application more apparent, the embodiments of the present application are described in further detail below with reference to the embodiments and the accompanying drawings. The exemplary embodiments and descriptions of the embodiments are provided to explain the embodiments and should not be construed as limiting the embodiments.
Referring to fig. 1, an online mock test system according to the embodiment of the present application includes an application server 1 to be tested, where the application server 1 to be tested includes an application server 11 and a mock server 12 that is dynamically injected into the application server 1 to be tested in advance, where:
the application server 11 is configured to provide a request to the mock server 11 when receiving the request carrying the use case identifier; when receiving a mock response provided by the mock server 12, returning the mock response as a response of the request;
and the mock server 12 is configured to match a corresponding mock object from a built-in mock object set according to the use case identifier, perform simulation processing on the request based on the mock object, and provide a mock response obtained after the processing to the application server 11.
In an embodiment of the present application, the mock server 12 may be injected into the application server 1 to be tested in advance through a dynamic injection agent module (agent program) deployed in the application server 1 to be tested. The dynamic injection agent module can be used for receiving a mock server injection instruction. For example, the application system to be tested runs on the linux system, a specified jar package (agent program) can be uploaded on the linux system, and the dynamic injection agent module is started through java-jar agent. Of course, in the embodiment of the present application, the above-mentioned launching of the state injection agent module by using java-jar agent. In other embodiments of the present application, the dynamic injection agent module deployed in the application system to be tested may also be a script program (such as a shell) implemented based on other languages. In addition, in another embodiment of the present application, it may be considered that the dynamic injection proxy module is automatically deployed through a paas (Platform-as-a-Service) Platform when conditions allow.
In an embodiment of the present application, the mock server 12 may be sent to the dynamic injection agent module through a preset platform in advance. For example, after the dynamic injection agent module is deployed in an application system to be tested, a mock server injection instruction can be sent to the dynamic injection agent module through the mock platform; in this case, the dynamic injection agent module and the mock platform can communicate with each other by using a protocol such as socket; in addition, the dynamic injection agent module can be remotely connected through a local IDE (Integrated Development Environment) platform; in this case, the dynamic injection agent module and the IDE platform may communicate using a protocol such as RMI (Remote Method Invocation). In an exemplary embodiment of the present application, the IDE platform may be Eclipse or Intellij ideal, for example.
In one embodiment of the application, some tool classes can be used for generating mock server injection instructions. For example, if it is desired to simulate the response time of some external dependency interface for more than 5 seconds, the java code of the external dependency interface can be edited in the local IDE to obtain the corresponding java byte code or java class file. The java file can be obtained by using a dynamic editing interface of java or a java command; the java byte code can be obtained through other frameworks (such as ASM byte code plug-in).
In an embodiment of the present application, after receiving the mock server injection instruction, the dynamic injection agent module may extract the mock server 12 from information (such as bytecode to be injected or class to be replaced) in the mock server injection instruction, and then may dynamically inject the mock server 12 into the application server 1 to be tested through the java instrumentation interface. In addition, no matter the mock object is directed at an internal method or the mock object is directed at an external interface service, the dynamic injection can be realized through a dynamic injection agent module in the embodiment of the application; of course, after the mock test is completed, the mock server 12 can be deleted in the normal operation process of the application system to be tested by sending the restoring instruction to the dynamic injection agent module, so that the application system to be tested is restored. Therefore, the embodiment of the application also facilitates the unified management of the mock test.
In an embodiment of the present application, the mock server 12 may include a mock object set, where the mock object set is a set of correspondence between use case identifiers and mock objects, and the mock objects in the mock object set may be internal business logic and/or external business logic, and the number of the mock objects may be determined according to specific needs. The correspondence between the use case identifier and the mock object can be shown in the following table 1:
TABLE 1
Use case identification
|
mock object
|
001
|
X1
|
002
|
X2
|
…
|
… |
Therefore, the mock server 12 can match the corresponding mock object for the mock request corresponding to the use case identifier according to the corresponding relationship between the use case identifier and the mock object, so as to perform service simulation.
In the embodiment of the present application, the dynamic injection refers to injecting the mock server 12 into the application server 1 to be tested during the normal operation of the application system to be tested, and the mock server can take effect without restarting the application server 1 to be tested.
As shown in fig. 2, the application server 11 of the online mock testing system may include:
the request forwarding module 111 may be configured to provide the request to the mock server when receiving the request carrying the use case identifier;
the response returning module 112 may be configured to, when receiving a mock response provided by the mock server, return the mock response as the response of the request.
As shown in fig. 3, the mock server 12 of the online mock testing system may include:
a request receiving module 121, configured to receive a request carrying a use case identifier provided by an application server;
an object matching module 122, configured to match a corresponding mock object from a built-in mock object set according to the use case identifier;
and the service simulation module 123 is configured to simulate and process the request based on the mock object, and provide a mock response obtained after processing to the application server.
The following describes the interaction flow of the application server 11 and the mock server 12 with reference to fig. 4:
step 1, the application server 11 receives a request sent by a request sender. The request sender may be an upstream system or a client of the application server 11.
In this embodiment of the application, the request sender may send the request to the application server 11 in a context transparent transmission manner. For example, in an exemplary embodiment of the present application, the method may be implemented by a tracker component under a sofa (service organized Fabric architecture) development framework, that is, the sent request may be a transparent tracker context, and the tracker context includes a use case identifier.
And 2, the application server 11 judges whether the request carries a use case identifier. If the request carries the use case identifier, the request is a mock request, and then step 3a is executed.
In an embodiment of the application, the use case identifier in the mock request can be embedded in the mock request in advance in a point embedding manner. The buried point can be realized by a tool class, so that corresponding codes do not need to be written aiming at the mock logic realization, and the development cost and the maintenance cost of the codes are saved.
In an embodiment of the present application, for the application server 11, the use case identifier may be used to distinguish whether the received request is a mock request or a service request, thereby implementing on-line mock test and isolation of normal service.
In an embodiment of the application, for the mock server 12, the use case identifier can also be used for distinguishing each mock request, so that the mock server 12 can select a corresponding mock object for the corresponding mock request according to each use case identifier, and the mock test of multiple concurrent scenes can be effectively supported.
And 3a, the application server 11 transmits the request carrying the use case identifier to the mock server 12.
Step 4a, after receiving a mock request carrying a use case identifier provided by the application server 11, the mock server 12 matches a corresponding mock object from a built-in mock object set according to the use case identifier; and then, simulating and processing the mock request based on the mock object to obtain a mock response.
And step 5a, the mock server 12 provides the mock response to the application server 11.
And 6a, after receiving the mock response provided by the mock server 12, the application server 11 returns the mock response to the request sender as the response of the mock request.
In the embodiment of the present application, after step 2, the following steps may also be included:
and 3b, when the application server 11 receives a request which does not carry a use case identifier, indicating that the request is a normal service request. Therefore, the application server 11 may process the service request according to a preset service logic, and obtain a service result.
And 4b, the application server 11 encapsulates the service result into service and correspondingly returns the service result to the request sender.
In the embodiment of the application, the mock server is pre-stored in the application server to be tested in a dynamic injection mode, so that the embodiment of the application does not need an additional server to deploy the mock server, and does not need to modify the code of the application system to be tested; therefore, the on-line mock test is realized by using the application system to be tested while the normal operation of the application system to be tested is not influenced, and the mock test cost is low. In addition, in the embodiment of the application, the received request can be distinguished as a mock request or a service request through the use case identification, so that the isolation of the on-line mock test and the normal service is realized; and the use case identification can be used for distinguishing each mock request, so that the application example can effectively support the mock test of multiple concurrent scenes.
Referring to fig. 5, an inline mock testing method according to an embodiment of the present application may include the following steps:
step S501, when a request carrying a use case identifier is received, providing the request to the mock server.
And step S502, when a mock response provided by the mock server is received, returning the mock response as the response of the request.
For details of each step in the online mock testing method according to the embodiment of the present application, please refer to an interaction flow of the application server 11 and the mock server 12 shown in fig. 4, which is not described herein again.
In the embodiment of the application, the mock server is pre-stored in the application server to be tested in a dynamic injection mode, so that the embodiment of the application does not need an additional server to deploy the mock server, and does not need to modify the code of the application system to be tested; therefore, the on-line mock test is carried out by using the application system to be tested while the normal operation of the application system to be tested is not influenced, the mock test cost is reduced, and the mock test efficiency is improved. In addition, in the embodiment of the application, the received request can be distinguished as a mock request or a service request through the use case identification, so that the isolation of the on-line mock test and the normal service is realized; and the use case identification can be used for distinguishing each mock request, so that the application example can effectively support the mock test of multiple concurrent scenes.
Referring to fig. 6, the on-line mock testing method according to the embodiment of the present application may include the following steps:
step S601, receiving a request carrying a use case identifier provided by an application server;
step S602, matching corresponding mock objects from a built-in mock object set according to the use case identifiers;
and S603, simulating and processing the request based on the mock object, and providing the processed mock response to the application server.
For details of each step in the online mock testing method according to the embodiment of the present application, please refer to an interaction flow of the application server 11 and the mock server 12 shown in fig. 4, which is not described herein again.
In the embodiment of the application, the mock server is pre-stored in the application server to be tested in a dynamic injection mode, so that the embodiment of the application does not need an additional server to deploy the mock server, and does not need to modify the code of the application system to be tested; therefore, the on-line mock test is carried out by using the application system to be tested while the normal operation of the application system to be tested is not influenced, the mock test cost is reduced, and the mock test efficiency is improved. In addition, in the embodiment of the application, the received request can be distinguished as a mock request or a service request through the use case identification, so that the isolation of the on-line mock test and the normal service is realized; and the use case identification can be used for distinguishing each mock request, so that the application example can effectively support the mock test of multiple concurrent scenes.
Although the process flows described in the above method embodiments include a number of operations occurring in a particular order, it should be appreciated that the processes may include more or fewer operations, which may be performed sequentially or in parallel (e.g., using parallel processors or a multi-threaded environment).
In the 90 s of the 20 th century, improvements in a technology could clearly distinguish between improvements in hardware (e.g., improvements in circuit structures such as diodes, transistors, switches, etc.) and improvements in software (improvements in process flow). However, as technology advances, many of today's process flow improvements have been seen as direct improvements in hardware circuit architecture. Designers almost always obtain the corresponding hardware circuit structure by programming an improved method flow into the hardware circuit. Thus, it cannot be said that an improvement in the process flow cannot be realized by hardware physical modules. For example, a Programmable Logic Device (PLD), such as a Field Programmable Gate Array (FPGA), is an integrated circuit whose Logic functions are determined by programming the Device by a user. A digital system is "integrated" on a PLD by the designer's own programming without requiring the chip manufacturer to design and fabricate application-specific integrated circuit chips. Furthermore, nowadays, instead of manually making an Integrated Circuit chip, such Programming is often implemented by "logic compiler" software, which is similar to a software compiler used in program development and writing, but the original code before compiling is also written by a specific Programming Language, which is called Hardware Description Language (HDL), and HDL is not only one but many, such as abel (advanced Boolean Expression Language), ahdl (alternate Hardware Description Language), traffic, pl (core universal Programming Language), HDCal (jhdware Description Language), lang, Lola, HDL, laspam, hardward Description Language (vhr Description Language), vhal (Hardware Description Language), and vhigh-Language, which are currently used in most common. It will also be apparent to those skilled in the art that hardware circuitry that implements the logical method flows can be readily obtained by merely slightly programming the method flows into an integrated circuit using the hardware description languages described above.
The controller may be implemented in any suitable manner, for example, the controller may take the form of, for example, a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro) processor, logic gates, switches, an Application Specific Integrated Circuit (ASIC), a programmable logic controller, and an embedded microcontroller, examples of which include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320, the memory controller may also be implemented as part of the control logic for the memory. Those skilled in the art will also appreciate that, in addition to implementing the controller as pure computer readable program code, the same functionality can be implemented by logically programming method steps such that the controller is in the form of logic gates, switches, application specific integrated circuits, programmable logic controllers, embedded microcontrollers and the like. Such a controller may thus be considered a hardware component, and the means included therein for performing the various functions may also be considered as a structure within the hardware component. Or even means for performing the functions may be regarded as being both a software module for performing the method and a structure within a hardware component.
The systems, devices, modules or units illustrated in the above embodiments may be implemented by a computer chip or an entity, or by a product with certain functions. One typical implementation device is a computer. In particular, the computer may be, for example, a personal computer, a laptop computer, a cellular telephone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
For convenience of description, the above devices are described as being divided into various units by function, and are described separately. Of course, the functionality of the units may be implemented in one or more software and/or hardware when implementing the present application.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The application may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. The application may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the system embodiment, since it is substantially similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
The above-mentioned embodiments are intended to illustrate the objects, technical solutions and advantages of the present application in further detail, and it should be understood that the above-mentioned embodiments are only examples of the embodiments of the present application and are not intended to limit the scope of the present application, and any modifications, equivalents, improvements and the like made within the spirit and principle of the present application should be included in the scope of the present application.