Distributed file system, unit testing method and device thereof and medium
By using the main thread and multiple unit testers to perform unit test tasks concurrently in distributed file systems, the shortcomings of existing unit test methods in multi-threaded and external dependency testing are solved, and wider test coverage and efficient resource utilization.
Patent Information
- Application Number
- CN202411332267.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-24
- Publication Date
- 2025-01-14
- Estimated Expiration
- 2044-09-24
AI Technical Summary
Existing unit testing methods cannot effectively cover test scenarios in multi-threaded or concurrent situations, lack testing on external dependencies, and may ignore interaction problems between functions, resulting in insufficient unit testing in distributed file systems.
采用基于分布式文件系统的单元测试方法,通过主线程和多个单元测试器,利用工作业务线程和工作队列进行并发执行单元测试任务,支持多客户端和多线程场景,分解任务并发执行,覆盖更广泛的测试场景。
It improves the efficiency and coverage of unit tests, can discover concurrency-related problems such as concurrency performance problems, race conditions and deadlocks, broadens the test scenarios, and improves resource utilization.
Smart Images

Figure CN119311579A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of unit testing technology, and in particular to a distributed file system and a unit testing method, device and medium thereof. Background Art
[0002] In the software development process, unit testing is the lowest level of testing activity that needs to be performed. It is also a simple and common testing method in software development. Unit testing is usually used to test independent functions or modules to verify the correctness of independent software units. However, for systems such as distributed file systems that rely on interactions between multiple nodes to implement functions, current unit testing also has some defects that need to be addressed:
[0003] 1. Unit testing cannot cover problem test scenarios of multi-threaded or concurrent situations: Single-threaded testing cannot simulate multi-threaded concurrent scenarios and may not be able to discover related race conditions or deadlock problems.
[0004] 2. Lack of testing for external dependencies: Unit testing only targets independent functions or modules, and the scenarios are limited to a single client, which cannot cover the interaction between functions or modules and external systems and services.
[0005] 3. Interaction issues between functions may be ignored: Unit testing usually focuses on the independent logic of functions or modules, and may ignore the interaction issues between different functions or modules. Manually designing and implementing integration testing solutions is too cumbersome and is not conducive to the development of operation and maintenance work.
[0006] Therefore, technicians in this field now urgently need a unit testing method based on a distributed file system to implement unit testing in application scenarios such as distributed file systems that emphasize interaction. Summary of the invention
[0007] The purpose of the present invention is to provide a distributed file system and a unit testing method, device and medium thereof, so as to solve the problem that the current unit testing scheme lacks the testing function in the external interaction scenario.
[0008] To solve the above technical problems, the present invention provides a unit testing method based on a distributed file system, which is applied to a distributed file system, wherein the distributed file system comprises: a main thread and multiple unit testers; different unit testers are mounted to different clients in the distributed file system; the unit tester comprises: a work service thread and a work queue; wherein the work service thread is composed of multiple threads, and the multiple threads are used to concurrently execute tasks in the work queue;
[0009] Applied to the main thread side, this method includes:
[0010] Obtain a unit test task; wherein the unit test task includes a task type;
[0011] If the unit test task is determined to be a multi-client task according to the task type, then:
[0012] Decomposing the unit test task according to the client to obtain subtasks corresponding to different clients;
[0013] Adding each of the subtasks to the work queue in the unit tester mounted on the corresponding client, so that each of the unit testers executes the subtasks concurrently;
[0014] The task execution results of each of the unit testers are obtained, and the unit test results are determined according to each of the task execution results.
[0015] In a possible embodiment, it further includes:
[0016] If the unit test task is determined to be a single-client, multi-threaded task according to the task type, then:
[0017] Adding the unit test task to the work queue in the unit tester mounted to the corresponding client, so that the unit tester concurrently executes the unit test task through multiple threads in the work business thread;
[0018] The task execution result of the unit tester is obtained, and the unit test result is determined according to the task execution result.
[0019] In a possible embodiment, it further includes:
[0020] If the unit test task is determined to be a single-client, single-threaded task according to the task type, then:
[0021] Execute the unit test task through the main thread;
[0022] The unit test result is determined according to the task execution result of the unit test task.
[0023] In a possible embodiment, the unit test task further includes: an operation type; wherein the operation type includes: read, write, delete, truncate, delete during write, and overwrite;
[0024] The unit test task is decomposed according to the client, and the subtasks corresponding to different clients include:
[0025] According to the operation type of the unit test task, a corresponding operation behavior is defined for each of the clients and encapsulated as the subtask.
[0026] To solve the above technical problems, the present invention also provides a unit testing method based on a distributed file system, which is applied to a distributed file system, wherein the distributed file system comprises: a main thread and multiple unit testers; different unit testers are mounted to different clients in the distributed file system; the unit tester comprises: a work service thread and a work queue; wherein the work service thread is composed of multiple threads, and the multiple threads are used to concurrently execute tasks in the work queue;
[0027] Applied to the unit tester side, the method includes:
[0028] The working service thread obtains a subtask from the working queue; wherein the subtask is obtained by decomposing the unit test task with the task type of multi-client and multi-threaded task according to the client and added to the working queue when the main thread obtains the unit test task;
[0029] Concurrently executing the subtasks through multiple threads in the working business thread;
[0030] The task execution result obtained after executing the subtask is returned to the main thread.
[0031] In a possible embodiment, the subtask includes: operation type, read / write mode, operation directory, operation file name, move operation file name, move target directory, read / write offset and read / write length;
[0032] The operation types include read, write, delete, truncate, delete during write, and overwrite; the read and write modes include: operation order, random order, and reverse order.
[0033] To solve the above technical problems, the present invention also provides a unit testing device based on a distributed file system, which is applied to a distributed file system, wherein the distributed file system comprises: a main thread and a plurality of unit testers; different unit testers are mounted to different clients in the distributed file system; the unit tester comprises: a work service thread and a work queue; wherein the work service thread is composed of a plurality of threads, and the plurality of threads are used to concurrently execute tasks in the work queue;
[0034] Applied to the main thread side, the device includes:
[0035] A task acquisition module, used for acquiring a unit test task; wherein the unit test task includes a task type; wherein, if the unit test task is determined to be a multi-client, multi-threaded task according to the task type, the task decomposition module, the first adding module and the first determining module are triggered;
[0036] The task decomposition module is used to decompose the unit test task according to the client to obtain subtasks corresponding to different clients;
[0037] The first adding module is used to add each of the subtasks to the work queue mounted on the unit tester corresponding to the client, so that each of the unit testers executes the subtasks concurrently;
[0038] The first determination module is used to obtain the task execution results of each of the unit testers, and determine the unit test results according to each of the task execution results.
[0039] To solve the above technical problems, the present invention also provides a unit testing device based on a distributed file system, which is applied to a distributed file system, wherein the distributed file system comprises: a main thread and a plurality of unit testers; different unit testers are mounted to different clients in the distributed file system; the unit tester comprises: a work service thread and a work queue; wherein the work service thread is composed of a plurality of threads, and the plurality of threads are used to concurrently execute tasks in the work queue;
[0040] Applied to the unit tester side, the device includes:
[0041] A task receiving module, used for the working service thread to obtain a subtask from the working queue; wherein the subtask is obtained by decomposing the unit test task with the task type of multi-client and multi-threaded task according to the client and added to the working queue when the main thread obtains the unit test task;
[0042] A task execution module, used for concurrently executing the subtasks through multiple threads in the work business thread;
[0043] The result returning module is used to return the task execution result obtained after executing the subtask to the main thread.
[0044] To solve the above technical problems, the present invention also provides a distributed file system, including: a main thread and multiple unit testers;
[0045] Different unit testers are mounted on different clients in the distributed file system; the unit tester includes: a work service thread and a work queue; the work service thread is composed of multiple threads, and the multiple threads are used to concurrently execute tasks in the work queue;
[0046] Wherein, the main thread is used to implement the steps of the unit testing method based on the distributed file system applied to the main thread side as described above;
[0047] The unit tester is used to implement the steps of the unit testing method based on a distributed file system applied to the unit tester side as described above.
[0048] To solve the above technical problem, the present invention also provides a non-volatile storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the unit testing method based on a distributed file system as described above are implemented.
[0049] The present invention provides a unit test method based on a distributed file system, in which a unit tester for unit testing is mounted in multiple clients of the distributed file system. Based on this, the main thread can simulate concurrent requests of multiple clients through the unit testers in multiple clients; first, the efficiency of unit testing can be improved; second, unit testing in multi-client interactive scenarios in the distributed file system can be realized, which broadens the test scenarios of unit testing; third, multiple different test scenarios can be simulated simultaneously through multiple clients, which improves resource utilization. Further, the unit test task involving multiple clients must be a multi-threaded task, and the subtask after decomposition may be a single-threaded task or a multi-threaded task. In this method, the unit tester implements the execution of subtasks through a work business thread containing multiple threads, so it can support the execution of single-threaded tasks and multi-threaded tasks at the same time. That is, in a single client, this method can also support unit testing of multi-threaded concurrent requests, which is conducive to broadening the test function of unit testing in interactive scenarios, and can discover concurrent performance problems, race conditions, deadlocks and other concurrency-related problems.
[0050] The distributed file system and its unit testing device, and non-volatile storage medium provided by the present invention correspond to the above method and have the same effect as above. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] In order to more clearly illustrate the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only 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.
[0052] FIG1 is a structural diagram of a distributed file system provided by an embodiment of the present invention;
[0053] FIG2 is a flow chart of a unit testing method applied to the main thread side provided by an embodiment of the present invention;
[0054] 3 is a flow chart of a unit testing method applied to a unit tester side provided by an embodiment of the present invention;
[0055] FIG4 is a structural diagram of a unit testing device applied to the main thread side provided by an embodiment of the present invention;
[0056] FIG5 is a structural diagram of a unit testing device applied to a unit tester side provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0057] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0058] The core of the present invention is to provide a distributed file system and a unit testing method, device and medium thereof.
[0059] In order to enable those skilled in the art to better understand the solution of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0060] Unit, that is, the smallest functional module to be tested that is artificially specified. The specific meaning of unit is different in different scenarios. For example, in C language (a computer programming language), unit generally refers to a function; in Java (a computer programming language), unit generally refers to a class; in graphical software, unit generally refers to a window or a menu, etc. Unit testing is the lowest level of testing activity to be performed during the software development process. Independent units of the software will be tested in isolation from other parts of the program. Based on the above unit testing scheme, the correctness of the unit in a single execution environment can be guaranteed, but there are also some limitations: unit testing cannot cover problem test scenarios of multi-threading or concurrency, lacks testing of external dependencies, and may ignore problems with interactions between functions.
[0061] Therefore, the above-mentioned single-client, single-threaded unit testing is suitable for verifying the basic logic and data processing of the code. However, when faced with complex systems that emphasize interaction, concurrent scenarios, or external dependencies such as distributed file systems, traditional unit testing solutions cannot meet the needs.
[0062] Based on this, the present invention provides a unit testing method based on a distributed file system, which is applied to a distributed file system. As shown in Figure 1, the distributed file system includes: a main thread and multiple unit testers; different unit testers are mounted on different clients in the distributed file system; the unit tester includes: a working business thread and a working queue; wherein the working business thread is composed of multiple threads, and the multiple threads are used to concurrently execute tasks in the working queue. Exemplarily, in a possible application scenario, the working business thread contains 6 threads by default, and the number of threads can be configured.
[0063] Applied to the main thread side, as shown in FIG2 , this method includes:
[0064] S100: Obtain unit test tasks.
[0065] Among them, the unit test task includes a task type. However, it should be noted that the unit test task including the task type is only the most basic solution. In other possible embodiments, the unit test task may also include more task information, such as: operation (op) type, read-write mode, operation directory, operation file name, move operation file name, move target directory, read-write offset, read-write length, etc., which is not limited in this embodiment. The above task information clearly shows the unit test items that need to be performed in this unit test task.
[0066] In another possible implementation scenario, the unit test task may also include specific test cases. The execution of the unit test task can be achieved by sending the corresponding test cases to the thread that executes the test cases, without the need for the multiple task information in the above example, or in other words, the test cases include the multiple task information in the above example. In addition, in this scenario, the subsequent step S111 decomposes the unit test task, that is, the decomposition of the test case. Specifically, when designing unit test cases for concurrent execution by multiple clients, corresponding test cases can be designed for each client, and finally the final test case, that is, the unit test task, is obtained. The subsequent step S111 is the process of reversely restoring the unit test task to the corresponding test case of each client.
[0067] If the unit test task is determined to be a multi-client task based on the task type, then:
[0068] S111: Decompose the unit test task according to the client to obtain subtasks corresponding to different clients.
[0069] S112: adding each subtask to a work queue in a unit tester mounted on a corresponding client, so that each unit tester executes the subtask concurrently.
[0070] S113: Obtain the task execution results of each unit tester, and determine the unit test results according to each task execution result.
[0071] Among them, steps S111 to S113 are branch steps of this method when the task type of the unit test task is a multi-client task. It should be noted that the multi-client task must be a multi-threaded task, which at least includes a test task concurrently executed by unit testers mounted by multiple clients. Therefore, step S111 is based on the client, and the unit test task is decomposed according to the client to obtain subtasks corresponding to each client. However, it should be noted that the decomposed subtasks here can further be single-threaded tasks or multi-threaded tasks.
[0072] For example, taking the common write task in unit testing as an example, the write task test executed concurrently by multiple clients can be specifically as follows: Client A and Client B concurrently write 100M data to the file. Among them, Client A writes data with an offset of 0-50M to the file, and Client B writes data with an offset of 50-100M to the file, thereby completing this multi-client concurrent write test task. This example corresponds to the decomposition of the multi-client unit test task to each client for execution, and the subtask executed by each client is a single-threaded write task.
[0073] Furthermore, an example is given of the decomposed subtask being a multi-threaded task: Taking the write task as an example, the subtask assigned to client A after the unit test task is decomposed is to write data with an offset of 0-50M to the file. However, unlike the above single-threaded subtask example, the subtask in this example requires client A to use 2 threads to concurrently write data with an offset of 0-50M to the file. Specifically, thread 1 may write data with an offset of 0-25M, and thread 2 may write data with an offset of 25-50M. Since each client in this method is mounted with a unit tester for executing test tasks, the unit tester includes a working business thread, and the working business thread is composed of multiple threads, the above write task can be implemented concurrently by multiple threads.
[0074] In addition, for step S112, it can be seen from the above that the unit tester includes a work queue, and the work business thread is used to execute tasks in the work queue. This method is applied to the main thread side, so by adding the subtasks obtained after decomposing the unit test task to the work queue, each unit tester is commanded to execute the unit test task. Among them, how the main thread adds tasks to the work queue in the work business thread can be implemented through function tools, such as the add_task function.
[0075] For step S113, it is a process of obtaining the task execution results of the unit testers mounted on each client after completing the corresponding subtasks and determining the final unit test results. Specifically, the main thread can obtain the task execution results actively (that is, the main thread asks the unit tester for the task execution results) or passively (that is, the unit tester sends the task execution results to the main thread), and this embodiment does not limit this. However, this embodiment provides a possible solution for the main thread to obtain the task execution results of the unit tester:
[0076] At the beginning of subtask creation, the main thread creates a collector; the main thread waits for the subtask execution of each unit tester to be completed through the collector; after all unit testers have completed their subtasks, the main thread calls back the task execution results of each unit tester through the collector.
[0077] The task execution result acquisition solution provided in this embodiment is adapted to the structural characteristics of the distributed file system, and can effectively realize the acquisition of the task execution result of the main thread mounting the unit tester in multiple different clients. In addition, the solution itself is simple to implement, and will not cause too much burden on the main thread or the distributed file system itself, and will not cause too much impact on the normal operation of this method and the distributed file system.
[0078] On the other hand, in addition to the above-mentioned unit test tasks involving multiple clients, this embodiment also provides an embodiment scheme of how to implement a unit test task involving only one client:
[0079] If the unit test task is determined to be a single-client, multi-threaded task according to the task type, the method further includes:
[0080] S121: adding the unit test task to the work queue of the unit tester mounted on the corresponding client, so that the unit tester can concurrently execute the unit test task through multiple threads in the work business thread.
[0081] S122: Obtain the task execution result of the unit tester, and determine the unit test result according to the task execution result.
[0082] In addition, this embodiment also provides a possible implementation scheme:
[0083] If the unit test task is determined to be a single-client, single-threaded task according to the task type, the method further includes:
[0084] S131: Execute unit test tasks through the main thread.
[0085] S132: Determine the unit test result according to the task execution result of the unit test task.
[0086] That is, the above embodiment provides two unit test task scenarios of different task types.
[0087] First, this unit test targets a single client, but involves multi-threaded concurrent request testing. At this point, it can be seen from the above that the working business threads used to execute test tasks in each unit tester in the distributed file system used by this method are composed of multiple threads, which can meet the requirements of multi-threaded concurrent testing. Therefore, in step S121 of the above embodiment, the unit test task is added to the work queue of the unit tester for execution. It should also be noted that the single-client and multi-threaded tasks targeted by steps S121 and S122 may have the requirement to be executed by a specific client. If there is such a requirement, the unit test task is added to the work queue of the unit tester mounted on the corresponding client. If there is no such requirement, the unit test task can be added to the work queue of any unit tester.
[0088] Second, this unit test is the most traditional unit test, targeting a single client and a single thread. At this time, since this unit test task is simple, there is no need to hand it over to a unit tester that supports multi-threaded testing. The main thread can complete this unit test task by itself, which also saves the intermediate steps of adding tasks and obtaining task execution results, thus improving the efficiency of unit testing.
[0089] Based on the above embodiments, the unit testing method based on a distributed file system provided by the present invention can cover the unit testing needs in various different testing scenarios such as multi-client multi-threading, single-client multi-threading and single-client single-threading, which greatly broadens the test scenarios supported by unit testing and helps to improve test coverage.
[0090] On the other hand, the above embodiment provides a specific implementation scheme for a unit test task when it includes a specific test case for the specific implementation of step S111. In another possible embodiment, the unit test task does not include a specific test case, but indicates the test type or test purpose of this unit test task through other task information such as the operation type.
[0091] Accordingly, this embodiment provides a possible implementation scheme, in which the above-mentioned unit test task includes, in addition to the task type, an operation type, wherein the operation type includes: read, write, delete, truncate, delete during write, and overwrite.
[0092] Then step S111 specifically includes: defining corresponding operation behaviors for each client according to the operation type of the unit test task and encapsulating them into subtasks.
[0093] It should be noted that the several operation types in the above examples are several common unit test types currently. If there is a new unit test requirement in actual application, the above operation types can be expanded, and this embodiment does not limit this.
[0094] In addition, based on the above-mentioned different operation types, other task information may be required in the unit test task. Exemplarily, when the operation type is a write or rewrite type, the task information required in the unit test task includes: operation directory, operation file name, write operation mode, write offset and write length (amount of data written). Furthermore, the main thread defines the corresponding operation behavior for the client according to the operation type, which may specifically include: opening the target file according to the operation directory and operation file name; writing data according to the write operation mode, write offset and write length; after writing the data, close the file and return the task execution result.
[0095] In addition, if it is a deletion operation, the task information required in the task information unit test task includes: operation directory, operation file name. The corresponding operation behavior can be specifically: determine the target file according to the operation directory and operation file name; delete the target file; return the task execution result.
[0096] If it is a write-delete operation, the task information required in the unit test task includes: operation directory, operation file name, write operation mode, write offset and write length. The corresponding operation behavior can be: open the target file according to the operation directory and operation file name; write half of the data according to the write operation mode, write offset and write length; delete the target file; write the other half of the data according to the write operation mode; close the target file and return the task execution result.
[0097] Similarly, the reading, overwriting, truncation, etc. mentioned in the above operation types are all common unit test cases. For these operation types, they are also based on the same principle. According to the task information required to complete the unit test of this operation type and the corresponding operation behavior, the unit test task is completed to obtain the task execution result and return it. This embodiment will not give examples one by one here.
[0098] The corresponding unit test task of this embodiment does not directly include the scenario of the test case, but indicates the test type required for this unit test through task information. The main thread then defines the specific operation type, thereby encapsulating it into executable subtasks for the unit tester to execute, which is conducive to simplifying the burden of unit testing on the front end, simplifying personnel operations, and improving test efficiency.
[0099] Based on the above, it is not difficult to see that the unit testing method based on a distributed file system provided by the present invention provides conditions for simulating multiple client concurrent request test scenarios through multiple unit testers mounted on different clients. At the same time, the working business thread for executing the test task in each unit tester is composed of multiple threads, that is, it supports multi-threaded concurrent request simulation in each client. On this basis, when the main thread receives a unit test task of a single client and a single thread, the main thread can complete the unit test by itself. This method covers the original unit test scenario, and supports single client, multi-threaded testing, as well as multi-client, multi-threaded testing, covering a wider range of test scenarios. It can simulate concurrent requests from multiple clients to improve test efficiency; and it can discover concurrent performance, race conditions, deadlocks and other concurrency-related problems; it can also take advantage of the multi-core advantages of multiple clients to run multiple test scenarios at the same time to improve resource utilization; it can perform stress testing on the distributed file system through a large number of concurrent requests, which is conducive to helping the system discover stability problems and bottlenecks under high load.
[0100] On the other hand, in addition to the above main thread side, the unit test method based on a distributed file system provided by the present invention is also applied to the unit tester side. This embodiment provides an implementation scheme on the unit tester side. The method is applied to the distributed file system shown in FIG1 . The specific structure is as described in the above embodiment, and this embodiment will not be repeated. The method applied to the unit tester side of this embodiment is shown in FIG3 , including:
[0101] S21: The working business thread obtains the subtask from the working queue.
[0102] Among them, when the main thread obtains a unit test task with a task type of multi-client and multi-threaded task, the subtask is decomposed according to the client and added to the work queue.
[0103] S22: Execute subtasks concurrently through multiple threads in the working business thread.
[0104] S23: Return the task execution result obtained after executing the subtask to the main thread.
[0105] Since the present embodiment is a unit testing method based on a distributed file system provided by the unit tester side, and is the same method as the above-mentioned embodiment based on the main thread side, the unit tester side also has an embodiment that is the same as or corresponding to the main thread side of the above-mentioned embodiment. For details, please refer to the above-mentioned embodiment part, and no further details will be given here.
[0106] However, the above embodiments mainly explain how the main thread side determines the corresponding test case based on the unit test task, such as designing the corresponding test case for execution when the unit test task is created, or the unit test task contains task information describing the unit test operation type and other necessary information, and the main thread obtains the test case based on the operation type definition operation behavior. This embodiment provides a possible solution for determining and executing the test case based on the subtask on the unit tester side:
[0107] The subtasks include: operation type, read / write mode, operation directory, operation file name, move operation file name, move target directory, read / write offset, and read / write length.
[0108] The operation types include read, write, delete, truncate, delete during write, and overwrite. The read and write modes include: operation order, random order, and reverse order.
[0109] The subtask added to the unit tester does not contain specific test cases, but includes a description of the operation type of this unit test and other necessary task information, so that the unit tester can define the operation behavior and execute the corresponding test cases.
[0110] It should be noted that the specific embodiments of defining operation behaviors according to operation types have been fully described in the above embodiments, such as the write / rewrite, delete, and delete during write examples provided above. The specific implementation plans can be found in the above embodiments, which will not be repeated here. The difference between this embodiment and the above embodiments is that the steps of defining operation behaviors are transferred from the main thread side to the unit tester side, and the other parts are the same. The advantage of this solution is that it further reduces the amount of data transmitted during communication, which is conducive to further improving the efficiency of unit testing. At the same time, for multi-client scenarios, sinking the operation behavior definition from the main thread to the unit tester implementation also helps to disperse the task load, which is also conducive to improving the efficiency of unit testing.
[0111] In addition, when the solution provided in the above embodiment is used to perform the test task, this embodiment also provides a possible implementation scheme:
[0112] First determine whether the operation type is write or rewrite, if so, perform the corresponding operation behavior;
[0113] If not, determine whether the operation type is deletion, and if so, perform the corresponding operation behavior;
[0114] If not, determine whether the operation type is write-delete, and if so, perform the corresponding operation;
[0115] If not, the corresponding operation behavior is performed according to the operation type.
[0116] In this embodiment, judging in the order of writing / rewriting, deleting, deleting during writing, and other operation types is an efficient and simple unit test execution process, which is conducive to improving the overall efficiency of unit testing.
[0117] In the above embodiment, a unit testing method based on a distributed file system is described in detail, and the present invention also provides a corresponding embodiment of a unit testing device based on a distributed file system. It should be noted that the present invention describes the method from both the main thread and the unit tester, and the corresponding embodiment also describes the embodiment of the device part from both the main thread and the unit tester, and both devices are applied to the distributed file system as described in Figure 1 and the above embodiment.
[0118] Applied to the main thread side, this embodiment provides a unit testing device based on a distributed file system, as shown in FIG4 , including:
[0119] The task acquisition module 11 is used to acquire a unit test task, wherein the unit test task includes a task type; wherein if the unit test task is determined to be a multi-client, multi-threaded task according to the task type, the task decomposition module, the first adding module and the first determining module are triggered.
[0120] The task decomposition module 12 is used to decompose the unit test task according to the client to obtain subtasks corresponding to different clients.
[0121] The first adding module 13 is used to add each subtask to the work queue of the unit tester mounted on the corresponding client, so that each unit tester executes the subtask concurrently.
[0122] The first determination module 14 is used to obtain the task execution results of each unit tester and determine the unit test results according to each task execution result.
[0123] Applied to the unit tester side, this embodiment provides a unit testing device based on a distributed file system, as shown in FIG5 , including:
[0124] The task receiving module 21 is used for the working business thread to obtain subtasks from the working queue; wherein, when the main thread obtains a unit test task with a task type of multi-client, multi-threaded task, the subtask is decomposed according to the client and added to the working queue.
[0125] The task execution module 22 is used to concurrently execute subtasks through multiple threads in the working business thread.
[0126] The result returning module 23 is used to return the task execution result obtained after executing the subtask to the main thread.
[0127] Since the embodiments of the apparatus part correspond to the embodiments of the method part, please refer to the description of the embodiments of the method part for the embodiments of the apparatus part, which will not be repeated here.
[0128] On the other hand, the present invention also provides an embodiment corresponding to a distributed file system, as shown in Figure 1, a distributed file system main thread and multiple unit testers; different unit testers are mounted on different clients in the distributed file system; the unit tester includes: a working business thread and a working queue; the working business thread is composed of multiple threads, and the multiple threads are used to concurrently execute tasks in the working queue.
[0129] The main thread is used to implement a unit test method based on a distributed file system on the main thread side of the above method embodiment. The unit tester is used to implement a unit test method based on a distributed file system on the unit tester side of the above method embodiment. The distributed file system provided in this embodiment has the same or corresponding technical features as the above method embodiment and can bring the same technical effects.
[0130] In addition to the embodiments of a distributed file system and a unit testing method and device thereof provided in the above embodiments, the present invention also provides an embodiment corresponding to a computer program product. A computer program product includes a computer program / instruction, and when the computer program / instruction is executed by a processor, the steps of the unit testing method based on a distributed file system described in any of the above embodiments can be implemented.
[0131] Since the embodiments of the computer program product part correspond to the embodiments of the method part, please refer to the description of the embodiments of the method part for the embodiments of the computer program product part, which will not be repeated here.
[0132] Finally, the present invention also provides an embodiment corresponding to a non-volatile storage medium. A computer program is stored on the non-volatile storage medium, and when the computer program is executed by a processor, the steps described in the above method embodiment (which may be a method corresponding to the main thread side, or a method corresponding to the unit tester side, or a method corresponding to both the main thread side and the unit tester side) are implemented.
[0133] It is understandable that if the method in the above embodiment is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a non-volatile storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium to execute all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc. Various media that can store program codes.
[0134] The above is a detailed introduction to a distributed file system and its unit testing method, device, and medium provided by the present invention. The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the various embodiments can be referenced to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description. It should be pointed out that for ordinary technicians in this technical field, without departing from the principle of the present invention, the present invention can also be improved and modified in a number of ways, and these improvements and modifications also fall within the scope of protection of the present invention.
[0135] It should also be noted that, in this specification, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the statement "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element.
Claims
1. A unit testing method based on a distributed file system, characterized in that: Applied to a distributed file system, the distributed file system comprises: a main thread and multiple unit testers; different unit testers are mounted on different clients in the distributed file system; the unit tester comprises: a work service thread and a work queue; wherein the work service thread is composed of multiple threads, and the multiple threads are used to concurrently execute tasks in the work queue; Applied to the main thread side, this method includes: Obtain a unit test task; wherein the unit test task includes a task type; If the unit test task is determined to be a multi-client task according to the task type, then: Decomposing the unit test task according to the client to obtain subtasks corresponding to different clients; Adding each of the subtasks to the work queue in the unit tester mounted on the corresponding client, so that each of the unit testers executes the subtasks concurrently; The task execution results of each of the unit testers are obtained, and the unit test results are determined according to each of the task execution results.
2. The unit testing method based on a distributed file system according to claim 1, characterized in that: Also includes: If the unit test task is determined to be a single-client, multi-threaded task according to the task type, then: Adding the unit test task to the work queue in the unit tester mounted to the corresponding client, so that the unit tester concurrently executes the unit test task through multiple threads in the work business thread; The task execution result of the unit tester is obtained, and the unit test result is determined according to the task execution result.
3. The unit testing method based on a distributed file system according to claim 2, characterized in that: Also includes: If the unit test task is determined to be a single-client, single-threaded task according to the task type, then: Execute the unit test task through the main thread; The unit test result is determined according to the task execution result of the unit test task.
4. The unit testing method based on a distributed file system according to claim 1, characterized in that: The unit test task also includes: operation type; wherein the operation type includes: read, write, delete, truncate, delete during write, overwrite; The unit test task is decomposed according to the client, and the subtasks corresponding to different clients include: According to the operation type of the unit test task, a corresponding operation behavior is defined for each of the clients and encapsulated as the subtask.
5. A unit testing method based on a distributed file system, characterized in that: Applied to a distributed file system, the distributed file system comprises: a main thread and multiple unit testers; different unit testers are mounted on different clients in the distributed file system; the unit tester comprises: a work service thread and a work queue; wherein the work service thread is composed of multiple threads, and the multiple threads are used to concurrently execute tasks in the work queue; Applied to the unit tester side, the method includes: The working service thread obtains a subtask from the working queue; wherein the subtask is obtained by decomposing the unit test task with the task type of multi-client and multi-threaded task according to the client and added to the working queue when the main thread obtains the unit test task; Concurrently executing the subtasks through multiple threads in the working business thread; The task execution result obtained after executing the subtask is returned to the main thread.
6. The unit testing method based on a distributed file system according to claim 5, characterized in that: The subtasks include: operation type, read / write mode, operation directory, operation file name, move operation file name, move target directory, read / write offset and read / write length; The operation types include read, write, delete, truncate, delete during write, and overwrite; the read and write modes include: operation order, random order, and reverse order.
7. A unit testing device based on a distributed file system, characterized in that: Applied to a distributed file system, the distributed file system comprises: a main thread and multiple unit testers; different unit testers are mounted on different clients in the distributed file system; the unit tester comprises: a work service thread and a work queue; wherein the work service thread is composed of multiple threads, and the multiple threads are used to concurrently execute tasks in the work queue; Applied to the main thread side, the device includes: A task acquisition module, used for acquiring a unit test task; wherein the unit test task includes a task type; wherein, if the unit test task is determined to be a multi-client, multi-threaded task according to the task type, the task decomposition module, the first adding module and the first determining module are triggered; The task decomposition module is used to decompose the unit test task according to the client to obtain subtasks corresponding to different clients; The first adding module is used to add each of the subtasks to the work queue mounted on the unit tester corresponding to the client, so that each of the unit testers executes the subtasks concurrently; The first determination module is used to obtain the task execution results of each of the unit testers, and determine the unit test results according to each of the task execution results.
8. A unit testing device based on a distributed file system, characterized in that: Applied to a distributed file system, the distributed file system comprises: a main thread and multiple unit testers; different unit testers are mounted on different clients in the distributed file system; the unit tester comprises: a work service thread and a work queue; wherein the work service thread is composed of multiple threads, and the multiple threads are used to concurrently execute tasks in the work queue; Applied to the unit tester side, the device includes: A task receiving module, used for the working service thread to obtain a subtask from the working queue; wherein the subtask is obtained by decomposing the unit test task with the task type of multi-client and multi-threaded task according to the client and added to the working queue when the main thread obtains the unit test task; A task execution module, used for concurrently executing the subtasks through multiple threads in the work business thread; The result returning module is used to return the task execution result obtained after executing the subtask to the main thread.
9. A distributed file system, characterized in that: include: Main thread and multiple unit testers; Different unit testers are mounted on different clients in the distributed file system; The unit tester includes: a work service thread and a work queue; the work service thread is composed of multiple threads, and the multiple threads are used to concurrently execute tasks in the work queue; Wherein, the main thread is used to implement the steps of the unit testing method based on a distributed file system as described in any one of claims 1 to 4 above; The unit tester is used to implement the steps of the unit testing method based on the distributed file system as described in claim 5 or 6 above.
10. A non-volatile storage medium, characterized in that: The non-volatile storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the unit testing method based on a distributed file system as described in any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Method for performing unified performance test on distributed file system
CN105808428A
Code coverage rate testing method and device
CN112988551A
Test method and device and mobile equipment
CN114153733A
Network file system test method, device, equipment and medium
CN117171120A
Application testing using multiple context-aware threads
US10387295B1