Performance Testing Oracle via JDBC with LoadRunner – Basics

Pre-requisites

1.JDK 1.6 or above should be installed in your machine to run the script.
2.Required OJDBC.jar (5 or 6 & 14 )  Drivers are required.

/*
 * LoadRunner Java script.
 * Description: Oracle Database Testing via JDBC
 */

import lrapi.lr;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.*;

//char *request;// variable decleration
//
//    char *openReq;//variable decleration

public class Actions
{
    // Create global connection variable
    private Connection connection;
    public int SequnceId ;
    // VUser Init
    public int init() throws ClassNotFoundException, SQLException {
        // Initialize DB connection
        //connection = null;
        try {
        // Load Oracle JDBC Driver
            Class.forName("oracle.jdbc.driver.OracleDriver");
        } catch (Exception ex) {
        // If driver load is unsuccessful
        lr.log_message("Database Driver not found");
        lr.abort();
    }
    try {
        // Specify the JDBC Connection String (jdbc:oracle:thin:@HOST:PORT:SID)

      
        String url="jdbc:oracle:thin:@host:SID";
          
       
        // Connect to URL using USERNAME and PASSWORD
        connection = DriverManager.getConnection(url,"",lr.decrypt("Password"));
        lr.log_message("JDBC Connection Successful");
        } catch (SQLException e) {
        // If Connection Failed
        lr.log_message("Database Connection Failed, Please check your connection string");
        lr.abort();
    }
        return 0;
    } //end of init

    public int action() throws ClassNotFoundException, SQLException {

    // Database Query Example 1
    lr.start_transaction("Database_Query_1");
  
//    int SeqId=("Insert into STAGPHUB1.STG_ENROLLMENT_CNTRL (BAN,MSISDN,PROCESSED_FLG,ENROLL_TYPE,COMMIT_TIMESTAMP,PROGRAM,ENROLL_DATE,DEENROLL,DE_ENROLL_REASON,ROW_ID,EQUIPMENT_ID,SOC_PROVISION_FLG,REDEEMED_FLAG,REDEMPTION_DATE,OVERRIDE_FLAG,OVERRIDE_DATE,OVERRIDE_REF_NO,MANUAL_PUBLISH_FLG,RETRY_COUNTER,LAST_UPD_SOURCE,LAST_UPD) 

  
    //int SeqId = database_query("update wholesale.wholesale_transaction set results='SUCCESS', status='COMPLETE' where status ='BILLING'and CREATED_DATE > sysdate-1");
//    
//    int SeqId1 = database_query("update wholesale.wholesale_transaction set  status='COMPLETE' where status ='NEW'and CREATED_DATE > sysdate-1");
//    
//    int SeqID2 = database_query("update wholesale.wholesale_transaction set  status='COMPLETE' where status ='SWITCH-COMPLETE'and CREATED_DATE > sysdate-1");
  
  
    int seqID = database_query("Enter your Query ");
  
    //seqId.execute();
  
    //int seqid1= database_query("commit");
  
    lr.end_transaction("Database_Query_1", lr.AUTO);
      
    return 0;
    }

    public int end() throws Throwable {
    connection = null;
        return 0;
    }
    public int database_query(String SQL_QUERY) {
       Statement stmt = null;
       ResultSet rset = null;

       try {
       connection.setAutoCommit(true);
       stmt = connection.createStatement();
       int rsetstr = stmt.executeUpdate(SQL_QUERY);
       lr.set_transaction_status(lr.PASS);
       // while (rset.next()) {                // Print the results of the query
       lr.log_message(""+rsetstr);          // Note: This should be used for debugging only,
       // }                            // as it slows down execution time
       lr.log_message("SQL Query Executed Successfully");
      // rset.close();
      stmt.executeQuery("Commit");
       stmt.close();
     
       //return SequnceId;
    } catch (SQLException e) {
        // SQL Query has failed
        lr.log_message("Caught Exception: " + e.getMessage());
        lr.set_transaction_status(lr.FAIL);
        return 1;
    }
    return 0;
    }
}

HTML vs. URL based scripting Load Runner

  • HTML based scripting
  • URL based scripting

HTML:

  • It records/captures a user scenario similar to how a user interacts with an application, it can be called as browser context recording.
  • It will not send any explicit requests to static resources (.css, .js, .png...etc) or dependent requests, but downloads them automatically along with main request, unlike the URL based scripting
Script Type 1: A script describing user actions (eg: web_link, web_submit_form)

  • web_link, web_submit_form..etc are context sensitive functions and they depend on previous operations.
  • It works at HTML level(i.e DOM elements level)
     Eg:





As shown above web_image function("Search Flight Button") works only when the DOM elements (i.e <IMG> and its attributes) are loaded upon successful completion of previous operations.

Script Type 2: A script containing explicit URLs  only (eg: web_url, web_submit_data)
  • web_url, web_submit_data..etc are context less functions and they are independent of previous operations.
  • It works at HTTP level (i.e Request - Response based) 
     Eg: 

Observe that "search flight button" is recorded as web_url function, it sends an explicit request(i.e using URL attribute) when user clicks 'Flight' button, so it is independent of previous operations.

URL:


  • It will send explicit requests to static resources (.css, .js, .png...etc) and dependent requests along with main request.(refer below screenshot)
  • Its a context-less recording unlike the HTML based scripting.
  • It works at HTTP level (i.e Request - Response based).
Script Type 1: Create concurrent groups for resources after their HTML page

  • Records URLs and their resources in concurrent groups, a concurrent group represents links and resources that are loaded on a page at the same time.
      Eg: 



Observe that for a 'Search Flight Button' action, it records dependent and static resources requests       explicitly(web_concurrent requests) along with main request. (i.e all the web_concurrent group requests above belongs to "Search Flight Button" action).

Script Type 2: Use Web Custom Requests only


  • It records all requests as web_custom requests
  • The web_custom_request function is an action function that allows you to create a custom HTTP request using any method or body.
     Eg: 





Note: What kind of recording options to be selected depends on kind of application and how you want to emulate the scenario, but generally "HTML" with "Script Type 2: A script containing explicit URLs  only (eg: web_url, web_submit_data)" is preferred. 

Loadrunner C Functions


Error handling

1.Text verification points
2.Image verification Points

Text Verification Error handling:

web_reg_find("Text=XXXX","SaveCount=XXX",LAST)

Text=This text has to be captured from the response page which is static String

SaveCount = Here Save count will be integer value and it will count text.

if(strcmp(lr_eval_string("{XXX}","0")==0)
{

lr_output_message("text check is filed")

}

else
{
lr_output_message("Text check is passed')

}





An introduction to Workload Modelling for Cloud Applications


Add Script Dialog Box

This dialog box enables you to add Vuser scripts to a scenario.
To access
Use one of the following:
  • All scenarios: Design tab > Right-click in Scenario Scripts pane > Add Script
  • Goal-oriented scenario: Design tab > Scenario Scripts pane > Add Script
  • Manual scenario (percentage mode): Design tab > Add Group 
Important information
While a scenario is running, you can add scripts to the scenario and enable them. However, if you add a script after all the Vusers in the scenario have started running, the added script will not run in the scenario.
Relevant tasks
See Also
User interface elements are described below:
UI Element
Description
Enables you to add Vuser scripts to the list of scripts.
Opens VuGen for recording a new Vuser script. For more information, see Record a Vuser Script.
Use existing LoadRunner script
Lists the available scripts that have been added to the scenario. When you select a script, its name and path are displayed above the list.
To display the scripts with their full paths, right-click the list area and select Show Paths.
Use a Noise Generator script with the following URL
The URL to which you want to apply noise testing. You can provide a server name, IP address, or a full URL. After a URL is used once, it appears in a dropdown list.
 
LoadRunner automatically generates a script name using the following format:Noise_<domain>_<index>, e.g. Noise_HP_1.
Note: There is no built-in validation, so you must verify that the URL you provide is operational.

Add Group Dialog Box

This dialog box enables you to add Vuser groups to participate in a scenario.
To access
Manual scenario > Design tab > Scenario Groups/Scripts pane > Add Group
Important information
While a scenario is running, you can add Vuser groups to the scenario and enable them. However, if you add a Vuser group after all the Vusers in the scenario have started running, the new group will not run in the scenario.
Relevant tasks
See also
User interface elements are described below:
UI Element
Description
Enables you to add Vuser or JMeter scripts to the list of scripts.
Opens VuGen where you can record a Vuser script. For more information on recording Vuser scripts, see Record a Vuser Script.
Group Name
The name of the Vuser group.
When you select a script the Vuser group is automatically given the same name as the script. You can modify the group name.
Note: The name is limited to a maximum of 55 characters.
Vuser Quantity
The number of Vusers to add to the group. The default value is 1.
Load Generator Name
The load generator assigned to the Vuser group.
To add a load generator to this list, select Add from the list. For user interface details, see Add New Load Generator/Load Generator Information Dialog Box.
Use existing LoadRunner Script
Lists the available scripts that have been added to the scenario. When you select a script, its name and path are displayed above the list.
To display the scripts with their full paths, right-click the list area and select Show Paths.
Note: If a script uses Unique file parameterization, running more than one Vuser group with that script in the same scenario may cause unexpected scenario results. For more information about Unique file parameterization, see Data Assignment Methods for File-Type Parameters.
Use a Noise Generator script with the following URL
The URL to which you want to apply noise testing. You can provide a server name, IP address, or a full URL. After a URL is used once, it appears in a dropdown list.
 
LoadRunner automatically generates a script name using the following format:Noise_<domain>_<index>, e.g. Noise_HP_1.
Note: There is no built-in validation, so you must verify that the URL you provide is operational.

Vuser Statuses

The following table describes the possible statuses of Vusers before, during, and after a scenario run.
Status
Description
Down
The Vuser is down.
Pending
The Vuser is ready to be initialized and is waiting for an 
available load generator, or is transferring files to the load generator. The Vuser will run when the conditions set in its scheduling attributes are met.
Initializing
The Vuser is being initialized on the remote machine.
Ready
The Vuser already performed the init section of the script and is ready to run.
Running
The Vuser is running. The Vuser script is being executed on a load generator.
Rendezvous
The Vuser has arrived at the rendezvous point and is waiting to be released by LoadRunner.
Done.Passed
The Vuser has finished running. The script passed.
Done.Failed
The Vuser has finished running. The script failed.
Error
A problem occurred with the Vuser. Check the Status field on the Vuser dialog box or the output window for a complete explanation of the error.
Gradual Exiting
The Vuser is completing the iteration or action it is running (as defined in Tools > Options > Runtime Settings) before exiting.
Exiting
The Vuser has finished running or has been stopped, and is now exiting.
Stopped
The Vuser stopped when the Stop command was invoked.

Relative Paths for Scripts

You can specify a relative location for a script in your scenario. The location can be relative to the current scenario folder, or relative to the LoadRunner installation folder.
When you run a scenario, the script is automatically copied from this relative location to a temporary folder on the load generator running the script. This enables the load generator to access the script locally instead of over a network.
To specify a path relative to the current scenario director, type either of the following notations at the start of the script path:
Notation
Description
.\
Indicates that the path is relative to the location of the scenario folder
..\
Indicates that the path is relative to the location of the parent folder of the scenario folder
For example, if the current scenario is located at F:\scenarios, to specify that the script, user1, is located in F:\scenarios\scripts, you could type:
.\scripts\user1
To specify a path relative to the LoadRunner installation folder, type a percent sign (%) at the beginning of the script path. For example, if the LoadRunner installation folder is located at F:\LoadRunner, to specify that the script, user1, is located in F:\LoadRunner\scripts, you could type:
%\scripts\user1

How to View/Modify Scripts in the Scenario

This section describes how to view and modify scripts used in your load test scenario.
You view/modify the details of the scripts in the Group Information dialog box (see Group Information Dialog Box) or in the Script Information dialog box (see Script Information Dialog Box).
In this topic:

View script details

You can view the details of a script by right-clicking the script in the Scenario Groups/Scripts pane and selecting Details.
In the Group/Script Information dialog box that opens, you can:
  • View details about the script, including:
  • Note: If you do not see some of the details listed below, click More.
  • Script path
  • Command line options
  • Rendezvous points included in the script
  • Vusers associated with the script
  • Files associated with the script
  • Open the script in VuGen by clicking the View Script button
  • View the script's runtime settings by clicking the Runtime Settings button

Modify a script's runtime settings

  • To view or modify a script's runtime settings, in the Scenario Groups/Scripts pane right-click the script and select Runtime Settings.
  • To view or modify runtime settings of a script associated with a particular Vuser, in the Vusers dialog box (Scenario Groups pane > Vusers ) right-click the Vuser and select Runtime Settings.
  • Modifying the runtime settings for one Vuser in a group modifies the runtime settings for all the Vusers in that group that are using the same script.

Modify multiple scripts' runtime settings

This section describes how to modify runtime settings of multiple scripts or of a Vuser group that includes multiple scripts.
  1. In the Scenario Groups/Scripts pane select multiple scripts or the Vuser group that includes multiple scripts.
  2. Right-click the selection and select Runtime Settings.
  3. In the Multiple runtime settings Mode dialog box that opens:
    • To modify runtime settings for all of the scripts simultaneously, click Shared RTS.
    • To modify runtime settings per script, click Individual RTS.
      For user interface details, see Multiple Runtime Settings Mode Dialog Box.
    • For details about specific runtime settings, see Runtime Settings Overview.
    • When you modify the runtime settings from the Controller, LoadRunner runs the script using the modified settings.

View/Edit a script in VuGen

To view/edit a script included in your scenario, right-click the script and select View Script. The script opens in VuGen. For more information on editing scripts, see the Debugging Overview.

Specify command line options

You can specify command line options to use when running a script.
  1. In the Scenario Groups/Scripts pane, right-click the script and select Details.
  2. In the Group/Script Information dialog box that opens, if Command line is not displayed near the bottom, click More.
  3. Enter a command in the command line, for example: -x value -y value.
    For information about passing command line argument values to a script, see Enhance a Java Script.

View rendezvous points included in the script

  1. In the Scenario Groups/Scripts pane, right-click the script and select Details.
  2. In the Group/Script Information dialog box, if the Rendezvous tab is not displayed near the bottom, click More.
    If there are rendezvous points included in the script, they are displayed in the Rendezvous tab. For details about rendezvous points, see Rendezvous Points Overview.
View Vusers associated with the script
  1. In the Scenario Groups/Scripts pane, right-click the script and select Details.
  2. In the Group/Script Information dialog box, if the Vusers tab is not displayed near the bottom, click More.
    The Vusers tab displays the Vusers associated with the script.

View files associated with the script

  1. In the Scenario Groups/Scripts pane, right-click the script and select Details.
  2. In the Group/Script Information dialog box, if the Files tab is not displayed near the bottom, click More.
  3. By default, the Files tab lists all the files in the script's folder (only after your script has been added to the script list). These files include the configuration settings file, the init, run, and end portions of the script, the parameterization definitions file, and the .usr file. To add a file to the list, click Add.
    Example:  
    To run Visual C++ Vusers on a remote load generator, you must add the .dll of the Vuser to the list of files.
    You can delete the files that you add, but not the other files listed.