Mock method, device and computer readable storage medium for RPC service

By generating a pseudo-class for implementing the RPC interface and delegating it to the general processing module of the Mock server, the problem of the existing Mock service needing to be redesigned is solved, and fast and flexible RPC interface Mock service configuration is achieved, reducing development and operation and maintenance costs.

CN115268985BActive Publication Date: 2025-10-17CHINA UNIONPAY
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210813993.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-07-11
Publication Date
2025-10-17
Estimated Expiration
2042-07-11

AI Technical Summary

Technical Problem

When existing mock services have similarities in processing flow and functional logic, they still need to be designed and developed from scratch, resulting in a long tool readiness cycle and a lack of universality and promotion value.

Method used

This paper provides a mock method for RPC services. It receives service configuration fragments that follow the RPC framework specification, maps them into configuration class objects, builds a class loader, reflects and analyzes the inheritance relationship and method declarations of the RPC interface class, generates an implementation pseudo-class, and delegates it to the general processing module of the mock server to publish the mock service of the RPC interface.

Benefits of technology

It implements the rapid configuration of RPC interface mock services, ensures service flexibility and efficiency, reduces development and operation and maintenance costs, and supports real-time updates and management.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115268985B_ABST
    Figure CN115268985B_ABST
Patent Text Reader

Abstract

The application provides a Mock method, device and computer readable storage medium for RPC service, the method comprising: receiving a service configuration fragment conforming to an RPC framework specification, mapping the service configuration fragment into a corresponding configuration class object; extracting service element information of the configuration class object, constructing an independent class loader, and loading an RPC interface class and its dependencies; reflecting an inheritance relationship and a public method declaration of the RPC interface class to obtain an analysis and sorting result; using a bytecode operation framework, generating an implementation pseudo class of the RPC interface according to the analysis and sorting result, and delegating interface methods of the implementation pseudo class to a general processing module of a Mock service side; and adding the configuration class object and the implementation pseudo class to a context environment of the RPC framework to publish a Mock service of the RPC interface. Using the above method, a high-flexibility Mock service can be quickly configured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of computers, and in particular relates to a mock method, device and computer-readable storage medium for RPC services. Background Art

[0002] This section is intended to provide a background or context to embodiments of the invention that are recited in the claims. No statement herein is admitted to be prior art by inclusion in this section.

[0003] In today's era of multi-service collaboration, most systems are no longer isolated islands but instead rely on each other. Simultaneously, due to inherent challenges with environmental stability, data preparation, and parallel development across multiple systems, joint debugging and testing requires significant communication and troubleshooting costs. The Mock service was created to address these issues.

[0004] Currently, many mock services still adopt a maintenance model of separate development and deployment. Even though they have many similarities in processing processes and functional logic, every time a new mock service is required, database design and code writing usually have to be started from scratch, which prolongs the tool readiness cycle and lacks universality and promotion value.

[0005] Therefore, how to quickly provide Mock services is an urgent problem to be solved. Summary of the Invention

[0006] In response to the above problems in the prior art, a mock method, device and computer-readable storage medium for RPC service are proposed. By using this method, device and computer-readable storage medium, the above problems can be solved.

[0007] The present invention provides the following solutions.

[0008] In a first aspect, a mock method for an RPC service is provided, comprising: receiving a service configuration fragment that complies with an RPC framework specification, and mapping the service configuration fragment into a corresponding configuration class object; extracting service element information of the configuration class object, constructing an independent class loader, and loading an RPC interface class and its dependencies; reflectively analyzing the inheritance relationship and public method declarations of the RPC interface class to obtain an analysis and sorting result; utilizing a bytecode operation framework to generate an implementation pseudo class of the RPC interface based on the analysis and sorting result, and delegating the interface methods of the implementation pseudo class to a general processing module of a mock server; and adding the configuration class object and the implementation pseudo class to the context of the RPC framework to publish a mock service of the RPC interface.

[0009] In one embodiment, the service element information includes: a service identifier and an RPC interface class name.

[0010] In an embodiment, the public method declaration includes: return value, calling parameters and exception information.

[0011] In an embodiment, the interface method of the implementation pseudo-class is delegated to the general processing module of the Mock service side, further comprising: merging the method name and method parameters of the interface method into a unified JSON array structure, and delegating to the general processing module.

[0012] In an embodiment, after the interface method of the implementation pseudo-class is delegated to the general processing module of the Mock service side, further comprising: observing whether the implementation pseudo-class of the RPC interface has been generated in real time in the virtual machine and / or whether the calling delegation of the interface method is completed through a diagnostic tool.

[0013] In an embodiment, after the Mock service of the RPC interface is published, the method further comprises: when the RPC request is received, the general processing module of the Mock service side intercepts the RPC request, obtains the corresponding class loader according to the service identifier of the RPC request, and dynamically injects the class loader into the RPC framework; the RPC framework uses the class loader to parse the calling parameters of the RPC request to locate the specified interface method in the corresponding pseudo-class implementation, and delegates the calling of the specified interface method to the general processing module; the general processing module generates an RPC response object according to the calling parameters of the RPC request and sends it to the RPC framework; the RPC framework encodes the RPC response object at the protocol level and sends it to the client.

[0014] In an embodiment, the general processing module generates an RPC response object according to the calling parameters of the RPC request, further comprising: the general processing module extracts the characteristic value of the calling parameters of the RPC request to match the response text template, and generates the RPC response object according to the response text template and the specified class loader.

[0015] In a second aspect, a Mock device for RPC service is provided, comprising: an RPC framework for receiving a service configuration fragment conforming to the RPC framework specification, and mapping the service configuration fragment into a corresponding configuration class object; a general processing module for extracting service element information of the configuration class object, building an independent class loader, loading an RPC interface class and its dependencies, and reflecting and analyzing inheritance relationship and public method declaration of the RPC interface class to obtain an analysis and sorting result; a bytecode operation framework for generating an implementation pseudo-class of the RPC interface according to the analysis and sorting result, and delegating the interface method of the implementation pseudo-class to the general processing module of the Mock service side; the general processing module is further configured to add the configuration class object and the implementation pseudo-class to the context environment of the RPC framework to publish the Mock service of the RPC interface.

[0016] In an embodiment, the service element information comprises: a service identifier, an RPC interface class name.

[0017] In an embodiment, the public method declaration comprises: a return value, a calling parameter, and exception information.

[0018] In an embodiment, the bytecode operation framework is further configured to: combine the method name and the method input parameter of the interface method into a unified JSON array structure, and delegate to the general processing module.

[0019] In an embodiment, the device is further configured to: through the diagnostic tool, observe whether the implementation pseudo-class of the RPC interface has been generated in real time in the virtual machine, and / or whether the calling delegation of the interface method is completed.

[0020] In an embodiment, the general processing module is further configured to: when receiving the RPC request, the general processing module of the Mock server intercepts the RPC request, obtains the corresponding class loader according to the service identifier of the RPC request, and dynamically injects the class loader into the RPC framework; the RPC framework is further configured to: use the class loader to parse the calling parameter of the RPC request, so as to locate the specified interface method in the pseudo-class implementation, and delegate the calling of the specified interface method to the general processing module; the general processing module is further configured to: generate an RPC response object according to the calling parameter of the RPC request, and send the RPC response object to the RPC framework; the RPC framework encodes the RPC response object at the protocol level, and sends the RPC response object to the client.

[0021] In an embodiment, the general processing module is further configured to: extract the calling parameter characteristic value of the RPC request, match the response text template, and generate the RPC response object according to the response text template and the specified class loader.

[0022] In a third aspect, a Mock device for RPC service is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method of the first aspect.

[0023] In a fourth aspect, a computer readable storage medium is provided, and the computer readable storage medium stores a program, when the program is executed by a multi-core processor, the multi-core processor executes the method of the first aspect.

[0024] One of the advantages of the above-mentioned embodiments is that the Mock service of the RPC interface can be quickly configured and implemented.

[0025] Other advantages of the present application will be described in more detail in conjunction with the following description and drawings.

[0026] It should be understood that the above description is merely a summary of the technical solutions of the present application, so as to enable a clearer understanding of the technical means of the present application, and thus the content of the specification can be implemented. In order to make the above and other objects, features and advantages of the present application more apparent, the following specific embodiments of the present application are described by way of example. BRIEF DESCRIPTION OF DRAWINGS

[0027] The advantages and benefits described herein, as well as other advantages and benefits, will be apparent to those of ordinary skill in the art upon reading the following detailed description of exemplary embodiments. The drawings are for purposes of illustration only and are not intended to limit the present application. Moreover, in the drawings, the same reference numerals are used to designate the same components throughout the several views. In the drawings:

[0028] Figure 1 Structure diagram of a Mock device for RPC service according to an embodiment of the present application;

[0029] Figure 2 Flowchart of a Mock method for RPC service according to an embodiment of the present application;

[0030] Figure 3 Flowchart of a Mock method for RPC service according to an embodiment of the present application;

[0031] Figure 4 Flowchart of a Mock method for RPC service according to another embodiment of the present application;

[0032] Figure 5 Flowchart of a Mock method for RPC service according to an embodiment of the present application.

[0033] In the drawings, the same or corresponding reference numerals indicate the same or corresponding parts. DETAILED DESCRIPTION

[0034] Exemplary embodiments of the present disclosure will be described in greater detail below with reference to the accompanying drawings. Although exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. Rather, these embodiments are provided so that the present disclosure can be more thoroughly understood and the scope of the present disclosure can be accurately conveyed to those skilled in the art.

[0035] In the description of embodiments of the present application, it should be understood that terms such as "include" or "have" are intended to indicate that the features, numbers, steps, actions, components, parts or combinations thereof disclosed in the specification are present, and are not intended to exclude the possibility that one or more other features, numbers, steps, actions, components, parts or combinations thereof exist.

[0036] Unless otherwise defined, " / " means or, for example, A / B can mean A or B; "and / or" in this document merely describes an associated relationship for associated objects, which means that there can be three relationships, for example, A and / or B, which can mean that A exists alone, A and B exist together, and B exists alone.

[0037] The terms "first", "second", and the like are used only for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined with "first", "second", and the like can explicitly or implicitly include one or more of the features. In the description of the embodiments of the present application, unless otherwise specified, the meaning of "a plurality of" is two or more.

[0038] In order to clearly describe the embodiments of the present application, some concepts that may appear in subsequent embodiments will be introduced first.

[0039] Concept description:

[0040] RPC, Remote Procedure Call, as a common cross-process communication mode, has the advantages of shielding protocol coding and network communication, convenient calling and high transmission efficiency.

[0041] Mock refers to creating a Mock object to simulate the behavior of an object during testing for objects that are not easy to construct / obtain.

[0042] The present application will be described in detail below with reference to the accompanying drawings and in conjunction with the embodiments.

[0043] First, refer to Figure 1 which schematically shows a schematic diagram of an environment 100 in which an exemplary implementation according to the present disclosure can be used.

[0044] Figure 1 A schematic diagram of an example of a computing device 100 according to an embodiment of the present disclosure is shown. It should be noted that Figure 1 which is a structural schematic diagram of a hardware execution environment for a Mock method for executing an RPC service. The device of the embodiments of the present application can be a PC, a portable computer, or the like terminal device.

[0045] As Figure 1As shown, the Mock device for performing RPC service can include a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, and a communication bus 1002. The communication bus 1002 is used to realize the connection communication between the components. The user interface 1003 can include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 can also include a standard wired interface, a wireless interface. The network interface 1004 can optionally include a standard wired interface, a wireless interface (such as a WI-FI interface). The memory 1005 can be a high-speed RAM memory, or a stable memory (non-volatile memory), such as a disk memory. The memory 1005 can also be an independent storage device from the aforementioned processor 1001.

[0046] Those skilled in the art can understand that, Figure 1 The Mock device structure for performing RPC service shown in the figure does not constitute a limitation on the Mock device for performing RPC service, and can include more or fewer components than the figure, or combine certain components, or different component arrangements.

[0047] As Figure 1 As shown, the memory 1005 as a computer storage medium can include an operating system, a network communication module, a user interface module, and a Mock program for performing RPC service. The operating system is a program that manages and controls the hardware and software resources of the XX device, supports the running of the Mock program for performing RPC service and other software or programs.

[0048] In Figure 1 In the Mock device for performing RPC service shown in the figure, the user interface 1003 is mainly used to receive the requests, data, etc. sent by the first terminal, the second terminal and the supervision terminal; the network interface 1004 is mainly used to connect the background server and the background server for data communication; and the processor 1001 can be used to call the Mock program for performing RPC service stored in the memory 1005, and perform the following operations:

[0049] receive a service configuration fragment following the RPC framework specification, map the service configuration fragment to a corresponding configuration class object; extract service element information of the configuration class object, build an independent class loader, load the RPC interface class and its dependencies; reflectively analyze inheritance relationship and public method declaration of the RPC interface class to obtain an analysis and sorting result; use a bytecode operation framework to generate an implementation pseudo class of the RPC interface according to the analysis and sorting result, and delegate interface methods of the implementation pseudo class to a general processing module of the Mock service side; and add the configuration class object and the implementation pseudo class to a context environment of the RPC framework to publish the Mock service of the RPC interface.

[0050] Thus, the Mock service of the RPC interface can be quickly formed, and the flexibility is high.

[0051] Figure 2 A flowchart of a Mock method for executing an RPC service according to an embodiment of the present disclosure is shown. The method may, for example, be executed by a computing device 100 as shown in Figure 1 It should be understood that the method 200 can also include additional blocks not shown and / or can omit blocks shown without departing from the scope of the present disclosure in this regard.

[0052] In step 210, a service configuration fragment following the RPC framework specification is received, and the service configuration fragment is mapped to a corresponding configuration class object.

[0053] In step 220, service element information of the configuration class object is extracted, an independent class loader is built, and the RPC interface class and its dependencies are loaded.

[0054] In step 230, inheritance relationship and public method declaration of the RPC interface class are reflectively analyzed to obtain an analysis and sorting result.

[0055] In step 240, an implementation pseudo class of the RPC interface is generated according to the analysis and sorting result using a bytecode operation framework, and interface methods of the implementation pseudo class are delegated to a general processing module of the Mock service side.

[0056] In step 250, the configuration class object and the implementation pseudo class are added to a context environment of the RPC framework to publish the Mock service of the RPC interface.

[0057] In the embodiments of the present application, it is not necessary to design and develop the Mock service from the beginning again, and only a part of configuration fragments is provided according to the use specification of the used RPC framework, so that the Mock service of an RPC interface is ready in a short time. In addition, the RPC interface file is dynamically loaded by using an independent custom class loader, which ensures that the services are isolated from each other and are not affected by each other, and when it is necessary to update, it can also be replaced in real time to take effect, thereby ensuring flexibility. In addition, the pseudo class implementation can be generated in real time, and only the RPC interface file needs to be provided, and the user does not need to write any code, and the platform will automatically analyze the inheritance structure and all method declarations of the interface class, and generate the corresponding pseudo class implementation to serve the call processing. Centralized operation and maintenance reduces cost: the platform management mode can collect the originally independently developed and deployed Mock services to provide unified intelligent management and service, which can greatly reduce the development and operation and maintenance cost.

[0058] Referring to Figure 3 which takes the implementation in Java language as an example to give a specific example of the implementation mode of the present application.

[0059] Firstly, in S301, the RPC framework receives and parses a static XML service configuration fragment following the corresponding RPC framework specification sent by the general processing module, such as <service name="foo_service" version="1.0" interface="com.unionpay.demo.FooService" / >; in S302, the RPC framework converts the service configuration fragment into a service configuration class (ServiceConfig) object that can be directly recognized and used at runtime, and returns the general processing module. In S303, the general processing module extracts service element information composed of related fields in the mapped service configuration class object, and constructs a service-specific independent class loader (ClassLoader) to load the RPC interface class, such as com.unionpay.demo.FooService, that is, in the Java platform, the general form is a jar file in standard format. Next, in S304, the general processing module reflects the inheritance relationship of the RPC interface, and sorts out all declared public methods, including return value, call parameter and explicitly thrown exception information, etc. Then, in S305, with the help of the bytecode operation framework, an implementation pseudo-class (pseudo is compared with the real interface implementation class originally existing in the service end) with a default name of interface fully qualified name + Impl fixed suffix is generated according to the analysis and sorting result, and the interface method implementation is all delegated to the functions defined in advance in the general processing module for unified processing, to simulate the real effect of RPC call. Finally, in S306, the parsed configuration object and the generated pseudo-class are added to the context environment of the RPC framework; in S307, the RPC framework drives the framework to complete the subsequent service publishing process. Thus, a Mock service of an RPC interface is realized.

[0060] In an embodiment, in step 240, the method name and method input parameter of the interface method are combined into a unified JSON array structure and delegated to the general processing module. Specifically, in the pseudo-class implementation, when the interface method is delegated to the general processing module, in addition to passing the service identifier and other basic information, the method name and method input parameter of the interface method can be combined into a unified JSON array structure. In this way, the user can select a specific parameter as a characteristic value for response strategy rule matching according to the array index order in the front-end response template configuration interface, so as to achieve personalized differential response for each different request. At the same time, the method name is exposed to the user as the 0th index value of the array, which can be used as a matching rule candidate in addition to classifying and managing response templates, which is more intuitive and convenient.

[0061] In an embodiment, after step 240, it is observed by a diagnostic tool whether the implementation pseudo-class of the RPC interface has been generated in real time in the virtual machine, and / or whether the invocation delegation of the interface method is completed. For example, after the above operations are completed, it can be observed by using a diagnostic tool related to the Java platform that the implementation pseudo-class com.unionpay.demo.FooServiceImpl of the RPC interface has been generated in real time in the JVM, and the method invocation delegation is completed. Then, step 250 is executed, that is, the parsed configuration object and the generated pseudo-class are added to the context environment of the RPC framework, and the framework is driven to complete the subsequent service publishing process.

[0062] In an embodiment, the service element information includes a service identifier, an RPC interface class name, etc.

[0063] In an embodiment, the public method declaration includes a return value, a calling parameter, and exception information, etc.

[0064] Referring to Figure 4 , a flow of calling the Mock service after the Mock service of the RPC interface is published is shown, including:

[0065] Step 410, when the RPC request is received, the general processing module of the Mock service intercepts the RPC request, acquires the corresponding class loader according to the service identifier of the RPC request, and dynamically injects the class loader into the RPC framework;

[0066] Step 420, the RPC framework uses the class loader to parse the calling parameter of the RPC request, so as to locate the specified interface method in the pseudo-class implementation, and delegate the invocation of the specified interface method to the general processing module;

[0067] Step 430, the general processing module generates an RPC response object according to the calling parameter of the RPC request, and sends it to the RPC framework;

[0068] Step 440, the RPC framework encodes the RPC response object at the protocol level, and sends it to the client.

[0069] In an embodiment, in step 430, the general processing module extracts the characteristic value of the calling parameter of the RPC request, so as to match the response text template, and generates the RPC response object according to the response text template and the specified class loader.

[0070] As shown in Figure 5 , specific examples of the implementation of steps 410-440 are given by taking the implementation under the Java language as an example.

[0071] At S501, the user sends an RPC request to the Mock server through the client; at S502, the general processing module intercepts the RPC request and acquires the corresponding class loader according to the service identifier of the RPC request. This is because when the service is published, a custom class loader is used to load the interface class and its related dependencies, and the generated pseudo class implementation is also managed by the class loader. Therefore, in order to ensure that the RPC framework can successfully complete the deserialization operation of the byte stream to the related parameter type object when processing the request, the general processing module intercepts and finds the specific class loader according to the service identifier information, and binds it to the target working thread. At S503, the general processing module dynamically injects the class loader into the RPC framework; at S504, the RPC request reaches the RPC framework; at S505, the RPC framework uses the corresponding class loader to parse the call parameters of the RPC request, and then successfully locates a specified interface method in the corresponding pseudo class implementation; and because in the foregoing step 240, the call of all interface methods of the RPC interface has been delegated to the general processing module when the pseudo class is generated, next, at S506, the call of the specific method of the RPC request is delegated to the general processing module; in the general processing module, all RPC requests will be processed without difference, at S507, the general processing module extracts the call parameter characteristic value of the RPC request to match the response text template; at S508, the general processing module generates an RPC response object according to the response text template and the specified class loader; at S509, the general processing module sends the RPC response object to the RPC framework, at this time, the initiative is returned to the RPC framework, and the RPC framework completes the encoding at the protocol level; at S510, the RPC framework sends the RPC response to the client. Thus, the call of the RPC interface Mock service is completed.

[0072] It should be noted that the steps not described in detail in the embodiments can refer to the descriptions of the related steps in the embodiments shown in the above table, and will not be described here. Figure 2

[0073] In the description of the present specification, the description referring to the terms "some possible embodiments", "some embodiments", "examples", "specific examples", or "some examples" and the like means that the specific features, structures, materials or characteristics described in connection with the embodiments or examples are included in at least one embodiment or example of the present application. In the present specification, the illustrative description of the above terms is not necessarily directed to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any appropriate manner in any one or more embodiments or examples. Furthermore, the person skilled in the art can combine and combine the different embodiments or examples described in the present specification and the features of the different embodiments or examples without contradiction.​

[0074] With respect to the method flowcharts of the embodiments of the present application, certain operations are described as distinct steps performed in a certain order. Such flowcharts are illustrative and not limiting. Certain steps described herein can be grouped together and performed in a single operation, certain steps can be split into multiple sub-steps, and certain steps can be performed in an order different from that shown herein. The individual steps shown in the flowcharts can be implemented in any manner by any circuitry structure and / or tangible mechanism (e.g., by software running on a computer device, hardware (e.g., a processor or a chip-implemented logic function), etc., and / or any combination thereof) in any way.

[0075] Based on the same technical concept, the embodiments of the present application also provide a Mock device for an RPC service, configured to perform the Mock method of the RPC service provided by any of the above embodiments.

[0076] The device comprises: an RPC framework configured to receive a service configuration fragment complying with an RPC framework specification, and map the service configuration fragment into a corresponding configuration class object; a general processing module configured to extract service element information of the configuration class object, build an independent class loader, and load an RPC interface class and its dependencies; and analyze inheritance relationship and public method declaration of the RPC interface class by reflection, and obtain an analysis and sorting result; a bytecode operation framework configured to generate an implementation pseudo class of the RPC interface according to the analysis and sorting result, and delegate interface methods of the implementation pseudo class to the general processing module of the Mock service side; and the general processing module is further configured to add the configuration class object and the implementation pseudo class to a context environment of the RPC framework, so as to publish a Mock service of the RPC interface.

[0077] In an embodiment, the service element information comprises: a service identifier and an RPC interface class name.

[0078] In an embodiment, the public method declaration comprises: a return value, a calling parameter, and exception information.

[0079] In an embodiment, the bytecode operation framework is further configured to: combine a method name and a method input parameter of the interface method into a unified JSON array structure, and delegate to the general processing module.

[0080] In an embodiment, the device is further configured to: through a diagnosis tool, observe whether the implementation pseudo class of the RPC interface has been generated in real time in a virtual machine, and / or whether the calling delegation of the interface method has been completed.

[0081] In an implementation, the universal processing module is further configured to: when receiving the RPC request, intercept the RPC request by the universal processing module of the Mock server, acquire the corresponding class loader according to the service identifier of the RPC request, and dynamically inject the class loader into the RPC framework; the RPC framework is further configured to parse the calling parameter of the RPC request by using the class loader, locate the specified interface method in the corresponding pseudo-class implementation, and delegate the calling of the specified interface method to the universal processing module; the universal processing module is further configured to generate an RPC response object according to the calling parameter of the RPC request, and send the RPC response object to the RPC framework; and the RPC framework encodes the RPC response object at the protocol level, and sends the RPC response object to the client.

[0082] In an implementation, the universal processing module is further configured to: extract the calling parameter characteristic value of the RPC request, match the response text template, and generate the RPC response object according to the response text template and the specified class loader.

[0083] It should be noted that the device in the embodiments of the present application can implement the various processes of the embodiments of the foregoing method, and achieve the same effects and functions, which will not be described here.

[0084] According to some embodiments of the present application, a non-volatile computer storage medium of a Mock method of an RPC service is provided, and the computer executable instructions are stored on the non-volatile computer storage medium, and the computer executable instructions are configured to execute the method described in the above embodiments when executed by a processor.

[0085] Each of the embodiments in the present application is described in a progressive manner, and the same or similar parts of each of the embodiments can be referred to each other. Each of the embodiments mainly describes the differences from other embodiments. In particular, the device, the equipment and the computer readable storage medium embodiments are basically similar to the method embodiments, so the description is simplified, and the relevant parts can be referred to the part of the method embodiment.

[0086] The device, the equipment and the computer readable storage medium provided by the embodiments of the present application are one-to-one corresponding to the method, so the device, the equipment and the computer readable storage medium also have the similar beneficial technical effects as the method. Since the beneficial technical effects of the method have been described in detail above, the beneficial technical effects of the device, the equipment and the computer readable storage medium will not be described here.

[0087] Those skilled in the art will appreciate that embodiments of the application can be readily used on a variety of computer architectures and that the application can be implemented as computer software programs or modules. Furthermore, the software implemented aspects of the application are not limited to any particular programming language or computer system. Those skilled in the art will appreciate that an embodiment of the application can be provided as a method, an apparatus (device or system), or a computer readable storage medium. Accordingly, the application can take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the application can take the form of a computer program product on one or more computer readable storage media (including, but not limited to, disk memory, CD-ROMs, optical storage devices, etc.) embodying computer readable instructions.

[0088] The application is described in reference to the flowchart and / or block diagrams of the methods, apparatus (devices or systems), and computer readable storage media according to embodiments of the application. It will be understood that each block of the flowchart and / or block diagrams, and combinations of blocks in the flowchart and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general purpose computer, special purpose computer, embedded processing device, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart and / or block diagram block or blocks. Figure 1 one or more functions specified in the flowchart and / or block diagram block or blocks. Figure 1 one or more functions specified in the flowchart and / or block diagram block or blocks.

[0089] These computer program instructions can also be stored in a computer readable storage medium that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer readable storage medium produce an article of manufacture including instructions which implement the functions specified in the flowchart and / or block diagram block or blocks. Figure 1 one or more functions specified in the flowchart and / or block diagram block or blocks. Figure 1 one or more functions specified in the flowchart and / or block diagram block or blocks.

[0090] These computer program instructions can also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart and / or block diagram block or blocks. Figure 1 one or more functions specified in the flowchart and / or block diagram block or blocks. Figure 1 one or more functions specified in the flowchart and / or block diagram block or blocks.

[0091] In one typical configuration, the computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.

[0092] Memory can include non-persistent memory in computer-readable media, random access memory (RAM), and / or non-volatile memory, such as read only memory (ROM) or flash memory, etc. Memory is an example of computer-readable media.

[0093] Computer-readable media includes permanent and non-permanent, removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read only memory (ROM), electrically erasable programmable read only memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), digital versatile disc (DVD), or other optical storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information accessible to a computing device. In addition, although the operations of the method of the present application are described in a particular order in the drawings, this does not require or imply that the operations must be performed in that particular order, or that all of the illustrated operations must be performed to achieve the desired result. Additionally or alternatively, certain steps can be omitted, combined into a single step, and / or divided into multiple steps.

[0094] Although the spirit and principles of the present application have been described with reference to several specific embodiments, it should be understood that the present application is not limited to the disclosed specific embodiments, and the division of aspects does not mean that the features in these aspects cannot be combined to benefit. This division is only for the convenience of expression. The present application is intended to cover various modifications and equivalent arrangements included in the spirit and scope of the appended claims.

Claims

1. A mock method for RPC service, characterized in that: include: Receive a service configuration fragment that complies with the RPC framework specification, and map the service configuration fragment to a corresponding configuration class object; Extracting service element information of the configuration class object, building an independent class loader, the independent class loader is used to implement isolation and dynamic update between multiple RPC interface services, and load the RPC interface class and its dependencies; Reflectively analyze the inheritance relationship and public method declarations of the RPC interface class to obtain analysis and sorting results; Using the bytecode manipulation framework, an implementation pseudo-class of the RPC interface is generated according to the analysis and combing results, and the interface method of the implementation pseudo-class is delegated to the general processing module of the Mock server; The configuration class object and the implementation pseudo class are added to the context of the RPC framework to publish the Mock service of the RPC interface.

2. The method according to claim 1, characterized in that The service element information includes: service identification and RPC interface class name.

3. The method according to claim 1, characterized in that The public method declaration includes: return value, calling parameters and exception information.

4. The method according to claim 1, wherein Delegating the interface method of the pseudo-class to the general processing module of the Mock server also includes: The method name and method input parameters of the interface method are merged into a unified JSON array structure and delegated to the general processing module.

5. The method according to claim 1, wherein After delegating the interface method of the pseudo class to the general processing module of the Mock server, it also includes: Through the diagnostic tool, observe whether the implementation pseudo class of the RPC interface has been generated in real time in the virtual machine and / or whether the call delegation of the interface method has been completed.

6. The method according to claim 1, characterized in that After publishing the Mock service of the RPC interface, the method further includes: When an RPC request is received, the general processing module of the Mock server intercepts the RPC request, obtains the corresponding class loader according to the service identifier of the RPC request, and dynamically injects the class loader into the RPC framework; The RPC framework uses the class loader to parse the call parameters of the RPC request to locate the specified interface method in the corresponding pseudo-class implementation, and delegates the call of the specified interface method to the general processing module; The general processing module generates an RPC response object according to the call parameters of the RPC request and sends it to the RPC framework; The RPC framework encodes the RPC response object at the protocol level and sends it to the client.

7. The method according to claim 1, characterized in that The general processing module generates an RPC response object according to the call parameters of the RPC request, and further includes: The general processing module extracts the call parameter feature value of the RPC request to match the response text template, and generates the RPC response object according to the response text template and a specified class loader.

8. A mock device for RPC service, characterized in that: include: The RPC framework is used to receive service configuration fragments that comply with the RPC framework specification and map the service configuration fragments to corresponding configuration class objects; A general processing module is used to extract the service element information of the configuration class object, build an independent class loader, and implement the isolation and dynamic update between multiple RPC interface services, and load the RPC interface class and its dependencies; And, reflectively analyzing the inheritance relationship and public method declarations of the RPC interface class to obtain analysis and sorting results; A bytecode operation framework is used to generate an implementation pseudo-class of the RPC interface according to the analysis and combing results, and to delegate the interface method of the implementation pseudo-class to the general processing module of the Mock server; The general processing module is further configured to add the configuration class object and the implementation pseudo class to the context of the RPC framework to publish the Mock service of the RPC interface.

9. The device according to claim 8, characterized in that The service element information includes: service identification and RPC interface class name.

10. The device according to claim 8, characterized in that The public method declaration includes: return value, calling parameters and exception information.

11. The device according to claim 8, characterized in that The bytecode manipulation framework is also used to: The method name and method input parameters of the interface method are merged into a unified JSON array structure and delegated to the general processing module.

12. The device according to claim 8, characterized in that The device is also used for: Through the diagnostic tool, observe whether the implementation pseudo class of the RPC interface has been generated in real time in the virtual machine and / or whether the call delegation of the interface method has been completed.

13. The device according to claim 8, characterized in that The general processing module is further configured to: when receiving an RPC request, intercept the RPC request by the general processing module of the Mock server, obtain the corresponding class loader according to the service identifier of the RPC request, and dynamically inject the class loader into the RPC framework; The RPC framework is further configured to use the class loader to parse the call parameters of the RPC request to locate the specified interface method in the corresponding pseudo-class implementation, and delegate the call of the specified interface method to the general processing module; The general processing module is further configured to generate an RPC response object according to the call parameters of the RPC request and send the RPC response object to the RPC framework; The RPC framework encodes the RPC response object at the protocol level and sends it to the client.

14. The device according to claim 13, characterized in that The general processing module is further configured to: Extract the call parameter feature value of the RPC request to match the response text template, and generate the RPC response object according to the response text template and a specified class loader.

15. A mock device for RPC service, characterized in that: include: at least one processor; And, a memory communicatively connected to at least one processor; wherein the memory stores instructions executable by at least one processor, and the instructions are executed by at least one processor to enable the at least one processor to execute: the method described in any one of claims 1-7. 16 . A computer-readable storage medium storing a program, wherein when the program is executed by a multi-core processor, the multi-core processor is caused to execute the method according to claim 1 .

Citation Information

Patent Citations

  • Testing method and device

    CN111782535A

  • Test processing method and device

    CN113760701A