CN115658543A - Service simulation method, device, computer equipment and storage medium - Google Patents
Service simulation method, device, computer equipment and storage medium Download PDFInfo
- Publication number
- CN115658543A CN115658543A CN202211412122.2A CN202211412122A CN115658543A CN 115658543 A CN115658543 A CN 115658543A CN 202211412122 A CN202211412122 A CN 202211412122A CN 115658543 A CN115658543 A CN 115658543A
- Authority
- CN
- China
- Prior art keywords
- service
- information
- class
- simulation
- simulated
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Landscapes
- Management, Administration, Business Operations System, And Electronic Commerce (AREA)
Abstract
The application relates to a service simulation method, a service simulation device, computer equipment and a storage medium. The method can be used in the financial or other fields, an input message template is generated according to the service information to be simulated, the simulation method information and the method input parameter and is stored in a database, a target simulation service class is generated according to the service information to be simulated and the method information to be simulated, and the IP port is stored in a registration center so as to respond to a service calling request aiming at the target simulation service class by using the IP port information. The registry stores IP port information of a plurality of analog service classes, and each analog service class comprises service information and method information. Compared with the traditional mode of compiling the simulation service in real time after manually intercepting the request, the scheme carries out message matching of service simulation based on the simulation service class registered in the registration center in advance, and improves the simulation efficiency.
Description
Technical Field
The present application relates to the field of distributed service technologies, and in particular, to a service simulation method, apparatus, computer device, storage medium, and computer program product.
Background
During development of the distributed framework, remote invocation testing needs to be performed on each developed service, however, since the development of each service is not completed synchronously, when one service needs to remotely invoke another service, the other service is not completed and cannot be invoked, and therefore the invoked service needs to be simulated, so that the service initiating invocation can obtain information returned by the simulated service, and the testing on the service is completed. The conventional method for simulating the service generally adopts a mode of manually intercepting a service call request and then writing a simulation service in real time based on the service call request for calling. However, the simulation efficiency is reduced by implementing the call between services in a manner of writing simulation services in real time after manually intercepting the request.
Therefore, the current service simulation method has the defect of low simulation efficiency of the service.
Disclosure of Invention
In view of the above, it is necessary to provide a service simulation method, apparatus, computer device, computer readable storage medium and computer program product capable of improving simulation efficiency.
In a first aspect, the present application provides a service simulation method, including:
acquiring service information to be simulated, information of a method to be simulated corresponding to the service information to be simulated and method access parameters corresponding to the information of the method to be simulated;
generating a target simulation service class according to the service information to be simulated and the method information to be simulated, storing IP port information corresponding to the target simulation service class in a registration center, generating an input message template corresponding to the target simulation service class according to the service information to be simulated, the method information to be simulated and the method input parameter, and storing the input message template in a database so that the registration center stores the IP port information to respond to a service calling request of a test terminal to the target simulation service class;
the registration center stores IP port information of a plurality of analog service classes, and each analog service class comprises service information and method information corresponding to the service information.
In one embodiment, after the storing the IP port information corresponding to the target analog service class in the registry, the method further includes:
receiving a service calling request sent by a testing end; the service calling request comprises service information to be called, method information to be called corresponding to the service information to be called and method entry parameters corresponding to the method information to be called;
when the service information to be called and the method information to be called are a target service and a target method contained in the target simulation service class, acquiring IP port information of the corresponding registered target simulation service class from a registration center, calling the target simulation service class according to the IP port information, acquiring at least one input message template corresponding to the target method information from a database by the target simulation service class, matching the method with the at least one input message template, acquiring a service calling result corresponding to the service calling request according to the matching result, and returning the service calling result to the testing end; the target method information corresponds to the method information to be simulated.
In one embodiment, the method further comprises:
acquiring a service name and a service version of a service to be simulated as service information to be simulated;
acquiring a method name, a method entry parameter type and a method message type corresponding to the service information to be simulated as the information of the method to be simulated;
generating an input message template corresponding to the target simulation service class according to the service information to be simulated, the method information to be simulated and the method input parameters, and storing the input message template in a database, wherein the method comprises the following steps:
acquiring a template input message corresponding to the method input type and a template message corresponding to the method message type, generating an input message template according to the service information to be simulated, the method information to be simulated, the template input message and the template message corresponding to the template input message, and storing the input message template in a database.
In one embodiment, the generating a target simulation service class according to the service information to be simulated and the method information to be simulated includes:
converting the service information to be simulated from a state to be registered into a state in which the service information is registered;
generating a custom class loader corresponding to the service information being registered and service information object configuration of the dubbo distributed service framework;
generating a simulation service interface class and a simulation service implementation class according to the service name and method information in the service information which is registered;
and storing the user-defined class loader, the service information object configuration, the simulation service interface class and the simulation service implementation class into service configuration information to obtain a target simulation service class.
In one embodiment, the converting the service information to be simulated from the state to be registered to the state in registration includes:
storing the service information to be simulated into an interface information cache;
and inquiring real-time refreshing interface information by the idle asynchronous thread based on the service information to be simulated, if the service information to be simulated does not exist in the real-time refreshing interface information, removing the service information to be simulated from interface information cache, and adding the service information to be simulated to the real-time refreshing interface information to obtain the service information in the registered state.
In one embodiment, before generating the service information object configuration of the custom class loader and the distributed service framework corresponding to the service information being registered after converting the service information to be simulated from the state to be registered to the state to be registered, the method further includes:
removing old version simulation service registration information corresponding to the service information which is being registered from a service configuration information cache, and performing revocation exposure on the old version simulation service registration information;
and if the IP port information of the service information which is being registered does not exist in the online registration center, determining to generate the custom class loader corresponding to the service information which is being registered and the service information object configuration of the distributed service framework.
In one embodiment, the generating a simulation service interface class and a simulation service implementation class according to the service name and the method information in the service information being registered includes:
generating a simulation service interface class object and a simulation service realization class object through a Java byte code class library according to the service name;
adding a non-parameter constructor in the simulation service realization class object, and initializing the simulation service realization class added with the non-parameter constructor;
respectively adding method contents corresponding to the method information into the simulation service interface class object and the simulation service implementation class object;
and compiling the simulation service interface class object and the simulation service implementation class object added with the method content into a simulation service interface class file and a simulation service implementation class file respectively, and loading the simulation service interface class file and the simulation service implementation class file through the custom class loader to obtain a simulation service interface class and a simulation service implementation class.
In one embodiment, the service information to be called comprises a service name to be called and a service version to be called, and the method information to be called comprises a method name to be called; the acquiring IP port information of the corresponding registered target analog service class from the registry includes:
and inquiring the IP port information of the corresponding registered target simulation service class in the registration center according to the service name to be called and the service version to be called in the service calling request.
In one embodiment, the input message template includes message parameters; the obtaining, by the target simulation service class, at least one input message template corresponding to the target method information from a database, matching the method entry with the at least one input message template, obtaining a service invocation result corresponding to the service invocation request according to the matching result, and returning the service invocation result to the test end includes:
acquiring at least one input message template corresponding to target method information from a database by the target simulation service class, performing parameter matching on at least one input message template of the target method information participating in the target simulation service class, and determining a target input message template matched with the method input parameter in the at least one input message template;
and returning the target message parameters in the target input message template to the test end as a service calling result.
In one embodiment, if there are a plurality of input message templates, the performing parameter matching on at least one input message template of the target method information participating in the target simulation service class, and determining a target input message template matching with the method input parameter in the at least one input message template includes:
acquiring a plurality of input message templates in the target method information and the priority of each input message template;
and performing parameter matching on the input message templates of the method entries according to the sequence of the priority from high to low, and taking the first input message template matched with the method entries as a target input message template.
In a second aspect, the present application provides a service simulation apparatus, the apparatus comprising:
the data preparation module is used for acquiring service information to be simulated, information of a method to be simulated corresponding to the service information to be simulated and method access parameters corresponding to the information of the method to be simulated;
the registration module is used for generating a target simulation service class according to the service information to be simulated and the method information to be simulated, storing IP port information corresponding to the target simulation service class into a registration center, generating an input message template corresponding to the target simulation service class according to the service information to be simulated, the method information to be simulated and the method parameter, and storing the input message template into a database so that the registration center stores the IP port information and responds to a service calling request of a test terminal to the target simulation service class; the registration center stores IP port information of a plurality of analog service classes, and each analog service class comprises service information and method information corresponding to the service information;
in a third aspect, the present application provides a computer device comprising a memory storing a computer program and a processor implementing the steps of the method described above when the processor executes the computer program.
In a fourth aspect, the present application provides a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, performs the steps of the method described above.
In a fifth aspect, the present application provides a computer program product comprising a computer program which, when executed by a processor, performs the steps of the method described above.
The service simulation method, the service simulation device, the computer equipment, the storage medium and the computer program product can be used in the financial or other fields, an input message template is generated according to the service information to be simulated, the simulation method information and the method input parameter and is stored in the database, a target simulation service class is generated according to the service information to be simulated and the method information to be simulated, and the IP port is stored in the registration center so as to respond to the service call request aiming at the target simulation service class by using the IP port information. The registry stores IP port information of a plurality of analog service classes, and each analog service class comprises service information and method information. Compared with the traditional mode of compiling simulation service in real time after intercepting a request manually, the scheme performs message matching of service simulation based on the simulation service class registered in the registration center in advance, and improves the simulation efficiency.
Drawings
FIG. 1 is a diagram of an application environment of a service simulation method in one embodiment;
FIG. 2 is a schematic flow chart diagram illustrating a service simulation method in one embodiment;
FIG. 3 is a flow diagram that illustrates the steps of creating a simulation service class in one embodiment;
FIG. 4 is a schematic flow chart diagram of a service simulation method in another embodiment;
FIG. 5 is a block diagram showing the construction of a service simulation apparatus according to an embodiment;
FIG. 6 is a diagram illustrating an internal structure of a computer device according to an embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
The service simulation method provided by the embodiment of the application can be applied to the application environment shown in fig. 1. Wherein the testing end 102 communicates with the server 104 through a network. The data storage system may store data that the server 104 needs to process. The data storage system may be integrated on the server 104, or may be located on the cloud or other network server. The server 104 may receive the service invocation request sent by the test terminal 102, and determine, from the registry according to the service invocation request, IP port information of a target simulation class of a method to be invoked in the service invocation request, so as to perform a test on whether the service can be invoked based on matching between the target method information of the target simulation class and method entry parameters of the method to be invoked. The testing terminal 102 may be, but is not limited to, various personal computers and notebook computers. The server 104 may be implemented as a stand-alone server or as a server cluster comprised of multiple servers.
In one embodiment, as shown in fig. 2, a service simulation method is provided, which is described by taking the application of the method to the server in fig. 1 as an example, and includes the following steps:
step S202, obtaining service information to be simulated, information of a method to be simulated corresponding to the service information to be simulated and method parameters corresponding to the information of the method to be simulated.
The application program in the test end can perform service calling test by calling the corresponding service in the server. However, the service that the application program needs to call in the server may not be called, for example, the developed code of service 1 needs to call service 2 remotely, and service 2 cannot be completed or is not deployed in the current environment in time, so that service 1 cannot perform the interface test, and at this time, service 2 needs to perform the service simulation mock. Wherein, mock refers to simulation, that is, simulating information returned by an interface, and replacing the information which needs to be returned by the existing information, thereby realizing the test of a calling party. Mock may be roughly divided into an interface test level Mock and a unit test level Mock by hierarchy. The scheme may be mock for interface test level. For example, for some object interfaces which are not easy to construct and not completed, the server can come out from a mock virtual object interface, and the mock virtual object interface is called to return pre-set mock data, so that the test can be completed. That is, the server may be configured with the simulation service class in advance, so that the simulation service class responds when the test end calls the corresponding service.
The server can obtain the service information to be simulated, the information of the method to be simulated corresponding to the service information to be simulated and the method corresponding to the information of the method to be simulated in advance. The service information to be simulated may be related information of the called service, such as a service name, a service version, and the like. The information of the method to be simulated can be information of a method in the service to be simulated, one service can comprise a plurality of methods, the information of the method to be simulated can comprise information such as a method name, and the method parameter can be an input parameter in the information of the method to be simulated, for example, { "a":1, "b":2, "c": { "d":3} } can be a method parameter. The server may determine the information that needs to be returned by the simulation service class based on the input parameters.
Step S204, generating a target simulation service class according to the service information to be simulated and the method information to be simulated, storing IP port information corresponding to the target simulation service class in a registration center, generating an input message template corresponding to the target simulation service class according to the service information to be simulated, the method information to be simulated and the method input parameter, and storing the input message template in a database so that the registration center stores the IP port information to respond to a service calling request of a test terminal to the target simulation service class; the registration center stores IP port information of a plurality of analog service classes, and each analog service class comprises service information and method information corresponding to the service information.
The server can perform mock simulation on the service to be called in advance, the service to be called comprises an input message template, and the input message template is used for matching the input message in the input message template with the method input parameter sent by the test end and returning the matching result to the test end as the calling result to realize the calling of the service. The server may generate an input message template based on the received service information, where the service information may be service information corresponding to the called target simulation service class, and for example, the server may generate the input message template corresponding to the target simulation service class according to the service information to be simulated, the method information to be simulated, and the method parameter. After the server generates the input message template corresponding to the target simulation service class, the input message template can be stored in the database, so that when the target simulation service class is called, the corresponding input message template can be called from the database.
The server may communicate with a plurality of registration centers, each registration center includes IP port information of a plurality of service providers, each service provider may be a called party, that is, a party providing an interface, that is, a service to be called, and the services may include a simulated service class, that is, a service class obtained through mock simulation. The service simulation request may be a request for simulating a service sent by the test terminal, and after receiving the service simulation request, the server may generate a target simulation service class and target method information based on the service information to be simulated and the method information to be simulated in the service simulation request, and store the IP port information of the target simulation service class in the registration center, so that the registration center may store the IP port information and be used to respond to a service call request of the test terminal to the target simulation service class. The registry stores the IP port information of a plurality of registered analog service classes. The simulation service class comprises service information, the service corresponding to the service information comprises at least one corresponding method information, the at least one method information can correspond to at least one input message template, and each input message template comprises an input message field, input message content corresponding to the input message field and message content corresponding to the input message. For example, an input message template contains an input message field and input message content corresponding to the input message field "{" a ":1," b ":2," c ": {" d ":3} }", and message content corresponding to the input message: "{" msg ": match template 1" } ".
The registry may be a Zookeeper, and in Dubbo, the Zookeeper serves as a registry for a service producer and a service consumer, and provides a publish/subscribe service. The service producer registers the IP port information of the service provided by the service producer to the Zookeeper registration center, the service consumer searches which producers of the corresponding service exist in the registration center before calling the service, and after acquiring the detailed information of the service producer, for example, after acquiring the IP port information of the target simulation service class, the service consumer calls the content and data of the service producer. The Dubbo is a distributed service framework, and aims to provide a high-performance and transparent RPC (Remote Procedure Call) Remote service calling scheme, and the core of the Dubbo comprises Remote communication, cluster fault tolerance and automatic discovery. The service information may be a service existing in a Dubbo distributed service framework, and when the test end needs to invoke the service in the Dubbo, the service information may be performed in a dynamic proxy manner, and a proxy manner created by the proxy class during program running is called a dynamic proxy. The implementation class is dynamically specified by code, as it is not known which service implementation class to expose when creating the Dubbo service configuration class. When the Dubbo service needs to be called by the outside, the proxy class receives the request and calls a specific method of the implementation class.
The service simulation method can be used in the financial or other fields, an input message template is generated according to the service information to be simulated, the simulation method information and the method input parameter and is stored in the database, a target simulation service class is generated according to the service information to be simulated and the method information to be simulated, and the IP port is stored in the registration center so as to respond to the service calling request aiming at the target simulation service class by using the IP port information. The registry stores IP port information of a plurality of analog service classes, and each analog service class comprises service information and method information. Compared with the traditional mode of compiling the simulation service in real time after manually intercepting the request, the scheme carries out message matching of service simulation based on the simulation service class registered in the registration center in advance, and improves the simulation efficiency.
In one embodiment, after storing the IP port information corresponding to the target analog service class in the registry, the method further includes: receiving a service calling request sent by a testing end; the service calling request comprises service information to be called, method information to be called corresponding to the service information to be called and method parameters corresponding to the method information to be called; when the service information to be called and the method information to be called are a target service and a target method contained in a target simulation service class, acquiring IP port information of the corresponding registered target simulation service class from a registration center, calling the target simulation service class according to the IP port information, acquiring at least one input message template corresponding to the target method information from a database by the target simulation service class, matching the method with the at least one input message template, acquiring a service calling result corresponding to a service calling request according to a matching result, and returning the service calling result to a testing end.
The testing end can be a device held by a user, an application program can exist in the testing end, and the application program can perform service calling test by calling corresponding services in the server. However, the service that the application program needs to call in the server may not be called, for example, the developed code of service 1 needs to remotely call service 2, and service 2 cannot be completed or is not deployed in the current environment in time, so that service 1 cannot perform interface test, and at this time, service 2 needs to perform service simulation mock. Wherein, mock refers to simulation, that is, simulating information returned by an interface, and replacing the information which needs to be returned by the existing information, thereby realizing the test of the service 1 code. That is, the server may be configured with the simulation service class in advance, so that the simulation service class responds when the test end invokes the corresponding service.
In the calling test process, the test end can send a service calling request to the server, the server can receive the service calling request sent by the test end and detect the service information to be called and the method information to be called based on the service calling request, when the server determines that the service information to be called and the method information to be called are the target service and the target method contained in the target simulation service class, the server can search the corresponding IP port from the registration center and obtain the corresponding simulation service based on the IP port. The service calling request comprises service information to be called, method information to be called corresponding to the service information to be called and method access parameters corresponding to the method information to be called. The server may determine the information that needs to be returned by the simulation service class based on the input parameters.
The method entry parameter may be an input parameter corresponding to the information of the method to be called, after the server obtains the IP port information of the target simulation service class based on the query, the server may send a service calling request to the target simulation service class based on the IP port information, and the target service class determines the information of the target method corresponding to the information of the method to be called based on the service calling request. Wherein the target method information corresponds to at least one input message template. The input message template comprises message parameters, the input message template can be stored in a database, the server can obtain a corresponding registered target IP port of a target simulation service class from a registry according to a service calling request, obtain the registered target simulation service class corresponding to the service calling request of the target IP port, obtain at least one input message template corresponding to target method information from the database by the target simulation service class, and the server can utilize the target simulation service class to perform parameter matching on the method corresponding to the method information to be called and the at least one input message template participating in the obtained target method information, so as to determine the target input message template matched with the method parameters in the plurality of input message templates.
The service to be called may include a name of the service to be called and a version of the service to be called, and the method information to be called includes the name of the method to be called. The server can determine the target method information according to the name of the service to be called, the version of the service to be called and the name of the method to be called. In addition, in one embodiment, acquiring IP port information of a corresponding registered target emulated service class from the registry includes: and inquiring the IP port information of the registered target simulation service class in the registration center according to the name and the version of the service to be called in the service calling request. In this embodiment, the server may obtain service information to be called in the service calling request, where the service information to be called includes a name of the service to be called and a version of the service to be called, and the server may query a registration center according to information such as the service to be called and the version of the service to be called, obtain IP port information of a registered target simulation service class in the registration center, where the name of the registered target simulation service class is consistent with the name of the service to be called and is consistent with the version of the service version to be called, and use a simulation service class corresponding to the IP port information as the registered target simulation service class corresponding to the service calling request. Because the target simulation service class includes a plurality of methods, the server can query the methods according to the names of the methods to be called, and obtain the methods in the registered target simulation service class, which are consistent with the names of the methods to be called, as the target method information. Thus, the server can obtain at least one input message template contained in the target method information.
Specifically, the input message template may include an input message and message contents, where the input message includes an input message field and input message contents corresponding to the input message field, the method entry may be equivalent to a field and field contents, and the server may match the method entry with the input message in the input message template. For example, an input message template may include input messages "{" a ":1," b ":2," c ": {" d ":3} }", and the message content corresponding to the input message: "{" msg ": match template 1" } ". Then the input message may be considered to match the input message template when the fields and field contents in the method arguments are both fields in "{" a ":1," b ":2," c ": {" d ":3} }".
When the at least one input message template is multiple, the input message template comprises priority. The server can match the above method parameters with each input message template respectively. For example, in one embodiment, if there are multiple input message templates, performing parameter matching on at least one input message template of the target method information participating in the target simulation service class, and determining a target input message template matching with the method participation in the at least one input message template, includes: acquiring a plurality of input message templates in target method information and the priority of each input message template; and performing parameter matching on the method entry participation input message templates according to the sequence of the priority from high to low, and taking the first input message template matched with the method entry participation as a target input message template. In this embodiment, the server may match the above method with multiple input message templates. The server may first obtain a plurality of input message templates in the target method information and a priority of each input message template. The priority of the input message template can be set according to actual needs. The server can match the method entries with each input message template according to the priority of the input message templates from high to low. The server may use the first input message template matched with the method parameter as the target input message template.
Specifically, the method entry parameter may be "{" a ": 1", "b": 2"," c ": {" d ":3} }", and the server may analyze the method entry parameter and the input message template into the same key-value key value pair data through the target simulation service class, and if all matched input message templates exist, take the input message template as the target input message template, and return the Mock message corresponding to the target input message template. For the above method, the corresponding key value pair is "a =1, b =2, c, d =3", if there is an input message template 1, the priority thereof is 1, the content of the input message template 1 is "{" c ": {" d ":4} }", the corresponding key value pair is "c, d =4", the message content of the input message template 1 is "{" msg ": matching template 1" } "; an input message template 2, the priority of which is 5, the content of the input message template 2 is "{" c ":" { "d":3} } ", the corresponding key value pair is" c, d =3", the message content of the input message template 2 is" { "msg": matching template 2"}"; and inputting a message template 3, wherein the priority of the message template 3 is 9, the content of the message template 3 is ' { "b ': 2, ' c ' {" d ': 3} } ', the corresponding key value pair is ' b =2, c, d =3 ', and the message content of the message template 3 is ' { "msg ': 3 ' }. Wherein the priority decreases as the number increases. The target simulation service class can be matched from high to low according to the priority, firstly, the method is entered and compared with the input message template 1, the target simulation service class can detect that the values of c and d are not equal, therefore, the matching of the method entry and the input message template 1 fails, then, the target simulation service class can be matched with the input message template 2, and the target simulation service class can detect that the input message template 2 contains all key value pairs in the method entry, therefore, the target simulation service class can determine that the input message template 2 is the target input message template. Therefore, the target simulation service class can acquire the message content "{" msg ": matching template 2" } "of the input message template 2 as the returned target message. Although the input message template 3 is also matched with the method parameters, the priority of the input message template 3 is lower than that of the input message template 2, and the input message template 2 is matched with the method parameters and returns the corresponding target message, so that the target simulation service class can finish the subsequent matching.
The target simulation service class can also return target message parameters in the target input message template to the test end as service calling results. The target input message template may be an input message template matched with the method parameters. The input message template includes a target message parameter corresponding to the input message, for example, the above-mentioned "{" msg ": matching template 2" } ", which may be regarded as a target message parameter. After the target simulation service class obtains the target input message template, the target message parameter in the target message template can be used as the service calling result of the service calling request and returned to the test end. The test end can configure the target message parameters in the webpage, so that service configuration can be performed in a simple interactive mode.
In one embodiment, further comprising: acquiring service information to be simulated, method information corresponding to the service information to be simulated and an input message template corresponding to the method information; and generating a simulation service class according to the service information to be simulated, the method information and the input message template.
In this embodiment, the server may generate the simulation service class in advance. The IP port information of the emulated service class may be stored in the registry of the server. The server can obtain the service information to be simulated, the method information corresponding to the service information to be simulated and the input message template corresponding to the method information. The information of the service to be simulated, the information of the method and the template of the input message can be input in a webpage of the testing end by a user and sent to the server by the testing end to obtain the information of the input message. The server may register the information to be simulated, for example, the server may register a simulation service class according to the information about the service to be simulated, the method information corresponding to the information about the service to be simulated, and the input message template, and store the IP port information of the simulation service class in a registration center, thereby implementing registration of the simulation service. The server can obtain various service information as service information to be simulated, and can also obtain various method information as method information corresponding to the service information to be simulated. For example, in an embodiment, acquiring service information to be simulated, method information corresponding to the service information to be simulated, and an input packet template corresponding to the method information includes: acquiring a service name and a service version of a service to be simulated as service information to be simulated; and acquiring a method name, a method entry parameter type and a method message type corresponding to the service information to be simulated as the information of the method to be simulated.
In this embodiment, the server may obtain a service name and a service version of the service to be simulated as the service information to be simulated, one service may include at least one method, and the server may further obtain a method name, a method entry type, and a method packet type corresponding to the service information to be simulated as the method information corresponding to the service information to be simulated. The method entry parameter type is a data type of a method input parameter, and the method message type is a message type in an input message template corresponding to the method information. The server may generate an input message template based on the service information and the method information, for example, in an embodiment, the generating an input message template corresponding to the target simulation service class according to the service information to be simulated, the method information to be simulated, and the method parameter, and storing the input message template in the database includes: and acquiring a template input message corresponding to the method input type and a template message corresponding to the method message type, generating an input message template corresponding to the target simulation service type according to the service information to be simulated, the method information to be simulated, the template input message and the template message corresponding to the template input message, and storing the input message template in a database. In this embodiment, the server may obtain a template input message corresponding to the type of the method entry, for example, { "c": { "d":4} } and obtain a template message corresponding to the type of the method message, for example, { "msg": matching template 1 "}. And the server may generate an input message template corresponding to the target simulation service class according to the template input and the template message corresponding to the template input message. For example, an input message template 1 is generated that contains input messages "{" c ": {" d ":4} }", and message content "{" msg ": a" match template 1"}".
Specifically, the user may configure the service information, the method information, the input message template, and other information on the test end, and send the information to the server after configuration is completed, and the server registers and generates the corresponding simulation service class. For example, a Mock service front-end configuration module may be configured in the test end, and a user may input a service name, a service version, a method name and a method type of a desired Mock to the webpage end through the Mock service front-end configuration module. The configuration can be quickly generated through database import, excel import and other modes, so that the configuration workload of a user is reduced. The user can configure an input message matching template and a corresponding return message of the mock method at the webpage end, and simultaneously configure the template matching priority. The setting of the priority is based on the service processing logic of the current service method, and the test end can rank the template priority of the service processing before. And the web page side in the test side automatically judges whether the input information is complete and legal, and transmits the service information, the method information and the input message template information to a Mock service registration preparation module in the server through the web page side after the input information passes the verification. The Mock service registration preparation module is used for preprocessing the service information, the method information and the input message template to be simulated.
Through the embodiment, the server can obtain various types of service information as the service information to be simulated and various types of method information as the method information corresponding to the service information to be simulated, and can obtain the pre-configured input message template based on the method information, so that the server can register and generate the simulation service class based on the information. Service simulation is carried out based on the simulation service class, and the efficiency of service simulation is improved.
In one embodiment, generating a target simulation service class according to the service information to be simulated and the method information to be simulated includes: converting the service information to be simulated from the state to be registered into the state in registration; generating a custom class loader corresponding to the service information being registered and service information object configuration of the dubbo distributed service framework; generating a simulation service interface class and a simulation service implementation class according to the service name and method information in the service information which is registered; and storing the custom class loader, the service information object configuration, the simulation service interface class and the simulation service implementation class into the service configuration information to obtain the simulation service class.
In this embodiment, the service information obtained from the test end may be a service that has not been registered yet, and needs to be registered in a registration center of the server, and when a service to be registered needs to be registered, the server may convert the service information to be simulated from a state to be registered into a state in which the service is being registered. The server can realize the conversion of the registration state by converting the setting position of the service information to be simulated. For the service in the registration state, the server can generate a custom class loader corresponding to the service information in the registration and the service information object configuration of the distributed service framework. The custom class loader may be referred to as thisscustlasloader, the dubbo service is a distributed service framework, and the service information object configuration may be referred to as thissserviceconfig. After the server generates the loader and the configuration, a simulation service interface class and a simulation service implementation class can be generated according to the service name and the method information in the service information which is registered. The simulation service interface class declares the definition of a method owned by the service, and the interior of the method is empty; the simulation service implementation class declares the same method of the interface class, and the method is internally implemented; this writing is intended to support the same interface, with a number of different implementation mechanisms. After the server obtains the simulation service interface class and the simulation service implementation class, the custom class loader, the service information object configuration, the simulation service interface class and the simulation service implementation class may be stored in service configuration information, so as to obtain the simulation service class.
Specifically, the registration process may be performed by a Mock service registration module in the server, and when the server registers the analog service class, the server may first create a class loader shared by the current Mock analog service through the Mock service registration module, and set the current thread class loader as the thiscustomclass loader, so that the server may complete the step of loading the analog service class, and if the loader is not set, the server may have a problem that the class cannot be found. The server may create a dubbo service information object corresponding to the current emulated service class, i.e. the thisseviceconfig described above, and the server may also initialize its registry configuration, application configuration, protocol configuration, method configuration, and other single configurations, for example, the restful option, which may be used for enabling the dubbo service to support HTTP mode invocation at the same time. The registration center configuration, the application configuration, the protocol configuration and the method configuration are the minimum configuration of the dubbo service, and only if the configuration is complete, the registration center can be successfully registered on the dubbo registration center and called, so that the server can put the thisCustomSchlassLoader and the thisServiceConfig as attribute values into the ServiceConfigInfo, namely, the attribute values are stored in the service configuration information. And the server can also create a Mock service class, namely the simulation service class comprises a Mock service interface class and a Mock service implementation class. When the creation is completed, the server may store the above Mock service interface class and Mock service implementation class in the service configuration information. Thereby completing registration of the analog service class.
According to the embodiment, the server can realize the registration premise of the simulation service class through the generated custom class loader and the service information object configuration, and generate the simulation service class comprising the interface class and the implementation class based on the service information, so that the server can perform access test based on the simulation service class, and the service simulation efficiency is improved.
In one embodiment, converting the service information to be emulated from the state to be registered to the state being registered comprises: storing the service information to be simulated into an interface information cache; and inquiring real-time refreshing interface information by the idle asynchronous thread based on the service information to be simulated, if the service information to be simulated does not exist in the real-time refreshing interface information, removing the service information to be simulated from the interface information cache, and adding the service information to be simulated to the real-time refreshing interface information to obtain the service information in the registration state.
In this embodiment, the service information acquired by the server from the test end may be a to-be-registered state, and the server may convert the to-be-registered service information into a registration state, so that registration of the simulation service class may be performed. The server may store the obtained service information to be emulated into an interface information cache, where the interface information cache may be an interface info cache of a securrentmap type, and the securrentmap type may solve the problem of thread security under high concurrency. And the idle asynchronous thread inquires real-time refreshing interface information based on the service information to be simulated, and detects whether the acquired service information to be simulated exists. The real-time refreshing interface information can be called currentRefreshInterfaceInfo, if the currentRefreshInterfaceInfo exists, the same Mock service is registered, the thread gives up registration, and the conflict caused by the fact that a plurality of threads register the same Mock service at the same time is avoided; if the service information to be simulated does not exist, the server can remove the service information to be simulated from the interface information cache, which indicates that the service information to be simulated needs to be registered, and the server adds the service information to be simulated to the real-time refreshing interface information, for example, adds the IP port information of the service to be simulated to the real-time refreshing interface information, so as to obtain the service information in the registration state.
Specifically, a Mock service registration preparation module is arranged in the server, and the server can receive the service information to be simulated, the method information and the template information through the Mock service registration module and persistently store the service information to be simulated, the method information and the template information in a database. When registering the analog service class, the server may add the information of the service to be simulated, which is configured at the front end by the user, to the ConcurrentMap-type interfaceInfo cache as the Mock service to be registered, with the service name + service version as a key, and may submit an asynchronous thread task and wait for an idle thread to perform Mock service registration. When the idle thread obtains the simulation service registration task, the server can inquire whether the service name and the service version key exist in currentRefreshInterfaceInfo of the ConcurrentMap type through the idle thread. Wherein, the currentRefreshInterfaceInfo is used for saving the currently registered Mock service. If the service name does not exist in the multimedia service class, the server may obtain and remove the service information to be simulated corresponding to the service name and the service version from the interworking infocache, and then add the service information to be simulated corresponding to the service name and the service version to the currentRefreshInterfaceInfo, which represents that the service information to be simulated is changed from the state to be registered to the state being registered, and perform registration of the service information, for example, the server may transmit the service information in the state being registered to a Mock service registration module, which may be disposed in the server and used for registering a Mock service class.
By the embodiment, the server can realize the conversion of the registration state of the service information to be simulated by transferring the storage position of the service to be simulated, so that the server can identify the service information in the registration state and register the simulation service class of the service information, and the efficiency of service simulation is improved.
In an embodiment, after converting the service information to be simulated from the state to be registered into the state being registered, before generating the service information object configuration of the custom class loader and the distributed service framework corresponding to the service information being registered, the method further includes: removing old version simulation service registration information corresponding to the service information which is being registered from the service configuration information cache, and performing revocation exposure on the old version simulation service registration information; and if the IP port information of the service information which is registered does not exist in the online registration center, determining to generate the custom class loader corresponding to the service information which is registered and the service information object configuration of the distributed service framework.
In this embodiment, after the server converts the service information to be simulated from the state to be registered into the state being registered, the server may perform validity detection on the service information in the state being registered before generating the simulation service class. The server may remove the old version simulation service registration information corresponding to the service information being registered from the service configuration information cache, and the server may also revoke the old version simulation service registration information. The service configuration information cache may be referred to as serviceconfiglnfomap, and the emulated service registration information may be referred to as serviceconfiglnfo. The serviceconfiglnfomap is a concurrent hash mapping (ConcurrentHashMap) which takes a service name and a service version as keys and takes the serviceConfigInfo as a value, and saves the successfully registered Mock service information. The ServiceConfigInfo is a custom type, and includes two attributes, serviceConfig and CustomClassLoader. The ServiceConfig is a main carrier for registration of the dubbo service, and various Mock service attributes can be configured.
The server is provided with a corresponding registration center, the server can acquire the online registration center as the registration center corresponding to the service information being registered, and detect whether the service information being registered exists in the online registration center, if not, the server can determine to generate the service information object configuration of the custom class loader and the distributed service framework corresponding to the service information being registered. Specifically, the server can perform judgment processing on the address of the registration center needing to be registered, filter off-line registration centers and avoid cycle waiting caused by off-line registration of the Mock service registration. And the server can also inquire an online registration center, if the Dubbo service of the corresponding service information exists in the registration center, the server can skip the registration of the service information which is being registered, and the problem of coexistence of true and false services is avoided. Wherein the dubbo service of the service information represents a real service class, not a simulated service class.
Through the embodiment, the server can detect the registration validity of the service in the registration state, thereby avoiding the failure or repeated registration of the registration simulation service and improving the efficiency of service simulation.
In one embodiment, generating a simulation service interface class and a simulation service implementation class according to a service name and method information in service information being registered includes: generating a simulation service interface class object and a simulation service realization class object through a Java byte code class library according to the service name; adding a non-parameter constructor in the simulation service realization class object, and initializing the simulation service realization class added with the non-parameter constructor; respectively adding method contents corresponding to the method information into the simulation service interface class object and the simulation service realization class object; and compiling the simulation service interface class object and the simulation service implementation class object added with the method content into a simulation service interface class file and a simulation service implementation class file respectively, and loading the simulation service interface class file and the simulation service implementation class file through a custom class loader to obtain a simulation service interface class and a simulation service implementation class.
In this embodiment, the server may obtain the simulation service class by generating the simulation service interface class and the simulation service implementation class. In the generating process, the server may generate the simulation service interface class object and the simulation service implementation class object through the Java bytecode class library according to the service name of the service information being registered. The simulation service interface class object may be referred to as ctClass, and the simulation service implementation class object may be referred to as ctImplClass. The server may add a non-parameter constructor to the simulation service implementation class object, and initialize the simulation service class to which the non-parameter constructor is added. In the java definition, a class at least needs to contain a constructor to be initialized by a java virtual machine; since ctImplClass is an empty Mock service implementation class, a parameterless constructor needs to be added so that it can be initialized. The server can add the method contents corresponding to the method information into the simulation service interface class object and the simulation service implementation class object respectively, compile the simulation service interface class object and the simulation service implementation class object added with the method contents into a simulation service implementation class file of the simulation service interface class file respectively, and load the simulation service interface class file and the simulation service implementation class file through the custom class loader, so that the simulation service interface class and the simulation service implementation class are obtained.
Specifically, as shown in fig. 3, fig. 3 is a flowchart illustrating a step of creating a simulation service class in one embodiment. In dubbo, the configuration file and the calling statement may use a service interface class, and the service consumer calls the service provider through the service interface class, and the service provider finds a corresponding service interface implementation class according to the service interface class to execute the final service logic. The service consumer may be an application program in the test terminal, and the service provider may be a simulation service class in the registry in the server. The server can generate a Mock service interface class object ctClass through classPool. MakeInterface of Java byte code library Javassist according to the service name provided by the service information, and generate a Mock service interface through classPool. MakeClass to realize the class object ctImplClass. The Mock service interface class is the simulation service interface class, and the Mock service interface implementation class is the simulation service implementation class. The server adds a parameterless constructor to the ctImplClass described above, so that it can be initialized by calling the newInstance method. The server can also splice method contents into ctClass and ctImplClass according to a method information List in the registered service information, and uniformly convert all the methods into List types after receiving the input parameters and transmit the List types to a Mock message matching module in the server, and then analyze the Mock messages returned by the matching module into the output parameter types returned by the method statement. Wherein, because: javassist does not support generic, dynamic parameters, boxing and unpacking, so the server needs to convert the base type into a package type and add it to the List. The server may compile the above ctClass, ctImplClass as a class file into a class load path. In JAVA, a class can be loaded in the same loader only once, and the attribute of the Mock service can be modified, so that the requirement of multiple times of loading exists; therefore, the user-defined class loader is needed, one Mock service class is used independently, the old class loader is destroyed after the attribute of the Mock service class is modified, and a new class loader is regenerated to bear a new Mock service class; the Mock service class is loaded into the class context before it can invoke other service functions in the class context.
The server may load the Class file to the current Class context through the custom Class loader, by using a ctclass. Therefore, the server can obtain the instance of the Mock service implementation class through the implClass, that is, the analog service implementation class file is injected into the thissserviceconfig, so as to realize that the dubbo service implementation class proxy points to the Mock service instance realized by the server, and the actual codes can be as follows: thissserviceconfig.setref (implclass.newinstant ()). The server can call the export method of the thissserviceconfig, register the Mock service information, namely the analog service class, in the registration center, and finally place the ServiceConfigInfo in the cache ServiceConfigInfo map for storage, so that the Mock service can be stopped through the cache. At this time, any consumer subscribed to the registry can call the Mock service, and the Mock service registration is completed successfully.
According to the embodiment, the server can generate the simulation service interface class and the simulation service implementation class based on the Java byte code class library so as to obtain the simulation service class, service simulation is realized through the simulation service class, a service interface dependence package is not required to be introduced, service information can be refreshed to the registration center in real time only by modifying the service information at the webpage end by a user, and the efficiency of service simulation is improved.
In one embodiment, as shown in fig. 4, fig. 4 is a flow chart of a service simulation method in another embodiment. In this embodiment, the analog service class may be referred to as a Mock service, and the server may be provided with a Mock service registration preparation module, a Mock service registration module, a registration center, and a Mock message matching module. And a Mock service front-end configuration module can be arranged in the test end. When the simulation service class is generated, a user can input Mock service information in a Mock service front-end configuration module, the integrity and the legality of the Mock service information are verified through the Mock service front-end configuration module, the Mock service information is sent to a Mock service registration preparation module in a server after the verification is passed, the Mock service registration preparation module receives service information, method information and template information, the service information, the method information and the template information are stored in a database in a lasting mode, the Mock service to be registered is converted into the Mock service in the registration state, the server can send the Mock service information in the registration state to the Mock service registration module, and an asynchronous registration task is called.
The server receives the Mock service information needing to be registered through the Mock service registration module, creates a Mock service interface class and a Mock service implementation class after legality detection is carried out on the Mock service information, integrates the Mock service interface class and the Mock service implementation class into the Mock service class, completes registration of the Mock service class, and can register IP port information of the Mock service class in the registration center, so that any service consumer can subscribe the Mock service, and calling of the Mock service is realized through the IP port information registered in the registration center.
When the test end tests the service, the server can receive the service information to be called, and the method entry parameter information in the service information is matched with each input message in each simulation service class in a simulation mode through the Mock message matching module, so that the target message of the corresponding target input message template is obtained, and the target message is returned to the test end.
Through the embodiment, the user can issue the Mock service to the registration center in real time only by performing configuration operation on the webpage, the Mock service is realized, the Mock service does not need to be deployed independently, the platform is used for unified management, and the resource consumption caused by the Mock service deployment is greatly reduced. And the server performs service simulation message matching based on the pre-registered simulation service class in the registration center, so that the simulation efficiency is improved.
It should be understood that, although the steps in the flowcharts related to the embodiments as described above are sequentially displayed as indicated by arrows, the steps are not necessarily performed sequentially as indicated by the arrows. The steps are not performed in the exact order shown and described, and may be performed in other orders, unless explicitly stated otherwise. Moreover, at least a part of the steps in the flowcharts related to the embodiments described above may include multiple steps or multiple stages, which are not necessarily performed at the same time, but may be performed at different times, and the execution order of the steps or stages is not necessarily sequential, but may be rotated or alternated with other steps or at least a part of the steps or stages in other steps.
Based on the same inventive concept, the embodiment of the present application further provides a service simulation apparatus for implementing the service simulation method. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme described in the above method, so specific limitations in one or more embodiments of the service simulation device provided below can be referred to the limitations of the service simulation method in the foregoing, and details are not described here.
In one embodiment, as shown in fig. 5, there is provided a service simulation apparatus including: a data preparation module 500 and a registration module 502, wherein:
the data preparation module 500 is configured to obtain service information to be simulated, information of a method to be simulated corresponding to the service information to be simulated, and method parameters corresponding to the information of the method to be simulated.
The registration module 502 is configured to generate a target simulation service class according to the service information to be simulated and the method information to be simulated, store IP port information corresponding to the target simulation service class in a registration center, generate an input message template corresponding to the target simulation service class according to the service information to be simulated, the method information to be simulated and method parameters, and store the input message template in a database, so that the registration center stores the IP port information to respond to a service call request of a test terminal to the target simulation service class; the registration center stores IP port information of a plurality of analog service classes, and each analog service class comprises service information and method information corresponding to the service information.
In one embodiment, the above apparatus further comprises: the simulation module is used for receiving a service calling request sent by the test end; the service calling request comprises service information to be called, method information to be called corresponding to the service information to be called and method parameters corresponding to the method information to be called; when the service information to be called and the method information to be called are a target service and a target method contained in a target simulation service class, acquiring IP port information of the corresponding registered target simulation service class from a registration center, calling the target simulation service class according to the IP port information, acquiring at least one input message template corresponding to the target method information from a database by the target simulation service class, matching the method with the at least one input message template, acquiring a service calling result corresponding to a service calling request according to a matching result, and returning the service calling result to a test terminal; the target method information corresponds to the method information to be simulated.
In one embodiment, the above apparatus further comprises: the acquisition module is used for acquiring the service name and the service version of the service to be simulated as the service information to be simulated; and acquiring a method name, a method entry parameter type and a method message type corresponding to the service information to be simulated as the information of the method to be simulated.
In an embodiment, the data preparation module 500 is specifically configured to obtain a template input packet corresponding to the method entry type and a template packet corresponding to the method packet type, generate an input packet template corresponding to the target simulation service class according to the service information to be simulated, the method information to be simulated, the template input packet and the template packet corresponding to the template input packet, and store the input packet template in the database.
In an embodiment, the registration module is specifically configured to convert the service information to be simulated from a state to be registered into a state being registered; generating a custom class loader corresponding to the service information being registered and service information object configuration of the dubbo distributed service framework; generating a simulation service interface class and a simulation service implementation class according to the service name and method information in the service information which is registered; and storing the custom class loader, the service information object configuration, the simulation service interface class and the simulation service implementation class into the service configuration information to obtain the simulation service class.
In an embodiment, the registration module is specifically configured to store the service information to be simulated in the interface information cache; and inquiring real-time refreshing interface information by the idle asynchronous thread based on the service information to be simulated, if the service information to be simulated does not exist in the real-time refreshing interface information, removing the service information to be simulated from the interface information cache, and adding the service information to be simulated to the real-time refreshing interface information to obtain the service information in the registration state.
In an embodiment, the registration module is specifically configured to remove, from the service configuration information cache, old version simulation service registration information corresponding to service information being registered, and revoke and expose the old version simulation service registration information; and if the IP port information of the service information which is registered does not exist in the online registration center, determining to generate the custom class loader corresponding to the service information which is registered and the service information object configuration of the distributed service framework.
In an embodiment, the registration module is specifically configured to generate a simulation service interface class object and a simulation service implementation class object through a Java bytecode class library according to a service name; adding a non-parameter constructor in the simulation service realization class object, and initializing the simulation service realization class added with the non-parameter constructor; respectively adding method contents corresponding to the method information into the simulation service interface class object and the simulation service realization class object; and compiling the simulation service interface class object and the simulation service implementation class object added with the method content into a simulation service interface class file and a simulation service implementation class file respectively, and loading the simulation service interface class file and the simulation service implementation class file through a custom class loader to obtain a simulation service interface class and a simulation service implementation class.
In an embodiment, the simulation module is specifically configured to query, according to the name of the service to be called and the version of the service to be called in the service invocation request, IP port information of a corresponding registered target simulation service class in the registry.
In an embodiment, the simulation module is specifically configured to obtain, by the target simulation service class, at least one input packet template corresponding to the target method information from the database, perform parameter matching on the at least one input packet template of the target method information in the target simulation service class, and determine a target input packet template matching the method entry in the at least one input packet template; and returning the target message parameters in the target input message template to the test end as a service calling result.
In an embodiment, the matching module 502 is specifically configured to obtain a plurality of input packet templates in the target method information and a priority of each input packet template; and performing parameter matching on the method entry participation input message templates according to the sequence of the priority from high to low, and taking the first input message template matched with the method entry participation as a target input message template.
The modules in the service simulation device can be wholly or partially implemented by software, hardware and a combination thereof. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
It should be noted that the method and apparatus determined in the present disclosure may be used in the financial field to implement service simulation in the business of distributed services, and may also be used in any field other than the financial field to perform service simulation.
In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as shown in fig. 6. The computer device includes a processor, a memory, and a network interface connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. The database of the computer device is used for storing data such as simulation service information and the like. The network interface of the computer equipment is used for communicating with an external testing end through network connection. The computer program is executed by a processor to implement a service simulation method.
Those skilled in the art will appreciate that the architecture shown in fig. 6 is merely a block diagram of some of the structures associated with the disclosed aspects and is not intended to limit the computing devices to which the disclosed aspects apply, as particular computing devices may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
In an embodiment, a computer device is provided, comprising a memory in which a computer program is stored and a processor which, when executing the computer program, implements the service simulation method described above.
In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, which computer program, when being executed by a processor, carries out the above-mentioned service simulation method.
In an embodiment, a computer program product is provided, comprising a computer program which, when executed by a processor, implements the service simulation method described above.
It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) referred to in the present application are information and data authorized by the user or sufficiently authorized by each party.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware instructions of a computer program, which can be stored in a non-volatile computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. Any reference to memory, database, or other medium used in the embodiments provided herein may include at least one of non-volatile and volatile memory. The nonvolatile Memory may include Read-Only Memory (ROM), magnetic tape, floppy disk, flash Memory, optical Memory, high-density embedded nonvolatile Memory, resistive Random Access Memory (ReRAM), magnetic Random Access Memory (MRAM), ferroelectric Random Access Memory (FRAM), phase Change Memory (PCM), graphene Memory, and the like. Volatile Memory can include Random Access Memory (RAM), external cache Memory, and the like. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM), among others. The databases involved in the embodiments provided herein may include at least one of relational and non-relational databases. The non-relational database may include, but is not limited to, a block chain based distributed database, and the like. The processors referred to in the embodiments provided herein may be general purpose processors, central processing units, graphics processors, digital signal processors, programmable logic devices, quantum computing based data processing logic devices, etc., without limitation.
The technical features of the above embodiments can be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the above embodiments are not described, but should be considered as the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above-mentioned embodiments only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the present application. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present application shall be subject to the appended claims.
Claims (14)
1. A method for service simulation, the method comprising:
acquiring service information to be simulated, information of a method to be simulated corresponding to the service information to be simulated and method access parameters corresponding to the information of the method to be simulated;
generating a target simulation service class according to the service information to be simulated and the method information to be simulated, storing IP port information corresponding to the target simulation service class in a registration center, generating an input message template corresponding to the target simulation service class according to the service information to be simulated, the method information to be simulated and the method input parameter, and storing the input message template in a database so that the registration center stores the IP port information to respond to a service calling request of a test terminal to the target simulation service class;
the registration center stores IP port information of a plurality of analog service classes, and each analog service class comprises service information and method information corresponding to the service information.
2. The method of claim 1, wherein after storing the IP port information corresponding to the target emulated service class in the registry, the method further comprises:
receiving a service calling request sent by a testing end; the service calling request comprises service information to be called, method information to be called corresponding to the service information to be called and method entry parameters corresponding to the method information to be called;
when the service information to be called and the method information to be called are a target service and a target method contained in the target simulation service class, acquiring IP port information of the corresponding registered target simulation service class from a registration center, calling the target simulation service class according to the IP port information, acquiring at least one input message template corresponding to the target method information from a database by the target simulation service class, matching the method with the at least one input message template, acquiring a service calling result corresponding to the service calling request according to the matching result, and returning the service calling result to the testing end; the target method information corresponds to the method information to be simulated.
3. The method of claim 1, further comprising:
acquiring a service name and a service version of a service to be simulated as service information to be simulated;
acquiring a method name, a method entry parameter type and a method message type corresponding to the service information to be simulated as the information of the method to be simulated;
generating an input message template corresponding to the target simulation service class according to the service information to be simulated, the method information to be simulated and the method input parameters, and storing the input message template in a database, wherein the method comprises the following steps:
acquiring a template input message corresponding to the method input type and a template message corresponding to the method message type, generating an input message template corresponding to the target simulation service type according to the service information to be simulated, the method information to be simulated, the template input message and the template message corresponding to the template input message, and storing the input message template in a database.
4. The method according to claim 3, wherein the generating a target simulation service class according to the service information to be simulated and the method information to be simulated comprises:
converting the service information to be simulated from a state to be registered into a state in which the service information is registered;
generating a custom class loader corresponding to the service information being registered and service information object configuration of the dubbo distributed service framework;
generating a simulation service interface class and a simulation service implementation class according to the service name and method information in the service information which is registered;
and storing the user-defined class loader, the service information object configuration, the simulation service interface class and the simulation service implementation class into service configuration information to obtain a target simulation service class.
5. The method of claim 4, wherein the converting the service information to be emulated from the state to be registered to the state to be registered comprises:
storing the service information to be simulated into an interface information cache;
and inquiring real-time refreshing interface information by the idle asynchronous thread based on the service information to be simulated, if the service information to be simulated does not exist in the real-time refreshing interface information, removing the service information to be simulated from interface information cache, and adding the service information to be simulated to the real-time refreshing interface information to obtain the service information in the registered state.
6. The method according to claim 4, wherein before generating the service information object configuration of the custom class loader and the distributed service framework corresponding to the service information being registered after converting the service information to be simulated from the state to be registered to the state to be registered, the method further comprises:
removing old version simulation service registration information corresponding to the service information which is being registered from a service configuration information cache, and performing revocation exposure on the old version simulation service registration information;
and if the IP port information of the service information which is being registered does not exist in the online registration center, determining to generate the custom class loader corresponding to the service information which is being registered and the service information object configuration of the distributed service framework.
7. The method of claim 4, wherein generating the emulated service interface class and the emulated service implementation class according to the service name and the method information in the service information being registered comprises:
generating a simulation service interface class object and a simulation service realization class object through a Java byte code class library according to the service name;
adding a non-parameter constructor in the simulation service realization class object, and initializing the simulation service realization class added with the non-parameter constructor;
respectively adding the method content corresponding to the method information into the simulation service interface class object and the simulation service realization class object;
and compiling the simulation service interface class object and the simulation service implementation class object added with the method content into a simulation service interface class file and a simulation service implementation class file respectively, and loading the simulation service interface class file and the simulation service implementation class file through the custom class loader to obtain a simulation service interface class and a simulation service implementation class.
8. The method according to claim 2, wherein the service information to be called comprises a service name to be called and a service version to be called, and the method information to be called comprises a method name to be called; the acquiring IP port information of the corresponding registered target analog service class from the registry includes:
and inquiring the IP port information of the corresponding registered target simulation service class in the registration center according to the service name to be called and the service version to be called in the service calling request.
9. The method of claim 2, wherein the input message template comprises message parameters; the obtaining, by the target simulation service class, at least one input message template corresponding to the target method information from a database, matching the method entry with the at least one input message template, obtaining a service invocation result corresponding to the service invocation request according to the matching result, and returning the service invocation result to the test end includes:
acquiring at least one input message template corresponding to target method information from a database by the target simulation service class, performing parameter matching on at least one input message template participating in the target method information in the target simulation service class, and determining a target input message template matched with the method input parameters in the at least one input message template;
and returning the target message parameters in the target input message template to the test end as a service calling result.
10. The method of claim 9, wherein if there are multiple input message templates, said performing parameter matching on at least one input message template participating in target method information in the target simulation service class, and determining a target input message template in the at least one input message template that matches the method input parameters comprises:
acquiring a plurality of input message templates in the target method information and the priority of each input message template;
and performing parameter matching on the input message templates of the method entries according to the sequence of the priority from high to low, and taking the first input message template matched with the method entries as a target input message template.
11. A service simulation apparatus, the apparatus comprising:
the data preparation module is used for acquiring service information to be simulated, information of a method to be simulated corresponding to the service information to be simulated and method access parameters corresponding to the information of the method to be simulated;
the registration module is used for generating a target simulation service class according to the service information to be simulated and the method information to be simulated, storing IP port information corresponding to the target simulation service class into a registration center, generating an input message template corresponding to the target simulation service class according to the service information to be simulated, the method information to be simulated and the method parameter, and storing the input message template into a database so that the registration center stores the IP port information and responds to a service calling request of a test terminal to the target simulation service class; the registration center stores IP port information of a plurality of analog service classes, and each analog service class comprises service information and method information corresponding to the service information.
12. A computer device comprising a memory and a processor, the memory storing a computer program, characterized in that the processor realizes the steps of the method of any one of claims 1 to 10 when executing the computer program.
13. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the method of any one of claims 1 to 10.
14. A computer program product comprising a computer program, characterized in that the computer program realizes the steps of the method of any one of claims 1 to 10 when executed by a processor.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211412122.2A CN115658543A (en) | 2022-11-11 | 2022-11-11 | Service simulation method, device, computer equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211412122.2A CN115658543A (en) | 2022-11-11 | 2022-11-11 | Service simulation method, device, computer equipment and storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN115658543A true CN115658543A (en) | 2023-01-31 |
Family
ID=85021609
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202211412122.2A Pending CN115658543A (en) | 2022-11-11 | 2022-11-11 | Service simulation method, device, computer equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN115658543A (en) |
-
2022
- 2022-11-11 CN CN202211412122.2A patent/CN115658543A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN111625452B (en) | Flow playback method and system | |
US20180063226A1 (en) | Distributed steam processing | |
CN110058864B (en) | Micro-service deployment method and device | |
US11106641B2 (en) | Supporting graph database backed object unmarshalling | |
CN103092751B (en) | Web application performance test system based on customer behavior model in cloud environment | |
CN108108239A (en) | Method and device for providing service function and computer readable storage medium | |
CN114172966B (en) | Service calling method, service processing method and device under unitized architecture | |
JP2017514218A (en) | Running third-party applications | |
CN113177062A (en) | Data query method and device | |
US10873628B2 (en) | System and method for non-intrusive context correlation across cloud services | |
CN117632372A (en) | Helm-based continuous deployment management method | |
CN113722114A (en) | Data service processing method and device, computing equipment and storage medium | |
CN111324395B (en) | Calling method, device and computer readable storage medium | |
CN112561690A (en) | Method, system, equipment and storage medium for testing credit card staging service interface | |
CN113553250A (en) | Code testing method and device | |
CN116644122A (en) | Data transaction processing method, device, computer equipment and storage medium | |
CN113626001B (en) | API dynamic arrangement method and device based on script | |
CN114567571B (en) | Performance test method, device, electronic equipment and computer readable storage medium | |
CN115658543A (en) | Service simulation method, device, computer equipment and storage medium | |
CN113867776B (en) | Method and device for issuing middle-stage application, electronic equipment and storage medium | |
CN114677114A (en) | Approval process generation method and device based on graph dragging | |
US20220283789A1 (en) | Methods and apparatuses for providing a function as a service platform | |
CN113741868A (en) | Business calculation task processing method and device, computer equipment and storage medium | |
Gao et al. | A security problem in small scale private Ethereum network | |
CN117056028B (en) | Robot simulation platform building method and device, computer equipment and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |