ATE: Support multiple providers per suite & transactions per @Test
paul.robinson Nov 23, 2012 8:53 AMPulling out into a separate discussion from: https://community.jboss.org/message/777483
Problem
Currently you can only have one transaction provider per test suite. This is because the particular provider is found on the classpath, and there can only be one. Also, each @Test method can only span a single Transaction. This has the following issues/implications:
- Test suites that use two or more types of transactions cannot be supported. For example, this would be a problem for the TXBridge tests that bridge a JTA transaction to a WS-AT transaction and visa-versa. Here some tests start a JTA transaction and others start a WSAT transaction.
- Test suites that need to invoke two units of work inside separate transactions can't be supported.
Solution
This was proposed by Aslak in the above discussion:
One option would be to allow multiple @Transactional(manager="") annotations on a Test method, or possible introduce a programmable TransactionManager API as well.
@ArquillianResource TransactionManager tm;
tm.begin("JTA", "manager");
tm.begin("WS-AT", "manager"); ..
Can you explain how having "multiple @Transactional(manager="") annotations on a Test method" helps? I don't think I understand this.
The programmable TM API could be an option to support multiple tests per method. I asume the @Test code would look something like this:
@ArquillianResource TransactionManager tm; @Test public void someTest() { tm.begin("JTA", "manager"); //do some work tm.commit(); //Assert something tm.begin("JTA", "manager"); //do some different work tm.commit("JTA", "manager"); //Assert something }
Positives:
- Can run many separate transactions in the test.
- Can decide at run-time how many.
- Can mix different providers in the same test.
- Could omit the provider and manager to use the defaults.
- Assertions can be done between and after transactions.
- A common API for different transaction types (JTA, WS-AT, etc)
Negatives
- Removes a lot of the benefits of using the ATE abstractions. What we are left with is a much thinner abstraction layer and and API that is very similar to UserTransaction and it's counterparts.