Library for mocking JDBC connections in benchmarks, with ability to dynamically switch between access to real DB and calls mocked using Mockrunner-JDBC.
- Use URL in format
jdbc:perfmock:myDatabaseURL
, e.g.jdbc:perfmock:h2:mem:testDB
- this creates a wrapped connection tojdbc:h2:mem:testDB
. - Make sure that PerfMock is classloaded by calling
PerfMockDriver.getInstance();
- If you're using
javax.sql.DataSource
to access the connection, use classorg.perfmock.PerfMockDataSource
and addrealClass=my.db.DataSourceImplementation
to properties, e.g.realClass=org.h2.jdbcx.JdbcDataSource
- Once you want to start mocking the calls to DB, call
PerfMockDriver.getInstance().setMocking(true);
For concrete example please see src/test/java/org/perfmock/Example.java