Search code examples
databaseoracle-databasejmeterconnection

Connecting Jmeter to an Oracle database with two hosts and service name


I am trying to connect Jmeter to a geo redundant database with two hosts and I am struggling with finding the right Database Url format.

This is how my connection string looks like:

jdbc:oracle:thin:@(DESCRIPTION=(ENABLE=BROKEN)(FAILOVER=on)(CONNECT_TIMEOUT=5sec)(TRANSPORT_CONNECT_TIMEOUT=3sec)(RETRY_COUNT=3)(LOAD_BALANCE=on)(ADDRESS_LIST=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=HostName)(PORT=port)))(ADDRESS_LIST=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=HostName2)(PORT=port)))(CONNECT_DATA=(SERVICE_NAME=ServiceName)))

Database Connection Configuration is as following:

JDBC Driver Class: oracle.jdbc.OracleDriver Username: username Password: password

For the Database URL I tried different formats and I keep getting the error:

Cannot load JDBC driver class 'oracle.jdbc.OracleDriver'

Note that the ojdbc.jar file is in the /lib folder as per the Jmeter documentation. Also, the ports are the same for both hosts.

Any suggestion is welcome. :)


Solution

  • I don't think you will be able to establish the connection to Oracle RAC using JMeter's JDBC Connection Configuration as it doesn't allow full flexibility therefore you will not be able to properly instantiate the PoolDataSourceFactory

    So I would recommend switching to JSR223 Test Elements and Groovy language where you will have the full freedom when it comes to setting up the connection, executing queries, accessing results, etc. The relevant code would be something like:

    def prop = new Properties()
    prop.put('oracle.jdbc.thinForceDNSLoadBalancing','true')
    PoolDataSource pds = PoolDataSourceFactory.getPoolDataSource()
    pds.setConnectionProperties(prop)
    pds.setConnectionFactoryClassName('oracle.jdbc.pool.OracleDataSource'); pds.setUser('johndoe')
    pds.setPassword('secret')
    String dbURL =
            'jdbc:oracle:thin:@(DESCRIPTION=(ENABLE=BROKEN)(FAILOVER=on)(CONNECT_TIMEOUT=5sec)' +
                    '(TRANSPORT_CONNECT_TIMEOUT=3sec)(RETRY_COUNT=3)(LOAD_BALANCE=on)(ADDRESS_LIST=(LOAD_BALANCE=on)' +
                    '(ADDRESS=(PROTOCOL=TCP)(HOST=HostName)(PORT=port)))(ADDRESS_LIST=(LOAD_BALANCE=on)' +
                    '(ADDRESS=(PROTOCOL=TCP)(HOST=HostName2)(PORT=port)))(CONNECT_DATA=(SERVICE_NAME=ServiceName)))'
    pds.setURL(dbURL)
    

    More information: Configuring Fast Connection Failover for JDBC Clients