Daniel O.
Daniel O.

Reputation: 175

Resetting the DB after each test run

I have following problem:

I have a DB pre-filled with lot of test data. After each test run I would like to throw away changes made by the test procedure. I already tried to do this with an embedded H2 DB. I would just overwrite the DB files with the original ones and the problem would be solved. But another problem emerged: H2 doesn't support multi-threading without running as a server.

After that I looked at HSQLDB. If I understand it correctly, if it is used as normal file DB (not in-memory) it will still load the contents of the DB into the memory and persist the changed to disk after some time.

Is there any possibility to just read the file DB into memory, use it there and throw away any changes at the end? This would be perfect. A solution using rollbacks would be great too.

Thanks, Daniel

Upvotes: 0

Views: 789

Answers (2)

fredt
fredt

Reputation: 24372

HSQLDB has an option for this usage.

After creating the test database, perform SHUTDOWN. You will have a .properties and .script files. In the .properties file add this line:

files_readonly=true

Then use this database for the tests. No rollback or any special action will be necessary when the app exits.

Alternatively, append this to your test application's connection URL, ;files_readonly=true

See this Chapter of the Guide:

http://www.hsqldb.org/doc/2.0/guide/dbproperties-chapt.html#dpc_db_file_mem

For multi-threaded application testing, the database transaction model is usually MVCC, which you set in the original database.

Upvotes: 1

Thomas Mueller
Thomas Mueller

Reputation: 50127

For the H2 database:

Upvotes: 1

Related Questions