Description
The QueryBeforeLoopV2Gen connects to an SQL database via JDBC, uses a user-defined select statement to retrieve a finite set of values, and stores the values in a list to be iterated. GenRocket Runtime Engine executes this Generator only once before it starts generating data. Thus, the generator can be used to determine the engine's loop count by retrieving a finite number of values before the first iteration.
Generator Parameters
The following parameters may be configured for the QueryBeforeLoopV2Gen Generator. Items with an asterisk* are required.
- setLoop* - Gives the ability to override the loop count at the Scenario level to only produce the number of rows retrieved by the query.
- resourcePath* - Defines the path on a user's local machine, where the resource file for the JDBC configuration properties file exists.
- resourceSubDir - Defines an optional subdirectory under the resourcePath where the resource file for the JDBC configuration properties file exists.
- resourceName* - Defines the name of the configuration properties file that contains the database connection information.
- waitAmount* - Defines the number of iterations the generator should wait before moving to the next value in the list.
- queryOnce* - Defines whether the before loop query is only queried once (Default = True). If the Domain is a child Domain, then each time the parent traverses the child, the question will be executed once before the first iteration of the child, unless the value equals False.
- random* - Randomizes the list of queried values when True and not when False (Default = False).
- seed - Defines an optional seed for randomization. Using the seed will ensure that the same random data is generated each time data is generated as long as the values retrieved from the query are the same.
- grVar1 - The first of five possible variables to use in the SQL select statement.
- grVar2 - The second of five possible variables to use in the SQL select statement.
- grVar3 - The third of five possible variables to use in the SQL select statement.
- grVar4 - The fourth of five possible variables to use in the SQL select statement.
- grVar5 - The fifth of five possible variables to use in the SQL select statement.
- query* - Defines the SQL select statement to run.
- list - Defines a list of values that will be used for preview purposes only. Three values are all that are necessary for previewing data.
Restrictions
- This Generator will not run if any of the following keywords are found in the query (update, delete, set, or truncate).
JDBC Configuration File
This Generator utilizes a configuration file stored locally on the user's computer or a shared test server to obtain the necessary information to connect to a specific database via JDBC. For detailed information, refer to 'What is a JDBC Config File?'
Example Use Case
The Test Data Challenge
A Tester must generate customer data to populate a customer table associated with a branch table within the Acme Bank test database. However, generating customer data presents a few challenges for the test case.
- Multiple branches may exist within the same zip code.
- All customers associated with a given branch must also exist within the same zip code.
- A total of 10,000 customers must generated for each zip code.
The Test Data Solution
Since one or more Branches may exist within the same zip code, and only 10K customers may be populated for each zip code, the Tester must determine the distinct set of zip codes that exists for all branches and generate 10K customers for each zip code. This can be easily accomplished using the QueryBeforeLoopV2Gen to select the distinct set of zip codes from the branch table and set the Engine's loop count before the first iteration.
Let's take, for example, the following branch data. There are 10 unique branches, but not 10 unique zip codes. Some of the branches share the same zip code.
By using a SELECT DISTINCT SQL statement, the Tester can query for the seven unique zip codes that exist within the set of branches.
Thus, the Tester can use the QueryBeforeLoopV2Gen to accomplish the same goal during test data generation. In the example below, the QueryBeforeLoopV2Gen:
- The query parameter is defined with the SELECT DISTINCT SQL statement,
- The setLoop parameter is set to True,
- The list parameter just contains example data for the preview data within GenRocket's web view.
Thus, the query will return the seven distinct zip codes, and the Engine's loopCount will be set to 7 before the first iteration.