Local cache tool class test method and device, storage medium and computer equipment
By listening to the class name of the application under test and automatically processing local cached data, the problem of low testing efficiency in existing technologies is solved, and a more efficient local cache utility class test is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- VIPSHOP (GUANGZHOU) SOFTWARE CO LTD
- Filing Date
- 2022-10-26
- Publication Date
- 2026-04-28
AI Technical Summary
Existing local caching tools have low testing efficiency, relying on manual application restarts and code debugging to clear cached data, resulting in low testing efficiency.
By listening to the class names of the application under test, it is determined whether they meet the preset class name rules. Before the rules are met, data queries and/or data clearing are performed to ensure that there is no data to be cached in the local cache, thus executing the test in an automated manner.
This reduces manual intervention, improves the efficiency of local cache testing, and ensures the accuracy and reliability of test results.
Smart Images

Figure CN115563001B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of automatic testing technology, and in particular to a local caching tool-type testing method, apparatus, storage medium, and computer equipment. Background Technology
[0002] Currently, loading cache technology is widely used in data storage. For an application that needs to call a large number of downstream services or has high requirements for data retrieval efficiency, it needs to make extensive calls to loading cache utility classes to store data in memory, so that the application can directly read data from memory in subsequent processes.
[0003] When testing the application, the test content includes verifying the functionality of the local caching utility class. Specifically, after the application calls the local caching utility class, the test verifies whether the call successfully writes data to the local cache. To avoid the data stored in the local cache affecting the test results, before calling the local caching utility class, it is necessary to ensure that the data stored in the local cache has been cleared by restarting the application, debugging the application, and / or conducting code reviews. Only then should the local caching utility class be called for testing.
[0004] Restarting the service refers to manually restarting the application. After the application is closed, its corresponding local cache space will become invalid, and the data stored in that local cache space will be cleared. Debugging the application code refers to manually adding breakpoints at corresponding code locations through remote debugging to confirm that there is no data stored in the local cache space. Code review refers to manually reading the code to determine the configuration expiration time of the local cache service. This configuration expiration time indicates the duration for which data is retained in the local cache. After data is stored in the local cache, it will be cleared after the configuration expiration time. Therefore, the call time of the local cache utility class can be determined based on the configuration expiration time.
[0005] However, as can be seen from the above description, restarting, debugging, and code review all rely on manual processes, which greatly reduces testing efficiency. Summary of the Invention
[0006] The purpose of this application is to address at least one of the aforementioned technical defects, particularly the technical defect of low testing efficiency in the prior art.
[0007] In a first aspect, embodiments of this application provide a local caching utility class testing method, the method comprising:
[0008] When the application under test is detected to call a local caching utility class, the target class name is determined. The target class name is the class name of the local caching utility class that is called. The local caching utility class is used to write the data to be cached into the local cache.
[0009] Determine whether the target class name meets the preset class name rules;
[0010] If the target class name meets the preset class name rules, then before executing the code corresponding to the called local cache utility class, data query and / or data clearing are performed on the cached data in the local cache so that the local cache does not contain the data to be cached.
[0011] In one embodiment, the step of querying and / or clearing cached data in the local cache includes:
[0012] Determine the cache clearing mode for this operation;
[0013] If the cache clearing mode is a specified data clearing mode, then the target data identifier is obtained, and the cached data is queried according to the target data identifier to determine the target cached data corresponding to the target data identifier from the cached data, and the target cached data is cleared.
[0014] In one embodiment, the step of querying and / or clearing cached data in the local cache further includes:
[0015] If the cache clearing mode is the full data clearing mode, then all cached data will be cleared.
[0016] In one embodiment, the target data identifier is the data identifier corresponding to the function to be tested in the application to be tested.
[0017] In one embodiment, the method further includes: after executing the code corresponding to the invoked local caching utility class, obtaining and displaying the cached data in the local cache.
[0018] In one embodiment, the method further includes: if the target class name does not meet the preset class name rules, generating and displaying a prompt message.
[0019] Secondly, embodiments of this application provide a local caching utility testing device, the device comprising:
[0020] The class name acquisition module is used to determine the target class name when the application under test calls the local caching utility class. The target class name is the class name of the local caching utility class being called, and the local caching utility class is used to write the data to be cached into the local cache.
[0021] The rule judgment module is used to determine whether the target class name meets the preset class name rules;
[0022] The cached data processing module is used to perform data query and / or data clearing on the cached data in the local cache before executing the code corresponding to the called local cache utility class, provided that the target class name meets the preset class name rules, so that the local cache does not contain the data to be cached.
[0023] In one embodiment, the cached data processing module includes:
[0024] The mode determination unit is used to determine the cache clearing mode for this operation.
[0025] The query and clearing unit is used to obtain a target data identifier when the current cache clearing mode is a specified data clearing mode, and to perform a data query on the cached data according to the target data identifier to determine the target cached data corresponding to the target data identifier from the cached data. If the target cached data is not empty, the target cached data is cleared.
[0026] Thirdly, embodiments of this application provide a storage medium storing computer-readable instructions, which, when executed by one or more processors, cause the one or more processors to perform the steps of the local cache utility class testing method described in any of the above embodiments.
[0027] Fourthly, embodiments of this application provide a computer device, including: one or more processors, and a memory;
[0028] The memory stores computer-readable instructions, which, when executed by the one or more processors, perform the steps of the local cache utility class test method described in any of the above embodiments.
[0029] In the local caching utility class testing method, apparatus, storage medium, and computer device of this application, the computer device can monitor whether the application under test calls the local caching utility class, and if the application under test calls the local caching utility class, determine the target type of the called local caching utility class. If the target class name meets the preset class name rules, the computer device can perform data query and / or data clearing on the cached data in the local cache before executing the code corresponding to the local caching utility class. This ensures that when the code corresponding to the local caching utility class is executed, the local cache does not store the data to be cached by the local caching utility class, thereby testing whether the local caching utility class can write the data to be cached into the local cache. In this way, the degree of manual intervention in the local cache testing process can be reduced, thereby improving testing efficiency. Attached Figure Description
[0030] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art 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.
[0031] Figure 1 This is a flowchart illustrating the testing method of a local caching utility class in one embodiment;
[0032] Figure 2 This is a schematic diagram of the structure of a local caching utility class test device in one embodiment;
[0033] Figure 3 This is a schematic diagram of the structure of a computer device in one embodiment. Detailed Implementation
[0034] 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, and 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.
[0035] In one embodiment, this application provides a local caching utility testing method. The following embodiments illustrate this method using a computer device as an example. It is understood that the computer device can be any device with computing and processing capabilities, including but not limited to servers or personal laptops. In one embodiment, the computer device can be an application server, which can be a server used to run the application under test.
[0036] like Figure 1 As shown, the local caching utility class test method of this application may specifically include the following steps:
[0037] S102: When the application under test is detected to call the local caching utility class, the target class name is determined. The target class name is the class name of the local caching utility class that is called. The local caching utility class is used to write the data to be cached into the local cache.
[0038] In this context, the local cache utility class refers to a utility class used to write data to the local cache. The local cache refers to a cache space allocated from the local physical memory space, and "local" refers to the computer device used to run the application under test. It is understood that the specific execution logic of the local cache utility class can be determined based on the actual situation; this application does not impose specific restrictions on this, as long as the aforementioned functionality is achieved. In one example, the local cache utility class includes, but is not limited to, the MemCache utility class, the Guard utility class, and the Caffeine utility class.
[0039] Specifically, the computer device can monitor whether the application under test calls local cache utility classes. For example, the computer device can pre-configure the class names of each local cache utility class. Whenever the application under test is detected calling a utility class, the device obtains the class name of the called utility class and matches it with the pre-configured class names of each local cache utility class to determine whether the application under test is currently calling a local cache utility class.
[0040] When the computer device detects that the application under test is calling a local caching utility class, it can determine the class name of the local caching utility class being called, and the determined class name is the target class name.
[0041] S104: Determine whether the target class name meets the preset class name rules.
[0042] The preset class name rules can be used to determine whether a local caching utility class is supported. The computer device can determine whether the called local caching utility class is supported based on the target class name. For example, whether the computer device can execute the code corresponding to the called local caching utility class.
[0043] In one embodiment, because different local caching utility classes have different execution logic, the test code running on the computer device needs to execute different code to implement local cache data querying and / or data clearing for different local caching utility classes. For example, when the Guard utility class is called, data querying and clearing are implemented through test code segment A; when the Caffeine utility class is called, data querying and clearing are implemented through test code segment B. To avoid the test code configuration affecting the local caching utility class test, the computer device can determine whether the target class name meets the preset class name rules, and thus determine whether the test code can implement data querying and / or data clearing for the currently called local caching utility class. Further, the computer device can match the target class name with the pre-configured local caching utility class names and determine whether the target class name is the same as any pre-configured local caching utility class name. If so, it is confirmed that the target class name meets the preset class name rules; otherwise, it is confirmed that the target class name does not meet the preset class name rules.
[0044] S106: If the target class name meets the preset class name rules, before executing the code corresponding to the called local cache utility class, perform data query and / or data clearing on the cached data in the local cache so that the local cache does not cache the data to be cached.
[0045] Specifically, after invoking the local caching utility class, but before executing the code corresponding to the local caching utility class, the computer device can query and / or clear the cached data stored in the local cache. For example, the computer device can clear the local cache. Alternatively, the computer device can query the local cache and determine whether data clearing is necessary based on the query results.
[0046] After performing data querying and / or data clearing, the computer device can determine that the data to be cached by the local caching utility class is not stored in the local cache. Then, it executes the code corresponding to the called local caching utility class. After executing the code corresponding to the local caching utility class, if the data to be cached is stored in the local cache, it indicates that the local caching utility class has successfully written the data to be cached into the local cache, and the local caching utility class is functioning normally. Otherwise, it indicates that the local caching utility class has a defect.
[0047] In one embodiment, the computer device can use program instrumentation to insert corresponding data query code and / or data clearing code at the function entry point of the local cache utility class, so that the computer device can perform data query and / or data clearing on the cached data before executing the code corresponding to the local cache utility.
[0048] In one embodiment, if the target class name does not meet the preset class name rules, the computer device can generate and display a prompt message. Specifically, when the target class name does not meet the preset class name rules, it indicates that the called local caching utility class is not supported, such as the computer device running the application under test not having the code corresponding to the local caching utility class configured, or the test code lacking code snippets for the local caching utility class. In this case, the computer device can generate and display a prompt message to remind technicians and avoid misinterpreting the test results.
[0049] In this embodiment, the computer device can monitor whether the application under test calls the local caching utility class, and if so, determine the target type of the called local caching utility class. If the target class name meets the preset class name rules, the computer device can perform data querying and / or data clearing on the cached data in the local cache before executing the code corresponding to the local caching utility class. This ensures that when the code corresponding to the local caching utility class is executed, the local cache does not contain the data to be cached by the local caching utility class, thereby testing whether the local caching utility class can write the data to be cached into the local cache. This reduces the degree of manual intervention in the local cache testing process, thereby improving testing efficiency.
[0050] In one embodiment, the step of querying and / or clearing cached data in the local cache includes:
[0051] Determine the cache clearing mode for this operation;
[0052] If the cache clearing mode is a specified data clearing mode, then the target data identifier is obtained, and the cached data is queried according to the target data identifier to determine the target cached data corresponding to the target data identifier from the cached data, and the target cached data is cleared.
[0053] Specifically, before executing the code corresponding to the invoked local caching utility class, the computer device can determine the cache clearing mode for this operation. In one embodiment, the computer device can implement the local cache testing method described in this embodiment through a corresponding test function. In this case, the computer device can determine the cache clearing mode based on the input parameters of the test function. For example, when the input parameter is empty, the cache clearing mode is determined to be the full data clearing mode; when the input parameter is not empty, the cache clearing mode is determined to be the specified data clearing mode.
[0054] If the cache clearing mode is a specified data clearing mode, the computer device can obtain the data identifier corresponding to the data to be cleared, which is the target data identifier. The computer device can query the cached data in the local cache based on the target data identifier to determine the cached data in the local cache corresponding to the target data identifier, that is, to determine the target cached data.
[0055] If target cached data exists in the local cache, it indicates that the local cache contains data that needs to be cleared. Therefore, the computer can clear this data from the local cache, ensuring that the cleared local cache does not contain any target cached data, thus enabling the querying and clearing of the specified data. This avoids clearing all cached data in every call to the local caching utility class, further improving testing efficiency.
[0056] In one embodiment, the target data identifier is the data identifier corresponding to the function under test in the application under test. Specifically, each function point in the application under test can be configured with a unique data identifier. When a computer device executes the code segment corresponding to a certain function point and writes data to the local cache, the data will contain the data identifier corresponding to that function point. For example, when the computer device executes the code corresponding to the first function point and writes the first data to the local cache, the first data includes the data identifier corresponding to the first function point. Based on this, the computer device can selectively clear the cached data corresponding to the function under test in the local cache according to the data identifier corresponding to the function under test. In this way, the specified data in the local cache can be cleared more accurately, thereby improving the reliability of the test results and the test efficiency.
[0057] In one embodiment, the step of querying and / or clearing the cached data in the local cache further includes: if the current cache clearing mode is a full data clearing mode, then clearing all the cached data. Specifically, if the current cache clearing mode is a full data clearing mode, then all cached data in the local cache is cleared, so that the cleared local cache contains no cached data. This ensures that the data to be cached does not exist in the local cache, thereby improving the reliability of the test results.
[0058] In one embodiment, the method further includes: after executing the code corresponding to the invoked local caching utility class, retrieving and displaying the cached data in the local cache. Specifically, after executing the local caching utility class, if the local cache contains data to be cached, it indicates that the local caching utility class has successfully written the data to be cached into the local cache, and the local caching utility class functions normally. Otherwise, it indicates that the local caching utility class has a defect. Therefore, the computer device can retrieve and display the cached data in the local cache after executing the local caching utility class, so that technicians can determine whether the local caching utility class can achieve the expected function.
[0059] In one embodiment, the test code executing the test method of the local caching utility class described in this application can be encapsulated as a plugin service package to facilitate convenient and quick execution of the methods described in this application. Furthermore, this plugin service package can be injected into the application server in a pluggable manner.
[0060] The following describes the local cache utility class testing device provided in the embodiments of this application. The local cache utility class testing device described below can be referred to in correspondence with the local cache utility class testing method described above.
[0061] In one embodiment, this application provides a local caching utility class testing apparatus 200. For example... Figure 2 As shown, the device 200 includes a class name acquisition module 210, a rule judgment module 220, and a cache data processing module 230. Wherein:
[0062] The class name acquisition module 210 is used to determine the target class name when the application under test calls the local cache utility class. The target class name is the class name of the local cache utility class being called. The local cache utility class is used to write the data to be cached into the local cache.
[0063] Rule judgment module 220 is used to determine whether the target class name meets the preset class name rules;
[0064] The cache data processing module 230 is used to perform data query and / or data clearing on the cached data in the local cache before executing the code corresponding to the called local cache utility class, when the target class name meets the preset class name rules, so that the local cache does not cache the data to be cached.
[0065] In one embodiment, the cached data processing module 230 includes a mode determination unit and a query clearing unit. The mode determination unit determines the current cache clearing mode; the query clearing unit, when the current cache clearing mode is a specified data clearing mode, obtains a target data identifier and performs a data query on the cached data based on the target data identifier to determine the target cached data corresponding to the target data identifier from the cached data. If the target cached data is not empty, the target cached data is cleared.
[0066] In one embodiment, the cached data processing module 230 further includes a full clearing unit. This full clearing unit is used to clear all cached data when the current cache clearing mode is a full data clearing mode.
[0067] In one embodiment, the target data identifier is the data identifier corresponding to the function under test in the application under test.
[0068] In one embodiment, the apparatus 200 further includes a cached data display module. This cached data display module is used to retrieve and display cached data from the local cache after executing the code corresponding to the invoked local cache utility class.
[0069] In one embodiment, the device 200 further includes a prompt message display module. This prompt message display module is used to generate and display a prompt message when the target class name does not meet a preset class name rule.
[0070] In one embodiment, this application also provides a storage medium storing computer-readable instructions that, when executed by one or more processors, cause the one or more processors to perform the steps of the local cache utility class test method described in any of the above embodiments.
[0071] In one embodiment, this application also provides a computer device. The computer device stores computer-readable instructions that, when executed by one or more processors, cause the one or more processors to perform the steps of the local cache utility class testing method described in any of the above embodiments.
[0072] Indicatively, Figure 3 This is a schematic diagram of the internal structure of a computer device provided in an embodiment of this application. In one example, the computer device can be a server. (Refer to...) Figure 3The computer device 900 includes a processing component 902, which further includes one or more processors, and memory resources represented by memory 901 for storing instructions, such as application programs, that can be executed by the processing component 902. The application programs stored in memory 901 may include one or more modules, each corresponding to a set of instructions. Furthermore, the processing component 902 is configured to execute instructions to perform the steps of the local cache utility class test method described in any of the above embodiments.
[0073] The computer device 900 may also include a power supply component 903 configured to perform power management of the computer device 900, a wired or wireless network interface 904 configured to connect the computer device 900 to a network, and an input / output (I / O) interface 905. The computer device 900 may operate on an operating system stored in memory 901, such as Windows Server™, Mac OS X™, Unix™, Linux™, Free BSD™, or similar.
[0074] Those skilled in the art will understand that the internal structure of the computer device shown in this application is merely a block diagram of a portion of the structure related to the solution of this application, and does not constitute a limitation on the computer device to which the solution of this application is applied. A specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0075] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element. In this document, "a," "an," "the," "the," and "its" may also include plural forms unless the context clearly indicates otherwise. "Multiple" refers to at least two, such as 2, 3, 5, or 8, etc. "And / or" includes any and all combinations of the related listed items.
[0076] The various embodiments in this specification are described in a progressive manner. Each embodiment focuses on the differences from other embodiments. The various embodiments can be combined as needed, and the same or similar parts can be referred to each other.
[0077] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A testing method for a local caching utility class, characterized in that, The method includes: When the application under test is detected to call a local caching utility class, the target class name is determined. The target class name is the class name of the local caching utility class that is called. The local caching utility class is used to write the data to be cached into the local cache. Determine whether the target class name meets the preset class name rule; the preset class name rule is used to determine whether the local caching utility class is supported. If the target class name meets the preset class name rules, then before executing the code corresponding to the called local cache utility class, data query and / or data clearing are performed on the cached data in the local cache to ensure that the local cache does not contain the data to be cached; specifically, this includes: determining the cache clearing mode for this operation; if the cache clearing mode for this operation is a specified data clearing mode, then a target data identifier is obtained, and data query is performed on the cached data according to the target data identifier to determine the target cached data corresponding to the target data identifier from the cached data, and the target cached data is cleared; if the cache clearing mode for this operation is a full data clearing mode, then all the cached data is cleared.
2. The method according to claim 1, characterized in that, The target data identifier is the data identifier corresponding to the function to be tested in the application to be tested.
3. The method according to claim 1, characterized in that, The method further includes: After executing the code corresponding to the invoked local caching utility class, the cached data in the local cache is retrieved and displayed.
4. The method according to any one of claims 1 to 3, characterized in that, The method further includes: If the target class name does not meet the preset class name rules, a prompt message will be generated and displayed.
5. A local caching utility testing device, characterized in that, The device includes: The class name acquisition module is used to determine the target class name when the application under test calls the local caching utility class. The target class name is the class name of the local caching utility class being called, and the local caching utility class is used to write the data to be cached into the local cache. The rule judgment module is used to determine whether the target class name meets the preset class name rule; the preset class name rule is used to determine whether the local caching utility class is supported. The cached data processing module is used to perform data querying and / or data clearing on the cached data in the local cache before executing the code corresponding to the called local cache utility class, provided that the target class name meets the preset class name rules, so that the local cache does not contain the data to be cached; specifically, it includes: determining the cache clearing mode for this time; if the cache clearing mode for this time is a specified data clearing mode, then obtaining the target data identifier, and performing data querying on the cached data according to the target data identifier to determine the target cached data corresponding to the target data identifier from the cached data, and clearing the target cached data; if the cache clearing mode for this time is a full data clearing mode, then clearing all the cached data.
6. A storage medium, characterized in that, The storage medium stores computer-readable instructions that, when executed by one or more processors, cause the one or more processors to perform the steps of the local cache utility class test method as described in any one of claims 1 to 4.
7. A computer device, characterized in that, include: One or more processors, and memory; The memory stores computer-readable instructions, which, when executed by the one or more processors, perform the steps of the local cache utility class test method as claimed in any one of claims 1 to 4.
Citation Information
Patent Citations
Method and device for testing multi-machine-room cache synchronizing function
CN106294033A