How to test efficiently the acidity of transactions (Java/Spring/EJB or others)
Just wonder. In some applications, the atomicity and consistency are really reallly important that i guess it should be tested...
开发者_JS百科As i'm a Java developer i'll talk about what i know. Using Spring or EJB3 transaction management with annotations.
When doing some refactoring in the business layer of an application, we sometimes have to rework the transation propagation amon other things, and it can easily introduce regressions.
I just wonder if there are easy ways to test the transaction management of our application. For exemple, imagine you work at PayPal. You want to be sure that the customer PayPal account is credited, AND the customer is charged on his bank account. An exception should not permit to credit the paypal account without charging anything to the client.
- Are there tools to test such things?
- Have you already done such a thing?
- Or how would you do?
I guess it could be done "home made" using a bit of AOP and designing the methods so that it will be easier to test...
It's possible to inject exceptions in tests with bytecode tools like Byteman: http://java.dzone.com/articles/fault-injection-unit-tests
Once you raise an exception you can check if the db state has been inconsistently updated or been rollbacked...
You have to set up compensating transactions to deal with 3rd parties like PayPal or banks. Your client will have to interrogate the response and deal with it.
There's nothing as easy as the XA driver for two-phase commit between multiple databases that I know of. You'd need something like JCA with a transaction manager to oversee them.
精彩评论