A test account implementation method based on database routing

By implementing a test account method based on database routing, the problem of data impacting the production environment in internet project testing was solved, improving data accuracy and security, reducing resource waste, and increasing testing efficiency.

CN114138839BActive Publication Date: 2024-11-19ZHEJIANG SHUXIN NETWORK CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111485228.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-07
Publication Date
2024-11-19
Estimated Expiration
2041-12-07

AI Technical Summary

Technical Problem

During the testing process of internet projects, test data can affect the functionality of the production environment, leading to reduced data accuracy and security, increased testing complexity, and serious waste of resources.

Method used

A database-based routing approach is adopted for test accounts. Interceptors and middleware are used to distinguish between test and production data. MyCat and Redis are used to improve data routing efficiency and ensure that data is stored independently.

Benefits of technology

It improved the accuracy and security of data, reduced resource waste, lowered testing complexity and maintenance workload, and improved testing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114138839B_ABST
    Figure CN114138839B_ABST
Patent Text Reader

Abstract

The present invention discloses a test account implementation method based on database routing. After the present invention is used in an Internet project, the user enters an account and password to log in to the system, sends a request to the server on the client side, intercepts the user request through an interceptor, obtains user information and determines whether the current user is a test user, and the server side processes the user request logic and initiates a database request according to the user request, and routes the database request to the corresponding database through the database middleware according to the user account information, so as to realize independent storage of test data and real data. In this way, the impact of test data on production environment data is reduced, and the security, accuracy and authenticity of data are increased; at the same time, the problems caused by the deployment of programs on different servers are avoided, the workload of development, operation and maintenance, and test personnel is reduced, unnecessary waste of resources is reduced, and work efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of Internet project testing, and provides a convenient, fast and efficient Internet project testing technical solution. Background Art

[0002] At present, in the process of Internet project development and update iteration, the production environment testing of Internet projects is relatively cumbersome, and there is no relatively fixed Internet testing solution. At present, most Internet companies deploy projects in the pre-production environment in addition to the production environment for testing before and after the project goes online. The pre-production environment and production environment of the newly deployed project use the same database; some companies have improved the above solution and shared the same entrance for the pre-production environment and the production environment. After logging in, the user determines which environment to enter based on the user information. The subsequent process is the same as above, with the advantage of sharing the same user system.

[0003] However, because the above two methods use the same database as the production environment, test data needs to be deleted in a timely manner to reduce the impact of test data on existing business data. However, if the project contains similar functions such as real-time data statistical analysis, it will inevitably affect the accuracy of the data. In addition, when the functional cycle iteration of the project involves changes to the function, since the previous test data has been deleted, only some false data can be added for testing, which invisibly increases the complexity of the test and reduces the test efficiency of the tester; and frequently deletes test data in the database during the test process, which greatly reduces the security of the data. Especially with the rise of microservice architecture, each environment often requires multiple servers, resulting in a waste of resources. Summary of the invention

[0004] The purpose of the present invention is to provide a test account implementation method based on database routing to address the drawbacks that the test data generated during the testing process of traditional Internet projects affects some functions of the production environment (such as real-time data statistical analysis), and that after the test is completed, manual operation is required to delete the test data from the production environment database, which is not conducive to data security. By using database middleware, request interceptors, etc., the above problems are well solved, the workload of development, operation and maintenance, and testing personnel is reduced, unnecessary waste of resources is reduced, and work efficiency and data security and accuracy are improved.

[0005] The object of the present invention is to achieve the following technical solution: a test account implementation method based on database routing, the method comprising the following steps:

[0006] (1) Interceptor I and Interceptor II are set up on the server side, and database middleware, as well as a normal database and a test database connected to the database middleware, are deployed; a test account identifier is added to the user information of the user system to distinguish between normal user accounts and test user accounts;

[0007] (2) When the user initiates a request to the server, the user request is first intercepted by interceptor I, and user information is requested from the user system within interceptor I. The test account identifier in the user information is obtained to distinguish the type of the user, and the test account identifier is stored in the cache;

[0008] (3) The server processes the user request logic and initiates a database request based on the user request. Interceptor II intercepts the database request and obtains the test account identifier corresponding to the user added by Interceptor I from the cache in Interceptor II. The test account identifier is added to the database request and the database request is then sent to the database middleware.

[0009] (4) The database middleware parses the test account identifier in the database request and forwards the database request to the corresponding ordinary database or test database according to the test account identifier;

[0010] (5) The database operates the data in the database according to the database request and returns the result information, which is then passed through the database middleware and the server in turn and finally returned to the user.

[0011] Furthermore, if the user is not logged in, the test account identifier of the user stored in the cache of Interceptor I is identified as a normal user account by default.

[0012] Furthermore, the method is implemented in Java language, and the test account identifier is set in ThreadLocal in Interceptor I and Interceptor II, and ThreadLocal is used as a cache.

[0013] Furthermore, the database middleware adopts MyCat, which can adopt MyCat cluster under large amount of concurrent requests to improve the throughput of the project. In addition, MyCat is relatively complete in processing database transactions.

[0014] Furthermore, the cache adopts the cache middleware Redis. Since the data cached in Redis is stored in the memory, the efficiency of adding and deleting data information is high, and the data cached in Redis can be set with an expiration time. Therefore, when an exception occurs during the execution of the request, the cached data can be automatically deleted by the expiration time, thereby improving security.

[0015] The advantages and beneficial effects of the present invention are:

[0016] 1. Adding test accounts to the production environment allows testers to conduct tests in the production environment. Because real data and test data are stored in two independent databases through database routing, the accuracy and authenticity of the data are guaranteed.

[0017] 2. During the testing process, because the test and online share resources other than the database, the problems caused by non-program factors caused by environmental differences in actual testing are reduced.

[0018] 3. In terms of resources, the introduction of test accounts reduces the waste of resources caused by resource environment deployment, thereby saving costs and reducing the workload of testing and operation and maintenance personnel due to the need to deploy multiple environments. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0020] Figure 1 A project model diagram of one embodiment of the present invention;

[0021] Figure 2 The present invention is a flowchart of a method for implementing a test account based on database routing according to one embodiment of the present invention. DETAILED DESCRIPTION

[0022] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the specific embodiments of the present invention are described in detail below with reference to the accompanying drawings.

[0023] In the following description, many specific details are set forth to facilitate a full understanding of the present invention, but the present invention may also be implemented in other ways different from those described herein, and those skilled in the art may make similar generalizations without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.

[0024] like Figure 1 , 2 As shown, the present invention provides a test account implementation method based on database routing, the method comprising the following steps:

[0025] (1) Interceptor I and Interceptor II are set up on the server side, and database middleware, as well as a normal database and a test database connected to the database middleware, are deployed; a test account identifier is added to the user information of the user system to distinguish between normal user accounts and test user accounts;

[0026] (2) When the user initiates a request to the server, the user request is first intercepted by interceptor I, and user information is requested from the user system within interceptor I. The test account identifier in the user information is obtained to distinguish the type of the user, and the test account identifier is stored in the cache;

[0027] (3) The server processes the user request logic and initiates a database request based on the user request. Interceptor II intercepts the database request and obtains the test account identifier corresponding to the user added by Interceptor I from the cache in Interceptor II. The test account identifier is added to the database request and the database request is then sent to the database middleware.

[0028] (4) The database middleware parses the test account identifier in the database request and forwards the database request to the corresponding ordinary database or test database according to the test account identifier;

[0029] (5) The database operates the data in the database according to the database request and returns the result information, which is then passed through the database middleware and the server in turn and finally returned to the user.

[0030] Specifically, if the user is not logged in, the test account identifier of the user stored in the cache of Interceptor I is a normal user account by default.

[0031] Specifically, the method is implemented in Java language, and the test account identifier is set in ThreadLocal in Interceptor I and Interceptor II, and ThreadLocal is used as a cache.

[0032] Specifically, the database middleware uses MyCat, which can use MyCat cluster under large amounts of concurrent requests to improve the throughput of the project. In addition, MyCat is relatively complete in processing database transactions.

[0033] Specifically, the cache middleware Redis is used. Since the cached data in Redis is stored in the memory, the efficiency of adding and deleting data information is high, and the data cached in Redis can be set with an expiration time. Therefore, when an exception occurs during the request execution process, the cached data can be automatically deleted by the expiration time, thereby improving security.

[0034] Example 1

[0035] This embodiment is a quasi-e-commerce platform project. User roles are divided into four types: administrator, merchant user, customer user and unlogged-in visitor user. User account types are divided into two categories and six types, namely ordinary user accounts: administrator ordinary user account, merchant ordinary user account and customer ordinary user account; test user account: administrator test user account, merchant test user account and customer test user account. The platform administrator is mainly responsible for the user management of the platform, the management of all orders and product information, and the classification and statistics of data information. Merchant users are mainly responsible for the management of orders and product information placed by the merchant. Customer users are consumers who browse the goods sold by merchants and place orders according to their needs. Unlogged-in visitor users are consumers who have not logged in to their accounts. They browse the goods and select goods according to their needs, and then log in to the platform to purchase goods. The test user account is an account used by the internal personnel of the project development and testing to test the problems in the project to ensure the stability of the project.

[0036] The merchant user logs in to the system using the test user account and password and the ordinary user account and password respectively, adds product information to the system and puts the newly added products on the shelves.

[0037] Customer users use the test user account password and the ordinary user account password to log in to the system. After using the customer test user account to enter the system, only the product information added by the merchant test user account can be queried, and the product information added by the merchant ordinary user account cannot be queried. After using the customer ordinary user account to enter the system, only the product information added by the merchant user account of the same type as the current user account can be queried.

[0038] When the administrator logs into the system using the test user account and password and the normal user account and password respectively, the product information and order information that can be viewed are also only the product information added by the merchant user account of the same user account type as the current user account and the order information submitted by the consumer user account of the same user account type. The same is true for data information classification statistics.

[0039] For non-logged in guest users, when they enter the system to view product information without logging in to their account, they can only query product information listed by merchants whose user type is a normal user account.

[0040] The above description is merely a preferred embodiment of one or more embodiments of the present specification and is not intended to limit one or more embodiments of the present specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of the present specification shall be included in the scope of protection of one or more embodiments of the present specification.

Claims

1. A test account implementation method based on database routing, characterized in that: The following steps are involved: (1) Interceptor I and Interceptor II are set up on the server side, and database middleware, as well as a normal database and a test database connected to the database middleware, are deployed; a test account identifier is added to the user information of the user system to distinguish between normal user accounts and test user accounts; (2) When a user initiates a request to the server, the user request is first intercepted by Interceptor I, and user information is requested from the user system within Interceptor I. The test account ID in the user information is obtained to distinguish the type of the user, and the test account ID is stored in the cache; (3) The server processes the user request logic and initiates a database request based on the user request. Interceptor II intercepts the database request and obtains the test account identifier corresponding to the user added by Interceptor I from the cache in Interceptor II. The test account identifier is added to the database request and the database request is then sent to the database middleware. (4) The database middleware parses the test account identifier in the database request and forwards the database request to the corresponding normal database or test database according to the test account identifier; (5) The database operates the data in the database according to the database request and returns the result information, which is then passed through the database middleware and the server in turn and finally returned to the user.

2. The method according to claim 1, characterized in that If the user is not logged in, the test account identifier of the user stored in the cache of Interceptor I is a normal user account by default.

3. The method according to claim 1, characterized in that: This method is implemented in Java language. In interceptor I and interceptor II, the test account identifier is set in ThreadLocal, and ThreadLocal is used as a cache.

4. The method according to claim 1, characterized in that: The database middleware adopts MyCat, and the database middleware adopts MyCat cluster under the concurrent requests of large data volume.

5. The method according to claim 1, characterized in that: The cache uses the cache middleware Redis, and sets an expiration time for the data cached in Redis, so that when an exception occurs during the execution of a request, the cached data is automatically deleted according to the expiration time.