NAME
DbdaTestDriver – records and replays JDBC sessions for DataBase Driven Applications
DESCRIPTION
The DbdaTestDriver is a JDBC proxy driver that wraps the JDBC driver of an application. It operates in two modes:
RECORD - the driver stores the entire data retrieved from the JDBC layer into a file.
REPLAY - the driver reads the data previously recorded and replays it to the application, as if the underlying database was responding the requests.
The driver is very helpful during development and test of applications that depend on huge and/or slow databases (data warehouses, operational datastores, ...), or on databases where the content changes over time. Using the DbdaTestDriver the developer is no longer dependent on the current content, the speed, or even the availability of the database.
SCENARIOS
Application development – replaying data recorded with the DbdaTestDriver during application development is fast, usually faster than requesting data from the database via JDBC. So the develop–test–develop cycle can be run through faster.
Regression testing – running large testsuites against a database driven application is not only time consuming, it also requires the relevant database to be up and running. Additionally, changing database content could cause testcases to fail and require a lengthy analysis to track down the cause of the (non-)failure.
USAGE
Download and place the DbdaTestDriver.jar in a location where the application can find it.
Provide a properties file with the JDBC connection information of the original database driver, called <you-name-it>.properties. This could look like follows (Oracle example):
connectString=jdbc:oracle:thin:@oracle:1521:oracle
user=<username>
password=<password>
driverClassName=oracle.jdbc.driver.OracleDriver
recordFilename=<filename.dat>
The driver will record to / replay from the file configured unter the property „recordFilename“.
You can choose which backend to use by specifying the optional property:
backendHandler=<full qualified DataBackend class name>
See the DataBackend source on how to implement your own backend and the three example backends already provided.
Next, configure your application to use the class „conpar.dbda.test.driver.DbdaTestDriver“ as the JDBC driver and the URL
„jdbc:conpar:dbda:record:<younameit>.properties“ to save data in record mode
„jdbc:conpar:dbda:replay:<younameit>.properties“ to provide data in replay mode
If you are running in replay mode and the record file does not yet exist, the driver will switch to record mode by default. You can turn this behaviour off by the optional property
autRecord=false
EXAMPLE
A trivial case is shown below. It shows how to manually register the JDBC driver and get a connection for recording the data transferred between the application and the database.
DriverManager.registerDriver(new
DbdaTestDriver());
Connection con =
DriverManager.getConnection("jdbc:conpar:dbda:record:<younameit>.properties");
There is also a simple showcase main class in the DbdaTestDriver jar to support when doing the first steps with DbdaTestDriver. Simply call „java -cp <log4j jar, database driver jar, dbdatestdriver jar> conpar.dbda.test.driver.Showcase and let the usage guide help you.
The testcases in the code will also be helpful to see how the driver can be used in other setups, e.g. JPA/Hibernate.
ENVIRONMENT
The
DbdaTestDriver itself depends on the Log4J library
(http://logging.apache.org/).
Current
versions require a JVM version 8
or greater.
Versions
up to R3_2 require a JVM version 6 or greater.
Versions
up to R1_3 require a JVM version 1.4 or greater.
LIMITATIONS
It has been developed and tested extensively against Oracle 9i / 10g / 11g, using the DriverManager directly or using a ConnectionPool provided by Apache DBCP (http://commons.apache.org/dbcp/). Limited tests were done using MySQL 5. There is no guarantee that the driver will work well or even at all in a similar or different environment.
During tests the driver was recording several hundered megabytes of JDBC data, producing a storage file of about 15 megabyte. However, there is an internal lookup of values stored already used by the driver. So storing more than MAX_INTEGER different values will cause the driver to fail.
By nature of the recording process, the driver is not multi-thread safe. Trying to record the database session of a multi-user web application will fail. Using several connections serially should work.
AUTHOR
Matthias Baur
LICENSE
This project is licenced under the EUPL v1.1 (European Public License), see http://ec.europa.eu/idabc/eupl/ for details.
HOW TO GET
The
compiled library can be downloaded from
(http://sourceforge.net/projects/dbdatestdriver/).
Sourcecode is available from the git.