Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JUnit Test a Database Failure?

I'm trying to create a test that simulates a system failure to ensure the integrity of a Oracle Berkeley DB XML database. Data loss is currently being experienced during an insert operation so I'd like to setup a test that starts inserting an arbitrary number of documents and sack the process along the way (akin to someone yanking the power cord). After the process dies I want to spawn a new process and open the database to ensure it opens properly.

The unit test is one of many in a maven build and this test has to run in linux and windows XP environments. My current thought process is to hammer out a script for both operating systems since I can use the script to kill the process and start a new one in its place. Do I have any other options? Can I create a separate process space / VM using JUnit?

like image 500
toddk Avatar asked Jan 22 '10 18:01

toddk


1 Answers

I wouldn't consider this kind of test a unit test but nevertheless you may be able to do something like this.

  1. Use the ProcessBuilder class to construct and start the process, store the returned Process object.
  2. Start inserting records.
  3. At some point destroy() the process.

Please bear in mind previous comments on the non-deterministic nature of this test.

I have come across the SQLite team also doing a simulated failure strategy as part of their automated test suite.

like image 129
BenM Avatar answered Oct 06 '22 00:10

BenM