Hi all,
Can anybody recommend a way to replicate database deadlocks programmatically, which forces the database to kill one of the transactions?
The specific situation I'd like to replicate in an integration test is as follows:
Step 1) Transaction A starts
Step 2) Transaction A performs an update to 'MyTable'
Step 3) Transaction B starts
Step 4) Transaction B attempts to read from 'MyTable' but cannot as Transaction A has not completed, so the database (Sybase in this case) kills transaction B and "com.sybase.jdbc2.jdbc.SybSQLException: Your server command (family id #0, process id #388) encountered a deadlock situation. Please re-run your command. " is thrown
At the moment I get to Step 4 and then the read hangs. I want Step 4 to throw the exception immediately.
The test would then test the deadlock is handled correctly, where DeadlockLoserDataAccessException is used to signify the deadlock.
Ideas appreciated,
Eliot


Reply With Quote