Mock data returning method and device, computer device and storage medium

CN116484125BActive Publication Date: 2026-10-09CHINA PING AN PROPERTY INSURANCE CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202310571887.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-05-19
Publication Date
2026-10-09
Estimated Expiration
2043-05-19

AI Technical Summary

Technical Problem

[0004]本申请实施例提供一种Mock数据返回方法、装置、计算机设备及存储介质,以解决传统Mock数据技术方案导致软件开发成本增加和开发效率降低的问题

Benefits of technology

[0021] The aforementioned Mock data return method, apparatus, computer equipment, and storage medium receive a request for a target interface sent by the front-end project through a gateway; query a pre-deployed and configured in-memory database to check whether the corresponding target interface is set as a Mock interface type; if not, send the request for the target interface to the back-end business component of the corresponding business module in the back-end service cluster through the gateway; if yes, query the corresponding first target Mock result data in the in-memory database; use the first target Mock result data as the request return result data, or use the second Mock return result data returned by the back-end business component as the request return result data; and return the request return result data to the initiator of the corresponding request. This not only reduces the manpower and time costs of Mock data in the software development process, but also isolates the front-end and back-end development, further reducing the dependency between the front-end and back-end and improving the development efficiency of the software.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116484125B_ABST
    Figure CN116484125B_ABST
Patent Text Reader

Abstract

The application discloses a Mock data returning method, which is applied to the technical field of software development and the field of financial technology. The method provided by the application comprises the following steps: receiving a request of a target interface, wherein the request of the target interface contains a uniform resource locator; querying whether the target interface corresponding to the uniform resource locator is set as a Mock interface type in an in-memory database; if not, sending the request of the target interface to a backend service cluster, wherein the backend service cluster sends the request of the target interface to a corresponding backend business component; if yes, querying a first target Mock result data corresponding to the uniform resource locator in the in-memory database; taking the first target Mock result data as request return result data, or taking second Mock return result data returned by the backend business component as the request return result data; and returning the request return result data to an initiator of the request of the target interface.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of software development technology, and in particular to a method, apparatus, computer device, and storage medium for returning Mock data. Background Technology

[0002] In traditional software development workflows, front-end and back-end developers periodically conduct joint development and debugging. During development, back-end developers focus on implementing business logic, while front-end developers focus on loading and rendering data for the front-end interface. For example, in the development of a fintech platform, back-end developers focus on the logical implementation of various financial services (such as enabling users to complete car insurance purchases, credit card applications, loan applications, and investment transactions), while front-end developers focus on loading and rendering data for the various system applications' front-end pages (such as loading and rendering banner ads and properly loading and rendering user information after login). Furthermore, with the development of microservices and front-end / back-end separation technologies, front-end developers rely on data returned from back-end interfaces throughout the iterative development process of the software system.

[0003] Therefore, the mock data returned by the backend interface is crucial for frontend data rendering. However, if backend developers need to constantly work with frontend developers to create mock data, it incurs significant time and manpower costs. For example, backend developers of the auto insurance subsystem on a fintech platform, in addition to completing basic development tasks, must also create a large amount of mock data related to the auto insurance business to provide frontend developers with data for debugging. Furthermore, traditional methods for creating mock data are overly complex to manage, increasing the probability of frontend developers receiving incorrect mock data and ultimately reducing development efficiency. Summary of the Invention

[0004] This application provides a method, apparatus, computer device, and storage medium for returning Mock data, in order to solve the problems of increased software development costs and reduced development efficiency caused by traditional Mock data technology solutions.

[0005] A first aspect of this application provides a method for returning Mock data, comprising:

[0006] The gateway receives requests from the target interface sent by the front-end project, wherein the request from the target interface contains a unique Unique Resource Locator (URL).

[0007] Query the pre-deployed and configured in-memory database to see if the target interface corresponding to the Uniform Resource Locator is set to the Mock interface type;

[0008] If not, the request for the target interface is sent to the backend service cluster through the gateway, so that the backend service cluster sends the request for the target interface to the backend business component of the corresponding business module according to the cluster configuration information.

[0009] If so, then query the corresponding first target Mock result data in the memory database according to the Uniform Resource Locator;

[0010] Use the first target Mock result data as the request return result data, or use the second Mock return result data returned by the backend business component as the request return result data;

[0011] The request result data is returned to the request initiator of the corresponding target interface through the gateway.

[0012] A second aspect of this application provides a Mock data return device, comprising:

[0013] The interface request receiving module is used to receive requests from the target interface sent by the front-end project through the gateway, wherein the request from the target interface contains a unique Unique Resource Locator (URL).

[0014] The interface type determination module is used to query in a pre-deployed and configured in-memory database whether the target interface corresponding to the Uniform Resource Locator is set to the Mock interface type;

[0015] The request forwarding module is used to send the request of the target interface to the backend service cluster through the gateway if no, so that the backend service cluster sends the request of the target interface to the backend business component of the corresponding business module according to the cluster configuration information.

[0016] The in-memory database module is used to query the corresponding first target Mock result data in the in-memory database according to the Uniform Resource Locator if the condition is met.

[0017] The result data module is used to use the first target Mock result data as the request return result data, or to use the second Mock return result data returned by the backend business component as the request return result data.

[0018] The request result return module is used to return the request result data to the request initiator of the corresponding target interface through the gateway.

[0019] A third aspect of this application provides a computer device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the above-described Mock data return method.

[0020] A fourth aspect of this application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the above-described Mock data return method.

[0021] The aforementioned Mock data return method, apparatus, computer equipment, and storage medium receive a request for a target interface sent by the front-end project through a gateway; query a pre-deployed and configured in-memory database to check whether the corresponding target interface is set as a Mock interface type; if not, send the request for the target interface to the back-end business component of the corresponding business module in the back-end service cluster through the gateway; if yes, query the corresponding first target Mock result data in the in-memory database; use the first target Mock result data as the request return result data, or use the second Mock return result data returned by the back-end business component as the request return result data; and return the request return result data to the initiator of the corresponding request. This not only reduces the manpower and time costs of Mock data in the software development process, but also isolates the front-end and back-end development, further reducing the dependency between the front-end and back-end and improving the development efficiency of the software. Attached Figure Description

[0022] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the description of the embodiments of this application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0023] Figure 1 This is a schematic diagram of an application environment for a Mock data return method in one embodiment of this application;

[0024] Figure 2 This is a flowchart of a Mock data return method in one embodiment of this application;

[0025] Figure 3 This is a schematic diagram of the structure of a Mock data return device in one embodiment of this application;

[0026] Figure 4 This is a schematic diagram of a computer device according to one embodiment of this application. Detailed Implementation

[0027] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0028] The Mock data return method provided in this application can be applied to applications such as... Figure 1 In the application environment, among which, Figure 1 The front-end engineering, in-memory database, and back-end service cluster are all deployed on computer devices. These computer devices can be, but are not limited to, various personal computers and laptops. They can also be servers, which can be standalone servers or cloud servers providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms. This is understandable. Figure 1 The number of computer devices shown is merely illustrative and can be expanded in any number according to actual needs.

[0029] In one embodiment, such as Figure 2 As shown, a method for returning mock data is provided, which can be applied to... Figure 1 The following steps, S101 to S106, are used as an example of computer equipment in the example:

[0030] S101. Receive a request from the target interface sent by the front-end project through the gateway, wherein the request from the target interface contains a unique Unique Resource Locator (URL).

[0031] The gateway, also known as an internetwork connector or protocol converter, is a computer system or device that acts as a translator when two systems use different communication protocols, data formats, languages, or even completely different architectures. Unlike a bridge, which simply transmits information, a gateway can repackage received information to suit the needs of the destination system. Furthermore, gateways can provide filtering and security functions. For example, in this embodiment, the gateway can filter out some illegal requests not sent by the front-end application. For instance, the gateway of a fintech platform can filter out some illegal requests not sent by the fintech platform's front-end pages (network interface requests simulated by other network attack tools, such as illegal access requests to the fintech platform's user information data interface).

[0032] Furthermore, the term "front-end engineering" is a term used in the field of software development technology. The request to the target interface can originate not only from the front-end engineering but also from other third-party back-end systems. For example, in the auto insurance subsystem of a fintech platform, this subsystem provides an interface for querying a user's annual auto insurance spending. The object initiating the interface request for this query could be the front-end app client of the auto insurance subsystem, or it could be another subsystem of the fintech platform (e.g., the credit card business subsystem, which queries a user's annual auto insurance information to determine whether to lower or raise the corresponding user's credit card limit).

[0033] The Uniform Resource Locator (URL) is a standard resource address on the Internet, also known as a web address or Uniform Resource Locator. A URL typically consists of four parts: mode, hostname, location, and filename, forming a fixed and uniform format that provides a consistent access method for client programs querying different information resources.

[0034] S102. Query the pre-deployed and configured memory database to see if the target interface corresponding to the Uniform Resource Locator is set to the Mock interface type.

[0035] Furthermore, in a more specific embodiment, the target in-memory database is implemented using Redis. An in-memory database is a database that stores all data in memory, unlike traditional databases that store data on external storage. All data access in an in-memory database is also performed in memory. Common in-memory databases include, but are not limited to, Redis, Memcached, SQLite, Oracle TimesTen, and Apache Ignite. Redis, in particular, is an in-memory database that stores key-value pairs. Its data structure storage system can be used as a database, cache, and message broker, and it supports rich data structure types, such as strings, hashes, and sorted sets. Redis also enables data persistence and backup. In another more specific embodiment, Redis is used to store the interface types of all backend interfaces, as well as the corresponding Uniform Resource Locators (URLs) for all backend interfaces.

[0036] Furthermore, after the in-memory database is deployed, a timed polling thread is started to query the backend system for any new backend interfaces. If a new backend interface is found, the interface type and corresponding new Uniform Resource Locator (URL) of the new backend interface are obtained and saved to the in-memory database. If the new URL already contains the same URL as one already existing in the in-memory database, a corresponding warning message with the same name is generated and sent to the relevant backend developer.

[0037] S103. If the target interface is set to a non-Mock interface type, the request of the target interface is sent to the backend service cluster through the gateway, so that the backend service cluster sends the request of the target interface to the backend business component of the corresponding business module according to the cluster configuration information.

[0038] The backend service cluster is a group of servers that manage and participate in workload management. The cluster can contain nodes or a single application server. Nodes are typically physical computer systems with different host IP addresses running one or more application servers. Compared to traditional high-performance computing technologies, cluster technology can utilize servers of varying levels as nodes, resulting in lower system costs, high computing speeds, large-scale computations, and high responsiveness, thus meeting the ever-growing demands of today's information services.

[0039] The backend service cluster deploys various backend business modules according to the system's business needs, and each of these backend business modules is composed of various backend business components. For example, in the backend service cluster of a fintech platform, backend business modules such as auto insurance, medical insurance, credit card, and consumer loan are deployed. The consumer loan module includes backend business component services such as user credit service components, user consumption service components, user loan service components, and user installment service components.

[0040] S104. If the target interface is set to the Mock interface type, then query the corresponding first target Mock result data in the memory database according to the Uniform Resource Locator.

[0041] The first target Mock result data is pre-stored in the memory database and is also saved when the target interface is first set as a Mock interface type. Further, if an interface type setting request to set the target interface as a Mock interface type is received, it is also necessary to check whether the interface type setting request contains the first target Mock result data corresponding to the target interface. If it does not contain it, setting the target interface as a Mock interface type fails. Further, if the interface type setting request contains the corresponding first target Mock result data, the first target Mock result data is also sent to the corresponding backend service component for data structure verification. If the data structure verification fails, setting the target interface as a Mock interface type fails.

[0042] Further, the step of querying the corresponding first target Mock result data in the in-memory database according to the Uniform Resource Locator includes: First, determining the Mock data return method of the Mock interface returning the Mock result data. If the Mock data return method is a field attribute value method, then the corresponding field value is searched in the in-memory database according to the returned field attribute of the target interface. Then, the field value is combined with the returned data structure of the target interface to form the first target Mock result data. If the Mock data return method is JSON data, then the interface-returned JSON data corresponding to the target interface is obtained from the Mock JSON data set in the in-memory database as the first Mock result data. For example, in the car insurance business subsystem of a fintech platform, the Mock data type returned by the user's basic car insurance information interface is a field attribute value method, while the Mock data returned by the user's car insurance consumption record information interface is a JSON data method. Further, in some other embodiments, the target interface returns neither a field attribute value method nor a JSON data method, but rather a file method such as an image or text, or other methods. In this case, the target interface returns the system file address or other network address data format corresponding to the returned file stored in the big data storage. For example, in the auto insurance business subsystem of a fintech platform, the user's accident record image information interface returns a set of data storage addresses for a set of corresponding accident scene photos stored in big data.

[0043] JSON (JavaScript Object Notation) is a lightweight data-interchange format based on a subset of ECMAScript (European Computer Manufacturers Association Script). It uses a text format completely independent of programming languages ​​to store and represent data. Its concise and clear hierarchical structure makes JSON an ideal data-interchange language, easy for developers to read and write, and also easy for machines to parse and generate, effectively improving network transmission efficiency. In another more specific embodiment, XML data format is used instead of the JSON data format. It should be noted that both JSON and XML data are data formats returned by the backend interface. The JSON data in this embodiment can be replaced with any data format returned by a backend interface in traditional technologies, or it can be replaced with a new data format returned by a future backend interface.

[0044] Further, if the Mock data return method is a field attribute value method, then searching for the corresponding field value in the in-memory database according to the returned field attribute of the target interface includes: First, if the request of the target interface is being received for the first time, then obtaining the returned data structure of the target interface from the backend business component. Then, according to the returned data structure, obtaining the different field attribute values ​​corresponding to different field attributes in the returned data structure from the in-memory database. Simultaneously, assembling the field values ​​into the first target Mock result data according to the returned data structure of the target interface, and storing the first target Mock result data and the corresponding Uniform Resource Locator (URL) in the in-memory database. Finally, if the request of the target interface is not being received for the first time, then obtaining the first target Mock result data in the in-memory database according to the URL corresponding to the target structure.

[0045] S105. Use the first target Mock result data as the request return result data, or use the second Mock return result data returned by the backend business component as the request return result data.

[0046] Furthermore, a response time threshold is set for the backend business components. If the response time threshold is exceeded, the request result data indicating a failed request to the target interface is returned. The initial timing for determining the response time threshold begins when the in-memory database receives a Mock data type query for the target interface. For example, if the in-memory database of the aforementioned fintech platform's auto insurance business subsystem receives a query request for a specific user's auto insurance consumption records from last year through a user auto insurance consumption information query interface, the timing begins when the in-memory database of the auto insurance business subsystem receives the interface type for querying the user's auto insurance reimbursement consumption information, and continues until the specific user's auto insurance consumption records from last year are received, or the timing exceeds the set response time threshold.

[0047] S106. The request result data is returned to the request initiator of the corresponding target interface through the gateway.

[0048] Furthermore, after the request return result data is returned, the mock data verification result of the front-end project is also received. That is, the relevant front-end developers of the front-end project also verify the correctness of the mock data and feed back the verification result of the mock data to the corresponding back-end service cluster through the gateway. For example, the front-end developers of the aforementioned fintech platform's auto insurance business subsystem receive the mock result data returned by the back-end service cluster. However, during the rendering of the front-end page using the mock result data, they find that the value of a field with a percentage attribute in the mock result data exceeds 100%, which leads to a rendering error during the front-end page rendering. Therefore, the front-end developers of the auto insurance business subsystem send the mock result data and the resulting front-end rendering error information to the back-end service cluster of the auto insurance business subsystem. After receiving the mock result data and the front-end rendering error information, the back-end developers of the auto insurance business subsystem modify the mock result data to resolve the front-end rendering error.

[0049] Furthermore, after returning the request result data to the request initiator of the corresponding target interface through the gateway, the process further includes: first, a setting request for the target interface, wherein the setting request is filtered for permissions by the gateway. Then, if the setting request is to disable the Mock flag of the target interface, the target interface is set to a non-Mock interface type in the memory database. Finally, if the setting request is to enable the Mock flag of the target interface, the target interface is set to a Mock interface type in the memory database.

[0050] Furthermore, after receiving the second Mock return result data returned by the backend business component as the request return result data, the method further includes: first, saving the second Mock return result data to the memory database. Then, if a request to enable the Mock identifier of the target interface is received, the second Mock return result data is used as the first target Mock result data corresponding to the target result.

[0051] Furthermore, the setting request also includes whether to delete the Mock data flag. If the setting request is to disable the Mock flag of the target interface, after setting the target interface to a non-Mock interface type in the memory database, the request further includes: First, if the "whether to delete Mock data" flag is True, then delete the first target Mock result data corresponding to the target interface in the memory database. Then, if the "whether to delete Mock data" flag is False, then transfer the first target Mock result data corresponding to the target interface to the logical deletion area in the memory database.

[0052] The aforementioned Mock data return method, apparatus, computer equipment, and storage medium receive a request for a target interface sent by the front-end project through a gateway; query a pre-deployed and configured in-memory database to check whether the corresponding target interface is set as a Mock interface type; if not, send the request for the target interface to the back-end business component of the corresponding business module in the back-end service cluster through the gateway; if yes, query the corresponding first target Mock result data in the in-memory database; use the first target Mock result data as the request return result data, or use the second Mock return result data returned by the back-end business component as the request return result data; and return the request return result data to the initiator of the corresponding request. This not only reduces the manpower and time costs of Mock data in the software development process, but also isolates the front-end and back-end development, further reducing the dependency between the front-end and back-end and improving the development efficiency of the software.

[0053] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.

[0054] In one embodiment, a Mock data return device 100 is provided, which corresponds one-to-one with the Mock data return method in the above embodiments. For example... Figure 4As shown, the Mock data return device 100 includes an interface request receiving module 11, an interface type judgment module 12, a request forwarding module 13, a memory database module 14, a result data module 15, and a request result return module 16. Detailed descriptions of each functional module are as follows:

[0055] The interface request receiving module 11 is used to receive a request for a target interface sent by the front-end project through the gateway, wherein the request for the target interface contains a unique Unique Resource Locator.

[0056] The interface type determination module 12 is used to query in a pre-deployed and configured memory database whether the target interface corresponding to the Uniform Resource Locator is set to the Mock interface type;

[0057] The request forwarding module 13 is used to send the request of the target interface to the backend service cluster through the gateway if the target interface is set to a non-Mock interface type, so that the backend service cluster sends the request of the target interface to the backend business component of the corresponding business module according to the cluster configuration information.

[0058] The in-memory database module 14 is used to query the corresponding first target Mock result data in the in-memory database according to the Uniform Resource Locator if the target interface is set to the Mock interface type.

[0059] The result data module 15 is used to use the first target Mock result data as the request return result data, or to use the second Mock return result data returned by the backend business component as the request return result data.

[0060] The request result return module 16 is used to return the request result data to the request initiator of the corresponding target interface through the gateway.

[0061] Furthermore, the in-memory database module 14 also includes:

[0062] The return method determination submodule is used to determine the return method of the Mock data returned by the Mock interface;

[0063] The first field value acquisition submodule is used to find the corresponding field value in the memory database according to the returned field attribute of the target interface if the Mock data is returned in the form of a field attribute value.

[0064] The first data structure composition submodule is used to compose the field values ​​into the first target Mock result data according to the return data structure of the target interface;

[0065] The first JSON data acquisition submodule is used to retrieve the interface-returned JSON data corresponding to the target interface from the Mock JSON data set in the memory database as the first Mock result data if the Mock data return method is JSON data.

[0066] Furthermore, the request result return module 16 also includes:

[0067] The gateway permission filtering submodule is used to handle setting requests from the target interface, wherein the setting requests are filtered for permissions by the gateway.

[0068] The first interface type setting submodule is used to set the target interface to a non-Mock interface type in the memory database if the setting request is to disable the Mock identifier of the target interface.

[0069] The second interface type setting submodule is used to set the target interface as a Mock interface type in the memory database if the setting request is to enable the Mock identifier of the target interface.

[0070] Furthermore, the result data module 15 also includes:

[0071] The first data storage submodule is used to save the second Mock return result data to the memory database;

[0072] The result data setting submodule is used to, if a setting request for enabling the Mock identifier of the target interface is received, use the second Mock return result data as the first target Mock result data corresponding to the target result.

[0073] Furthermore, the first interface type setting submodule also includes:

[0074] The first result data deletion subunit is used to delete the first target Mock result data corresponding to the target interface in the memory database if the Mock data deletion flag is True.

[0075] The second result data deletion subunit is used to transfer the first target Mock result data corresponding to the target interface to the logical deletion area in the memory database if the Mock data deletion flag is False.

[0076] Furthermore, the first field value retrieval submodule also includes:

[0077] The first interface returns a data subunit, which is used to obtain the return data structure of the target interface from the backend business component if the request of the target interface is received for the first time.

[0078] The attribute value acquisition subunit is used to acquire different field attribute values ​​corresponding to different field attributes in the returned data structure in the memory database according to the returned data structure.

[0079] The result data storage subunit is used to assemble the field values ​​into the first target Mock result data according to the return data structure of the target interface, and store the first target Mock result data and the corresponding Uniform Resource Locator in the memory database;

[0080] The second interface returns a data subunit, which is used to obtain the first target Mock result data from the memory database according to the Uniform Resource Locator corresponding to the target structure if the request of the target interface is not received for the first time.

[0081] The terms "first" and "second" in the above-mentioned modules / units are only used to distinguish different modules / units and are not intended to specify which module / unit has a higher priority or any other limiting meaning. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or modules is not necessarily limited to those steps or modules explicitly listed, but may include other steps or modules not explicitly listed or inherent to these processes, methods, products, or devices. The module divisions appearing in this application are merely logical divisions; in actual applications, different division methods may be used.

[0082] Specific limitations regarding the Mock data return device can be found in the limitations of the Mock data return method described above, and will not be repeated here. Each module in the aforementioned Mock data return device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in the computer device in hardware form, or stored in the memory of the computer device in software form, so that the processor can call and execute the operations corresponding to each module.

[0083] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 4As shown, the computer device includes a processor, memory, network interface, and database connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and database. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores data involved in the mock data return method. The network interface communicates with external terminals via a network connection. When the computer program is executed by the processor, it implements a mock data return method.

[0084] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the steps of the Mock data return method described in the above embodiment, for example... Figure 2 The steps S101 to S106 shown, as well as other extensions and related steps of the method, are examples. Alternatively, when the processor executes a computer program, it implements the functions of each module / unit of the Mock data return device in the above embodiments, for example... Figure 3 The functions of modules 11 to 16 are shown. To avoid repetition, they will not be described again here.

[0085] The processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor. The processor is the control center of the computer device, connecting various parts of the computer device via various interfaces and lines.

[0086] The memory can be used to store the computer programs and / or modules. The processor implements various functions of the computer device by running or executing the computer programs and / or modules stored in the memory and by calling data stored in the memory. The memory may mainly include a program storage area and a data storage area. The program storage area may store the operating system, applications required for at least one function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created based on the use of the mobile phone (such as audio data, video data, etc.).

[0087] The memory can be integrated into the processor or it can be set up separately from the processor.

[0088] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When executed by a processor, the computer program implements the steps of the Mock data return method described in the above embodiment, for example... Figure 2 The steps S101 to S106 shown, as well as other extensions and related steps of the method, are examples. Alternatively, when a computer program is executed by a processor, it implements the functions of each module / unit of the Mock data return device in the above embodiments, for example... Figure 3 The functions of modules 11 to 16 are shown. To avoid repetition, they will not be described again here.

[0089] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0090] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is used as an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.

[0091] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.

Claims

1. A method for returning mock data, characterized in that, include: The gateway receives requests from the target interface sent by the front-end project, wherein the request from the target interface contains a unique Unique Resource Locator (URL). Query the pre-deployed and configured in-memory database to see if the target interface corresponding to the Uniform Resource Locator is set to the Mock interface type; If not, the request for the target interface is sent to the backend service cluster through the gateway, so that the backend service cluster sends the request for the target interface to the backend business component of the corresponding business module according to the cluster configuration information. If so, then query the corresponding first target Mock result data in the memory database according to the Uniform Resource Locator. The first target Mock result data is the Mock result data saved in the memory database when the target interface is first set as a Mock interface type. Use the first target Mock result data as the request return result data, or use the second Mock return result data returned by the backend business component as the request return result data; The request result data is returned to the request initiator of the corresponding target interface through the gateway; The step of querying the corresponding first target Mock result data in the in-memory database according to the Uniform Resource Locator includes: determining the Mock data return method of the Mock interface; if the Mock data return method is a field attribute value method, then searching for the corresponding field value in the in-memory database according to the returned field attribute of the target interface; assembling the field value into the first target Mock result data according to the returned data structure of the target interface; if the Mock data return method is JSON data method, then obtaining the interface returned JSON data corresponding to the target interface from the Mock JSON data set in the in-memory database as the first target Mock result data; Wherein, if the Mock data return method is field attribute value method, then looking up the corresponding field value in the memory database according to the returned field attribute of the target interface includes: if the request of the target interface is received for the first time, then obtaining the returned data structure of the target interface from the backend business component; obtaining different field attribute values ​​corresponding to different field attributes in the returned data structure in the memory database according to the returned data structure; assembling the field values ​​into the first target Mock result data according to the returned data structure of the target interface, and storing the first target Mock result data and the corresponding Uniform Resource Locator in the memory database; if the request of the target interface is not received for the first time, then obtaining the first target Mock result data in the memory database according to the Uniform Resource Locator corresponding to the target interface. The process, after returning the request result data to the initiator of the corresponding target interface through the gateway, further includes: receiving a setting request for the target interface, wherein the setting request is filtered for permissions through the gateway; if the setting request is to disable the Mock flag of the target interface, then the target interface is set to a non-Mock interface type in the memory database; if the setting request is to enable the Mock flag of the target interface, then it is checked whether the interface type setting request contains the first target Mock result data corresponding to the target interface; if it does not contain it, then setting the target interface to the Mock interface type fails; if the interface type setting request contains the corresponding first target Mock result data, then the first target Mock result data is sent to the corresponding backend service component for data structure verification; if the data structure verification fails, then setting the target interface to the Mock interface type fails; if the data structure verification passes, then the target interface is set to the Mock interface type in the memory database. The data structure verification includes: verifying, through the backend service component, whether the first target Mock result data can be composed into the corresponding interface return data according to the return data structure of the target interface; if it cannot be composed into the corresponding interface return data according to the return data structure of the target interface, the data structure verification is determined to have failed; if it can be composed into the corresponding interface return data according to the return data structure of the target interface, the data structure verification is determined to have passed.

2. The Mock data return method according to claim 1, characterized in that, After receiving the second Mock return result data returned by the backend business component as the request return result data, the method further includes: The second Mock return result data is saved to the memory database; If a request to enable the Mock identifier of the target interface is received, the second Mock return result data is used as the first target Mock result data corresponding to the target interface.

3. The Mock data return method according to claim 1, characterized in that, The setting request also includes whether to delete the Mock data flag. If the setting request is to disable the Mock flag of the target interface, after setting the target interface to a non-Mock interface type in the memory database, the request further includes: If the flag indicating whether to delete Mock data is True, then the first target Mock result data corresponding to the target interface is deleted from the memory database; If the flag indicating whether to delete Mock data is False, then the first target Mock result data corresponding to the target interface is transferred to the logical deletion area in the memory database.

4. A Mock data return device, characterized in that, include: The interface request receiving module is used to receive requests from the target interface sent by the front-end project through the gateway, wherein the request from the target interface contains a unique Unique Resource Locator (URL). The interface type determination module is used to query in a pre-deployed and configured in-memory database whether the target interface corresponding to the Uniform Resource Locator is set to the Mock interface type; The request forwarding module is used to send the request of the target interface to the backend service cluster through the gateway if no, so that the backend service cluster sends the request of the target interface to the backend business component of the corresponding business module according to the cluster configuration information. The in-memory database module is used to query the corresponding first target Mock result data in the in-memory database according to the Uniform Resource Locator if the target interface is first set as a Mock interface type. The result data module is used to use the first target Mock result data as the request return result data, or to use the second Mock return result data returned by the backend business component as the request return result data. The request result return module is used to return the request result data to the request initiator of the corresponding target interface through the gateway; The in-memory database module further includes: a return method determination submodule, used to determine the return method of the Mock data returned by the Mock interface; a first field value acquisition submodule, used to find the corresponding field value in the in-memory database according to the returned field attribute of the target interface if the Mock data return method is a field attribute value method; a first data structure composition submodule, used to compose the field value into the first target Mock result data according to the returned data structure of the target interface; and a first JSON data acquisition submodule, used to obtain the interface returned JSON data corresponding to the target interface from the Mock JSON data set of the in-memory database as the first target Mock result data if the Mock data return method is JSON data method. The first field value acquisition submodule further includes: a first interface return data subunit, used to acquire the return data structure of the target interface from the backend business component if the request of the target interface is received for the first time; an attribute value acquisition subunit, used to acquire different field attribute values ​​corresponding to different field attributes in the return data structure according to the return data structure in the memory database; a result data storage subunit, used to assemble the field values ​​into the first target Mock result data according to the return data structure of the target interface, and store the first target Mock result data and the corresponding Uniform Resource Locator in the memory database; and a second interface return data subunit, used to acquire the first target Mock result data in the memory database according to the Uniform Resource Locator corresponding to the target interface if the request of the target interface is not received for the first time. The process, after returning the request result data to the initiator of the corresponding target interface through the gateway, further includes: receiving a setting request for the target interface, wherein the setting request is filtered for permissions through the gateway; if the setting request is to disable the Mock flag of the target interface, then the target interface is set to a non-Mock interface type in the memory database; if the setting request is to enable the Mock flag of the target interface, then it is checked whether the interface type setting request contains the first target Mock result data corresponding to the target interface; if it does not contain it, then setting the target interface to the Mock interface type fails; if the interface type setting request contains the corresponding first target Mock result data, then the first target Mock result data is sent to the corresponding backend service component for data structure verification; if the data structure verification fails, then setting the target interface to the Mock interface type fails; if the data structure verification passes, then the target interface is set to the Mock interface type in the memory database. The data structure verification includes: verifying, through the backend service component, whether the first target Mock result data can be composed into the corresponding interface return data according to the return data structure of the target interface; if it cannot be composed into the corresponding interface return data according to the return data structure of the target interface, the data structure verification is determined to have failed; if it can be composed into the corresponding interface return data according to the return data structure of the target interface, the data structure verification is determined to have passed.

5. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the Mock data return method as described in any one of claims 1 to 3.

6. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the Mock data return method as described in any one of claims 1 to 3.

Citation Information

Patent Citations

  • Interface calling method and device, and computer readable storage medium

    CN113722020A