Previous Topic: JDBCNext Topic: TCP


Virtualize JDBC

This section provides more detail about how to prepare to use the VSE framework to virtualize JDBC-based database traffic. Information about JDBC configuration is also available in Install the Database Simulator. This section documents the various ways that driver-based JDBC virtualization can be combined, and the configuration options supported. This section does not include any detail about how to implement the configuration on any specific app container.

Note: JDBC virtualization only works with Java 1.6; it does not work with Java 1.5.

 

System-Level Properties

You can specify the following properties in one of the following ways:

If a property exists in both locations, the system property overrides the configuration file.

lisa.jdbc.sim.require.remote

Determines whether the driver waits on a connection to VSE before processing commands.

Default: false

lisa.jdbc.hijack.drivermanager

Determines whether the driver attempts to take over all the database connections from this application.

Default: false

lisa.jdbc.sim.port

Defines the default listen port.

Default: 2999

lisa.log.level

Specifies the default log level.

Values:

Default: WARN

lisa.log.target

Specifies where the logs are written.

Values:

Default: stderr

 

VSE Driver (stand-alone)

The system under test can use the VSE driver directly or the VSE driver can be wrapped in a data source such as the Apache BasicDataSource. In such cases, the configuration (other than the username and password) is passed through the URL. The driver properties include:

URL

Specifies the actual URL that is passed to the underlying driver. This URL must be the last element passed.

State

Specifies the initial state for the driver.

Values:

JdbcSimPort

Designates the port on which to listen for connections from VSE. This value overrides the system-level property.

Driver

Designates the class name of the real driver to use.

User
Password

Specify the classname of the driver as com.itko.lisa.vse.jdbc.driver.Driver.

The following example shows the format of the URL. Everything is optional except the driver and the URL.

jdbc:lisasim:driver=<real driver class>;state=<initial state>;jdbcSimPort=<starting port>;url=<real url>

Note: The URL element must come last. Everything following "url=" is passed unchanged to the underlying driver. DevTest supports passing extra information to the underlying driver by embedding it in the real URL.

For example, the following URL is appropriate for a Derby connection:

jdbc:lisasim:driver=org.apache.derby.jdbc.ClientDriver;state=watch;jdbcSimPort=4000;url=jdbc:derby://localhost:1527/sample;create=true

This URL instructs the VSE driver to:

 

VSE Datasource Wrapping a Driver

VSE Datasource Wrapping a Driver could be a more typical configuration for app containers than using a VSE driver directly. VSE provides a data source that wraps a real driver. Most application containers provide a mechanism for directly specifying properties for the data source.

Specify the classname of the driver as com.itko.lisa.vse.jdbc.driver.VSEDataSource.

 

Datasource Properties

Driver

Specifies the name of the real driver to use (the normal configuration).

URL

Specifies the real URL to connect with (cannot start with jdbc:lisasim).

User
Password
JdbcSimPort

Specifies the port on which to listen for connections from VSE. This value overrides the system-level property.

CustomProperties

Defines a semicolon-separated list of name=value pairs. These properties are parsed and delegated to the wrapped data source, if any. If the first character is not alphanumeric, it is used as the delimiter instead of a semicolon.

 

VSE Data source Wrapping a Datasource

Wrapping a data source is an unusual configuration, when an application container does not permit a driver to be instantiated directly with Class.forName(). To use it, instead of specifying driver=<classname of real driver> (for example, oracle.jdbc.OracleDriver), specify datasource=<classname of real datasource> (for example, oracle.jdbc.pool.OracleDataSource).

Specify the class name for the driver as com.itko.lisa.vse.jdbc.driver.VSEDataSource.

 

Supporting Multiple Endpoints

If one application has multiple JDBC connections you want to virtualize (or if one appserver has multiple applications with different JDBC connections you want to virtualize), specify a different JdbcSimPort for each connection. You can specify this endpoint either as a property to the VSE Data source, or as a parameter on the URL for the driver.

Example:

Assume an application uses two JDBC connections, and you want to virtualize both of them. Also assume the application uses drivers directly.

Specify com.itko.lisa.vse.jdbc.driver.Driver for each connection, with the appropriate underlying parameters such as driver and URL for each. For the first connection, you could specify jdbcSimPort=3000 and for the second you could use jdbcSimPort=3001. Your configuration could look like:

connection1.url=jdbc:lisasim:driver=org.apache.derby.jdbc.ClientDriver;jdbcSimPort=3000;url=jdbc:derby://localhost:1527/sample;create=true
connection2.url=jdbc:lisasim:driver=org.apache.derby.jdbc.ClientDriver;jdbcSimPort=3001;url=jdbc:derby://localhost:1527/sample2;create=true

Although you must still record separately, you can deploy both services simultaneously, and can start and stop them independently.