Cross-database access test method, device and electronic equipment for database
By using DBLink to automate queries and result comparisons in cross-database access testing, the problems of insufficient manual coverage and consistency verification in cross-database access testing are solved, and efficient automated testing is achieved.
Patent Information
- Application Number
- CN202510897161.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-01
- Publication Date
- 2025-10-10
- Estimated Expiration
- 2045-07-01
AI Technical Summary
In the existing technology, database cross-database access testing has the following problems: insufficient coverage of manually written test cases, difficulty in verifying the consistency of cross-database query results and local data association operations, and lack of automation mechanism, resulting in low testing efficiency.
Through pre-generated test case scripts, cross-database related query statements are monitored, query requests are initiated to heterogeneous databases using DBLink links, and query results are compared to achieve automated testing.
It improves the automation level of cross-database access testing, ensures the consistency of cross-database query results, improves testing efficiency, and reduces manual intervention.
Smart Images

Figure CN120407423B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of database testing, and in particular to a database cross-database access testing method, device and electronic equipment. Background Art
[0002] Cross-database access and local data join operations are common requirements in database business scenarios. However, current database cross-database access testing suffers from the following technical flaws: manually written test cases fail to meet required coverage, data consistency between cross-database query results and local data join operations is difficult to effectively verify, and there is a lack of automated mechanisms to verify data consistency between cross-database query results and local executions. Furthermore, exception scenarios rely on manual simulation, resulting in poor repeatability.
[0003] Therefore, the above technical defects seriously affect the efficiency of cross-database access testing of the database. Summary of the Invention
[0004] In view of this, an object of the present invention is to provide a database cross-database access testing method, device and electronic device to alleviate the above technical problems.
[0005] In a first aspect, an embodiment of the present invention provides a method for testing cross-database access of a database, the method comprising: responding to a test execution command, executing a pre-generated test case script in the local database; during the execution process, monitoring whether the script contains a cross-database association query statement containing a heterogeneous database pointing tag; if so, initiating a DBLink request to the heterogeneous database corresponding to the heterogeneous database pointing tag through a pre-established DBLink link to initiate a cross-database data query request to the heterogeneous database; and triggering the heterogeneous database to execute a local association query statement corresponding to the cross-database association query statement to obtain a first query result; receiving a second query result returned by the heterogeneous database based on the cross-database data query request; comparing the first query result and the second query result, and testing the cross-database access function of the database according to the comparison result.
[0006] In combination with the first aspect, an embodiment of the present invention provides a first possible implementation method of the first aspect, wherein the above method also includes: deploying a local database and a heterogeneous database in response to a test environment deployment operation, and creating a DBLink link between the local database and the heterogeneous database; inputting a preset first data table into the heterogeneous database according to pre-configured test requirements, and inputting a preset second data table into the local database.
[0007] With reference to the first possible implementation manner of the first aspect, the second possible implementation manner of the first aspect provides that the method further comprises: parsing syntax rules compatible with the heterogeneous database from the local database, and extracting key information of the syntax rules; generating a query statement file of the test case according to the key information; wherein the query statement file comprises a local associated query statement and a corresponding cross-database associated query statement; the cross-database associated query statement is configured with a cross-database pointing label, and the cross-database pointing label is used to instruct the local database to query data of the first data table from the heterogeneous database.
[0008] With reference to the first aspect, the third possible implementation manner of the first aspect provides that the step of comparing the first query result and the second query result, and testing the cross-database access function of the database according to a comparison result comprises: comparing whether data contained in the first query result and data contained in the second query result are consistent; if yes, generating a test passed test result; if no, generating a difference report of the first query result and the second query result, and generating a test failed test result.
[0009] With reference to the first aspect, the fourth possible implementation manner of the first aspect provides that the method further comprises: after monitoring that the script contains the cross-database associated query statement with the cross-database pointing label, acquiring a pre-configured fault code; injecting the fault code into the script of the test case; executing the fault code, and automatically testing an abnormal scenario of the local database based on an execution result.
[0010] With reference to the first possible implementation manner of the first aspect, the fifth possible implementation manner of the first aspect provides that the local database is a GBase8s database; and the step of deploying the local database comprises: acquiring a configuration file of the local database; parsing the configuration file to acquire configuration parameters; creating an installation directory according to the configuration parameters, and installing the local database in the installation directory.
[0011] With reference to the first possible implementation manner of the first aspect, the sixth possible implementation manner of the first aspect provides that the step of deploying the heterogeneous database comprises: starting a container for deploying the heterogeneous database, and acquiring a configuration file of the heterogeneous database; configuring and starting the heterogeneous database according to the configuration file of the heterogeneous database.
[0012] In a second aspect, an embodiment of the present invention further provides a cross-database access test device for a database, the device comprising: a response module for responding to a test execution command and executing a pre-generated test case script in the local database; a monitoring module for monitoring whether there is a cross-database associated query statement containing a heterogeneous database pointing tag in the script during execution; a cross-database module for initiating a DBLink request to the heterogeneous database corresponding to the heterogeneous database pointing tag through a pre-established DBLink link when the monitoring result of the monitoring module is yes, so as to initiate a cross-database data query request to the heterogeneous database; and triggering the heterogeneous database to execute a local associated query statement corresponding to the cross-database associated query statement to obtain a first query result; a return module for receiving a second query result returned by the heterogeneous database based on the cross-database data query request; a comparison module for comparing the first query result and the second query result, and testing the cross-database access function of the database according to the comparison result.
[0013] In a third aspect, an embodiment of the present invention further provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the method described in the first aspect when executing the computer program.
[0014] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method described in the first aspect are executed.
[0015] The embodiments of the present invention bring the following beneficial effects:
[0016] The cross-database access testing method, device and electronic device of the database provided by the embodiment of the present invention, during the script execution of the test case, if it is detected that there is a cross-database associated query statement containing a heterogeneous database pointing tag in the script, a DBLink request can be initiated to the heterogeneous database corresponding to the heterogeneous database pointing tag through a pre-established DBLink link to initiate a cross-database data query request to the heterogeneous database; and the heterogeneous database is triggered to execute a local associated query statement corresponding to the cross-database associated query statement to obtain a first query result; the second query result returned by the heterogeneous database based on the cross-database data query request is received; the first query result and the second query result are compared, and the cross-database access function of the database is tested according to the comparison result. During the entire test process, the heterogeneous database can be queried, and the second query result obtained by the cross-database query can be compared for consistency with the first query result obtained locally in the heterogeneous database, which can effectively realize the cross-database testing of the local database, and no human participation is required during the test process, which can effectively improve the efficiency of the cross-database access testing of the database.
[0017] Other features and advantages of the present invention will be described in the following description, and in part will become apparent from the description, or understood by practicing the present invention. The purposes and other advantages of the present invention are realized and obtained by the structures particularly pointed out in the description, claims and drawings.
[0018] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the specific embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without paying any creative work.
[0020] Figure 1 A flowchart of a cross-database access testing method for a database provided by an embodiment of the present invention;
[0021] Figure 2 A flowchart of another database cross-database access testing method provided by an embodiment of the present invention;
[0022] Figure 3 A schematic diagram of the structure of a cross-database access testing device provided by an embodiment of the present invention;
[0023] Figure 4 A schematic structural diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0024] To make the objectives, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work shall fall within the scope of protection of the present invention.
[0025] Currently, cross-database access testing in the GBase8s database often faces technical defects such as difficulty in comprehensive test case coverage and data consistency verification, and often relies on manual simulation of abnormal scenarios, which seriously limits the efficiency of cross-database access testing.
[0026] Based on this, the embodiments of the present invention provide a cross-database access testing method, device, and electronic device, which can realize automated testing of functions such as connection, query, and exception injection between databases, thereby improving the above-mentioned technical problems.
[0027] To facilitate understanding of this embodiment, a database cross-database access testing method disclosed in an embodiment of the present invention is first introduced in detail.
[0028] In a possible implementation, an embodiment of the present invention provides a method for testing cross-database access of a database. The method is used to test cross-database access of a database to ensure that the results of various operations on the database are correct.
[0029] like Figure 1 The flowchart of a cross-database access testing method for a database shown includes the following steps:
[0030] Step S102, responding to the test execution command, executing the pre-generated test case script in the local database;
[0031] Step S104: During the execution process, monitor whether there is a cross-database association query statement containing a different-database pointing tag in the script;
[0032] Step S106: If yes, a DBLink request is initiated to the heterogeneous database corresponding to the heterogeneous database pointing tag through the pre-established DBLink link to initiate a cross-database data query request to the heterogeneous database; and the heterogeneous database is triggered to execute a local association query statement corresponding to the cross-database association query statement to obtain a first query result;
[0033] Step S108, receiving a second query result returned by the heterogeneous database based on the cross-database data query request;
[0034] Step S110 , comparing the first query result and the second query result, and testing the cross-database access function of the database according to the comparison result.
[0035] The cross-database access testing method for databases provided by an embodiment of the present invention can query heterogeneous databases during the entire testing process, and compare the second query result obtained by the cross-database query with the first query result obtained locally in the heterogeneous database for consistency, which can effectively implement cross-database testing of local databases. Moreover, no human participation is required during the testing process, which can effectively improve the efficiency of cross-database access testing of databases.
[0036] In actual use, a local database usually refers to a database running on the same electronic device, such as the same computer or server; while a heterogeneous database may be distributed on different computer architectures, such as other computers, workstations, PCs or embedded systems.
[0037] In an embodiment of the present invention, in order to achieve cross-database access, a systematic testing framework can be pre-built, in which local databases and heterogeneous databases are deployed to perform automated testing of functions such as connection, query, and exception injection between databases.
[0038] Therefore, in an embodiment of the present invention, in response to a test environment deployment operation, a local database and a heterogeneous database can be deployed, and a DBLink (Database Link) link can be created between the local database and the heterogeneous database; then, according to pre-configured test requirements, a preset first data table is input into the heterogeneous database, and a preset second data table is input into the local database.
[0039] Specifically, in the embodiment of the present invention, the local database is a GBase8s database; therefore, when deploying the local database, the GBase8s database can be deployed in an automated manner. Specifically, the process of automatically deploying the GBase8s database can include the following steps:
[0040] (1) Obtain the configuration file of the local database;
[0041] (2) Parse the configuration file to obtain configuration parameters;
[0042] (3) Create an installation directory based on the configuration parameters to install the local database in the installation directory.
[0043] Among them, the above configuration parameters can be obtained in the SERVICES_GROUP segment of the configuration file, and the port range can be parsed to further create an installation directory to install the GBase8s database. In addition, based on the content under SERVICES_IDS in the SERVICES_GROUP segment, a stand-alone database or a cluster database can be established. The specific settings can be made according to actual usage, and the embodiment of the present invention does not limit this.
[0044] Furthermore, the heterogeneous database in the embodiment of the present invention is deployed in a containerized manner. Taking the heterogeneous database as an Oracle database as an example, when deploying the heterogeneous database, it is necessary to start the container for deploying the heterogeneous database and obtain the configuration file of the heterogeneous database; then, configure and start the heterogeneous database according to the configuration file of the heterogeneous database.
[0045] In actual use, in order to realize cross-database access between databases, after the deployment of the database, the DBlink gateway program between the databases also needs to be further deployed, such as using a script to obtain the relevant information of the GBase8s database, configuring the DBlink gateway, and obtaining the configuration parameters of the heterogeneous database such as the Oracle database, and creating a DBLink link.
[0046] After the local database and the heterogeneous database are deployed by the above-mentioned manner, test cases can be further generated, so that the script can obtain the test cases and execute the test cases in response to the test execution command in the above-mentioned step S102. Specifically, in the embodiment of the present application, the process of generating the test cases is as follows: parsing the syntax rules of the local database compatible with the heterogeneous database, extracting the key information of the syntax rules; generating a query statement file of the test cases according to the key information; wherein the query statement file includes local join query statements and corresponding cross-database join query statements; the cross-database join query statement is configured with a heterogeneous database pointing tag, and the heterogeneous database pointing tag is used to indicate the local database to query the data of the first data table from the heterogeneous database.
[0047] In actual use, the ANTLR (ANother Tool for Language Recognition) tool can be used to parse the SQL (Structured Query Language) syntax rules of the GBase8s database compatible with the heterogeneous database, wherein the ANTLR tool is a powerful parser generator that supports multiple programming languages and can convert syntax rules into parser code.
[0048] Further, for the GBase8s database, the ANTLR syntax file obtained by parsing the SQL syntax rules of the GBase8s database compatible with the heterogeneous database is usually defined as a g4 file, and by writing the corresponding language syntax rules in the g4 file, the ANTLR tool can generate the corresponding language analyzer, therefore, in the embodiment of the present application, when parsing the syntax rules of the local database compatible with the heterogeneous database and extracting the key information of the syntax rules, the g4 file can be read, and then the defined SQL syntax rules are loaded, the parser code is generated by using the ANTLR tool, and the SQL statement is parsed by the parser to extract the table structure, field information, query conditions and other key information.
[0049] Furthermore, a specific test case file can be generated for the key information extracted above. Specifically, the test case file can include a table creation statement file, a local association query statement file, and a cross-database association query statement file, wherein the local association query statement file and the cross-database association query statement file can be collectively referred to as a query statement file. In an embodiment of the present invention, in order to realize cross-database query, a foreign database pointing tag needs to be injected into the cross-database association query statement of the above-mentioned cross-database association query statement file, so that when the script of the test case executes the cross-database association query statement, it can identify the foreign database pointing tag and then determine that the data of this query needs to be cross-database queried.
[0050] For example, the data table queried in a cross-database association query statement is the first data table. Since this first data table is input into a heterogeneous database, the heterogeneous database pointing tag can indicate that the first data table queried this time is in the heterogeneous database. Typically, when deploying a database, some data tables are designated as data tables for cross-database queries, such as the first data table described above in the embodiment of the present invention. Therefore, when generating test cases, cross-database association queries can be generated as needed and the corresponding heterogeneous database pointing tags can be injected.
[0051] Further, for ease of understanding, the following takes GBase8s database accessing a heterogeneous database (such as an Oracle database) as an example to further illustrate the cross-database access test process of the database in the embodiment of the present invention. Figure 2 The flowchart of another database cross-database access testing method shown includes the following steps:
[0052] Step S202, test execution;
[0053] This process requires executing the test case script. Prior to testing, the first data table is imported into the heterogeneous database, and the second data table is imported into the local database. Furthermore, a heterogeneous database pointing tag is configured in the cross-database association query statement of the test case.
[0054] In this embodiment of the present invention, the example of using the foreign database pointing tag represented by @dblinkname is used for explanation. In the test case, it is assumed that one of the SQL syntaxes in the generated local association query statement is as follows:
[0055] SELECT e.emp_name, d.dept_name FROM employees e JOIN departments d ONe.dept_id=d.dept_id;
[0056] The corresponding cross-database association query statement is configured with a different database pointing tag, and its SQL syntax is as follows:
[0057] SELECT e.emp_name, d.dept_name FROM employees e JOIN departments@linknamed ON e.dept_id=d.dept_id;
[0058] The table in front of the heterogeneous database pointing tag table @linkname represents a table in the heterogeneous database, that is, the first data table in the embodiment of the present invention. The first data table is pre-injected into the heterogeneous database as a data table for cross-database query.
[0059] Step S204: When the cross-database association query statement is executed, it is detected that the cross-database association query statement contains a different database pointing tag;
[0060] Step S206: Initiate a DBLink request to the heterogeneous database corresponding to the heterogeneous database pointing tag through the pre-established DBLink link, so as to initiate a cross-database data query request to the heterogeneous database;
[0061] Specifically, in an embodiment of the present invention, the gbase8s database initiates a DBLink request and requests data from the Oracle database across the database through the dblink gateway. At this time, the Oracle database can locally execute the local association query statement corresponding to the cross-database association query statement to obtain the first query result; usually, there is no difference between the local association query statement and the cross-database association query statement except that the foreign database pointing label @linkname is added after part of the first data table.
[0062] Step S208: receiving a second query result returned by the heterogeneous database based on the cross-database data query request;
[0063] Step S210, comparing the data included in the first query result and the data included in the second query result to see if they are consistent; if yes, executing step S212; if not, executing step S214;
[0064] Step S212, generating a test result indicating that the test has passed;
[0065] Step S214: Generate a difference report between the first query result and the second query result, and generate a test result indicating that the test failed.
[0066] Typically, the second query result file is named result_actual.txt, and the first query result file is named result_expected.txt. In step S210, the actual comparison is between the result_actual.txt and result_expected.txt files. If the two files are identical, the test passes. If they are different, a difference report is generated. Furthermore, if there are too many differences, the tester can manually compare the result_actual.txt file of the second query result for analysis.
[0067] In addition, during the test process of the above-mentioned GBase8s database accessing a heterogeneous database (such as an Oracle database), after detecting a cross-database association query statement containing a heterogeneous database pointing tag in the script, a pre-configured fault code is obtained; the fault code is injected into the script of the test case; after executing the fault code, the abnormal scenario of the local database is automatically tested based on the execution result.
[0068] That is, by injecting fault codes, the embodiments of the present invention can achieve automated testing of abnormal scenario injection. Typically, the open source ChaosMonkey tool can be introduced into the above-deployed systematic testing framework to inject random fault codes when testing cross-database queries. The fault code snippet is as follows:
[0069] def test_network_partition():
[0070] chaos = ChaosMonkey(config)
[0071] with chaos.simulate_fault_scenarios(["dblink1"], "connection_drop"):
[0072] result = db.query("SELECT * FROM shard1@dblink1...")
[0073] assert not result, "the query should have failed but returned a result"
[0074] The fault tolerance of the local database is then determined based on the execution result of the fault code. For example, when a network connection failure occurs, whether data in another shard, shard 1, can be queried. The specific fault code can be configured according to the actual test content and is not limited in this embodiment of the present invention.
[0075] In summary, the database cross-database access test method provided by the embodiment has the following beneficial effects:
[0076] (1) High degree of automation: through automatic deployment of test environment, generation of test cases and execution of tests, manual intervention is greatly reduced, and test efficiency is improved.
[0077] (2) Comprehensive test coverage: through syntax analysis and test case generation engine, a variety of test cases can be generated to cover more scenarios.
[0078] (3) Accurate result verification: by comparing the first query result and the second query result, differences can be quickly found to ensure the correctness of cross-database queries.
[0079] (4) Abnormal scene simulation is real: by automatically injecting abnormal scenes (fault codes), problems in the production environment can be more realistically simulated to improve the robustness of the system.
[0080] Further, on the basis of the above embodiment, the embodiment of the application further provides a database cross-database access test device, as shown in Figure 3 The structure diagram of a database cross-database access test device, including the following structures:
[0081] The response module 30 is used to respond to the test execution command and execute the pre-generated test case script in the local database;
[0082] The monitoring module 32 is used to monitor whether there is a cross-database association query statement containing a heterogeneous database pointing label in the script during execution;
[0083] The cross-database module 34 is used to, when the monitoring result of the monitoring module is yes, initiate a DBLink request to the heterogeneous database corresponding to the heterogeneous database pointing label through the pre-established DBLink link, to initiate a cross-database data query request to the heterogeneous database; and trigger the heterogeneous database to execute a local association query statement corresponding to the cross-database association query statement to obtain a first query result;
[0084] The return module 36 is used to receive a second query result returned by the heterogeneous database based on the cross-database data query request;
[0085] The comparison module 38 is used to compare the first query result and the second query result, and test the cross-database access function of the database according to the comparison result.
[0086] Furthermore, the above-mentioned device is also used to: deploy a local database and a heterogeneous database in response to a test environment deployment operation, and create a DBLink link between the local database and the heterogeneous database; input a preset first data table into the heterogeneous database according to pre-configured test requirements, and input a preset second data table into the local database.
[0087] Furthermore, the above-mentioned device is also used to: parse the grammatical rules of the local database compatible with the heterogeneous database, and extract key information of the grammatical rules; generate a query statement file of the test case based on the key information; wherein, the query statement file includes a local association query statement and a corresponding cross-database association query statement; the cross-database association query statement is configured with a heterogeneous database pointing tag, and the heterogeneous database pointing tag is used to instruct the local database to query the data of the first data table from the heterogeneous database.
[0088] Furthermore, the above-mentioned step of comparing the first query result and the second query result, and testing the cross-database access function of the database based on the comparison results, includes: comparing whether the data contained in the first query result and the data contained in the second query result are consistent; if so, generating a test result indicating that the test passed; if not, generating a difference report between the first query result and the second query result, and generating a test result indicating that the test failed.
[0089] Furthermore, the above-mentioned device is also used to: obtain a pre-configured fault code after detecting that there is a cross-library association query statement containing the foreign library pointing tag in the script; inject the fault code into the script of the test case; execute the fault code, and perform automated testing on the abnormal scenario of the local database based on the execution result.
[0090] Furthermore, the above-mentioned local database is a GBase8s database; the step of deploying the local database includes: obtaining a configuration file of the local database; parsing the configuration file to obtain configuration parameters; creating an installation directory according to the configuration parameters to install the local database in the installation directory.
[0091] Furthermore, the step of deploying a heterogeneous database includes: starting a container for deploying the heterogeneous database and obtaining a configuration file of the heterogeneous database; and configuring and starting the heterogeneous database according to the configuration file of the heterogeneous database.
[0092] The cross-database access testing device for a database provided in an embodiment of the present invention has the same technical features as the cross-database access testing method for a database provided in the above embodiment, and therefore can also solve the same technical problems and achieve the same technical effects.
[0093] Furthermore, an embodiment of the present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.
[0094] An embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above method are executed.
[0095] Furthermore, an embodiment of the present invention also provides a structural diagram of an electronic device, such as Figure 4 As shown, it is a structural diagram of the electronic device, wherein the electronic device includes a processor 41 and a memory 40, the memory 40 stores computer executable instructions that can be executed by the processor 41, and the processor 41 executes the computer executable instructions to implement the above method.
[0096] exist Figure 4 In the illustrated embodiment, the electronic device further includes a bus 42 and a communication interface 43 , wherein the processor 41 , the communication interface 43 and the memory 40 are connected via the bus 42 .
[0097] Among them, the memory 40 may include high-speed random access memory (RAM), and may also include non-volatile memory (non-volatile memory), such as at least one disk storage. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 43 (which can be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. can be used. The bus 42 can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. The bus 42 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 4 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or one type of bus.
[0098] Processor 41 may be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method may be performed by hardware integrated logic circuits or software instructions in processor 41. The above processor 41 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the embodiments of the present invention may be directly implemented and executed by a hardware decoding processor, or by a combination of hardware and software modules in the decoding processor. The software module may be located in a storage medium well-known in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, etc. The storage medium is located in the memory, and the processor 41 reads the information in the memory and completes the above method in combination with its hardware.
[0099] The embodiments of the present invention provide a computer program product for a cross-database access test method, device, and electronic device, including a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the method described in the previous method embodiment. For specific implementation, please refer to the method embodiment and will not be repeated here.
[0100] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0101] In addition, in the description of the embodiments of the present invention, unless otherwise expressly specified or limited, the terms "mounted," "connected," and "connected" should be understood in a broad sense. For example, they may refer to fixed connections, detachable connections, or integral connections; they may refer to mechanical connections or electrical connections; they may refer to direct connections or indirect connections through an intermediate medium; and they may refer to internal communication between two components. Those skilled in the art will understand the specific meanings of the above terms in the present invention based on the specific circumstances.
[0102] If the functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the portion that contributes to the prior art, or a portion 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 includes several instructions for causing a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present invention. The aforementioned storage media include various media capable of storing program code, such as USB flash drives, mobile hard drives, read-only memories (ROMs), random access memories (RAMs), magnetic disks, or optical disks.
[0103] In the description of the present invention, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicating orientations or positional relationships, are based on the orientations or positional relationships shown in the accompanying drawings and are intended solely to facilitate and simplify the description of the present invention. They are not intended to indicate or imply that the devices or components referred to must have, be constructed, or operate in a specific orientation, and therefore should not be construed as limitations on the present invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.
[0104] Finally, it should be noted that the above embodiments are only specific implementation methods of the present invention, which are used to illustrate the technical solutions of the present invention, rather than to limit them. The scope of protection of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that any person skilled in the art can modify or easily conceive of changes to the technical solutions described in the above embodiments within the technical scope disclosed by the present invention, or replace some of the technical features therein with equivalents. Such modifications, changes or replacements do not deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be based on the scope of protection of the claims.
Claims
1. A database cross-database access testing method, characterized in that: The method comprises: In response to the test environment deployment operation, deploying a local database and a heterogeneous database, and creating a DBLink link between the local database and the heterogeneous database; Inputting a preset first data table into a heterogeneous database according to pre-configured test requirements, and inputting a preset second data table into a local database; Respond to test execution commands and execute pre-generated test case scripts in the local database; During the execution process, monitoring whether there is a cross-database association query statement containing a heterogeneous database pointing tag in the script; wherein the cross-database association query statement is configured with the heterogeneous database pointing tag, and the heterogeneous database pointing tag is used to instruct the local database to query the heterogeneous database for data in the first data table; If so, a DBLink request is initiated to the heterogeneous database corresponding to the heterogeneous database pointing tag through a pre-established DBLink link to initiate a cross-database data query request to the heterogeneous database; and the heterogeneous database is triggered to execute a local association query statement corresponding to the cross-database association query statement to obtain a first query result; wherein, except for the heterogeneous database pointing tag, there is no other difference between the local association query statement and the cross-database association query statement; Receiving a second query result returned by the heterogeneous database based on the cross-database data query request; The first query result and the second query result are compared, and the cross-database access function of the database is tested according to the comparison result.
2. The method according to claim 1, characterized in that The method further comprises: Parsing the grammatical rules of the local database to ensure compatibility with the heterogeneous database, and extracting key information of the grammatical rules; A query statement file of the test case is generated according to the key information; wherein the query statement file includes a local associated query statement and a corresponding cross-database associated query statement.
3. The method according to claim 1, characterized in that The step of comparing the first query result and the second query result, and testing the cross-database access function of the database according to the comparison result, includes: comparing whether the data included in the first query result and the data included in the second query result are consistent; If yes, generate a test result indicating the test passed; If not, a difference report between the first query result and the second query result is generated, and a test result indicating that the test failed is generated.
4. The method according to claim 1, wherein The method further comprises: After detecting that a cross-database association query statement containing the foreign database pointing tag is present in the script, a pre-configured fault code is obtained; Injecting the fault code into the script of the test case; The fault code is executed, and based on the execution result, an automated test is performed on the abnormal scenario of the local database.
5. The method according to claim 1, wherein The local database is a GBase8s database; The steps to deploy a local database include: Obtaining a configuration file of the local database; Parsing the configuration file to obtain configuration parameters; An installation directory is created according to the configuration parameters, so as to install the local database in the installation directory.
6. The method according to claim 1, characterized in that The steps for deploying a heterogeneous database include: Start the container for deploying the heterogeneous database and obtain the configuration file of the heterogeneous database; The heterogeneous database is configured and started according to the configuration file of the heterogeneous database.
7. A database cross-database access testing device, characterized in that: The device comprises: The response module is used to respond to the test environment deployment operation, deploy the local database and the heterogeneous database, and create a DBLink between the local database and the heterogeneous database; input the preset first data table into the heterogeneous database according to the pre-configured test requirements, and input the preset second data table into the local database; respond to the test execution command, and execute the pre-generated test case script in the local database; A monitoring module is used to monitor whether there is a cross-database association query statement containing a heterogeneous database pointing tag in the script during execution; wherein the cross-database association query statement is configured with the heterogeneous database pointing tag, and the heterogeneous database pointing tag is used to instruct the local database to query the heterogeneous database for data in the first data table; A cross-database module is used for initiating a DBLink request to the heterogeneous database corresponding to the heterogeneous database pointing tag through a pre-established DBLink link when the monitoring result of the monitoring module is yes, so as to initiate a cross-database data query request to the heterogeneous database; and triggering the heterogeneous database to execute a local association query statement corresponding to the cross-database association query statement to obtain a first query result; wherein, there is no difference between the local association query statement and the cross-database association query statement except for the heterogeneous database pointing tag; A returning module, configured to receive a second query result returned by the heterogeneous database based on the cross-database data query request; A comparison module is used to compare the first query result and the second query result, and test the cross-database access function of the database according to the comparison result.
8. An electronic device, characterized in that: The method comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the method according to any one of claims 1 to 6 when executing the computer program.
9. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are executed.
Citation Information
Patent Citations
Test script execution method and device, computer equipment and storage medium
CN113051172A
Database processing method and system, electronic equipment and storage medium
CN115292348A
Automatic code testing method and system based on injectable fault
CN116860648A
Automatic interface testing method and device, equipment and storage medium
CN117421222A