Cross-database access test method and device of database and electronic equipment
By using DBLink linking and automated test cases in database cross-base access tests, the problem of insufficient manual coverage and consistency verification in cross-base access tests is solved, and efficient and automated cross-base query result comparison and exception scenario simulation are achieved.
Patent Information
- Application Number
- CN202510897161.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-01
- Publication Date
- 2025-08-01
- Estimated Expiration
- 2045-07-01
AI Technical Summary
In the prior art, there is insufficient coverage of manual writing test cases for database cross-base access testing, and the consistency of cross-base query results and local data correlation operations is difficult to verify, and the lack of automation mechanisms leads to inefficient testing.
The cross-border correlation query statement is monitored through pre-generated test case scripts, and a cross-border data query request is initiated to heterogeneous databases using DBLink link, triggering the heterogeneous database to execute the correlation query statement, comparing the query results and testing.
It realizes automation of cross-base access testing, improves testing efficiency, ensures consistency of query results, reduces manual intervention, covers more test scenarios, and simulates exception scenarios to improve system robustness.
Smart Images

Figure CN120407423A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of database testing, and in particular, to a cross-database access testing method, device, and electronic device for a database. Background Art
[0002] Generally, in the business scenarios of databases, cross-database access and local data association operations are common requirements. However, there are the following technical defects in the current cross-database access testing of databases: the coverage of manually written test cases is difficult to meet the requirements, it is difficult to effectively verify the data consistency between the cross-database query results and the local data association operations, there is a lack of an automated mechanism to verify the data consistency between the cross-database query results and the data executed locally, and moreover, abnormal scenarios also rely on manual simulation, resulting in poor repeatability.
[0003] Therefore, the above technical defects seriously affect the efficiency of cross-database access testing of databases. Summary of the Invention
[0004] In view of this, the purpose of the present invention is to provide a cross-database access testing method, device, and electronic device for a database to alleviate the above technical problems.
[0005] In a first aspect, an embodiment of the present invention provides a cross-database access testing method for a database, the method including: responding to a test execution command, and executing a script of a pre-generated test case in the local database; during the execution process, monitoring whether there is a cross-database association query statement in the script that contains 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] Combined with the first aspect, an embodiment of the present invention provides a first possible implementation manner of the first aspect, wherein, the above method further includes: responding to a 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 the heterogeneous database according to a pre-configured test requirement, and inputting a preset second data table into the local database.
[0007] Combined with the first possible implementation manner of the first aspect, the embodiment of the present invention provides a second possible implementation manner of the first aspect, wherein the above method further includes: parsing the syntax rules for which the local database is compatible with the heterogeneous 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 includes a local association query statement and a corresponding cross-database association query statement; the cross-database association query statement is configured with a different-database pointing tag, and the different-database pointing tag is used to instruct the local database to query the data of the first data table from the heterogeneous database.
[0008] Combined with the first aspect, the embodiment of the present invention provides a third possible implementation manner of the first aspect, wherein 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 the same; if so, generating a test result indicating that the test passes; 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 fails.
[0009] Combined with the first aspect, the embodiment of the present invention provides a fourth possible implementation manner of the first aspect, wherein the above method further includes: after monitoring that there is a cross-database association query statement including the different-database pointing tag in the script, obtaining a pre-configured fault code; injecting the fault code into the script of the test case; executing the fault code, and performing an automated test on the abnormal scenario of the local database based on the execution result.
[0010] Combined with the first possible implementation manner of the first aspect, the embodiment of the present invention provides a fifth possible implementation manner of the first aspect, wherein the above 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.
[0011] Combined with the first possible implementation manner of the first aspect, the embodiment of the present invention provides a sixth possible implementation manner of the first aspect, wherein the step of deploying the heterogeneous database includes: starting a container for deploying the heterogeneous database, and obtaining a configuration file of the heterogeneous database; configuring and starting the heterogeneous database according to the configuration file of the heterogeneous database.
[0012] Second aspect, an embodiment of the present invention further provides a cross-database access testing device for a database. The device includes: a response module, configured to respond to a test execution command and execute a script of a pre-generated test case in the local database; a monitoring module, configured to monitor whether there is a cross-database association query statement including a heterogeneous database pointing tag in the script during the execution process; a cross-database module, configured 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 tag through a pre-established DBLink link, so as 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; a return module, configured to receive a second query result returned by the heterogeneous database based on the cross-database data query request; a comparison module, configured 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.
[0013] Third aspect, an embodiment of the present invention further provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the steps of the method described in the first aspect above are implemented.
[0014] 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 run by a processor, the steps of the method described in the first aspect above are executed.
[0015] The embodiments of the present invention bring the following beneficial effects: The cross-database access testing method, device, and electronic device for a database provided by the embodiments of the present invention, during the process of executing the script of the test case, if a cross-database association query statement including a heterogeneous database pointing tag is detected 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, so as 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; receive a second query result returned by the heterogeneous database based on the cross-database data query request; 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. During the entire testing process, querying the heterogeneous database can be realized, and the second query result obtained by cross-database query can be compared with the first query result obtained locally by the heterogeneous database for consistency, which can effectively implement the cross-database testing of the local database, and no manual participation is required during the testing process, which can effectively improve the cross-database access testing efficiency of the database.
[0016] Other features and advantages of the present invention will be set forth in the following description, and in part will be obvious from the description, or may be learned by practice of the present invention. The objectives and other advantages of the present invention are realized and attained by the structure particularly pointed out in the specification, claims as well as the drawings.
[0017] To make the above objectives, features and advantages of the present invention more comprehensible, the following specific preferred embodiments are given, in conjunction with the accompanying drawings, and are described in detail as follows. Brief Description of the Drawings
[0018] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following will briefly introduce the drawings required for the description of the specific embodiments or the prior art. Obviously, the drawings in the following description are some embodiments of the present invention. For those skilled in the art, without creative efforts, other drawings can be obtained based on these drawings.
[0019] Figure 1 It is a flowchart of a method for cross-database access testing of a database provided by an embodiment of the present invention; Figure 2 It is a flowchart of another method for cross-database access testing of a database provided by an embodiment of the present invention; Figure 3 It is a schematic structural diagram of a device for cross-database access testing of a database provided by an embodiment of the present invention; Figure 4 It is a schematic structural diagram of an electronic device provided by an embodiment of the present invention. Detailed Embodiments
[0020] To make the objectives, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below in conjunction with the drawings. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those skilled in the art without creative efforts based on the embodiments of the present invention belong to the scope of protection of the present invention.
[0021] Currently, in the cross-database access testing of the GBase8s database, there are often technical defects such as it being difficult to comprehensively cover test cases, difficult to verify data consistency, and often relying on manual simulation of abnormal scenarios, which seriously limits the efficiency of cross-database access testing.
[0022] Based on this, a method, device and electronic device for cross-database access testing of a database provided by an embodiment of the present invention can realize automated testing of functions such as connection, query, and exception injection between databases, thereby improving the above technical problems.
[0023] To facilitate the understanding of this embodiment, a cross-database access test method for a database disclosed in the embodiments of the present invention will be introduced in detail first.
[0024] In a possible implementation manner, the embodiments of the present invention provide a cross-database access test method for a database. This method is used to test the cross-database access of the database to ensure that the operation results of the database are correct.
[0025] As Figure 1 shown in the flowchart of a cross-database access test method for a database, it includes the following steps: Step S102, in response to the test execution command, execute the script of the pre-generated test case in the local database; Step S104, during the execution process, monitor whether there is a cross-database association query statement containing a heterogeneous database pointing tag in the script; Step S106, if so, initiate a DBLink request 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 trigger the heterogeneous database to execute the local association query statement corresponding to the cross-database association query statement to obtain the first query result; Step S108, receive the second query result returned by the heterogeneous database based on the cross-database data query request; Step S110, 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.
[0026] The cross-database access test method for a database provided by the embodiments of the present invention can query the heterogeneous database during the entire test process, and compare the second query result obtained from the cross-database query with the first query result obtained locally from the heterogeneous database for consistency. It can effectively implement the cross-database test of the local database, and during the test process, no manual participation is required, which can effectively improve the efficiency of the cross-database access test of the database.
[0027] In actual use, the local database usually refers to the database running on the same electronic device, such as running on the same computer or server; while the heterogeneous database may be distributed on different computer architectures, other computers, workstations, PCs or embedded systems, etc.
[0028] In the embodiments of the present invention, in order to achieve cross-database access, a systematic test framework can be pre-constructed, and the local database and the heterogeneous database are deployed in this systematic test framework to implement automated tests for functions such as connection, query, and exception injection between databases.
[0029] Therefore, in the embodiments 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 between the local database and the heterogeneous database can be created; then, a preset first data table can be input into the heterogeneous database according to the pre-configured test requirements, and a preset second data table can be input into the local database.
[0030] Specifically, in the embodiments of the present invention, the local database is a GBase8s database; therefore, when deploying the local database as described above, the GBase8s database can be deployed in an automated manner. Specifically, the process of automatically deploying the GBase8s database can include the following steps: (1) Obtain the configuration file of the local database; (2) Parse the configuration file to obtain configuration parameters; (3) Create an installation directory according to the configuration parameters to install the local database in the installation directory.
[0031] Among them, the above configuration parameters can be obtained from the SERVICES_GROUP section of the configuration file and parsed to obtain the port range, and then an installation directory can be created to install the GBase8s database. And according to the content under SERVICES_IDS in the SERVICES_GROUP section, a single-node database or a cluster database can be established, which can be specifically set according to the actual usage situation, and the embodiments of the present invention do not limit this.
[0032] Furthermore, the heterogeneous database in the embodiments 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, the container for deploying the heterogeneous database needs to be started, and the configuration file of the heterogeneous database needs to be obtained; then, the heterogeneous database is configured and started according to the configuration file of the heterogeneous database.
[0033] In actual use, in order to achieve cross-database access between databases, generally, after the databases are deployed, it is also necessary to further deploy the DBlink gateway program between the databases, such as using a script to obtain relevant information of the GBase8s database, configure the DBlink gateway, and obtain the configuration parameters of the heterogeneous database, such as an Oracle database, to create a DBLink link.
[0034] After deploying the local database and heterogeneous database in the above manner, test cases can be further generated so that in step S102 above, when responding to the test execution command, the test cases can be obtained and the scripts of the test cases can be executed. Specifically, in the embodiments of the present invention, the process of generating test cases is as follows: Parse the syntax rules for the local database to be compatible with the heterogeneous database, and extract the key information of the syntax rules; Generate a query statement file for the test cases according to the key information; Among them, the query statement file includes local association query statements and corresponding cross-database association query statements; The cross-database association query statement is configured with a different-database pointing label, and the different-database pointing label is used to instruct the local database to query the data of the first data table from the heterogeneous database.
[0035] In actual use, the ANTLR (ANother Tool for Language Recognition) tool can be used to parse the SQL (Structured Query Language) syntax rules for the GBase8s database to be compatible with the heterogeneous database. Among them, the ANTLR tool is a powerful parser generator that supports multiple programming languages and can convert the syntax rules into parser code.
[0036] Furthermore, for the GBase8s database, the ANTLR grammar file obtained by parsing the SQL syntax rules for the GBase8s database to be compatible with the heterogeneous database is usually defined as a g4 file. By writing the corresponding language syntax rules in the g4 file, the ANTLR tool can generate the corresponding language parser. Therefore, in the embodiments of the present invention, when parsing the syntax rules for the local database to be 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 can be loaded, and the ANTLR tool can be used to generate the parser code, and the SQL statements can be parsed by the parser to extract key information such as table structure, field information, and query conditions.
[0037] Furthermore, for the key information extracted above, specific test case files can be generated. Specifically, the test case files can include a table creation statement file, a local association query statement file, and a cross-database association query statement file. Among them, the local association query statement file and the cross-database association query statement file can be collectively referred to as the query statement file. In the embodiments of the present invention, in order to implement cross-database query, in the cross-database association query statements of the cross-database association query statement file above, a different-database pointing label needs to be injected so that when the script of the test case executes to this cross-database association query statement, the different-database pointing label can be recognized and then it can be determined that the data to be queried this time needs to be cross-database queried.
[0038] For example, in a cross-database association query statement, the queried data table is the first data table. Since this first data table is input into a heterogeneous database, the above-mentioned cross-database pointing tag can indicate that the first data table queried this time is in the heterogeneous database. Usually, when deploying a database, some data tables are specified as the data tables for cross-database queries, such as the above-mentioned first data table in the embodiments of the present invention. Therefore, when generating test cases, cross-database association query statements can be generated as needed and the corresponding cross-database pointing tags can be injected.
[0039] Further, for the sake of easy understanding, the following takes the access of a GBase8s database to 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 embodiments of the present invention, as Figure 2 shown in the flowchart of another cross-database access test method of a database, which includes the following steps: Step S202, test execution; In this process, it is necessary to execute the script of the test case. And before the test, it includes inputting a preset first data table into the heterogeneous database and inputting a preset second data table into the local database. At the same time, cross-database pointing tags are configured in the cross-database association query statement of the test case.
[0040] Among them, in the embodiments of the present invention, the cross-database pointing tag is taken as an example and represented as @dblinkname for illustration. And in the test case, assume that one of the sql grammars in the generated local association query statement is as follows: SELECT e.emp_name, d.dept_name FROM employees e JOIN departments d ONe.dept_id=d.dept_id; The corresponding cross-database association query statement is configured with a cross-database pointing tag, and its sql grammar is as follows: SELECT e.emp_name, d.dept_name FROM employees e JOIN departments@linknamed ON e.dept_id=d.dept_id; Among them, the table in front of the cross-database pointing tag table @linkname at this time represents the table in the heterogeneous database, that is, the first data table in the embodiments of the present invention. This first data table is pre-injected into the heterogeneous database as the data table for cross-database queries.
[0041] Step S204, when the above cross-database association query statement is executed, it is monitored that the cross-database association query statement contains a cross-database pointing tag; Step S206: Initiate a DBLink request to the heterogeneous database corresponding to the cross-database pointing tag through the pre-established DBLink link, so as to initiate a cross-database data query request to the heterogeneous database. Specifically, in the embodiment of the present invention, the gbase8s database initiates a DBLink request. Through the dblink gateway, it requests data from the oracle database across databases. At this time, the oracle database can execute the local association query statement corresponding to the above cross-database association query statement locally to obtain the first query result. Generally, in the local association query statement and the cross-database association query statement, except that the @linkname of the cross-database pointing tag is added after a part of the first data table, there is no difference.
[0042] Step S208: Receive the second query result returned by the heterogeneous database based on the cross-database data query request. Step S210: Compare whether the data included in the first query result and the data included in the second query result are consistent; if so, execute Step S212; if not, execute Step S214. Step S212: Generate a test result indicating that the test passes. 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 fails.
[0043] Generally, the file of the second query result is recorded as result_actual.txt; the file of the first query result is recorded as result_expected.txt. In the above Step S210, what is actually compared is the result_actual.txt and result_expected.txt files. If the two files are the same, it means that the test passes; if they are different, a difference report is output. And when there are too many difference contents, the tester can also perform manual comparison to view the result_actual.txt file of the second query result for result analysis.
[0044] In addition, during the test process of the above GBase8s database accessing a heterogeneous database (such as an oracle database), after detecting a cross-database association query statement containing a cross-database pointing tag in the script, obtain the pre-configured fault code; inject the fault code into the script of the test case; after executing the fault code, perform an automated test on the abnormal scenario of the local database based on the execution result.
[0045] That is, through injecting fault codes, automated testing for abnormal scenario injection can be realized in the embodiments of the present invention. Generally, in the above-deployed systematic testing framework, an open-source ChaosMonkey tool can be introduced to inject random fault codes when testing cross-database queries. The fragments of the fault codes are as follows: def test_network_partition(): chaos = ChaosMonkey(config) with chaos.simulate_fault_scenarios(["dblink1"], "connection_drop"): result = db.query("SELECT * FROM shard1@dblink1...") assert not result, "Query should fail but returned a result" Then, the fault tolerance of the local database is judged according to the execution result of the fault code. For example, when a network connection failure occurs, whether it is possible to query the data in another shard, shard1. The specific fault code can be configured according to the actual test content, and the embodiments of the present invention do not limit this.
[0046] In summary, the cross-database access testing method for a database provided by the embodiments of the present invention has the following beneficial effects: (1) High degree of automation: By automatically deploying the test environment, generating test cases, and executing tests, manual intervention is greatly reduced, and the test efficiency is improved.
[0047] (2) Comprehensive test coverage: Through syntax parsing and a test case generation engine, various test cases can be generated to cover more scenarios.
[0048] (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.
[0049] (4) Realistic simulation of abnormal scenarios: By automatically injecting abnormal scenarios (fault codes), problems in the production environment can be more realistically simulated, improving the robustness of the system.
[0050] Furthermore, on the basis of the above embodiments, the embodiments of the present invention also provide a cross-database access testing device for a database, as Figure 3 shown in the structural schematic diagram of a cross-database access testing device for a database, including the following structures: A response module 30, configured to respond to a test execution command and execute a script of a pre-generated test case in the local database; A monitoring module 32, configured to monitor whether there is a cross-database association query statement containing a heterogeneous database pointing tag in the script during the execution process; A cross-database module 34, configured to, when the monitoring result of the monitoring module is positive, initiate a DBLink request to the heterogeneous database corresponding to the heterogeneous database pointing tag through a pre-established DBLink link, so as 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; A return module 36, configured to receive a second query result returned by the heterogeneous database based on the cross-database data query request; A comparison module 38, configured 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.
[0051] Furthermore, the above device is further configured to: respond to a test environment deployment operation, deploy a local database and a heterogeneous database, 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 a pre-configured test requirement, and input a preset second data table into the local database.
[0052] Furthermore, the above device is further configured to: analyze the syntax rules for the local database to be compatible with the heterogeneous database, and extract key information of the syntax rules; generate a query statement file of the test case according to 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 data of the first data table from the heterogeneous database.
[0053] Furthermore, 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 the same; if so, generating a test result indicating that the test passes; 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 fails.
[0054] Further, the above device is also used for: after detecting a cross-database association query statement containing the cross-database pointing tag in the script, obtaining a pre-configured fault code; injecting the fault code into the script of the test case; executing the fault code, and performing an automated test on the abnormal scenario of the local database based on the execution result.
[0055] Further, the above local database is a GBase8s database; the steps of deploying the local database include: obtaining the 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.
[0056] Further, the steps of deploying the heterogeneous database include: starting the container for deploying the heterogeneous database and obtaining the configuration file of the heterogeneous database; configuring and starting the heterogeneous database according to the configuration file of the heterogeneous database.
[0057] The cross-database access test device for a database provided by an embodiment of the present invention has the same technical features as the cross-database access test method provided by the above embodiment, so it can also solve the same technical problems and achieve the same technical effects.
[0058] Further, an embodiment of the present invention also provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the steps of the above method are implemented.
[0059] An embodiment of the present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is run by a processor, the steps of the above method are executed.
[0060] Further, an embodiment of the present invention also provides a schematic structural diagram of an electronic device, as Figure 4 shown, which is the schematic structural diagram of the electronic device. Among them, 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. The processor 41 executes the computer-executable instructions to implement the above method.
[0061] In Figure 4 the shown embodiment, the electronic device further includes a bus 42 and a communication interface 43. Among them, the processor 41, the communication interface 43, and the memory 40 are connected through the bus 42.
[0062] Among them, the memory 40 may include a high-speed random access memory (RAM), or may further include a non-volatile memory, such as at least one disk memory. The communication connection between this system network element and at least one other network element is implemented 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, 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 the sake of representation, Figure 4 only a bidirectional arrow is used in Figure 4 , but it does not mean that there is only one bus or one type of bus.
[0063] The processor 41 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the integrated logic circuit in the hardware of the processor 41 or the instructions in the form of software. The above-mentioned processor 41 can be a general-purpose processor, including a central processing unit (CPU for short), a network processor (NP for short), etc.; it can also be a digital signal processor (DSP for short), an application specific integrated circuit (ASIC for short), a field programmable gate array (FPGA for short), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in combination with the embodiments of the present invention can be directly embodied as being executed and completed by a hardware decoding processor, or executed and completed by a combination of the hardware and software modules in the decoding processor. The software module can be located in a mature storage medium in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. This storage medium is located in the memory, and the processor 41 reads the information in the memory and combines its hardware to complete the foregoing method.
[0064] A computer program product for a cross-database access test method, apparatus, and electronic device provided by an embodiment of the present invention includes 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 foregoing method embodiments. For specific implementation, reference can be made to the method embodiments and will not be elaborated herein.
[0065] Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working process of the above-described apparatus can refer to the corresponding process in the foregoing method embodiments and will not be elaborated herein.
[0066] In addition, in the description of the embodiments of the present invention, unless otherwise clearly defined and limited, the terms "installation", "connection", and "connection" should be understood in a broad sense. For example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be directly connected or indirectly connected through an intermediate medium, and it can be the communication inside two components. For those skilled in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0067] If the above function is implemented in the form of a software function unit and sold or used as an independent product, it can be stored in a computer-readable 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 a part of this 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 to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the embodiments of the present invention. The foregoing storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (ROMs), random access memories (RAMs), magnetic disks, or optical discs that can store program code.
[0068] In the description of the present invention, it should be noted that the orientation or positional relationship indicated by the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc. is based on the orientation or positional relationship shown in the drawings, and is only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be construed as a limitation of the present invention. In addition, the terms "first", "second", and "third" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance.
[0069] Finally, it should be noted that the above embodiments are only specific embodiments of the present invention, used to illustrate the technical solutions of the present invention, rather than limiting it. The protection scope of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any technician familiar with the technical field of the present invention can still modify the technical solutions recorded in the foregoing embodiments or easily think of changes, or perform equivalent replacements for some of the technical features; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be covered within the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.
Claims
1. A cross-database access test method for a database, characterized in that, The method includes: Responding to a test execution command and executing a script of a pre-generated test case in a 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; 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.
2. The method according to claim 1, wherein The method further includes: Responding to a 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 the heterogeneous database and a preset second data table into the local database according to pre-configured test requirements.
3. The method according to claim 2, wherein The method further includes: Parsing the syntax rules for the local database to be compatible with the heterogeneous database and extracting key information of the syntax rules; Generating a query statement file for the test case according to 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 data of the first data table from the heterogeneous database.
4. 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 the same; If so, generating a test result indicating that the test passes; 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 fails.
5. The method according to claim 1, characterized in that The method further includes: After monitoring that there is a cross-database association query statement containing the heterogeneous database pointing tag in the script, obtaining a pre-configured fault code; Injecting the fault code into the script of the test case; Executing the fault code and performing an automated test on an abnormal scenario of the local database based on the execution result.
6. The method according to claim 2, characterized in that, The 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.
7. The method according to claim 2, characterized in that, The step of deploying the heterogeneous database includes: Starting a container for deploying the heterogeneous database and obtaining a configuration file of the heterogeneous database; Configuring and starting the heterogeneous database according to the configuration file of the heterogeneous database.
8. A cross-database access test device for a database, characterized in that, The device includes: A response module, configured to respond to a test execution command and execute a script of a pre-generated test case in a local database; A monitoring module, configured to monitor whether there is a cross-database association query statement containing a heterogeneous database pointing tag in the script during the execution process; A cross-database module, configured to, when the monitoring result of the monitoring module is yes, initiate a DBLink request to a heterogeneous database corresponding to the heterogeneous database pointing tag through a pre-established DBLink link, so as 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; A return module, configured to receive a second query result returned by the heterogeneous database based on the cross-database data query request; A comparison module, configured 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.
9. An electronic device, characterized in that, It includes a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the steps of the method according to any one of claims 1-7 above are implemented.
10. A computer-readable storage medium, characterized in that, A computer program is stored on the computer-readable storage medium. When the computer program is run by a processor, the steps of the method according to any one of claims 1-7 above are executed.
Citation Information
Patent Citations
Test script execution method and device, computer equipment and storage medium
CN113051172A
Multilayer analysis method of structured query statement, computer equipment and storage medium
CN114756569A
Database processing method and system, electronic equipment and storage medium
CN115292348A
Heterogeneous database cross-database query method, device and equipment and storage medium
CN115408448A
Cross-database data comparison method, device and equipment and storage medium
CN116303646A