Fake datasource to help test XA rare cases?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Fake datasource to help test XA rare cases?

danielmeyer
I'm interested in a JDBC XA datasource that simulates various unusual behaviors that a resource participating in an XA transaction can exhibit.

I'm thinking of something I could point BTM to, and have the datasource be runtime-configurable to throw an exception at a certain point (while preparing for commit, for instance) -- this would allow us to test our application logic to make sure we're handling such cases appropriately.

I wonder how hard it would be to write... It looks like it might involve writing as few as three classes:
- a datasource class that provides a getXAConnection() method returning a reference to a javax.sql.XAConnection
- a class implementing javax.sql.XAConnection (which has a getXAResource() method returning an XAResource)
- a class implementing javax.transaction.xa.XAResource (prepare, rollback, commit, start, end...)  

Anyone know of something like this already out there?  Or alternatively, am I on the right track for what it would take to do this?  How do others test those rare-but-it's-part-of-why-we're-using-XA things like something going wrong between prepare and commit?

-Daniel-
Reply | Threaded
Open this post in threaded view
|

Re: Fake datasource to help test XA rare cases?

Bryan Jacobs
The question that you are asking is pretty complex.

Each Resoure Manager (Oracle, Derby...) has provided an XADataSource that will support XA Transactions.  If you implement your own for testing purposes you won't actually be testing how Oracle for example will work when involved in an XA Transaction. You would only be testing if your "datasource" is correct, and will work with Bitronix.

Couple of questions for you:

What databases and/or JMS Providers will you be using?

Are you planning on creating unit tests that will be checked into your respository that will exercise these use cases of: prepare, commit, start, end, recover, forget?  (If you are doing this you are now writing unit tests that should exist in Bitronix, the databases that you are using, and the JMS provider.)

OR, is this just a way to help you evaluate how well different databases, and JMS Providers will support XA Transactions?  If that is the case see the links below:

http://docs.codehaus.org/display/BTM/JdbcXaSupportEvaluation
http://docs.codehaus.org/display/BTM/JmsXaSupportEvaluation

If you still need to write some code to test how they are working I have some ideas.  I just wanted to understand what you are doing so I don't end up on a tangent.
Reply | Threaded
Open this post in threaded view
|

Re: Fake datasource to help test XA rare cases?

danielmeyer
I'm trying to answer the question, "Would our application do what we expect if...X?" Where X is some rare but possible scenario that can happen during an XA transaction.  I don't think this is the same as writing unit tests that should exist in Bitronix, the databases that I am using, and the JMS provider, because I'm not really evaluating what the database, etc. does in these scenarios -- I want to see how our application deals with these situations.

Perhaps a better way of approaching this is just to mock out the calls to JDBC and have the mock object throw the exception that could come back from the XAResource.  I think I could be satisfied with that -- this approach would answer my "Would our application do what we expect if...X?" question.  I was just interested as to whether anyone tests their application by simulating these rare conditions.

Do you have application code that does something different when one of these cases happens (say, a HeuristicException)?  Is there a different way you exercise that code?

Or maybe there's generally nothing special an application does in these cases, so no special logic to test and so it's just a matter of does the database support XA properly... ?

-Daniel-
Reply | Threaded
Open this post in threaded view
|

Re: Fake datasource to help test XA rare cases?

Ludovic Orban
Administrator
Daniel,

Mocking an XAResource is not an easy task. If you really want to do that, you'll have to mock at least these JDBC interfaces:

 - XADataSource
 - XAConnection
 - XAResource
 - Connection
 - Statement

and these ones for JMS:

 - XAConnectionFactory
 - XAConnection
 - XASession
 - XAResource
 - MessageConsumer
 - MessageProducer

BTM's XA connection pool intercepts method calls on methods of all these interfaces to perform enlistment / delistment which varies from a vendor's implementation to another. That's only valid for BTM, other transaction managers most probably behave differently and would certainly require more or less mocking. Ideally, you would have to recreate a fully working in-memory XA JDBC driver / JMS server.


If you're interested in such project, I'd be happy to give you directions and help you out (as that would greatly benefit BTM's test suite) but don't expect it to be a small task.


Generally speaking, I've never seen such in-depth testing being performed in any project. Most of the time this is covered by acceptance tests using the real database / JMS server.

Finally, when a heuristic exception is thrown by the transaction manager there is most certainly nothing at all your application could automatically do to repair the problem. The only sane thing to do when this happens is clearly log the error and make sure sysadmins / DBAs are alerted in some way as they'll have to manually fix the data corruption ASAP.

Ludovic
Reply | Threaded
Open this post in threaded view
|

Re: Fake datasource to help test XA rare cases?

Bryan Jacobs
If you're interested in such project, I'd be happy to give you directions and help you out (as that would greatly benefit BTM's test suite) but don't expect it to be a small task.
I would be happy to help out with this project as well.

I've recently finished enhancing a JMS Provider to support XA Transactions.  

I still have  a lot to learn, but would find such a project very worth while.
Reply | Threaded
Open this post in threaded view
|

Re: Fake datasource to help test XA rare cases?

danielmeyer

Bryan Jacobs wrote
If you're interested in such project, I'd be happy to give you directions and help you out (as that would greatly benefit BTM's test suite) but don't expect it to be a small task.
I would be happy to help out with this project as well.
Thanks, Bryan and Ludovic,
Honestly I probably won't be able to put in many cycles to develop this myself (was hoping something was just out there ready to use :) -- I should be able to help out testing it though.  And I am interested in being able to control what behavior the fake datasource or connection would have, so I could help with requirements brainstorming on that...

-Daniel-