Method for automatically converting single-instance use case of database into high-availability use case
Through an automated test framework and high availability converter, the database single instance use case is automatically converted into high availability use cases, solving the problem of high repetitive operation and maintenance costs in the existing technology, and improving the efficiency of use case writing and maintenance.
Patent Information
- Application Number
- CN202510554431.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-29
- Publication Date
- 2025-05-30
- Estimated Expiration
- 2045-04-29
AI Technical Summary
In the prior art, there are many repeated operation instructions and high maintenance costs, resulting in repeated writing and maintenance of database test cases in multiple scenarios.
Automatically convert database single-instance use cases into high-availability use cases with automated testing frameworks and high-availability converters, including syntax analysis, DSL statement replacement, and setting preconditions for high-availability clusters.
Reduces use case writing and maintenance time, reduces analysis time for failed use cases, and avoids the need to repeatedly write use cases in high availability scenarios.
Smart Images

Figure CN120066979A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of database testing, and particularly relates to a method for automatically converting database single-instance test cases into highly available test cases. Background Art
[0002] The writing of database test cases is generally completed by DSL (domain-specific language). Specifically, it is a custom script language designed specifically for testing its own database products, providing some built-in global objects. These objects provide various highly encapsulated interfaces, making the test cases short and easy to use.
[0003] Tools such as javacc or antlr can complete the design work of DSL. For javacc, a DSL is described by writing TOKEN and grammar rules in a.jj grammar file. For example: instance = system.getInstance(); it corresponds to a grammar rule: assignment statement. The rule for recognizing it as an assignment statement is: identifier = expression; in this example, the identifier is a string starting with a letter, and the expression is a function call (function call is another grammar rule: identifier.identifier left parenthesis parameter list right parenthesis, and the parameter list is another grammar rule, which will not be elaborated here). Describing various grammar rules with javacc's.jj file defines its own DSL. In addition, java code is embedded in the key grammar rules, defining what java statement it should be parsed (translated) into when the rule is recognized. Through the javacc command, a parser for this DSL can be generated. That is, taking the test case file written in DSL as the input stream and passing it to the parser can interpret (translate) it into java for execution. For example, a line print hello; in DSL becomes System.out.println(“hello”) after being parsed by the parser. However, in many cases, for database testing, for the same functional point, it needs to be tested in multiple scenarios (modes). For example, when inserting a piece of data into a certain table and then verifying that the data actually exists, generally only a single-instance scenario is written first when writing test cases. In fact, the highly available scenario also needs to test this test case. If multiple highly available test cases are written again (at least one for each cluster), it is obviously repetitive, and the number of test cases doubles, resulting in a very high maintenance cost. Summary of the Invention
[0004] In view of this, the present invention aims to propose a method for automatically converting database single-instance test cases into highly available test cases to solve the problems of a large number of repetitive operation instructions and high maintenance costs in the above-mentioned prior art.
[0005] To achieve the above object, the technical solution of the present invention is implemented as follows: A method for automatically converting a database single-instance use case into a highly available use case, comprising the following steps: Step 1: After the automated test framework is started, first use the parser to perform syntax analysis on the use case; Step 2: Add a pre-transformer to the highly available converter; Step 3: Call the apply method of HaTransformer to start converting the use case; In Step 1, the parser performs syntax analysis on the use case, including: After the use case script is passed to the parser as an input stream, the input character stream becomes TOKEN after lexical analysis; Identify which grammar rule the TOKEN belongs to. After entering the grammar rule corresponding to the DSL statement, use each element in the statement as the parameters of the constructor method of a DslStatement implementation class to construct an object of the DslStatement implementation class; After encountering a semicolon, it is considered that the current DSL statement ends, and then the next DSL statement is matched; After all DSL statements of the use case are analyzed by the parser, they become a List <dslstatement>; In step 2, a pre - converter is added to the highly available converter, including: When converting a single - instance use case to a highly available use case, DSL statement replacement is required, and necessary pre - conditions for setting up a highly available cluster are needed. If the GBase 8s database uses logical logs for master - standby synchronization, then if the database creation statement of the single - instance use case is in non - logging mode, conversion is required; The conversion process includes: Call the function apply, and the parameter of the function apply is the use - case object, and the use - case object includes List <dslstatement>, the return value of the function `apply` is also a test case object, representing the transformed test case. The two implementation classes of the function `apply` are `LogModeTransformer` and `HaTransformer`, where `LogModeTransformer` and `HaTransformer` are the log mode converter and the high availability converter respectively; In step 3, call the `apply` method of `HaTransformer` to start transforming the test case, including: Call the `apply` methods of all the pre-transformers; Call the core transformation logic of the high availability converter.
[0006] Furthermore, the constructor method of `LogModeTransformer` has two parameters, converting from the log mode represented by the first parameter to the log mode represented by the second parameter.
[0007] Furthermore, in the constructor method of `HaTransformer`, first add a `LogModeTransformer` as a pre-transformer. The two parameters are `NONE` and `LOG` respectively, representing converting from the non-log mode to the log mode; If the target of the high availability converter is `sec`, that is, using the previous single-instance variable name as the variable name of the cluster slave node, so for the log mode of the slave node, another `LogModeTransformer` needs to be added as a pre-transformer. The two parameters are `BUFFERED` and `LOG` respectively, representing converting the buffered log mode to the unbuffered log mode.
[0008] Furthermore, calling the `apply` methods of all the pre-transformers includes: Set both pre-transformers to `LogModeTransformer`, and the `apply` method directly uses the corresponding `visitor` of this transformer to transform the test case; Among them, the parent class of `visitor` is `DeepCopyVisitor`, whose function is to deeply copy each node of the abstract syntax tree; when using `visitor` to perform a depth-first traversal of the `testcase`, directly follow the `visit` of the parent class to copy the nodes; Among them, there are two statements in the DSL of the log mode converter for creating a database. The database creation methods include normal database creation and advanced database creation. The normal database creation and advanced database creation correspond to two method calls. The DSLStatement implementation classes corresponding to the method calls are both DslMethodCallStatement. DslMethodCallStatement has an element representing the method name. As long as it is determined that the method name is getDatabase or getAdvancedDatabase, it can be determined that it is a database creation statement; When traversing to the method call statement, the specific process of entering the visitor includes: Enter the visit method of the visitor, obtain the method name from the stmt parameter of visit. If it is getDatabase, then call the getDatabase method; if it is getAdvanceDatabase, then call the getAdvancedDatabase method; if it is neither, then directly call the visit method of the parent class to copy the statement.
[0009] Furthermore, the getDatabase call method includes: The first parameter is set to the set log mode, which specifically includes: Create a new parameter list. First, use the target log mode as the first list element, then add each element of the original parameter list with the first element removed to the new parameter list in the original order, and finally create a new method call statement object to replace the original object.
[0010] Furthermore, the getAdvancedDatabase call method includes: The db object returned by the getAdvancedDatabase method call is an empty shell. Subsequently, the set method is used for attribute setting. If it is necessary to change the log mode, there is no need to care about the previously set log mode. It only needs to be set again to overwrite the original log mode.
[0011] Furthermore, the core conversion logic of calling the high-availability converter includes: First, replace obtaining a single instance with obtaining a cluster. When visiting the assignment statement, make a judgment: The method parameter of visit is the object of the DslStatement implementation class corresponding to the assignment statement. The elements on the right side of the equal sign are obtained through the DslStatement implementation class object. If the element is a method call statement and the call object is system and the method name is getinstance, it indicates a DSL statement for obtaining a singleton instance, and then a cluster is constructed; if the element is a method call statement and the method name is getConnection, then getConnection is processed; if neither is the case, the visit method of the parent class is directly called to assign the statement.
[0012] Further, constructing a cluster includes: Define cluster = system.getCluser(); after parsing by the parser, a DslStatement will be obtained, and then manually construct: Construct a system object; Construct a method call statement object; Construct a cluster object to receive the return value of the method call statement object; Construct an assignment statement; Based on clusterObj in the assignment statement, obtain each node in the cluster: Obtain the DSL statement of the master node, and the manual construction steps are as follows: If the target object of the high-availability converter is the master node, then the master node object of the cluster directly uses the original singleton instance node object, that is, uses the variable name of the original singleton instance node; If the target object is a slave node, then a master node object needs to be manually constructed to obtain primaryObj as the master node object; Construct a method call statement object, with three parameters respectively: clusterObj, "getNode", parameter list, and the variable name of the obtained statement object is getPrimaryExpression; Construct an assignment statement object to obtain the DSL statement of the slave node; Then call the statement object for the two cluster nodes, with three parameters respectively: node object, "setConfig", parameter list; Then construct another method call statement object to instantiate the cluster, with three parameters respectively: clusterObj, "instantiate".
[0013] Further, processing getConnection includes: The steps of the test case script are to first obtain an instance, then obtain the connection getConnection, and then perform the following operations with getConnection: If it can only be performed on the primary node, when the cluster converter targets a secondary node and executes such an operation, it needs to temporarily switch to the primary node for execution and then resume execution by the secondary node after completion. Therefore, another connection to the primary node is required, and a method call statement object also needs to be constructed. The three parameters are: primaryObj, "getConnection", and the parameter list of the original getConnection. The constructed connection object is named: __tempPrimConn; In visit, when it is detected that the method name is one of the method names that must be executed on the primary node in the list, switch the current connection to __tempPrimConn. The specific steps include: I. Save the current connection; II. Switch the current connection to __tempPrimConn; III. Construct a method call statement object and obtain the database name connected by the current connection; IV. Construct a method call statement object and switch the database to the database name obtained in step III; V. After the statement of the current visit, restore the connection saved in step I.
[0014] Compared with the prior art, the method for automatically converting a database single-instance use case into a highly available use case according to the present invention has the following advantages: The method for automatically converting a database single-instance use case into a highly available use case according to the present invention, through the converter introduced in this method, can not only reduce the time for writing and maintaining use cases, but also reduce the analysis time for failed use cases. If the single-instance use case has failed, the highly available use case obtained through the converter directly skips execution, so there is no need to analyze. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] The drawings constituting a part of the present invention are used to provide a further understanding of the present invention. The schematic embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation to the present invention. In the drawings: Figure 1 It is a schematic diagram of the overall step flow described in the embodiments of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0016] It should be noted that, without conflict, the embodiments in the present invention and the features in the embodiments can be combined with each other.
[0017] In the description of the present invention, it should be understood that the orientation or positional relationship indicated by the terms "center", "longitudinal", "transverse", "upper", "lower", "front", "rear", "left", "right", "vertical", "horizontal", "top", "bottom", "inner", "outer", etc. is based on the orientation or positional relationship shown in the drawings. It 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 to the present invention. In addition, the terms "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying relative importance or implicitly specifying the quantity of the indicated technical features. Thus, the features defined with "first", "second", etc. may explicitly or implicitly include one or more of such features. In the description of the present invention, unless otherwise specified, the meaning of "a plurality" is two or more.
[0018] In the description of the present invention, it should be noted that unless otherwise clearly defined and limited, the terms "mounted", "connected", "coupled" should be understood in a broad sense. For example, it may be a fixed connection, a detachable connection, or an integral connection; it may be a mechanical connection or an electrical connection; it may be directly connected or indirectly connected through an intermediate medium, and it may be the communication inside two elements. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood through specific situations.
[0019] The present invention will be described in detail below with reference to the drawings and in conjunction with embodiments.
[0020] As Figure 1 shown, a method for automatically converting a database single-instance use case into a highly available use case includes the following steps: Step 1: After the automated test framework is started, first use the parser to perform syntax analysis on the use case. In this embodiment, each DSL statement must match a certain syntax rule. The Java code embedded in the syntax rule transforms it into an object of a subclass of DslStatement (interface). Each type of DSL statement has a corresponding syntax rule and thus a DslStatement implementation class. Then, after the use case is analyzed by the parser, there is a List <dslstatement>, which contains all the statements actually executed in the use case, such as print hello; corresponding to newDslPrintStatement("hello"); Among them, the automation testing framework is any existing testing framework. Among them, the parser analysis specifically includes: after the use case script is passed to the parser as the input stream, the input character stream becomes one TOKEN (a commonly used term in compilation principles) after lexical analysis, and further it can be recognized which grammar rule this string of TOKENs belongs to. After entering the grammar rule corresponding to the DSL statement, there is embedded Java code inside. The elements in the statement are used as the parameters of the constructor method of a DslStatement implementation class, and an object of the DslStatement implementation class is constructed. After encountering a semicolon, it is considered that the current DSL statement ends, and then the next DSL statement is matched. After all the DSL statements of the use case are analyzed by the parser, they become List <dslstatement>。
[0021] Step 2: Add a pre - converter to the highly available converter; In this embodiment, when converting a single - instance use case into a highly available use case, not only DSL statement replacement is required, but also the necessary pre - conditions for the highly available cluster need to be considered. For example, if the GBase 8s database uses logical logs for master - standby synchronization, then if the database creation statement in the single - instance use case is in non - logging mode, it needs to be converted. (The logging mode converter is actually an independently usable converter, and it can be applied alone to test different logging modes).
[0022] Transformer is an interface that has a method (function) apply, and the parameter of this method is a use - case object (which contains a List <dslstatement>), the return value is also a test case object, representing the test case after conversion. LogModeTransformer and HaTransformer are two implementation classes, namely the log mode converter and the high availability converter respectively.
[0023] The constructor of LogModeTransformer has two parameters, converting from the log mode represented by the first parameter to the log mode represented by the second parameter.
[0024] In the constructor of HaTransformer, first, a LogModeTransformer is added as a pre-transformer. The two parameters are NONE and LOG respectively, representing converting the non-log mode to the log mode. If the target of the high availability transformer is sec (slave node), that is, using the previous single-instance variable name as the variable name of the cluster slave node, then the subsequent operations of the original test case are also operations on the cluster slave node. Therefore, there are also requirements for the log mode of the slave node. Then, another LogModeTransformer is added as a pre-transformer. The two parameters are BUFFERED and LOG respectively, representing converting the buffered log mode to the unbuffered log mode. This is the requirement of the GBase 8s database for the HAC cluster and will not be elaborated here.
[0025] Step 3: Call the apply method of HaTransformer to start converting the test case; In this embodiment, it specifically includes: (1) First, call the apply methods of all pre-transformers; Both pre-transformers are LogModeTransformer (there is no pre-transformer). The apply method directly uses the visitor corresponding to this transformer to convert the test case. The following is the implementation of apply, which is also a typical writing of a general visitor: LogModeVistor visitor = new LogModeVistor(original log mode, target log mode); testcase.accept(visitor); return visitor.getTestcase(); Each DSL statement in the test case calls accept(visitor) and traverses downward (depth - first) until it reaches the leaf node of the syntax tree corresponding to the DSL statement. After visitor.visit(this); it returns to the upper layer. After all elements in this layer are visited by visitor.visit(this); a visit is made to the entire layer, and then it returns to the upper layer until the top layer. That is to say, all leaf nodes and non - leaf nodes have been visited once.
[0026] The superclass of all visitors in this method is DeepCopyVisitor. As the name implies, its function is to deeply copy each node of the abstract syntax tree. When making a depth - first traversal of the test case using the visitor, most of the node (DSL statement) types are not concerned, so the visit method of the superclass is directly called to copy the node.
[0027] Among them, the log mode converter actually modifies the parameters of the database creation statement. The designed DSL has 2 statements for creating a database. One is a normal database creation, and the other is an advanced database creation, corresponding to 2 method calls. The implementation class of DSLStatement corresponding to all method calls is DslMethodCallStatement. This class has an element representing the method name. As long as it is determined that the method name is getDatabase or getAdvancedDatabase, it can be determined that it is a database creation statement.
[0028] When traversing to a method call statement, it will enter the following method of the visitor, including: Enter the visitor's visit(DslMethodCallStatement stmt) method. Obtain the method name from the stmt parameter. If it is getDatabase, perform replacement 1) (see below). If it is getAdvanceDatabase, perform replacement 2) (see below). If it is neither, directly call the visit method of the superclass to copy the statement.
[0029] The specific description is as follows: @Override public void visit(DslMethodCallStatement stmt) { / / If the function name of stmt is getDatabase, perform replacement 1) / / If the function name of stmt is getAdvancedDatabase, perform replacement 2) / / If neither of them directly calls the visit method of the parent class, copy this statement } 1) getDatabase; For the method designed in this way, there are actually multiple overloaded methods. The invariant is that the first parameter is always the log mode setting. Therefore, only the first parameter in the parameter list needs to be replaced with the target log mode. Specifically, create a new parameter list. First, use the target log mode as the first list element, then add each element of the original parameter list with the first element removed to the new parameter list in the original order. Finally, create a new method call statement object to replace the original object, new TdlMethodCallExpression(the original object that called getDatabase, "getDatabase", the new parameter list); Specifically, "all pre - transformers" actually refers to two "log mode transformers" here. In the apply method of the log mode transformer, it will call the corresponding visitor (LogModeVistor) of the log mode transformer to traverse each DslStatement in the test case. When it traverses to visit(DslMethodCallStatement stmt), it gets the method name of the current DSL statement (i.e., the method call statement) through stmt. If the method name is getDatabase, perform the processing of this step.
[0030] 2) getAdvancedDatabase For this method call, the returned db object is actually an empty shell. Subsequently, there will be a series of set methods for various property settings. To change the log mode, there is no need to care about the previously set log mode. Just set it again to overwrite the original one. Specifically, the most important thing is new TdlMethodCallExpression(db object, "setLogMode", a new parameter list with only one element being the target log mode); as a subsequent DSL statement (note that the db object is obtained by visiting the assignment statement); Specifically, the same as the description in 1) getDatabase, perform this step of processing when the method name is detected as getAdvancedDatabase.
[0031] (2) Enter the core conversion logic of the high - availability converter First, replace obtaining a single instance with obtaining a cluster. When visiting the assignment statement, make a judgment: The method parameter of visit is the object of the DslStatement implementation class corresponding to the assignment statement. Through it, the element on the right side of the equal sign is retrieved. If this element is a method call statement and the calling object is system and the method name is getinstance, it indicates that it is a DSL statement for obtaining a singleton instance, and replacement 1) is performed (see below); if this element is a method call statement and the method name is getConnection (establish a connection and return a connection object), replacement 2) is performed (see below); if neither is the case, the visit method of the parent class is directly called to assign this statement.
[0032] The specific description is as follows: @Override; public void visit(DslAssignmentStatement stmt); { / / If the right side of the equal sign of stmt is a method call statement, and the calling object is system, and the method name is getInstance, perform replacement 1) / / If the right side of the equal sign of stmt is a method call statement, and the method name is getConnection (establish a connection and return), perform replacement 2) / / If neither is the case, directly call the visit method of the parent class to copy this statement }}
[0033] 1) Construct a cluster cluster = system.getCluser(); After being parsed (translated) by the parser, a series of DslStatement will be obtained, and now they need to be manually constructed: I. Construct a system object, systemObj = new DslObjectReference("system"); II. Construct a method call statement object, getClusterExpression = newDslMethodCallExpression(systemObj, "getCluster", empty parameter list); III. Construct a cluster object to receive the return value of II, clusterObj = newDslObjectReference("__cluster"); IV. Construct an assignment statement: new TdlAssignmentStatement(clusterObj, getClusterExpression), which actually assigns the return value of the second parameter to the first parameter during execution; Now clusterObj is just a shell, and next we need to obtain each node in the cluster: The DSL writing format for obtaining the primary node: primary = cluster.getNode(PRIMARY); The parameter is an enumeration representing the primary node type. The manual construction steps are as follows: I. If the target object of the high-availability converter is the primary node, then the primary node object of the cluster can directly use the original single-instance node object, that is, use the variable name of the original single-instance node. If the target object is a secondary node, then the primary node object needs to be manually constructed in the same way as the previous construction method. In either case, we get primaryObj as the primary node object in this step II. Construct a method call statement object with three parameters: clusterObj, "getNode", and the parameter list (with one element PRIMARY). The variable name of the obtained statement object is getPrimaryExpression; III. Construct an assignment statement object new TdlAssignmentStatement(primaryObj, getPrimaryExpression); The DSL statement for obtaining the secondary node is generally written as: secondary = cluster.getNode(SEC); The steps for constructing the statement to obtain the primary node are the same, except that step I is reversed, so it will not be elaborated here; Then perform some settings on the two cluster nodes, which is also to construct a method call statement object with three parameters: the node object, "setConfig", and the parameter list (the key and value of the configuration).
[0034] Construct another method call statement object to instantiate the cluster with three parameters: clusterObj, "instantiate", and the parameter list (empty).
[0035] This step is the first step of the core conversion logic for entering the high-availability converter in (2) above, which changes obtaining a single instance to constructing a cluster, corresponding to 1) above.
[0036] 2) Process getConnection The steps in the use case script generally involve first obtaining an instance (setting up a cluster), then obtaining a connection (getConnection), and then performing a series of operations using this connection. There are some operations that can only be performed on the primary node, such as creating a database space. Therefore, when the cluster converter target is a secondary node and such an operation is executed, it needs to be temporarily switched to the primary node for execution. After the execution, it resumes execution on the secondary node. So, another connection to the primary node is required, and a method call statement object also needs to be constructed. The three parameters are: primaryObj, "getConnection", and the parameter list of the original getConnection. The constructed connection object is named: __tempPrimConn; In visit(DslMethodCallExprssion), when it is detected that the method name is one of the items in the list of method names that must be executed on the primary node, switch the current connection to __tempPrimConn. The steps are as follows: I. Save the current connection; II. Switch the current connection to __tempPrimConn; III. Construct a method call statement object and obtain the database name connected by the current connection; IV. Construct a method call statement object and switch the database to the database name obtained in III; V. After the statement currently being visited, restore the connection saved in I; There are also some special cases. For example, some SQL statements need to be executed on the primary node or executed once on both nodes. Then, in visit(DslSqlStatement s), as long as such an SQL statement is matched, it is temporarily switched to the primary node for execution, or executed once on both nodes. The construction steps also involve constructing various method call statements, which will not be elaborated here.
[0037] This step is the second step of the core conversion logic of the high-availability converter in the above (2). After the first step, obtaining a single instance has been converted to constructing a cluster. Subsequently, there is still the process of handling the acquisition of connections. Because now it may be obtaining a connection from a secondary node and performing operations, however, in fact, some operations must be performed on the primary node or on both nodes simultaneously.
[0038] The startup parameter -xform of the automation framework, followed by each type of string, corresponds to the same high-availability converter, but with different passed parameters. According to the different parameters, there are different processing logics in the corresponding visitor of the high-availability converter. The basic methods are similar to the previous steps, and various DslStatements are manually constructed to replace the previous DSL statements.
[0039] The converter introduced by this method can not only reduce the time for writing and maintaining test cases, but also reduce the analysis time for failed test cases. If a single-instance test case has failed, the highly available test case obtained through the converter will directly skip execution, so there is no need for analysis.
[0040] The final effect of this method is that when adding -xform? (where? refers to a certain highly available transformation, and xform is the abbreviation of transform) to the startup parameters of the automated test framework, all the test cases to be run this time will be converted into highly available test cases. For example, -xform si_to_hacsec means converting a single instance (si = single instance) into a hac cluster (a type of HAC cluster mode of the GBase 8s database), and the variable names of the single instance in the original test case are used on the sec (secondary) node. Whether the variable name is the master or slave of the hac cluster determines whether the subsequent operations (such as sql) of the test case are executed on the master node or the slave node. Some conversions specific to the current database characteristics also need to be handled during this process.
[0041] This method can manually construct the actual execution statements that should originally be analyzed (translated) from DSL by the syntax analyzer to convert single-instance test cases into highly available test cases.
[0042] The above are only the preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.< / dslstatement> < / dslstatement> < / dslstatement> < / dslstatement> < / dslstatement>
Claims
1. A method for automatically converting a database single instance use case into a high-availability use case, characterized in that: The following steps are involved: Step 1: After the automated testing framework is started, use the parser to perform syntax analysis on the use case; Step 2: Add a pre-converter to the high-availability converter; Step 3: Call the apply method of HaTransformer to start transforming the use case; In step 1, the parser performs grammatical analysis on the use case, including: After the use case script is passed to the parser as an input stream, the input character stream is lexically analyzed and converted into a TOKEN; Identify which grammar rule the TOKEN belongs to, enter the grammar rule corresponding to the DSL statement, and use each element in the statement as the parameters of the constructor of a DslStatement implementation class to construct an object of the DslStatement implementation class; When a semicolon is encountered, the current DSL statement is considered to be ended, and the next DSL statement is matched; After all DSL statements of the use case are analyzed by the parser, they become List <dslstatement> ;< / dslstatement> In step 2, add a pre-converter to the high-availability converter, including: To convert a single-instance use case to a high-availability use case, you need to replace the DSL statements and set the necessary prerequisites for a high-availability cluster. If the GBase 8s database uses logical logs for master-slave synchronization, then if the database creation statement of the single-instance use case is in non-log mode, you need to convert it; The conversion process includes: Call the apply function. The parameter of the apply function is the use case object. The use case object includes List <dslstatement> ,The return value of the function apply is also a use case object, which represents the transformed use case. The two implementation classes of the function apply include LogModeTransformer and HaTransformer. LogModeTransformer and HaTransformer are log mode transformer and high availability transformer respectively;< / dslstatement> In step 3, call the apply method of HaTransformer to start transforming the use case, including: Call the apply method of all pre-converters; Calls the core conversion logic of the high-availability converter.
2. A method for automatically converting a database single instance use case into a high-availability use case according to claim 1, characterized in that: The LogModeTransformer constructor has two parameters, which are used to convert the log mode represented by the first parameter to the log mode represented by the second parameter.
3. A method for automatically converting a database single instance use case into a high availability use case according to claim 1, characterized in that: In the construction method of HaTransformer, first add a LogModeTransformer as a front transformer, the two parameters are NONE and LOG, which means to change the non-log mode to the log mode; If the target of the high-availability transformer is sec, that is, the previous single instance variable name is used as the variable name of the cluster slave node, so a LogModeTransformer needs to be added as a front transformer for the log mode of the slave node. The two parameters are BUFFERED and LOG, which means changing the buffered log mode to the unbuffered log mode.
4. A method for automatically converting a database single instance use case into a high-availability use case according to claim 1, characterized in that: Call the apply method of all pre-transformers, including: Set both pre-converters to LogModeTransformer, and the apply method directly uses the visitor corresponding to this converter to convert the use case; Among them, the parent class of visitor is DeepCopyVisitor, which is used to deep copy each node of the abstract syntax tree; when using visitor to do depth-first traversal of testcase, directly visit the copy node of the parent class; Among them, the DSL of the log mode converter has two statements for database creation. The database creation methods include ordinary database creation and advanced database creation. Ordinary database creation and advanced database creation correspond to two method calls. The DSLStatement implementation classes corresponding to the method calls are both DslMethodCallStatement. DslMethodCallStatement has an element representing the method name. As long as the method name is getDatabase or getAdvancedDatabase, it can be determined that it is a database creation statement. When traversing to the method call statement, the specific process of entering the visitor includes: Enter the visit method of visitor, get the method name from the stmt parameter of visit, if it is getDatabase, call the getDatabase method, if it is getAdvanceDatabase, call the getAdvancedDatabase method, if neither, directly call the visit method of the parent class to copy the statement.
5. A method for automatically converting a database single instance use case into a high-availability use case according to claim 4, characterized in that: The getDatabase call method includes: The first parameter is set to set the log mode, including: Create a new parameter list, first use the target log mode as the first list element, then remove the first element of the original parameter list and add each element to the new parameter list in the original order, and finally recreate a method call statement object to replace the original object.
6. A method for automatically converting a database single instance use case into a high availability use case according to claim 4, characterized in that: The getAdvancedDatabase call method includes: The db object returned by the getAdvancedDatabase method call is an empty shell. The set method is used to set properties later. If you need to change the log mode, you do not need to care about the previously set log mode. You only need to set it again to overwrite the original log mode.
7. A method for automatically converting a database single instance use case into a high availability use case according to claim 4, characterized in that: Call the core conversion logic of the high-availability converter, including: First, replace the acquisition of a single instance with the acquisition of a cluster, and make a judgment when visiting the assignment statement: The method parameter of visit is the DslStatement implementation class object corresponding to the assignment statement. The element on the right side of the equal sign is taken through the DslStatement implementation class object. If the element is a method call statement and the calling object is system and the method name is getinstance, it means that it is a DSL statement for obtaining a single instance, and a cluster is built; if the element is a method call statement and the method name is getConnection, getConnection is processed; if neither is the case, the parent class visit method is directly called to assign the statement.
8. A method for automatically converting a database single instance use case into a high availability use case according to claim 7, characterized in that: Build a cluster, including: Define cluster = system.getCluser(); after parsing by parser, DslStatement will be obtained, and then manually constructed: Construct a system object; Construct a method call statement object; Build a cluster object to receive the return value of the method call statement object; Construct an assignment statement; Based on clusterObj in the assignment statement, get each node in the cluster: Get the DSL statement of the master node. The manual construction steps are as follows: If the target object of the high-availability converter is the master node, the master node object of the cluster directly uses the original single instance node object, that is, uses the variable name of the original single instance node; If the target object is a slave node, then a master node object needs to be manually constructed to obtain primaryObj as the master node object; Construct a method call statement object with three parameters: clusterObj, "getNode", parameter list, and the variable name of the statement object is getPrimaryExpression; Construct an assignment statement object and obtain the DSL statement from the node; Then call the statement object on the two cluster nodes, with three parameters: node object, "setConfig", parameter list; Construct another method call statement object to instantiate the cluster. The three parameters are: clusterObj, "instantiate".
9. A method for automatically converting a database single instance use case into a high availability use case according to claim 7, characterized in that: Handle getConnection, including: The use case script steps are to first get the instance, then get the connection getConnection, and then use getConnection to perform the following operations: If it can only be performed on the master node, when the cluster converter targets the slave node and executes this operation, it is necessary to temporarily switch to the master node for execution, and then resume execution on the slave node after execution. Therefore, another connection to the master node is required, and a method call statement object needs to be constructed. The three parameters are: primaryObj, "getConnection" and the parameter list of the original getConnection. The constructed connection object is named: __tempPrimConn; In visit, when it is detected that the method name is one of the method names that must be executed on the main node, the current connection is switched to __tempPrimConn. The specific steps include: I. Save the current connection; II. Switch the current connection to __tempPrimConn; III. Construct a method call statement object to obtain the name of the database to which the current connection is connected; IV. Construct a method call statement object, and switch the library to the library name obtained in step III; V. After the current visit statement, restore the connection saved in step I.
Citation Information
Patent Citations
Automated testing method, device and system, medium and electronic equipment
CN109933519A
Test method, test device, computer readable storage medium and electronic equipment
CN115858337A
Page test method and device, equipment and medium
CN116069649A
Data center task resource prediction method based on massive logs
CN116089215A
Method and system for realizing general database adapter
CN117171192A
Cited By
Optimized database case execution method, system and device and medium
CN120371712A
Method, system, device and medium for optimizing database use case execution
CN120371712B