A distributed file system and its unit testing method, device and medium

By introducing a main thread and multiple unit testers into a distributed file system, and utilizing worker business threads and work queues to achieve multi-threaded concurrent task execution, the problem that existing unit testing methods cannot cover multi-threaded or concurrent situations and external dependencies in a distributed file system is solved, thereby improving test coverage and efficiency.

CN119311579BActive Publication Date: 2025-10-28JINAN INSPUR DATA TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411332267.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-24
Publication Date
2025-10-28
Estimated Expiration
2044-09-24

AI Technical Summary

Technical Problem

Existing unit testing methods cannot effectively cover multi-threaded or concurrent scenarios, lack testing for external dependencies, and may overlook inter-function interactions, especially in distributed file systems where they are difficult to meet testing requirements in interactive scenarios.

Method used

This paper presents a unit testing method based on a distributed file system. It uses a main thread and multiple unit testers, along with worker business threads and work queues, to achieve multi-threaded concurrent task execution. It supports unit testing in complex scenarios such as multi-client, multi-threaded, and single-client, multi-threaded scenarios.

Benefits of technology

It improves unit test coverage, enables the discovery of concurrency performance issues and deadlocks, broadens the testing scenarios, improves resource utilization and testing efficiency, and supports unit testing in multi-client interaction scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119311579B_ABST
    Figure CN119311579B_ABST
Patent Text Reader

Abstract

This invention discloses a distributed file system and its unit testing method, apparatus, and medium, relating to the field of unit testing technology. It addresses the limitations of traditional unit testing solutions in covering multi-threaded or concurrent scenarios by providing a unit testing method based on a distributed file system. This method involves mounting unit testers on multiple clients of the distributed file system. Based on this, the main thread can simulate concurrent requests from multiple clients through the unit testers on those clients, improving unit testing efficiency, enabling unit testing in multi-client interaction scenarios within the distributed file system, broadening the testing scenarios, and uncovering concurrency-related issues such as performance problems, race conditions, and deadlocks.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of unit testing technology, and in particular to a distributed file system and its unit testing method, apparatus, and medium. Background Technology

[0002] In software development, unit testing is the lowest level of testing activity required and a simple and common testing method. Unit tests are typically used to test individual functions or modules to verify the correctness of these individual software units. However, for systems like distributed file systems that rely on interaction between multiple nodes to achieve functionality, current unit testing methods have some shortcomings that urgently need to be addressed.

[0003] 1. Unit tests cannot cover multi-threaded or concurrent scenarios. Test scenario: Single-threaded tests cannot simulate multi-threaded concurrent scenarios and may not be able to detect related race conditions or deadlock issues.

[0004] 2. Lack of testing for external dependencies: Unit tests only target independent functions or modules, and the scenarios are limited to a single client, failing to cover the interaction between functions or modules and external systems or services.

[0005] 3. Potential oversight of inter-function interactions: Unit tests typically focus on the independent logic of functions or modules, potentially overlooking interactions between different functions or modules. Manually designing and implementing integration test solutions is overly cumbersome and detrimental to maintenance work.

[0006] Therefore, those skilled in the art urgently need a unit testing method based on distributed file systems to implement unit testing in application scenarios that emphasize interaction, such as distributed file systems. Summary of the Invention

[0007] The purpose of this invention is to provide a distributed file system and its unit testing method, apparatus, and medium to solve the problem that current unit testing schemes lack testing functions for scenarios involving external interaction.

[0008] To address the aforementioned technical problems, this invention provides a unit testing method based on a distributed file system, applied to a distributed file system, wherein the distributed file system includes: a main thread and multiple unit testers; different unit testers are mounted to different clients in the distributed file system; each unit tester includes: a worker business thread and a work queue; wherein the worker business thread consists 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 unit test tasks; wherein, the unit test tasks include task types;

[0011] If the unit test task is determined to be a multi-client task based on the task type, then:

[0012] The unit test task is decomposed according to the client to obtain sub-tasks corresponding to different clients;

[0013] Each of the subtasks is added to the work queue of the unit tester mounted to the corresponding client, so that each of the unit testers executes the subtasks concurrently;

[0014] Obtain the task execution results of each unit tester, and determine the unit test results based on the task execution results.

[0015] In one possible embodiment, it further includes:

[0016] If the unit test task is determined to be a single-client, multi-threaded task based on the task type, then:

[0017] The unit test task is added to the work queue of the unit tester mounted to the corresponding client, so that the unit tester executes the unit test task concurrently through multiple threads in the work business thread;

[0018] Obtain the task execution result of the unit tester, and determine the unit test result based on the task execution result.

[0019] In one possible embodiment, it further includes:

[0020] If the unit test task is determined to be a single-client, single-threaded task based on the task type, then:

[0021] The unit test task is executed through the main thread;

[0022] The unit test result is determined based on the task execution result of the unit test task.

[0023] In one possible embodiment, the unit test task further includes: operation types; wherein the operation types include: read, write, delete, truncate, delete during write, and overwrite write;

[0024] The unit test task is then decomposed according to the client, resulting in sub-tasks corresponding to different clients, including:

[0025] Based on the operation type of the unit test task, define corresponding operation behaviors for each client and encapsulate them as subtasks.

[0026] To address the aforementioned technical problems, this invention also provides a unit testing method based on a distributed file system, applied to a distributed file system, wherein the distributed file system includes: a main thread and multiple unit testers; different unit testers are mounted to different clients in the distributed file system; each unit tester includes: a worker business thread and a work queue; wherein the worker business thread consists of multiple threads, and the multiple threads are used to concurrently execute tasks in the work queue;

[0027] Applied to the unit tester side, this method includes:

[0028] The work business thread obtains subtasks from the work queue; wherein, the subtask is obtained by the main thread when it obtains a unit test task of the task type of multi-client, multi-threaded task, and it is decomposed according to the client and added to the work queue;

[0029] The subtasks are executed concurrently by multiple threads within the aforementioned work business thread;

[0030] The task execution result obtained after executing the subtask is returned to the main thread.

[0031] In one 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 / write modes include: operation sequence, random sequence, and reverse sequence.

[0033] To address the aforementioned technical problems, this invention also provides a unit testing device based on a distributed file system, applied to a distributed file system, wherein the distributed file system includes: a main thread and multiple unit testers; different unit testers are mounted to different clients in the distributed file system; each unit tester includes: a worker business thread and a work queue; wherein the worker business thread consists of multiple threads, and the multiple threads are used to concurrently execute tasks in the work queue;

[0034] Applied to the main thread side, the device includes:

[0035] The task acquisition module is used to acquire unit test tasks; wherein, the unit test tasks include task types; wherein, if the unit test task is determined to be a multi-client, multi-threaded task based on the task type, the task decomposition module, the first addition module, and the first determination module are triggered.

[0036] The task decomposition module is used to decompose the unit test task according to the client to obtain sub-tasks corresponding to different clients;

[0037] The first adding module is used to add each of the subtasks to the work queue of the unit tester mounted on the corresponding client, so that each of the unit testers executes the subtasks concurrently;

[0038] The first determining module is used to obtain the task execution results of each of the unit testers and determine the unit test results based on the task execution results.

[0039] To address the aforementioned technical problems, this invention also provides a unit testing device based on a distributed file system, applied to a distributed file system, wherein the distributed file system includes: a main thread and multiple unit testers; different unit testers are mounted to different clients in the distributed file system; each unit tester includes: a worker business thread and a work queue; wherein the worker business thread consists of multiple threads, and the multiple threads are used to concurrently execute tasks in the work queue;

[0040] Applied to the unit tester side, the device includes:

[0041] The task receiving module is used for the working business thread to obtain subtasks from the work queue; wherein, the subtask is obtained by the main thread when it obtains a unit test task of the task type of multi-client, multi-threaded task, and decomposes it according to the client, and adds it to the work queue;

[0042] The task execution module is used to concurrently execute the subtasks through multiple threads in the work business thread;

[0043] The result return module is used to return the task execution result obtained after executing the subtask to the main thread.

[0044] To address the aforementioned technical problems, this invention also provides a distributed file system, comprising: a main thread and multiple unit testers;

[0045] Different unit testers are mounted to different clients in the distributed file system; each unit tester includes: a worker business thread and a work queue; the worker business thread consists of multiple threads, and the multiple threads are used to concurrently execute tasks in the work queue;

[0046] 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 distributed file system-based unit testing method applied to the unit tester side as described above.

[0048] To address the aforementioned technical problems, the present invention also provides a non-volatile storage medium storing a computer program, which, when executed by a processor, implements the steps of the unit testing method based on a distributed file system as described above.

[0049] This invention provides a unit testing method based on a distributed file system, which mounts unit testers for unit testing on multiple clients of the distributed file system. Based on this, the main thread can simulate concurrent requests from multiple clients through the unit testers on multiple clients. This improves unit testing efficiency, enables unit testing in multi-client interaction scenarios within the distributed file system, broadening the testing scenarios, and improves resource utilization by simulating multiple different test scenarios simultaneously across multiple clients. Furthermore, unit testing tasks involving multiple clients are necessarily multi-threaded tasks, and the decomposed subtasks may be single-threaded or multi-threaded. In this method, the unit tester executes subtasks through a working business thread containing multiple threads, thus supporting both single-threaded and multi-threaded execution. That is, even within a single client, this method can support unit testing of multi-threaded concurrent requests, which helps broaden the testing capabilities of unit testing in interactive scenarios and can uncover concurrency-related issues such as performance problems, race conditions, and deadlocks.

[0050] The distributed file system and its unit testing device, as well as the non-volatile storage medium provided by this invention, correspond to the above methods and have the same effect. Attached Figure Description

[0051] To more clearly illustrate the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0052] Figure 1 A structural diagram of a distributed file system provided in an embodiment of the present invention;

[0053] Figure 2 A flowchart illustrating a unit testing method applied to the main thread side, provided as an embodiment of the present invention;

[0054] Figure 3 A flowchart of a unit testing method applied to the unit tester side is provided as an embodiment of the present invention;

[0055] Figure 4 A structural diagram of a unit testing device applied to the main thread side provided in an embodiment of the present invention;

[0056] Figure 5 This is a structural diagram of a unit testing device applied to the unit tester side, provided in an embodiment of the present invention. Detailed Implementation

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

[0058] The core of this invention is to provide a distributed file system and its unit testing method, apparatus, and medium.

[0059] To enable those skilled in the art to better understand the present invention, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.

[0060] A unit, or the smallest functional module to be tested, is defined by the developer. The specific meaning of a unit varies depending on the context. For example, in C, a unit generally refers to a function; in Java, a unit generally refers to a class; and in graphical software, a unit generally refers to a window or a menu. Unit testing is the lowest level of testing activity performed during software development. Independent units of software are tested in isolation from other parts of the program. This unit testing approach ensures the correctness of units in a single execution environment, but it also has limitations: unit testing cannot cover multi-threaded or concurrent scenarios, lacks testing for external dependencies, and may overlook inter-function interactions.

[0061] Therefore, the single-client, single-threaded unit tests described above are 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, applicable to distributed file systems. For example... Figure 1As shown, the distributed file system includes: a main thread and multiple unit testers; different unit testers are mounted to different clients in the distributed file system; each unit tester includes: worker business threads and a work queue; wherein, the worker business thread consists of multiple threads, and these threads are used to concurrently execute tasks in the work queue. For example, in one possible application scenario, the worker business thread contains 6 threads by default, and the number of threads can be configured.

[0063] Applied to the main thread side, such as Figure 2 As shown, this method includes:

[0064] S100: Obtain unit test tasks.

[0065] The unit test task includes a task type. However, it should be noted that including a task type is only a basic approach. In other possible embodiments, the unit test task may 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. This embodiment does not impose limitations on this. The above task information clearly indicates the unit test items required for this unit test task.

[0066] In another possible implementation scenario, unit test tasks can also include specific test cases. The execution of unit test tasks can be achieved by distributing the corresponding test cases to the threads that execute them, without the need for the multiple task information described in the previous example. In other words, the test cases themselves contain the aforementioned multiple task information. Furthermore, in this scenario, the subsequent step S111, the decomposition of the unit test task, is also the decomposition of the test cases. Specifically, when designing unit test cases for concurrent execution by multiple clients, corresponding test cases can be designed for each client. Finally, the final test cases, i.e., the unit test task, are obtained through synthesis. The subsequent step S111 is essentially the process of reverse engineering the unit test task to the corresponding test cases for 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 sub-tasks corresponding to different clients.

[0069] S112: Add each subtask to the work queue of the unit tester mounted on the corresponding client so that each unit tester can execute the subtask concurrently.

[0070] S113: Obtain the task execution results of each unit tester, and determine the unit test results based on the task execution results.

[0071] Steps S111 to S113 are branch steps of this method when the unit test task is a multi-client task. It should be noted that a multi-client task is necessarily a multi-threaded task, which includes at least test tasks executed concurrently by unit testers mounted on multiple clients. Therefore, step S111 decomposes the unit test task based on the client, obtaining sub-tasks corresponding to each client. However, it should be noted that the sub-tasks decomposed here can be either single-threaded or multi-threaded tasks.

[0072] For example, taking a common write task in unit testing as an example, a write task test executed concurrently by multiple clients can be specifically as follows: Client A and Client B concurrently write 100MB of data to a file. Specifically, Client A writes data with offsets from 0 to 50MB, and Client B writes data with offsets from 50 to 100MB, thus completing this multi-client concurrent write test task. This example corresponds to the subtask executed by each client in a multi-client unit test task being a single-threaded write task.

[0073] Furthermore, an example illustrating the decomposed subtasks as multi-threaded tasks is provided: Taking the write task as an example again, the subtask assigned to client A after the unit test task decomposes is to write data with offsets from 0 to 50M to a file. However, unlike the single-threaded subtask example above, this example requires client A to use two threads to concurrently write data with offsets from 0 to 50M to the file. Specifically, thread 1 could write data with offsets from 0 to 25M, and thread 2 could write data with offsets from 25 to 50M. Since each client in this method has a unit tester mounted to execute the test task, and the unit tester includes worker business threads, which in turn consist of multiple threads, the write task can be implemented concurrently by multiple threads.

[0074] Furthermore, regarding step S112, as mentioned above, the unit tester includes a work queue, and the worker business threads are used to execute tasks in the work queue. Since this method is applied to the main thread side, it commands each unit tester to execute the unit test tasks by adding the subtasks obtained after decomposing the unit test tasks to the work queue. Specifically, how the main thread adds tasks to the work queue of the worker business threads can be implemented using function tools, such as the `add_task` function.

[0075] Step S113 involves obtaining the task execution results of each unit tester mounted on each client after completing its corresponding subtask, and using this result to determine the final unit test result. Specifically, the main thread can obtain the task execution results actively (i.e., the main thread requests the task execution results from the unit tester) or passively (i.e., the unit tester sends the task execution results to the main thread). This embodiment does not impose any restrictions on this. However, this embodiment provides one possible scheme 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 subtasks of each unit tester to complete execution 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 scheme provided in this embodiment is adapted to the structural characteristics of a distributed file system, and can effectively realize the acquisition of task execution results of unit testers mounted on multiple different clients by the main thread. Furthermore, the scheme itself is simple to implement, will not place too much burden on the main thread or the distributed file system itself, and therefore will not have too much impact on the normal operation of this method and the distributed file system.

[0078] On the other hand, apart from the unit test tasks involving multiple clients mentioned above, this embodiment also provides an embodiment 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 based on the task type, then this method also includes:

[0080] S121: Add the unit test task to the work queue of the unit tester mounted to the corresponding client, so that the unit tester can execute the unit test task concurrently 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 based on the task execution result.

[0082] Furthermore, this embodiment also provides a possible implementation scheme:

[0083] If the unit test task is determined to be a single-client, single-threaded task based on the task type, then this method also includes:

[0084] S131: Execute unit test tasks via the main thread.

[0085] S132: Determine the unit test results based on the task execution results of the unit test task.

[0086] That is, the above embodiments provide two different unit test task scenarios with different task types.

[0087] Firstly, this unit test targets a single client but involves multi-threaded concurrent request testing. As mentioned above, in the distributed file system used in this method, each unit tester's work threads for executing test tasks consist of multiple threads, fulfilling the requirements for multi-threaded concurrent testing. Therefore, in step S121 of the above embodiment, the unit test task is added to the unit tester's work queue for execution. It should also be noted that the single-client, multi-threaded tasks targeted in steps S121 and S122 may have a requirement to be executed by a specific client. If this requirement exists, the unit test task is added to the work queue of the unit tester mounted on the corresponding client. If this requirement does not exist, the unit test task can be added to the work queue of any unit tester.

[0088] Secondly, this unit test is a traditional unit test, targeting a single client and a single thread. Because the unit test task is simple, it doesn't need to be handled by a multi-threaded unit tester; the main thread can complete the task itself. This eliminates intermediate steps such as adding tasks and retrieving execution results, thus improving the efficiency of the unit test.

[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 of various different testing scenarios such as multi-client multi-threaded, single-client multi-threaded, and single-client single-threaded, greatly expanding the testing scenarios supported by unit testing and helping to improve test coverage.

[0090] On the other hand, the specific implementation of step S111 in the above embodiments provides a specific implementation scheme when a unit test task includes specific test cases. In another possible embodiment, the unit test task does not include specific test cases, but instead indicates the test type or test purpose of this unit test task through other task information such as operation type.

[0091] Accordingly, this embodiment provides a possible implementation scheme. In addition to the task type, the unit test task described above also includes an operation type. The operation types include: read, write, delete, truncate, delete during write, and overwrite write.

[0092] Step S111 specifically involves defining corresponding operation behaviors for each client and encapsulating them into subtasks based on the operation type of the unit test task.

[0093] It should be noted that the operation types in the above examples are some of the more common unit test types. If there are new unit test needs in actual applications, the above operation types can be extended. This embodiment does not limit this.

[0094] Furthermore, based on the different operation types mentioned above, unit test tasks may require additional task information. For example, when the operation type is write or rewrite, the additional 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). Further, the main thread can define corresponding operation behaviors for the client based on the operation type, specifically including: 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; closing the file after writing the data and returning the task execution result.

[0095] In addition, for deletion operations, the unit test task also requires the following information: the operation directory and the operation file name. The corresponding operation behavior can be: determine the target file based on the operation directory and operation file name; delete the target file; and return the task execution result.

[0096] If it's a write-within-delete operation, the unit test task also needs the following task information: 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 read, overwrite, and truncation operations mentioned above are common unit test cases. The same principle applies to these operation types. Based on 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 provide examples of each of these operations.

[0098] In this embodiment, the unit test task does not directly include test cases. Instead, it uses task information to indicate the type of test required for this unit test. The main thread then defines the specific operation type, encapsulating it into an executable subtask for the unit tester to execute. This simplifies the burden of unit testing on the front end, reduces human intervention, and improves testing efficiency.

[0099] Based on the above, it is clear that the unit testing method based on a distributed file system provided by this invention offers the conditions to simulate concurrent request test scenarios from multiple clients by mounting multiple unit testers to different clients. Simultaneously, the working business threads in each unit tester for executing test tasks consist of multiple threads, thus supporting multi-threaded concurrent request simulation in each client. Furthermore, when the main thread receives a single-client, single-threaded unit test task, it can complete the unit test independently. This method covers existing unit testing scenarios and supports single-client, multi-threaded testing, as well as multi-client, multi-threaded testing, encompassing a wider range of testing scenarios. It can simulate concurrent requests from multiple clients, improving testing efficiency; it can also discover concurrency-related issues such as concurrency performance, race conditions, and deadlocks; it can leverage the multi-core advantages of multiple clients to run multiple test scenarios simultaneously, improving resource utilization; and it can perform stress testing on the distributed file system through a large number of concurrent requests, which helps to discover stability issues and bottlenecks under high load.

[0100] On the other hand, besides the main thread side mentioned above, the unit testing method based on a distributed file system provided by this invention also has applications on the unit tester side. This embodiment provides an implementation scheme on the unit tester side, and the method is applied to, for example... Figure 1 The distributed file system shown has the specific structure as described in the above embodiment, and will not be repeated in this embodiment. The method applied to the unit tester side in this embodiment is as follows: Figure 3 Shown, including:

[0101] S21: The work thread retrieves a subtask from the work queue.

[0102] Among them, when the main thread obtains a unit test task with the 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 work business thread.

[0104] S23: Return the task execution result obtained after executing the subtask to the main thread.

[0105] Since this embodiment is based on a unit testing method based on a distributed file system provided by the unit tester side, and it is the same method described on both sides as the embodiment based on the main thread side described above, the unit tester side also has the same or corresponding embodiments as the main thread side of the above embodiment. For details, please refer to the above embodiment section, which will not be repeated here.

[0106] However, the above embodiments mainly focus on how the main thread determines the corresponding test cases based on the unit test task. For example, the unit test task may have corresponding test cases designed for execution from the outset, or the unit test task may contain task information describing the unit test operation type and other necessary information, with the main thread defining the operation behavior based on the operation type to obtain the test cases. This embodiment provides a possible solution for determining and executing test cases based on subtasks 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. Read / write modes include: sequential, random, and reverse sequence.

[0109] Subtasks added to the unit tester do not contain specific test cases, but include descriptions of the operation type for this unit test and other necessary task information. This allows the unit tester to define the operation behavior and execute the corresponding test cases.

[0110] It should be noted that specific implementations of defining operation behaviors based on operation types have been fully described in the above embodiments, such as the write / rewrite, delete, and write-within-delete examples provided above. Specific implementation schemes can be found in the above embodiments, and will not be repeated here. The difference between this embodiment and the above embodiments is that the steps for defining operation behaviors are shifted from the main thread side to the unit tester side; other parts are the same. The advantage of this approach is that it further reduces the amount of data transmitted during communication, which is beneficial for further improving unit testing efficiency. Simultaneously, for multi-client scenarios, shifting the definition of operation behaviors from the main thread to the unit tester also helps to distribute the task load, which is also beneficial for improving unit testing efficiency.

[0111] In addition, when performing the test task using the solution provided in the above embodiments, this embodiment also provides a possible implementation scheme:

[0112] First, determine whether the operation type is write or rewrite; if so, execute the corresponding operation.

[0113] If not, determine whether the operation type is deletion; if so, execute the corresponding operation.

[0114] If not, determine whether the operation type is write-delete; if so, execute the corresponding operation.

[0115] If not, then perform the corresponding operation based on the operation type.

[0116] In this embodiment, the judgment is made in the order of write / rewrite, delete, write-within-delete, and other operation types. This is an efficient and simple unit test execution process, which helps to improve the overall efficiency of unit testing.

[0117] In the above embodiments, a unit testing method based on a distributed file system has been described in detail. This invention also provides an embodiment of a unit testing device based on a distributed file system. It should be noted that this invention describes the method from both the main thread and the unit tester perspectives; correspondingly, this embodiment also describes the device portion from both the main thread and the unit tester perspectives. Both devices are applied to... Figure 1 The distributed file system described in the above embodiments.

[0118] Applied to the main thread side, this embodiment provides a unit testing device based on a distributed file system, such as... Figure 4 Shown, including:

[0119] The task acquisition module 11 is used to acquire unit test tasks. The unit test tasks include task types; if the task type determines that the unit test task is a multi-client, multi-threaded task, then the task decomposition module, the first addition module, and the first determination module are triggered.

[0120] The task decomposition module 12 is used to decompose unit test tasks according to the client, resulting in sub-tasks corresponding to different clients.

[0121] The first addition 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 can execute the subtask concurrently.

[0122] The first determining module 14 is used to obtain the task execution results of each unit tester and determine the unit test results based on the task execution results.

[0123] Applied to the unit tester side, this embodiment provides a unit testing device based on a distributed file system, such as... Figure 5 Shown, including:

[0124] The task receiving module 21 is used for the working business thread to obtain subtasks from the work queue. The subtasks are obtained by the main thread when it obtains a unit test task of the task type of multi-client and multi-threaded task, and are decomposed according to the client and added to the work queue.

[0125] Task execution module 22 is used to execute subtasks concurrently through multiple threads in the work business thread.

[0126] Result return 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 and the embodiments of the method correspond to each other, please refer to the description of the embodiments of the method for the embodiments of the apparatus, which will not be repeated here.

[0128] On the other hand, the present invention also provides an embodiment corresponding to a distributed file system, such as... Figure 1 As shown, the distributed file system has a main thread and multiple unit testers; different unit testers are mounted to different clients in the distributed file system; each unit tester includes a worker business thread and a work queue; the worker business thread consists of multiple threads, and these threads are used to concurrently execute tasks in the work queue.

[0129] The main thread is used to implement a unit testing method based on a distributed file system in the main thread side of the above method embodiments. The unit tester is used to implement a unit testing method based on a distributed file system in the unit tester side of the above method embodiments. The distributed file system provided in this embodiment has the same or corresponding technical features as the above method embodiments and can bring the same technical effects.

[0130] In addition to the embodiments of a distributed file system and its unit testing method and apparatus 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 / instructions, which, when executed by a processor, can implement the steps of the unit testing method based on a distributed file system as described in any of the above embodiments.

[0131] Since the embodiments of the computer program product portion correspond to the embodiments of the method portion, please refer to the description of the embodiments of the method portion for the embodiments of the computer program product portion, 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, it implements the steps described in the above method embodiments (which may be a method corresponding to the main thread side, a method corresponding to the unit tester side, or a method corresponding to both the main thread side and the unit tester side).

[0133] It is understood that if the methods in the above embodiments are implemented as software functional units and sold or used as independent products, they can be stored in a non-volatile storage medium. Based on this understanding, the technical solution of the present invention, in essence, 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. This computer software product is stored in a storage medium and executes all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0134] The foregoing has provided a detailed description of a distributed file system and its unit testing method, apparatus, and medium provided by the present invention. The various embodiments in the specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section. It should be noted that those skilled in the art can make several improvements and modifications to the present invention without departing from the principles of the invention, and these improvements and modifications also fall within the protection scope of the present invention.

[0135] It should also be noted that, in this specification, 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. Without further limitations, 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.

Claims

1. A unit testing method based on a distributed file system, characterized in that, This is applied to a distributed file system, which includes a main thread and multiple unit testers; different unit testers are mounted to different clients in the distributed file system; each unit tester includes a worker business thread and a work queue; wherein the worker business thread consists 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 unit test tasks; wherein, the unit test tasks include task types; If the unit test task is determined to be a multi-client task based on the task type, then: The unit test task is decomposed according to the client to obtain sub-tasks corresponding to different clients; Each of the subtasks is added to the work queue of the unit tester mounted to the corresponding client, so that each of the unit testers executes the subtasks concurrently; Obtain the task execution results of each unit tester, and determine the unit test results based on the task execution results; If the unit test task is determined to be a single-client, multi-threaded task based on the task type, then: The unit test task is added to the work queue of the unit tester mounted to the corresponding client, so that the unit tester executes the unit test task concurrently through multiple threads in the work business thread; Obtain the task execution result of the unit tester, and determine the unit test result based on the task execution result; If the unit test task is determined to be a single-client, single-threaded task based on the task type, then: The unit test task is executed through the main thread; The unit test result is determined based on the task execution result of the unit test task.

2. The unit testing method based on a distributed file system according to claim 1, characterized in that, The unit test task also includes: operation types; wherein, the operation types include: read, write, delete, truncate, delete during write, and overwrite write; The unit test task is then decomposed according to the client, resulting in sub-tasks corresponding to different clients, including: Based on the operation type of the unit test task, define corresponding operation behaviors for each client and encapsulate them as subtasks.

3. A unit testing method based on a distributed file system, characterized in that, This is applied to a distributed file system, which includes a main thread and multiple unit testers; different unit testers are mounted to different clients in the distributed file system; each unit tester includes a worker business thread and a work queue; wherein the worker business thread consists of multiple threads, and the multiple threads are used to concurrently execute tasks in the work queue. Applied to the unit tester side, this method includes: The work process thread obtains subtasks from the work queue; wherein, the subtasks are: when the main thread obtains a unit test task of a multi-client, multi-threaded task type, it decomposes the subtasks according to the client type and adds them to the work queue; or when the main thread obtains a unit test task of a single-client, multi-threaded task type, it adds the unit test task to the work queue; the main thread is also used to execute the unit test task when it is determined from the task type that the unit test task is a single-client, single-threaded task. The subtask or the unit test task is executed concurrently by multiple threads in the work business thread; The task execution result obtained after executing the subtask or the unit test task will be returned to the main thread.

4. The unit testing method based on a distributed file system according to claim 3, 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 / write modes include: operation sequence, random sequence, and reverse sequence.

5. A unit testing device based on a distributed file system, characterized in that, This is applied to a distributed file system, which includes a main thread and multiple unit testers; different unit testers are mounted to different clients in the distributed file system; each unit tester includes a worker business thread and a work queue; wherein the worker business thread consists 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 is used to acquire unit test tasks; 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 based on the task type, the task decomposition module, the first addition module, and the first determination module are triggered; if the unit test task is determined to be a single-client, multi-threaded task based on the task type, the second addition module and the second determination module are triggered; if the unit test task is determined to be a single-client, single-threaded task based on the task type, the third execution module and the third determination module are triggered. The task decomposition module is used to decompose the unit test task according to the client to obtain sub-tasks corresponding to different clients; The first adding module is used to add each of the subtasks to the work queue of the unit tester mounted on the corresponding client, so that each of the unit testers executes the subtasks concurrently; The first determining module is used to obtain the task execution results of each of the unit testers, and determine the unit test results based on the task execution results; The second adding module is used to add the unit test task to the work queue of the unit tester mounted to the corresponding client, so that the unit tester can concurrently execute the unit test task through multiple threads in the work business thread; The second determining module is used to obtain the task execution result of the unit tester and determine the unit test result based on the task execution result; The third execution module is used to execute the unit test task through the main thread; The third determining module is used to determine the unit test result based on the task execution result of the unit test task.

6. A unit testing device based on a distributed file system, characterized in that, This is applied to a distributed file system, which includes a main thread and multiple unit testers; different unit testers are mounted to different clients in the distributed file system; each unit tester includes a worker business thread and a work queue; wherein the worker business thread consists 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: The task receiving module is used by the working business thread to obtain subtasks from the work queue; wherein, the subtask is obtained by the main thread when it obtains a unit test task of multi-client, multi-threaded task type, and decomposes it according to the client, and adds it to the work queue; or when the main thread obtains a unit test task of single-client, multi-threaded task type, it adds the unit test task to the work queue; the main thread is also used to execute the unit test task when it is determined that the unit test task is a single-client, single-threaded task according to the task type. The task execution module is used to concurrently execute the subtask or the unit test task through multiple threads in the work business thread; The result return module is used to return the task execution result obtained after executing the subtask or the unit test task to the main thread.

7. A distributed file system, characterized in that, include: The main thread and multiple unit testers; Different clients that mount the unit testers to the distributed file system; The unit tester includes: a worker business thread and a work queue; the worker business thread consists of multiple threads, and the multiple threads are used to concurrently execute the tasks in the work queue; The main thread is used to implement the steps of the unit testing method based on the distributed file system as described in claim 1 or 2 above; The unit tester is used to implement the steps of the unit testing method based on a distributed file system as described in claim 3 or 4 above.

8. A non-volatile storage medium, characterized in that, The non-volatile storage medium stores a computer program, which, when executed by a processor, implements the steps of the unit testing method based on a distributed file system as described in any one of claims 1 to 4.

Citation Information

Patent Citations

  • Method for performing unified performance test on distributed file system

    CN105808428A

  • Network file system test method, device, equipment and medium

    CN117171120A